0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.naming.ldap;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport com.sun.jndi.ldap.Ber;
0N/Aimport com.sun.jndi.ldap.BerDecoder;
0N/A
0N/A/**
0N/A * Indicates the end of a batch of search results.
0N/A * Contains an estimate of the total number of entries in the result set
0N/A * and an opaque cookie. The cookie must be supplied to the next search
0N/A * operation in order to get the next batch of results.
0N/A * <p>
0N/A * The code sample in {@link PagedResultsControl} shows how this class may
0N/A * be used.
0N/A * <p>
0N/A * This class implements the LDAPv3 Response Control for
0N/A * paged-results as defined in
0N/A * <a href="http://www.ietf.org/rfc/rfc2696">RFC 2696</a>.
0N/A *
0N/A * The control's value has the following ASN.1 definition:
0N/A * <pre>
0N/A *
0N/A * realSearchControlValue ::= SEQUENCE {
0N/A * size INTEGER (0..maxInt),
0N/A * -- requested page size from client
0N/A * -- result set size estimate from server
0N/A * cookie OCTET STRING
0N/A * }
0N/A *
0N/A * </pre>
0N/A *
0N/A * @since 1.5
0N/A * @see PagedResultsControl
0N/A * @author Vincent Ryan
0N/A */
0N/Afinal public class PagedResultsResponseControl extends BasicControl {
0N/A
0N/A /**
0N/A * The paged-results response control's assigned object identifier
0N/A * is 1.2.840.113556.1.4.319.
0N/A */
0N/A public static final String OID = "1.2.840.113556.1.4.319";
0N/A
0N/A private static final long serialVersionUID = -8819778744844514666L;
0N/A
0N/A /**
0N/A * An estimate of the number of entries in the search result.
0N/A *
0N/A * @serial
0N/A */
0N/A private int resultSize;
0N/A
0N/A /**
0N/A * A server-generated cookie.
0N/A *
0N/A * @serial
0N/A */
0N/A private byte[] cookie;
0N/A
0N/A /**
0N/A * Constructs a paged-results response control.
0N/A *
0N/A * @param id The control's object identifier string.
0N/A * @param criticality The control's criticality.
0N/A * @param value The control's ASN.1 BER encoded value.
0N/A * It is not cloned - any changes to value
0N/A * will affect the contents of the control.
0N/A * @exception IOException If an error was encountered while decoding
0N/A * the control's value.
0N/A */
0N/A public PagedResultsResponseControl(String id, boolean criticality,
0N/A byte[] value) throws IOException {
0N/A
0N/A super(id, criticality, value);
0N/A
0N/A // decode value
0N/A BerDecoder ber = new BerDecoder(value, 0, value.length);
0N/A
0N/A ber.parseSeq(null);
0N/A resultSize = ber.parseInt();
0N/A cookie = ber.parseOctetString(Ber.ASN_OCTET_STR, null);
0N/A }
0N/A
0N/A /**
0N/A * Retrieves (an estimate of) the number of entries in the search result.
0N/A *
0N/A * @return The number of entries in the search result, or zero if unknown.
0N/A */
0N/A public int getResultSize() {
0N/A return resultSize;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the server-generated cookie. Null is returned when there are
0N/A * no more entries for the server to return.
0N/A *
0N/A * @return A possibly null server-generated cookie. It is not cloned - any
0N/A * changes to the cookie will update the control's state and thus
0N/A * are not recommended.
0N/A */
0N/A public byte[] getCookie() {
0N/A if (cookie.length == 0) {
0N/A return null;
0N/A } else {
0N/A return cookie;
0N/A }
0N/A }
0N/A}