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 2014 ForgeRock AS.
016 */
017package org.forgerock.opendj.config.client;
018
019import java.util.Collection;
020
021import org.forgerock.i18n.LocalizableMessage;
022import org.forgerock.opendj.config.ManagedObjectPath;
023import org.forgerock.opendj.ldap.LdapException;
024
025/**
026 * An interface for performing client-side constraint validation.
027 * <p>
028 * Constraints are evaluated immediately before the client performs a write
029 * operation. If one or more constraints fails, the write operation is refused
030 * and fails with an {@link OperationRejectedException}.
031 * <p>
032 * A client constraint handler must override at least one of the provided
033 * methods.
034 *
035 * @see org.forgerock.opendj.config.Constraint
036 */
037public abstract class ClientConstraintHandler {
038
039    /**
040     * Creates a new client constraint handler.
041     */
042    protected ClientConstraintHandler() {
043        // No implementation required.
044    }
045
046    /**
047     * Determines whether or not the newly created managed object which is about
048     * to be added to the server configuration satisfies this constraint.
049     * <p>
050     * If the constraint is not satisfied, the implementation must return
051     * <code>false</code> and add a message describing why the constraint was
052     * not satisfied.
053     * <p>
054     * The default implementation is to return <code>true</code>.
055     *
056     * @param context
057     *            The management context.
058     * @param managedObject
059     *            The new managed object.
060     * @param unacceptableReasons
061     *            A list of messages to which error messages should be added.
062     * @return Returns <code>true</code> if this constraint is satisfied, or
063     *         <code>false</code> if it is not.
064     * @throws LdapException
065     *             If an error occurs.
066     */
067    public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject,
068        Collection<LocalizableMessage> unacceptableReasons) throws LdapException {
069        return true;
070    }
071
072    /**
073     * Determines whether or not the changes to an existing managed object which
074     * are about to be committed to the server configuration satisfies this
075     * constraint.
076     * <p>
077     * If the constraint is not satisfied, the implementation must return
078     * <code>false</code> and add a message describing why the constraint was
079     * not satisfied.
080     * <p>
081     * The default implementation is to return <code>true</code>.
082     *
083     * @param context
084     *            The management context.
085     * @param managedObject
086     *            The modified managed object.
087     * @param unacceptableReasons
088     *            A list of messages to which error messages should be added.
089     * @return Returns <code>true</code> if this modify is satisfied, or
090     *         <code>false</code> if it is not.
091      * @throws LdapException
092     *             If an error occurs.
093     */
094    public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject,
095        Collection<LocalizableMessage> unacceptableReasons) throws LdapException {
096        return true;
097    }
098
099    /**
100     * Determines whether or not the existing managed object which is about to
101     * be deleted from the server configuration satisfies this constraint.
102     * <p>
103     * If the constraint is not satisfied, the implementation must return
104     * <code>false</code> and add a message describing why the constraint was
105     * not satisfied.
106     * <p>
107     * The default implementation is to return <code>true</code>.
108     *
109     * @param context
110     *            The management context.
111     * @param path
112     *            The path of the managed object which is about to be deleted.
113     * @param unacceptableReasons
114     *            A list of messages to which error messages should be added.
115     * @return Returns <code>true</code> if this constraint is satisfied, or
116     *         <code>false</code> if it is not.
117     * @throws LdapException
118     *             If an error occurs.
119     */
120    public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path,
121        Collection<LocalizableMessage> unacceptableReasons) throws LdapException {
122        return true;
123    }
124}