Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/PersistentSearchControl.java
41161 views
/*1* Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.ldap;2627import java.io.IOException;2829/**30* This class implements the LDAPv3 Request Control for the persistent search31* mechanism as defined in32* <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.33*34* The control's value has the following ASN.1 definition:35* <pre>36*37* PersistentSearch ::= SEQUENCE {38* changeTypes INTEGER,39* changesOnly BOOLEAN,40* returnECs BOOLEAN41* }42*43* </pre>44*45* @see EntryChangeResponseControl46* @author Vincent Ryan47*/48public final class PersistentSearchControl extends BasicControl {4950/**51* The persistent search control's assigned object identifier52* is 2.16.840.1.113730.3.4.3.53*/54public static final String OID = "2.16.840.1.113730.3.4.3";5556/**57* Indicates interest in entries which have been added.58*/59public static final int ADD = 1;6061/**62* Indicates interest in entries which have been deleted.63*/64public static final int DELETE = 2;6566/**67* Indicates interest in entries which have been modified.68*/69public static final int MODIFY = 4;7071/**72* Indicates interest in entries which have been renamed.73*/74public static final int RENAME = 8;7576/**77* Indicates interest in entries which have been added, deleted,78* modified or renamed.79*/80public static final int ANY = ADD | DELETE | MODIFY | RENAME;8182/**83* The change types of interest. All changes, by default.84*85* @serial86*/87private int changeTypes = ANY;8889/**90* Return original entries and changed entries or only changed entries.91*92* @serial93*/94private boolean changesOnly = false;9596/**97* Return entry change controls.98*99* @serial100*/101private boolean returnControls = true;102103private static final long serialVersionUID = 6335140491154854116L;104105/**106* Constructs a persistent search non-critical control.107* The original entries, any changed entries (additions,108* deletions, modifications or renames) and entry change109* controls are requested.110*111* @exception IOException If a BER encoding error occurs.112*/113public PersistentSearchControl() throws IOException {114super(OID);115super.value = setEncodedValue();116}117118/**119* Constructs a persistent search control.120*121* @param changeTypes The change types of interest.122* @param changesOnly Return original entries and changed entries123* or only the changed entries.124* @param returnControls Return entry change controls.125* @param criticality The control's criticality.126* @exception IOException If a BER encoding error occurs.127*/128public PersistentSearchControl(int changeTypes, boolean changesOnly,129boolean returnControls, boolean criticality) throws IOException {130131super(OID, criticality, null);132this.changeTypes = changeTypes;133this.changesOnly = changesOnly;134this.returnControls = returnControls;135super.value = setEncodedValue();136}137138/*139* Sets the ASN.1 BER encoded value of the persistent search control.140* The result is the raw BER bytes including the tag and length of141* the control's value. It does not include the controls OID or criticality.142*143* @return A possibly null byte array representing the ASN.1 BER encoded144* value of the LDAP persistent search control.145* @exception IOException If a BER encoding error occurs.146*/147private byte[] setEncodedValue() throws IOException {148149// build the ASN.1 encoding150BerEncoder ber = new BerEncoder(32);151152ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);153ber.encodeInt(changeTypes);154ber.encodeBoolean(changesOnly);155ber.encodeBoolean(returnControls);156ber.endSeq();157158return ber.getTrimmedBuf();159}160}161162163