src/java.naming/share/classes/javax/naming/ldap/PagedResultsResponseControl.java
author stefank
Mon, 25 Nov 2019 15:00:32 +0100
changeset 59255 a74627659f96
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234602: ZGC: Windows compile error in ZHeuristic Reviewed-by: pliden, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jndi.ldap.Ber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jndi.ldap.BerDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Indicates the end of a batch of search results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Contains an estimate of the total number of entries in the result set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * and an opaque cookie. The cookie must be supplied to the next search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * operation in order to get the next batch of results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The code sample in {@link PagedResultsControl} shows how this class may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class implements the LDAPv3 Response Control for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * paged-results as defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <a href="http://www.ietf.org/rfc/rfc2696">RFC 2696</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The control's value has the following ASN.1 definition:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     realSearchControlValue ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *         size      INTEGER (0..maxInt),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *                           -- requested page size from client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *                           -- result set size estimate from server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *         cookie    OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see PagedResultsControl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Vincent Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
final public class PagedResultsResponseControl extends BasicControl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The paged-results response control's assigned object identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * is 1.2.840.113556.1.4.319.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final String OID = "1.2.840.113556.1.4.319";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final long serialVersionUID = -8819778744844514666L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * An estimate of the number of entries in the search result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private int resultSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * A server-generated cookie.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private byte[] cookie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Constructs a paged-results response control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param   id              The control's object identifier string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param   criticality     The control's criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param   value           The control's ASN.1 BER encoded value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *                          It is not cloned - any changes to value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *                          will affect the contents of the control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @exception IOException   If an error was encountered while decoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *                          the control's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public PagedResultsResponseControl(String id, boolean criticality,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        byte[] value) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super(id, criticality, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // decode value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        BerDecoder ber = new BerDecoder(value, 0, value.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        ber.parseSeq(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        resultSize = ber.parseInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        cookie = ber.parseOctetString(Ber.ASN_OCTET_STR, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Retrieves (an estimate of) the number of entries in the search result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return The number of entries in the search result, or zero if unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public int getResultSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return resultSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Retrieves the server-generated cookie. Null is returned when there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * no more entries for the server to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return A possibly null server-generated cookie. It is not cloned - any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *         changes to the cookie will update the control's state and thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *         are not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public byte[] getCookie() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (cookie.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return cookie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}