jdk/src/java.naming/share/classes/com/sun/jndi/ldap/PersistentSearchControl.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 5506 jdk/src/share/classes/com/sun/jndi/ldap/PersistentSearchControl.java@202f599c92aa
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
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) 1999, 2002, 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 com.sun.jndi.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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class implements the LDAPv3 Request Control for the persistent search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * mechanism as defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The control's value has the following ASN.1 definition:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *     PersistentSearch ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *         changeTypes INTEGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *         changesOnly BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *         returnECs BOOLEAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see EntryChangeResponseControl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Vincent Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
final public class PersistentSearchControl extends BasicControl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The persistent search control's assigned object identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * is 2.16.840.1.113730.3.4.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final String OID = "2.16.840.1.113730.3.4.3";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Indicates interest in entries which have been added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static final int ADD = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Indicates interest in entries which have been deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static final int DELETE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Indicates interest in entries which have been modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final int MODIFY = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Indicates interest in entries which have been renamed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int RENAME = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Indicates interest in entries which have been added, deleted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * modified or renamed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int ANY = ADD | DELETE | MODIFY | RENAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * The change types of interest. All changes, by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private int changeTypes = ANY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Return original entries and changed entries or only changed entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private boolean changesOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Return entry change controls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private boolean returnControls = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final long serialVersionUID = 6335140491154854116L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Constructs a persistent search non-critical control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * The original entries, any changed entries (additions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * deletions, modifications or renames) and entry change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * controls are requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @exception IOException If a BER encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public PersistentSearchControl() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        super(OID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        super.value = setEncodedValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Constructs a persistent search control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param   changeTypes     The change types of interest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param   changesOnly     Return original entries and changed entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *                          or only the changed entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param   returnControls  Return entry change controls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param   criticality     The control's criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @exception IOException If a BER encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public PersistentSearchControl(int changeTypes, boolean changesOnly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        boolean returnControls, boolean criticality) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super(OID, criticality, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        this.changeTypes = changeTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this.changesOnly = changesOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        this.returnControls = returnControls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super.value = setEncodedValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Sets the ASN.1 BER encoded value of the persistent search control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * The result is the raw BER bytes including the tag and length of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * the control's value. It does not include the controls OID or criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return A possibly null byte array representing the ASN.1 BER encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *         value of the LDAP persistent search control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @exception IOException If a BER encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private byte[] setEncodedValue() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // build the ASN.1 encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        BerEncoder ber = new BerEncoder(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            ber.encodeInt(changeTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            ber.encodeBoolean(changesOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            ber.encodeBoolean(returnControls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return ber.getTrimmedBuf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}