Class VirtualListViewRequestControl
- All Implemented Interfaces:
Control
This control must be used in conjunction with the server-side sort request control in order to ensure that results are returned in a consistent order.
This control is similar to the simple paged results request control, except that it allows the client to move backwards and forwards in the result set.
The following example demonstrates use of the virtual list view controls.
ByteString contextID = ByteString.empty();
// Add a window of 2 entries on either side of the first sn=Jensen entry.
SearchRequest request = Requests.newSearchRequest("ou=People,dc=example,dc=com",
SearchScope.WHOLE_SUBTREE, "(sn=*)", "sn", "givenName")
.addControl(ServerSideSortRequestControl.newControl(true, new SortKey("sn")))
.addControl(VirtualListViewRequestControl.newAssertionControl(
true, ByteString.valueOf("Jensen"), 2, 2, contextID));
SearchResultHandler resultHandler = new MySearchResultHandler();
Result result = connection.search(request, resultHandler);
ServerSideSortResponseControl sssControl =
result.getControl(ServerSideSortResponseControl.DECODER, new DecodeOptions());
if (sssControl != null && sssControl.getResult() == ResultCode.SUCCESS) {
// Entries are sorted.
} else {
// Entries not necessarily sorted
}
VirtualListViewResponseControl vlvControl =
result.getControl(VirtualListViewResponseControl.DECODER, new DecodeOptions());
// Position in list: vlvControl.getTargetPosition()/vlvControl.getContentCount()
The search result handler in this case displays pages of results as LDIF on
standard out.
private static class MySearchResultHandler implements SearchResultHandler {
@Override
public void handleExceptionResult(LdapException error) {
// Ignore.
}
@Override
public void handleResult(Result result) {
// Ignore.
}
@Override
public boolean handleEntry(SearchResultEntry entry) {
final LDIFEntryWriter writer = new LDIFEntryWriter(System.out);
try {
writer.writeEntry(entry);
writer.flush();
} catch (final IOException e) {
// The writer could not write to System.out.
}
return true;
}
@Override
public boolean handleReference(SearchResultReference reference) {
System.out.println("Got a reference: " + reference.toString());
return false;
}
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe user-friendly aliases for the virtual list view request control.static final ControlDecoder<VirtualListViewRequestControl>A decoder which can be used for decoding theVirtualListViewRequestControl.static final StringThe OID for the virtual list view request control. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of entries after the target entry to be included in the search results.getAlias()Returns the control "friendly name" alias for the control.Returns the assertion value that will be used to locate the target entry, if applicable.Returns the assertion value that will be used to locate the target entry, if applicable, decoded as a UTF-8 string.intReturns the number of entries before the target entry to be included in the search results.intReturns the content count returned by the server in the last virtual list view response, if applicable.Returns the context ID provided by the server in the last virtual list view response for the same set of criteria, ornullif there was no previous virtual list view response or the server did not include a context ID in the last response.intReturns the positional offset of the target entry in the result set, if applicable, where1is the first entry.getOid()Returns the numeric OID associated with this control.getValue()Returns the value, if any, associated with this control.booleanReturnstrueif this control is using a target offset, orfalseif this control is using a target assertion.booleanhasValue()Returnstrueif this control has a value.booleanReturnstrueif it is unacceptable to perform the operation without applying the semantics of this control.newAssertionControl(boolean isCritical, ByteString assertionValue, int beforeCount, int afterCount, ByteString contextId) Creates a new virtual list view request control that will identify the target entry by an assertion value.newOffsetControl(boolean isCritical, int offset, int contentCount, int beforeCount, int afterCount, ByteString contextId) Creates a new virtual list view request control that will identify the target entry by a positional offset within the complete result set.toString()
-
Field Details
-
OID
The OID for the virtual list view request control.- See Also:
-
ALIASES
The user-friendly aliases for the virtual list view request control. -
DECODER
A decoder which can be used for decoding theVirtualListViewRequestControl.
-
-
Method Details
-
newAssertionControl
public static VirtualListViewRequestControl newAssertionControl(boolean isCritical, ByteString assertionValue, int beforeCount, int afterCount, ByteString contextId) Creates a new virtual list view request control that will identify the target entry by an assertion value. The assertion value is encoded according to the ORDERING matching rule for the attribute description in the sort control. The assertion value is used to determine the target entry by comparison with the values of the attribute specified as the primary sort key. The first list entry whose value is no less than (less than or equal to when the sort order is reversed) the supplied value is the target entry.- Parameters:
isCritical-trueif it is unacceptable to perform the operation without applying the semantics of this control, orfalseif it can be ignored.assertionValue- The assertion value that will be used to locate the target entry.beforeCount- The number of entries before the target entry to be included in the search results.afterCount- The number of entries after the target entry to be included in the search results.contextId- The context ID provided by the server in the last virtual list view response for the same set of criteria, ornullif there was no previous virtual list view response or the server did not include a context ID in the last response.- Returns:
- The new control.
- Throws:
IllegalArgumentException- IfbeforeCountorafterCountwere less than0.NullPointerException- IfassertionValuewasnull.
-
newOffsetControl
public static VirtualListViewRequestControl newOffsetControl(boolean isCritical, int offset, int contentCount, int beforeCount, int afterCount, ByteString contextId) Creates a new virtual list view request control that will identify the target entry by a positional offset within the complete result set.- Parameters:
isCritical-trueif it is unacceptable to perform the operation without applying the semantics of this control, orfalseif it can be ignored.offset- The positional offset of the target entry in the result set, where1is the first entry.contentCount- The content count returned by the server in the last virtual list view response, or0if this is the first virtual list view request.beforeCount- The number of entries before the target entry to be included in the search results.afterCount- The number of entries after the target entry to be included in the search results.contextId- The context ID provided by the server in the last virtual list view response for the same set of criteria, ornullif there was no previous virtual list view response or the server did not include a context ID in the last response.- Returns:
- The new control.
- Throws:
IllegalArgumentException- IfbeforeCount,afterCount, orcontentCountwere less than0, or ifoffsetwas less than1.
-
getAfterCount
public int getAfterCount()Returns the number of entries after the target entry to be included in the search results.- Returns:
- The number of entries after the target entry to be included in the search results.
-
getAssertionValue
Returns the assertion value that will be used to locate the target entry, if applicable.- Returns:
- The assertion value that will be used to locate the target entry,
or
nullif this control is using a target offset.
-
getAssertionValueAsString
Returns the assertion value that will be used to locate the target entry, if applicable, decoded as a UTF-8 string.- Returns:
- The assertion value that will be used to locate the target entry
decoded as a UTF-8 string, or
nullif this control is using a target offset.
-
getBeforeCount
public int getBeforeCount()Returns the number of entries before the target entry to be included in the search results.- Returns:
- The number of entries before the target entry to be included in the search results.
-
getContentCount
public int getContentCount()Returns the content count returned by the server in the last virtual list view response, if applicable.- Returns:
- The content count returned by the server in the last virtual list
view response, which may be
0if this is the first virtual list view request, or-1if this control is using a target assertion.
-
getContextId
Returns the context ID provided by the server in the last virtual list view response for the same set of criteria, ornullif there was no previous virtual list view response or the server did not include a context ID in the last response.- Returns:
- The context ID provided by the server in the last virtual list
view response, or
nullif unavailable.
-
getOffset
public int getOffset()Returns the positional offset of the target entry in the result set, if applicable, where1is the first entry.- Returns:
- The positional offset of the target entry in the result set, or
-1if this control is using a target assertion.
-
getOid
Description copied from interface:ControlReturns the numeric OID associated with this control. -
getValue
Description copied from interface:ControlReturns the value, if any, associated with this control. Its format is defined by the specification of this control. -
hasTargetOffset
public boolean hasTargetOffset()Returnstrueif this control is using a target offset, orfalseif this control is using a target assertion.- Returns:
trueif this control is using a target offset, orfalseif this control is using a target assertion.
-
hasValue
public boolean hasValue()Description copied from interface:ControlReturnstrueif this control has a value. In some circumstances it may be useful to determine if a control has a value, without actually calculating the value and incurring any performance costs. -
isCritical
public boolean isCritical()Description copied from interface:ControlReturnstrueif it is unacceptable to perform the operation without applying the semantics of this control.The criticality field only has meaning in controls attached to request messages (except UnbindRequest). For controls attached to response messages and the UnbindRequest, the criticality field SHOULD be
false, and MUST be ignored by the receiving protocol peer. A value oftrueindicates that it is unacceptable to perform the operation without applying the semantics of the control.- Specified by:
isCriticalin interfaceControl- Returns:
trueif this control must be processed by the Directory Server, orfalseif it can be ignored.
-
toString
-
getAlias
Description copied from interface:ControlReturns the control "friendly name" alias for the control.
-