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