public final class SortControl extends BasicControl
下面的代码示例演示如何使用类:
// Open an LDAP association
LdapContext ctx = new InitialLdapContext();
// Activate sorting
String sortKey = "cn";
ctx.setRequestControls(new Control[]{
new SortControl(sortKey, Control.CRITICAL) });
// Perform a search
NamingEnumeration results =
ctx.search("", "(objectclass=*)", new SearchControls());
// Iterate over search results
while (results != null && results.hasMore()) {
// Display an entry
SearchResult entry = (SearchResult)results.next();
System.out.println(entry.getName());
System.out.println(entry.getAttributes());
// Handle the entry's response controls (if any)
if (entry instanceof HasControls) {
// ((HasControls)entry).getControls();
}
}
// Examine the sort control response
Control[] controls = ctx.getResponseControls();
if (controls != null) {
for (int i = 0; i < controls.length; i++) {
if (controls[i] instanceof SortResponseControl) {
SortResponseControl src = (SortResponseControl)controls[i];
if (! src.isSorted()) {
throw src.getException();
}
} else {
// Handle other response controls (if any)
}
}
}
// Close the LDAP association
ctx.close();
...
实现了服务器端排序中定义的RFC 2891 LDAPv3要求控制这类。控制的价值具有以下ASN. 1定义:
sortkeylist::=序列{序列attributedescription AttributeType,orderingrule [ 0 ] matchingruleid可选,阶[ 1 ]布尔默认错误}
SortKey
,
SortResponseControl
,
Serialized Form
Modifier and Type | Field and Description |
---|---|
static String |
OID
服务器端排序控制分配的对象标识符是1.2.840.113556.1.4.473。
|
criticality, id, value
CRITICAL, NONCRITICAL
Constructor and Description |
---|
SortControl(SortKey[] sortBy, boolean criticality)
构造一个控件来对排序键列表进行排序。
|
SortControl(String[] sortBy, boolean criticality)
构造一个控件以在一个属性的列表中进行排序。
|
SortControl(String sortBy, boolean criticality)
构造一个以提升顺序对单个属性进行排序的控件。
|
public static final String OID
public SortControl(String sortBy, boolean criticality) throws IOException
sortBy
-属性ID进行排序。
criticality
-如果真那么服务器必须控制和返回搜索结果排序的要求或拒绝执行搜索。如果是错误的,那么服务器就不需要控制了。
IOException
如果编码提供的参数到控制时出错。
public SortControl(String[] sortBy, boolean criticality) throws IOException
sortBy
-一个非空的列属性ID进行排序。该列表是在最高到最低的排序键优先顺序。
criticality
-如果真那么服务器必须控制和返回搜索结果排序的要求或拒绝执行搜索。如果是错误的,那么服务器就不需要控制了。
IOException
如果编码提供的参数到控制时出错。
public SortControl(SortKey[] sortBy, boolean criticality) throws IOException
sortBy
-一个非空的列键排序。该列表是在最高到最低的排序键优先顺序。
criticality
-如果真那么服务器必须控制和返回搜索结果排序的要求或拒绝执行搜索。如果是错误的,那么服务器就不需要控制了。
IOException
如果编码提供的参数到控制时出错。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.