KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > ldap > PagedResultsResponseControl


1 /*
2  * @(#)PagedResultsResponseControl.java 1.3 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.naming.ldap;
9
10 import java.io.IOException JavaDoc;
11 import com.sun.jndi.ldap.Ber;
12 import com.sun.jndi.ldap.BerDecoder;
13
14 /**
15  * Indicates the end of a batch of search results.
16  * Contains an estimate of the total number of entries in the result set
17  * and an opaque cookie. The cookie must be supplied to the next search
18  * operation in order to get the next batch of results.
19  * <p>
20  * The code sample in {@link PagedResultsControl} shows how this class may
21  * be used.
22  * <p>
23  * This class implements the LDAPv3 Response Control for
24  * paged-results as defined in
25  * <a HREF="http://www.ietf.org/rfc/rfc2696">RFC 2696</a>.
26  *
27  * The control's value has the following ASN.1 definition:
28  * <pre>
29  *
30  * realSearchControlValue ::= SEQUENCE {
31  * size INTEGER (0..maxInt),
32  * -- requested page size from client
33  * -- result set size estimate from server
34  * cookie OCTET STRING
35  * }
36  *
37  * </pre>
38  *
39  * @since 1.5
40  * @see PagedResultsControl
41  * @author Vincent Ryan
42  */

43 final public class PagedResultsResponseControl extends BasicControl JavaDoc {
44
45     /**
46      * The paged-results response control's assigned object identifier
47      * is 1.2.840.113556.1.4.319.
48      */

49     public static final String JavaDoc OID = "1.2.840.113556.1.4.319";
50
51     private static final long serialVersionUID = -8819778744844514666L;
52
53     /**
54      * An estimate of the number of entries in the search result.
55      *
56      * @serial
57      */

58     private int resultSize;
59
60     /**
61      * A server-generated cookie.
62      *
63      * @serial
64      */

65     private byte[] cookie;
66
67     /**
68      * Constructs a paged-results response control.
69      *
70      * @param id The control's object identifier string.
71      * @param criticality The control's criticality.
72      * @param value The control's ASN.1 BER encoded value.
73      * It is not cloned - any changes to value
74      * will affect the contents of the control.
75      * @exception IOException If an error was encountered while decoding
76      * the control's value.
77      */

78     public PagedResultsResponseControl(String JavaDoc id, boolean criticality,
79         byte[] value) throws IOException JavaDoc {
80
81         super(id, criticality, value);
82
83         // decode value
84
BerDecoder ber = new BerDecoder(value, 0, value.length);
85
86         ber.parseSeq(null);
87         resultSize = ber.parseInt();
88     cookie = ber.parseOctetString(Ber.ASN_OCTET_STR, null);
89     }
90
91     /**
92      * Retrieves (an estimate of) the number of entries in the search result.
93      *
94      * @return The number of entries in the search result, or zero if unknown.
95      */

96     public int getResultSize() {
97         return resultSize;
98     }
99
100     /**
101      * Retrieves the server-generated cookie. Null is returned when there are
102      * no more entries for the server to return.
103      *
104      * @return A possibly null server-generated cookie. It is not cloned - any
105      * changes to the cookie will update the control's state and thus
106      * are not recommended.
107      */

108     public byte[] getCookie() {
109     if (cookie.length == 0) {
110         return null;
111     } else {
112             return cookie;
113     }
114     }
115 }
116
Popular Tags