001    /*
002     * Copyright 2007-2016 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2007-2016 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     * Ping Identity, UnboundID, and Alcatel-Lucent 8661 Directory Server
066     * implementations.
067     * <BR><BR>
068     * <H2>Example</H2>
069     * The following example demonstrates the process for attempting to perform a
070     * modify operation including the LDAP no-op control so that the change is not
071     * actually applied:
072     * <PRE>
073     * ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com",
074     *      new Modification(ModificationType.REPLACE, "description",
075     *           "new value"));
076     * modifyRequest.addControl(new DraftZeilengaLDAPNoOp12RequestControl());
077     *
078     * try
079     * {
080     *   LDAPResult result = connection.modify(modifyRequest);
081     *   if (result.getResultCode() == ResultCode.NO_OPERATION)
082     *   {
083     *     // The modification would likely have succeeded if the no-op control
084     *     // hadn't been included in the request.
085     *   }
086     *   else
087     *   {
088     *     // The modification would likely have failed if the no-op control
089     *     // hadn't been included in the request.
090     *   }
091     * }
092     * catch (LDAPException le)
093     * {
094     *   // The modification failed even with the no-op control in the request.
095     * }
096     * </PRE>
097     */
098    @NotMutable()
099    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
100    public final class DraftZeilengaLDAPNoOp12RequestControl
101           extends Control
102    {
103      /**
104       * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control.
105       */
106      public static final String NO_OP_REQUEST_OID =
107           "1.3.6.1.4.1.4203.1.10.2";
108    
109    
110    
111      /**
112       * The serial version UID for this serializable class.
113       */
114      private static final long serialVersionUID = -7435407787971958294L;
115    
116    
117    
118      /**
119       * Creates a new no-op request control.  It will be marked critical, as
120       * required by the control specification.
121       */
122      public DraftZeilengaLDAPNoOp12RequestControl()
123      {
124        super(NO_OP_REQUEST_OID, true, null);
125      }
126    
127    
128    
129      /**
130       * Creates a new no-op request control which is decoded from the provided
131       * generic control.
132       *
133       * @param  control  The generic control to be decoded as a no-op request
134       *                  control.
135       *
136       * @throws  LDAPException  If the provided control cannot be decoded as a
137       *                         no-op request control.
138       */
139      public DraftZeilengaLDAPNoOp12RequestControl(final Control control)
140             throws LDAPException
141      {
142        super(control);
143    
144        if (control.hasValue())
145        {
146          throw new LDAPException(ResultCode.DECODING_ERROR,
147                                  ERR_NOOP_REQUEST_HAS_VALUE.get());
148        }
149      }
150    
151    
152    
153      /**
154       * {@inheritDoc}
155       */
156      @Override()
157      public String getControlName()
158      {
159        return INFO_CONTROL_NAME_NOOP_REQUEST.get();
160      }
161    
162    
163    
164      /**
165       * {@inheritDoc}
166       */
167      @Override()
168      public void toString(final StringBuilder buffer)
169      {
170        buffer.append("NoOpRequestControl(isCritical=");
171        buffer.append(isCritical());
172        buffer.append(')');
173      }
174    }