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 */ 016package org.forgerock.opendj.config; 017 018import java.util.Collection; 019import java.util.Collections; 020 021import org.forgerock.opendj.config.client.ClientConstraintHandler; 022import org.forgerock.opendj.config.server.ServerConstraintHandler; 023 024/** 025 * An interface for enforcing constraints and dependencies between managed 026 * objects and their properties. Constraints express relationships between 027 * managed objects and their properties, for example: 028 * <ul> 029 * <li>referential integrity: where one managed object references another a 030 * constraint can enforce referential integrity. The constraint can prevent 031 * creation of references to non-existent managed objects, and also prevent 032 * deletion of referenced managed objects 033 * <li>property dependencies: for example, when a boolean property is 034 * <code>true</code>, one or more additional properties must be specified. This 035 * is useful for features like SSL, which when enabled, requires that various 036 * SSL related configuration options are specified 037 * <li>property constraints: for example, when an upper limit property must not 038 * have a value which is less than the lower limit property. 039 * </ul> 040 * On the client-side constraints are enforced immediately before a write 041 * operation is performed. That is to say, immediately before a new managed 042 * object is created, changes to a managed object are applied, or an existing 043 * managed object is deleted. 044 */ 045public abstract class Constraint { 046 047 /** 048 * Creates a new constraint. 049 */ 050 protected Constraint() { 051 // No implementation required. 052 } 053 054 /** 055 * Gets the client-side constraint handlers which will be used to enforce 056 * this constraint in client applications. The default implementation is to 057 * return an empty set of client constraint handlers. 058 * 059 * @return Returns the client-side constraint handlers which will be used to 060 * enforce this constraint in client applications. The returned 061 * collection must not be <code>null</code> but maybe empty 062 * (indicating that the constraint can only be enforced on the 063 * server-side). 064 */ 065 public Collection<ClientConstraintHandler> getClientConstraintHandlers() { 066 return Collections.emptySet(); 067 } 068 069 /** 070 * Gets the server-side constraint handlers which will be used to enforce 071 * this constraint within the server. The default implementation is to 072 * return an empty set of server constraint handlers. 073 * 074 * @return Returns the server-side constraint handlers which will be used to 075 * enforce this constraint within the server. The returned 076 * collection must not be <code>null</code> and must not be empty, 077 * since constraints must always be enforced on the server. 078 */ 079 public Collection<ServerConstraintHandler> getServerConstraintHandlers() { 080 return Collections.emptySet(); 081 } 082 083 /** 084 * Initializes this constraint. The default implementation is to do nothing. 085 * 086 * @throws Exception 087 * If this constraint could not be initialized. 088 */ 089 protected void initialize() throws Exception { 090 // Default implementation is to do nothing. 091 } 092 093}