@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class SubtreeDeleteRequestControl extends Control
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.
// 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);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SUBTREE_DELETE_REQUEST_OID
The OID (1.2.840.113556.1.4.805) for the subtree delete request control.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
static SubtreeDeleteRequestControl |
decodeJSONControl(JSONObject controlObject,
boolean strict)
Attempts to decode the provided object as a JSON representation of a
subtree delete request control.
|
java.lang.String |
getControlName()
Retrieves the user-friendly name for this control, if available.
|
JSONObject |
toJSONControl()
Retrieves a representation of this subtree delete request control as a
JSON object.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP control to the provided
buffer.
|
decode, decode, decodeControls, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
@NotNull public static final java.lang.String SUBTREE_DELETE_REQUEST_OID
public SubtreeDeleteRequestControl()
public SubtreeDeleteRequestControl(boolean isCritical)
isCritical
- Indicates whether the control should be marked
critical.public SubtreeDeleteRequestControl(@NotNull Control control) throws LDAPException
control
- The generic control to be decoded as a subtree delete
request control.LDAPException
- If the provided control cannot be decoded as a
subtree delete request control.@NotNull public java.lang.String getControlName()
getControlName
in class Control
@NotNull public JSONObject toJSONControl()
value-base64
nor
value-json
fields 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, the oid
field should be used to identify the type of control.
criticality
-- A mandatory Boolean field used to indicate
whether this control is considered critical.
toJSONControl
in class Control
@NotNull public static SubtreeDeleteRequestControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException
controlObject
- The JSON object to be decoded. It must not be
null
.strict
- Indicates whether to use strict mode when decoding
the provided JSON object. If this is true
,
then this method will throw an exception if the
provided JSON object contains any unrecognized
fields. If this is false
, then unrecognized
fields will be ignored.LDAPException
- If the provided JSON object cannot be parsed as a
valid subtree delete request control.