001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2016 ForgeRock AS. 016 */ 017package org.forgerock.opendj.config; 018 019import java.util.Collection; 020import java.util.Collections; 021 022import org.forgerock.opendj.config.client.ClientConstraintHandler; 023import org.forgerock.opendj.config.server.ServerConstraintHandler; 024 025/** 026 * An interface for enforcing constraints and dependencies between managed 027 * objects and their properties. Constraints express relationships between 028 * managed objects and their properties, for example: 029 * <ul> 030 * <li>referential integrity: where one managed object references another a 031 * constraint can enforce referential integrity. The constraint can prevent 032 * creation of references to non-existent managed objects, and also prevent 033 * deletion of referenced managed objects 034 * <li>property dependencies: for example, when a boolean property is 035 * <code>true</code>, one or more additional properties must be specified. This 036 * is useful for features like SSL, which when enabled, requires that various 037 * SSL related configuration options are specified 038 * <li>property constraints: for example, when an upper limit property must not 039 * have a value which is less than the lower limit property. 040 * </ul> 041 * On the client-side constraints are enforced immediately before a write 042 * operation is performed. That is to say, immediately before a new managed 043 * object is created, changes to a managed object are applied, or an existing 044 * managed object is deleted. 045 */ 046public abstract class Constraint { 047 048 /** Creates a new constraint. */ 049 protected Constraint() { 050 // No implementation required. 051 } 052 053 /** 054 * Gets the client-side constraint handlers which will be used to enforce 055 * this constraint in client applications. The default implementation is to 056 * return an empty set of client constraint handlers. 057 * 058 * @return Returns the client-side constraint handlers which will be used to 059 * enforce this constraint in client applications. The returned 060 * collection must not be <code>null</code> but maybe empty 061 * (indicating that the constraint can only be enforced on the 062 * server-side). 063 */ 064 public Collection<ClientConstraintHandler> getClientConstraintHandlers() { 065 return Collections.emptySet(); 066 } 067 068 /** 069 * Gets the server-side constraint handlers which will be used to enforce 070 * this constraint within the server. The default implementation is to 071 * return an empty set of server constraint handlers. 072 * 073 * @return Returns the server-side constraint handlers which will be used to 074 * enforce this constraint within the server. The returned 075 * collection must not be <code>null</code> and must not be empty, 076 * since constraints must always be enforced on the server. 077 */ 078 public Collection<ServerConstraintHandler> getServerConstraintHandlers() { 079 return Collections.emptySet(); 080 } 081 082 /** 083 * Initializes this constraint. The default implementation is to do nothing. 084 * 085 * @throws Exception 086 * If this constraint could not be initialized. 087 */ 088 protected void initialize() throws Exception { 089 // Default implementation is to do nothing. 090 } 091 092}