public final class PagedResultsControl extends BasicControl
以下代码示例显示了如何使用类:
// Open an LDAP association LdapContext ctx = new InitialLdapContext(); // Activate paged results int pageSize = 20; // 20 entries per page byte[] cookie = null; int total; ctx.setRequestControls(new Control[]{ new PagedResultsControl(pageSize, Control.CRITICAL) }); do { // Perform the search NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); // Iterate over a batch of 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 paged results control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl)controls[i]; total = prrc.getResultSize(); cookie = prrc.getCookie(); } else { // Handle other response controls (if any) } } } // Re-activate paged results ctx.setRequestControls(new Control[]{ new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } while (cookie != null); // Close the LDAP association ctx.close(); ...
此类实现中定义为分页结果的LDAPv3的控制RFC 2696 。 控件的值具有以下ASN.1定义:
realSearchControlValue ::= SEQUENCE { size INTEGER (0..maxInt), -- requested page size from client -- result set size estimate from server cookie OCTET STRING }
PagedResultsResponseControl
, Serialized Form
Modifier and Type | Field and Description |
---|---|
static String |
OID
分页结果控件的分配对象标识符为1.2.840.113556.1.4.319。
|
criticality, id, value
CRITICAL, NONCRITICAL
Constructor and Description |
---|
PagedResultsControl(int pageSize, boolean criticality)
构造一个控件以设置每页结果返回的条目数。
|
PagedResultsControl(int pageSize, byte[] cookie, boolean criticality)
构造一个控件以设置每页结果返回的条目数。
|
public static final String OID
public PagedResultsControl(int pageSize, boolean criticality) throws IOException
pageSize
- 页面中要返回的条目数。
criticality
- 如果为true,则服务器必须遵守由pageSize所指示的控制并返回搜索结果,否则拒绝执行搜索。
如果是虚假的,那么服务器不需要尊重控制权。
IOException
- 如果在将所提供的参数编码到控件中时遇到错误。
public PagedResultsControl(int pageSize, byte[] cookie, boolean criticality) throws IOException
通过将pageSize设置为零并将cookie设置为从服务器接收的最后一个cookie,可以放弃一系列分页结果。
pageSize
- 页面返回的条目数。
cookie
- 可能为空的服务器生成的cookie。
criticality
- 如果为true,则服务器必须遵守由pageSize所指示的控制和返回搜索结果,否则拒绝执行搜索。
如果是虚假的,那么服务器不需要尊重控制权。
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.