com.unboundid.ldap.sdk.controls
Class SubtreeDeleteRequestControl

java.lang.Object
  extended by com.unboundid.ldap.sdk.Control
      extended by com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl
All Implemented Interfaces:
java.io.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 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:
Serialized Form

Field Summary
static java.lang.String SUBTREE_DELETE_REQUEST_OID
          The OID (1.2.840.113556.1.4.805) for the subtree delete request control.
 
Constructor Summary
SubtreeDeleteRequestControl()
          Creates 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
 java.lang.String getControlName()
          Retrieves the user-friendly name for this control, if available.
 void toString(java.lang.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, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, toString, writeTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SUBTREE_DELETE_REQUEST_OID

public static final java.lang.String SUBTREE_DELETE_REQUEST_OID
The OID (1.2.840.113556.1.4.805) for the subtree delete request control.

See Also:
Constant Field Values
Constructor Detail

SubtreeDeleteRequestControl

public SubtreeDeleteRequestControl()
Creates a new subtree delete request control. The control will not be marked critical.


SubtreeDeleteRequestControl

public SubtreeDeleteRequestControl(boolean isCritical)
Creates a new subtree delete request control.

Parameters:
isCritical - Indicates whether the control should be marked critical.

SubtreeDeleteRequestControl

public SubtreeDeleteRequestControl(Control control)
                            throws LDAPException
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 Detail

getControlName

public java.lang.String 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:
getControlName in class Control
Returns:
The user-friendly name for this control, or the OID if no user-friendly name is available.

toString

public void toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP control to the provided buffer.

Overrides:
toString in class Control
Parameters:
buffer - The buffer to which to append the string representation of this buffer.