Package com.unboundid.ldap.sdk.controls
Class SubtreeDeleteRequestControl
java.lang.Object
com.unboundid.ldap.sdk.Control
com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl
- All Implemented Interfaces:
Serializable
@NotMutable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class SubtreeDeleteRequestControl
extends Control
This class provides an implementation of the subtree delete request control
as defined in draft-armijo-ldap-treedelete. This can be used to delete an
entry and all subordinate entries in a single operation.
Normally, if an entry has one or more subordinates, a directory server will refuse to delete it by rejecting the request with a
Normally, if an entry has one or more subordinates, a directory server will refuse to delete it by rejecting the request with a
ResultCode.NOT_ALLOWED_ON_NONLEAF result. In such cases, it is
necessary to first recursively remove all of its subordinates before the
target entry can be deleted. However, this subtree delete request control
can be used to request that the server remove the entry and all subordinates
as a single operation. For servers that support this control, it is
generally much more efficient and convenient than removing all of the
subordinate entries one at a time.
Example
The following example demonstrates the use of the subtree delete control:
// First, try to delete an entry that has children, but don't include the
// subtree delete control. This delete attempt should fail, and the
// "NOT_ALLOWED_ON_NONLEAF" result is most appropriate if the failure reason
// is that the entry has subordinates.
DeleteRequest deleteRequest =
new DeleteRequest("ou=entry with children,dc=example,dc=com");
LDAPResult resultWithoutControl;
try
{
resultWithoutControl = connection.delete(deleteRequest);
// We shouldn't get here because the delete should fail.
}
catch (LDAPException le)
{
// This is expected because the entry has children.
resultWithoutControl = le.toLDAPResult();
ResultCode resultCode = le.getResultCode();
String errorMessageFromServer = le.getDiagnosticMessage();
}
LDAPTestUtils.assertResultCodeEquals(resultWithoutControl,
ResultCode.NOT_ALLOWED_ON_NONLEAF);
// Update the delete request to include the subtree delete request control
// and try again.
deleteRequest.addControl(new SubtreeDeleteRequestControl());
LDAPResult resultWithControl;
try
{
resultWithControl = connection.delete(deleteRequest);
// The delete should no longer be rejected just because the target entry
// has children.
}
catch (LDAPException le)
{
// The delete still failed for some other reason.
resultWithControl = le.toLDAPResult();
ResultCode resultCode = le.getResultCode();
String errorMessageFromServer = le.getDiagnosticMessage();
}
LDAPTestUtils.assertResultCodeEquals(resultWithControl, ResultCode.SUCCESS);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe OID (1.2.840.113556.1.4.805) for the subtree delete request control. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new subtree delete request control.SubtreeDeleteRequestControl(boolean isCritical) Creates a new subtree delete request control.SubtreeDeleteRequestControl(Control control) Creates a new subtree delete request control which is decoded from the provided generic control. -
Method Summary
Modifier and TypeMethodDescriptionstatic SubtreeDeleteRequestControldecodeJSONControl(JSONObject controlObject, boolean strict) Attempts to decode the provided object as a JSON representation of a subtree delete request control.Retrieves the user-friendly name for this control, if available.Retrieves a representation of this subtree delete request control as a JSON object.voidtoString(StringBuilder buffer) Appends a string representation of this LDAP control to the provided buffer.Methods inherited from class com.unboundid.ldap.sdk.Control
decode, decode, decodeControls, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
-
Field Details
-
SUBTREE_DELETE_REQUEST_OID
The OID (1.2.840.113556.1.4.805) for the subtree delete request control.- See Also:
-
-
Constructor Details
-
SubtreeDeleteRequestControl
public SubtreeDeleteRequestControl()Creates a new subtree delete request control. The control will not be marked critical. -
SubtreeDeleteRequestControl
Creates a new subtree delete request control.- Parameters:
isCritical- Indicates whether the control should be marked critical.
-
SubtreeDeleteRequestControl
Creates a new subtree delete request control which is decoded from the provided generic control.- Parameters:
control- The generic control to be decoded as a subtree delete request control.- Throws:
LDAPException- If the provided control cannot be decoded as a subtree delete request control.
-
-
Method Details
-
getControlName
Retrieves the user-friendly name for this control, if available. If no user-friendly name has been defined, then the OID will be returned.- Overrides:
getControlNamein classControl- Returns:
- The user-friendly name for this control, or the OID if no user-friendly name is available.
-
toJSONControl
Retrieves a representation of this subtree delete request control as a JSON object. The JSON object uses the following fields (note that since this control does not have a value, neither thevalue-base64norvalue-jsonfields may be present):-
oid-- A mandatory string field whose value is the object identifier for this control. For the subtree delete request control, the OID is "1.2.840.113556.1.4.805". -
control-name-- An optional string field whose value is a human-readable name for this control. This field is only intended for descriptive purposes, and when decoding a control, theoidfield should be used to identify the type of control. -
criticality-- A mandatory Boolean field used to indicate whether this control is considered critical.
- Overrides:
toJSONControlin classControl- Returns:
- A JSON object that contains a representation of this control.
-
-
decodeJSONControl
@NotNull public static SubtreeDeleteRequestControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException Attempts to decode the provided object as a JSON representation of a subtree delete request control.- Parameters:
controlObject- The JSON object to be decoded. It must not benull.strict- Indicates whether to use strict mode when decoding the provided JSON object. If this istrue, then this method will throw an exception if the provided JSON object contains any unrecognized fields. If this isfalse, then unrecognized fields will be ignored.- Returns:
- The subtree delete request control that was decoded from the provided JSON object.
- Throws:
LDAPException- If the provided JSON object cannot be parsed as a valid subtree delete request control.
-
toString
Appends a string representation of this LDAP control to the provided buffer.
-