001/* 002 * Copyright 2007-2014 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2007-2014 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 */ 021package com.unboundid.ldap.sdk.experimental; 022 023 024 025import com.unboundid.ldap.sdk.Control; 026import com.unboundid.ldap.sdk.LDAPException; 027import com.unboundid.ldap.sdk.ResultCode; 028import com.unboundid.util.NotMutable; 029import com.unboundid.util.ThreadSafety; 030import com.unboundid.util.ThreadSafetyLevel; 031 032import 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 DraftZeilengaLDAPNoOp12RequestControl()); 076 * 077 * try 078 * { 079 * LDAPResult result = connection.modify(modifyRequest); 080 * if (result.getResultCode() == ResultCode.NO_OPERATION) 081 * { 082 * // The modification would likely have succeeded if the no-op control 083 * // hadn't been included in the request. 084 * } 085 * else 086 * { 087 * // The modification would likely have failed if the no-op control 088 * // hadn't been included in the request. 089 * } 090 * } 091 * catch (LDAPException le) 092 * { 093 * // The modification failed even with the no-op control in the request. 094 * } 095 * </PRE> 096 */ 097@NotMutable() 098@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 099public final class DraftZeilengaLDAPNoOp12RequestControl 100 extends Control 101{ 102 /** 103 * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control. 104 */ 105 public static final String NO_OP_REQUEST_OID = 106 "1.3.6.1.4.1.4203.1.10.2"; 107 108 109 110 /** 111 * The serial version UID for this serializable class. 112 */ 113 private static final long serialVersionUID = -7435407787971958294L; 114 115 116 117 /** 118 * Creates a new no-op request control. It will be marked critical, as 119 * required by the control specification. 120 */ 121 public DraftZeilengaLDAPNoOp12RequestControl() 122 { 123 super(NO_OP_REQUEST_OID, true, null); 124 } 125 126 127 128 /** 129 * Creates a new no-op request control which is decoded from the provided 130 * generic control. 131 * 132 * @param control The generic control to be decoded as a no-op request 133 * control. 134 * 135 * @throws LDAPException If the provided control cannot be decoded as a 136 * no-op request control. 137 */ 138 public DraftZeilengaLDAPNoOp12RequestControl(final Control control) 139 throws LDAPException 140 { 141 super(control); 142 143 if (control.hasValue()) 144 { 145 throw new LDAPException(ResultCode.DECODING_ERROR, 146 ERR_NOOP_REQUEST_HAS_VALUE.get()); 147 } 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override() 156 public String getControlName() 157 { 158 return INFO_CONTROL_NAME_NOOP_REQUEST.get(); 159 } 160 161 162 163 /** 164 * {@inheritDoc} 165 */ 166 @Override() 167 public void toString(final StringBuilder buffer) 168 { 169 buffer.append("NoOpRequestControl(isCritical="); 170 buffer.append(isCritical()); 171 buffer.append(')'); 172 } 173}