001    /*
002     * Copyright 2008-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 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.unboundidds.controls;
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.unboundidds.controls.ControlMessages.*;
033    
034    
035    
036    /**
037     * <BLOCKQUOTE>
038     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
039     *   LDAP SDK for Java.  It is not available for use in applications that
040     *   include only the Standard Edition of the LDAP SDK, and is not supported for
041     *   use in conjunction with non-UnboundID products.
042     * </BLOCKQUOTE>
043     * This class provides an implementation of the LDAP no-op control as defined in
044     * draft-zeilenga-ldap-noop.  This control may be included in an add, delete,
045     * modify, or modify DN request to indicate that the server should validate the
046     * request but not actually make any changes to the data.  It allows the client
047     * to verify that the operation would likely succeed (including schema
048     * validation, access control checks, and other processing) without making any
049     * changes to the server data.
050     * <BR><BR>
051     * Note that an operation which includes the no-op control will never have a
052     * {@link ResultCode#SUCCESS} result.  Instead, if the operation would likely
053     * have completed successfully if the no-op control had not been included, then
054     * the server will include a response with the {@link ResultCode#NO_OPERATION}
055     * result.  If the operation would not have been successful, then the result
056     * code in the response will be the appropriate result code for that failure.
057     * Note that if the response from the server includes the
058     * {@link ResultCode#NO_OPERATION} result, then the LDAP SDK will not throw an
059     * exception but will instead return the response in an
060     * {@link com.unboundid.ldap.sdk.LDAPResult} object.  There is no corresponding
061     * response control.
062     * <BR><BR>
063     * Note that at the time this control was written, the latest version of the
064     * specification may be found in draft-zeilenga-ldap-noop-11.  This version of
065     * the document does not explicitly specify either the OID that should be used
066     * for the control, or the result code that should be used for the associated
067     * operation if all other processing is completed successfully but no changes
068     * are made as a result of this control.  Until such time as these are defined,
069     * this implementation uses the OID temporarily assigned for its use by the
070     * OpenLDAP Foundation, which is used by at least the OpenLDAP, OpenDS, and the
071     * UnboundID Directory Server implementations.
072     * <BR><BR>
073     * <H2>Example</H2>
074     * The following example demonstrates the process for attempting to perform a
075     * modify operation including the LDAP no-op control so that the change is not
076     * actually applied:
077     * <PRE>
078     * ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com",
079     *      new Modification(ModificationType.REPLACE, "description",
080     *           "new value"));
081     * modifyRequest.addControl(new NoOpRequestControl());
082     *
083     * try
084     * {
085     *   LDAPResult result = connection.modify(modifyRequest);
086     *   if (result.getResultCode() == ResultCode.NO_OPERATION)
087     *   {
088     *     // The modify would likely have succeeded.
089     *   }
090     *   else
091     *   {
092     *     // The modify would likely have failed.
093     *   }
094     * }
095     * catch (LDAPException le)
096     * {
097     *   // The modify attempt failed even with the no-op control.
098     * }
099     * </PRE>
100     */
101    @NotMutable()
102    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
103    public final class NoOpRequestControl
104           extends Control
105    {
106      /**
107       * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control.
108       */
109      public static final String NO_OP_REQUEST_OID =
110           "1.3.6.1.4.1.4203.1.10.2";
111    
112    
113    
114      /**
115       * The serial version UID for this serializable class.
116       */
117      private static final long serialVersionUID = -7435407787971958294L;
118    
119    
120    
121      /**
122       * Creates a new no-op request control.  It will be marked critical, as
123       * required by the control specification.
124       */
125      public NoOpRequestControl()
126      {
127        super(NO_OP_REQUEST_OID, true, null);
128      }
129    
130    
131    
132      /**
133       * Creates a new no-op request control which is decoded from the provided
134       * generic control.
135       *
136       * @param  control  The generic control to be decoded as a no-op request
137       *                  control.
138       *
139       * @throws  LDAPException  If the provided control cannot be decoded as a
140       *                         no-op request control.
141       */
142      public NoOpRequestControl(final Control control)
143             throws LDAPException
144      {
145        super(control);
146    
147        if (control.hasValue())
148        {
149          throw new LDAPException(ResultCode.DECODING_ERROR,
150                                  ERR_NOOP_REQUEST_HAS_VALUE.get());
151        }
152      }
153    
154    
155    
156      /**
157       * {@inheritDoc}
158       */
159      @Override()
160      public String getControlName()
161      {
162        return INFO_CONTROL_NAME_NOOP_REQUEST.get();
163      }
164    
165    
166    
167      /**
168       * {@inheritDoc}
169       */
170      @Override()
171      public void toString(final StringBuilder buffer)
172      {
173        buffer.append("NoOpRequestControl(isCritical=");
174        buffer.append(isCritical());
175        buffer.append(')');
176      }
177    }