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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.admin.client;
028    
029    
030    
031    import java.util.Collection;
032    
033    import org.opends.messages.Message;
034    import org.opends.server.admin.ManagedObjectPath;
035    
036    
037    
038    /**
039     * An interface for performing client-side constraint validation.
040     * <p>
041     * Constraints are evaluated immediately before the client performs a
042     * write operation. If one or more constraints fails, the write
043     * operation is refused and fails with an
044     * {@link OperationRejectedException}.
045     * <p>
046     * A client constraint handler must override at least one of the
047     * provided methods.
048     *
049     * @see org.opends.server.admin.Constraint
050     */
051    public abstract class ClientConstraintHandler {
052    
053      /**
054       * Creates a new client constraint handler.
055       */
056      protected ClientConstraintHandler() {
057        // No implementation required.
058      }
059    
060    
061    
062      /**
063       * Determines whether or not the newly created managed object which
064       * is about to be added to the server configuration satisfies this
065       * constraint.
066       * <p>
067       * If the constraint is not satisfied, the implementation must
068       * return <code>false</code> and add a message describing why the
069       * constraint was not satisfied.
070       * <p>
071       * The default implementation is to return <code>true</code>.
072       *
073       * @param context
074       *          The management context.
075       * @param managedObject
076       *          The new managed object.
077       * @param unacceptableReasons
078       *          A list of messages to which error messages should be
079       *          added.
080       * @return Returns <code>true</code> if this constraint is
081       *         satisfied, or <code>false</code> if it is not.
082       * @throws AuthorizationException
083       *           If an authorization failure prevented this constraint
084       *           from being evaluated.
085       * @throws CommunicationException
086       *           If a communications problem prevented this constraint
087       *           from being evaluated.
088       */
089      public boolean isAddAcceptable(ManagementContext context,
090          ManagedObject<?> managedObject, Collection<Message> unacceptableReasons)
091          throws AuthorizationException, CommunicationException {
092        return true;
093      }
094    
095    
096    
097      /**
098       * Determines whether or not the changes to an existing managed
099       * object which are about to be committed to the server
100       * configuration satisfies this constraint.
101       * <p>
102       * If the constraint is not satisfied, the implementation must
103       * return <code>false</code> and add a message describing why the
104       * constraint was not satisfied.
105       * <p>
106       * The default implementation is to return <code>true</code>.
107       *
108       * @param context
109       *          The management context.
110       * @param managedObject
111       *          The modified managed object.
112       * @param unacceptableReasons
113       *          A list of messages to which error messages should be
114       *          added.
115       * @return Returns <code>true</code> if this modify is satisfied,
116       *         or <code>false</code> if it is not.
117       * @throws AuthorizationException
118       *           If an authorization failure prevented this constraint
119       *           from being evaluated.
120       * @throws CommunicationException
121       *           If a communications problem prevented this constraint
122       *           from being evaluated.
123       */
124      public boolean isModifyAcceptable(ManagementContext context,
125          ManagedObject<?> managedObject, Collection<Message> unacceptableReasons)
126          throws AuthorizationException, CommunicationException {
127        return true;
128      }
129    
130    
131    
132      /**
133       * Determines whether or not the existing managed object which is
134       * about to be deleted from the server configuration satisfies this
135       * constraint.
136       * <p>
137       * If the constraint is not satisfied, the implementation must
138       * return <code>false</code> and add a message describing why the
139       * constraint was not satisfied.
140       * <p>
141       * The default implementation is to return <code>true</code>.
142       *
143       * @param context
144       *          The management context.
145       * @param path
146       *          The path of the managed object which is about to be
147       *          deleted.
148       * @param unacceptableReasons
149       *          A list of messages to which error messages should be
150       *          added.
151       * @return Returns <code>true</code> if this constraint is
152       *         satisfied, or <code>false</code> if it is not.
153       * @throws AuthorizationException
154       *           If an authorization failure prevented this constraint
155       *           from being evaluated.
156       * @throws CommunicationException
157       *           If a communications problem prevented this constraint
158       *           from being evaluated.
159       */
160      public boolean isDeleteAcceptable(ManagementContext context,
161          ManagedObjectPath<?, ?> path, Collection<Message> unacceptableReasons)
162          throws AuthorizationException, CommunicationException {
163        return true;
164      }
165    }