001 /*
002 * Copyright 2009-2013 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2009-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.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.controls.ControlMessages.*;
033
034
035
036 /**
037 * This class provides an implementation of the permissive modify request
038 * control, which is supported by a number of servers and may be included in a
039 * modify request to indicate that the server should not reject a modify
040 * request which attempts to add an attribute value which already exists or
041 * remove an attribute value which does not exist. Normally, such modification
042 * attempts would be rejected.
043 * <BR><BR>
044 * The OID for this control is "1.2.840.113556.1.4.1413". It does not have a
045 * value.
046 * <BR><BR>
047 * <H2>Example</H2>
048 * The following example demonstrates the use of the permissive modify request
049 * control to remove a value of "test" from the description attribute, or to do
050 * nothing if that value is not contained in the entry.
051 * <PRE>
052 * Modification mod = new Modification(ModificationType.DELETE,
053 * "description", "test");
054 * ModifyRequest modifyRequest = new ModifyRequest(
055 * "uid=john.doe,ou=People,dc=example,dc=com", mod);
056 * modifyRequest.addControl(new PermissiveModifyRequestControl());
057 * LDAPResult modifyResult = connection.modify(modifyRequest);
058 * </PRE>
059 */
060 @NotMutable()
061 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
062 public final class PermissiveModifyRequestControl
063 extends Control
064 {
065 /**
066 * The OID (1.2.840.113556.1.4.1413) for the permissive modify request
067 * control.
068 */
069 public static final String PERMISSIVE_MODIFY_REQUEST_OID =
070 "1.2.840.113556.1.4.1413";
071
072
073
074 /**
075 * The serial version UID for this serializable class.
076 */
077 private static final long serialVersionUID = -2599039772002106760L;
078
079
080
081 /**
082 * Creates a new permissive modify request control. The control will not be
083 * marked critical.
084 */
085 public PermissiveModifyRequestControl()
086 {
087 super(PERMISSIVE_MODIFY_REQUEST_OID, false, null);
088 }
089
090
091
092 /**
093 * Creates a new permissive modify request control.
094 *
095 * @param isCritical Indicates whether the control should be marked
096 * critical.
097 */
098 public PermissiveModifyRequestControl(final boolean isCritical)
099 {
100 super(PERMISSIVE_MODIFY_REQUEST_OID, isCritical, null);
101 }
102
103
104
105 /**
106 * Creates a new permissive modify request control which is decoded from the
107 * provided generic control.
108 *
109 * @param control The generic control to be decoded as a permissive modify
110 * request control.
111 *
112 * @throws LDAPException If the provided control cannot be decoded as a
113 * permissive modify request control.
114 */
115 public PermissiveModifyRequestControl(final Control control)
116 throws LDAPException
117 {
118 super(control);
119
120 if (control.hasValue())
121 {
122 throw new LDAPException(ResultCode.DECODING_ERROR,
123 ERR_PERMISSIVE_MODIFY_HAS_VALUE.get());
124 }
125 }
126
127
128
129 /**
130 * {@inheritDoc}
131 */
132 @Override()
133 public String getControlName()
134 {
135 return INFO_CONTROL_NAME_PERMISSIVE_MODIFY_REQUEST.get();
136 }
137
138
139
140 /**
141 * {@inheritDoc}
142 */
143 @Override()
144 public void toString(final StringBuilder buffer)
145 {
146 buffer.append("PermissiveModifyRequestControl(isCritical=");
147 buffer.append(isCritical());
148 buffer.append(')');
149 }
150 }