001    /*
002     * Copyright 2007-2013 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2007-2013 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk.experimental;
022    
023    
024    
025    import com.unboundid.ldap.sdk.Control;
026    import com.unboundid.ldap.sdk.LDAPException;
027    import com.unboundid.ldap.sdk.ResultCode;
028    import com.unboundid.util.NotMutable;
029    import com.unboundid.util.ThreadSafety;
030    import com.unboundid.util.ThreadSafetyLevel;
031    
032    import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*;
033    
034    
035    
036    /**
037     * This class provides an implementation of the LDAP no-op control as defined in
038     * draft-zeilenga-ldap-noop-12.  This control may be included in an add, delete,
039     * modify, or modify DN request to indicate that the server should validate the
040     * request but not actually make any changes to the data.  It allows the client
041     * to verify that the operation would likely succeed (including schema
042     * validation, access control checks, and other processing) without making any
043     * changes to the server data.
044     * <BR><BR>
045     * Note that an operation which includes the no-op control will never have a
046     * {@link ResultCode#SUCCESS} result.  Instead, if the operation would likely
047     * have completed successfully if the no-op control had not been included, then
048     * the server will include a response with the {@link ResultCode#NO_OPERATION}
049     * result.  If the operation would not have been successful, then the result
050     * code in the response will be the appropriate result code for that failure.
051     * Note that if the response from the server includes the
052     * {@link ResultCode#NO_OPERATION} result, then the LDAP SDK will not throw an
053     * exception but will instead return the response in an
054     * {@link com.unboundid.ldap.sdk.LDAPResult} object.  There is no corresponding
055     * response control.
056     * <BR><BR>
057     * Note that at the time this control was written, the latest version of the
058     * specification may be found in draft-zeilenga-ldap-noop-11.  This version of
059     * the document does not explicitly specify either the OID that should be used
060     * for the control, or the result code that should be used for the associated
061     * operation if all other processing is completed successfully but no changes
062     * are made as a result of this control.  Until such time as these are defined,
063     * this implementation uses the OID temporarily assigned for its use by the
064     * OpenLDAP Foundation, which is used by at least the OpenLDAP, OpenDS, and the
065     * UnboundID Directory Server implementations.
066     * <BR><BR>
067     * <H2>Example</H2>
068     * The following example demonstrates the process for attempting to perform a
069     * modify operation including the LDAP no-op control so that the change is not
070     * actually applied:
071     * <PRE>
072     *   ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com",
073     *        new Modification(ModificationType.REPLACE, "description",
074     *                         "new value"))
075     *   modifyRequest.addControl(new NoOpRequestControl());
076     *
077     *   try
078     *   {
079     *     LDAPResult result = connection.modify(modifyRequest);
080     *     if (result.getResultCode() == ResultCode.NO_OPERATION)
081     *     {
082     *       System.out.println("The modify would likely have succeeded.");
083     *     }
084     *     else
085     *     {
086     *       System.err.println("The modify would have failed.");
087     *     }
088     *   }
089     *   catch (LDAPException le)
090     *   {
091     *     System.err.println("The modify would have failed.");
092     *   }
093     * </PRE>
094     */
095    @NotMutable()
096    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
097    public final class DraftZeilengaLDAPNoOp12RequestControl
098           extends Control
099    {
100      /**
101       * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control.
102       */
103      public static final String NO_OP_REQUEST_OID =
104           "1.3.6.1.4.1.4203.1.10.2";
105    
106    
107    
108      /**
109       * The serial version UID for this serializable class.
110       */
111      private static final long serialVersionUID = -7435407787971958294L;
112    
113    
114    
115      /**
116       * Creates a new no-op request control.  It will be marked critical, as
117       * required by the control specification.
118       */
119      public DraftZeilengaLDAPNoOp12RequestControl()
120      {
121        super(NO_OP_REQUEST_OID, true, null);
122      }
123    
124    
125    
126      /**
127       * Creates a new no-op request control which is decoded from the provided
128       * generic control.
129       *
130       * @param  control  The generic control to be decoded as a no-op request
131       *                  control.
132       *
133       * @throws  LDAPException  If the provided control cannot be decoded as a
134       *                         no-op request control.
135       */
136      public DraftZeilengaLDAPNoOp12RequestControl(final Control control)
137             throws LDAPException
138      {
139        super(control);
140    
141        if (control.hasValue())
142        {
143          throw new LDAPException(ResultCode.DECODING_ERROR,
144                                  ERR_NOOP_REQUEST_HAS_VALUE.get());
145        }
146      }
147    
148    
149    
150      /**
151       * {@inheritDoc}
152       */
153      @Override()
154      public String getControlName()
155      {
156        return INFO_CONTROL_NAME_NOOP_REQUEST.get();
157      }
158    
159    
160    
161      /**
162       * {@inheritDoc}
163       */
164      @Override()
165      public void toString(final StringBuilder buffer)
166      {
167        buffer.append("NoOpRequestControl(isCritical=");
168        buffer.append(isCritical());
169        buffer.append(')');
170      }
171    }