0N/A/*
2362N/A * Copyright (c) 1999, 2002, 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 com.sun.jndi.ldap;
0N/A
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * This class implements the LDAPv3 Request Control for the persistent search
0N/A * mechanism as defined in
0N/A * <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.
0N/A *
0N/A * The control's value has the following ASN.1 definition:
0N/A * <pre>
0N/A *
0N/A * PersistentSearch ::= SEQUENCE {
0N/A * changeTypes INTEGER,
0N/A * changesOnly BOOLEAN,
0N/A * returnECs BOOLEAN
0N/A * }
0N/A *
0N/A * </pre>
0N/A *
0N/A * @see EntryChangeResponseControl
0N/A * @author Vincent Ryan
0N/A */
0N/Afinal public class PersistentSearchControl extends BasicControl {
0N/A
0N/A /**
0N/A * The persistent search control's assigned object identifier
0N/A * is 2.16.840.1.113730.3.4.3.
0N/A */
0N/A public static final String OID = "2.16.840.1.113730.3.4.3";
0N/A
0N/A /**
0N/A * Indicates interest in entries which have been added.
0N/A */
0N/A public static final int ADD = 1;
0N/A
0N/A /**
0N/A * Indicates interest in entries which have been deleted.
0N/A */
0N/A public static final int DELETE = 2;
0N/A
0N/A /**
0N/A * Indicates interest in entries which have been modified.
0N/A */
0N/A public static final int MODIFY = 4;
0N/A
0N/A /**
0N/A * Indicates interest in entries which have been renamed.
0N/A */
0N/A public static final int RENAME = 8;
0N/A
0N/A /**
0N/A * Indicates interest in entries which have been added, deleted,
0N/A * modified or renamed.
0N/A */
0N/A public static final int ANY = ADD | DELETE | MODIFY | RENAME;
0N/A
0N/A /**
0N/A * The change types of interest. All changes, by default.
0N/A *
0N/A * @serial
0N/A */
0N/A private int changeTypes = ANY;
0N/A
0N/A /**
0N/A * Return original entries and changed entries or only changed entries.
0N/A *
0N/A * @serial
0N/A */
0N/A private boolean changesOnly = false;
0N/A
0N/A /**
0N/A * Return entry change controls.
0N/A *
0N/A * @serial
0N/A */
0N/A private boolean returnControls = true;
0N/A
0N/A private static final long serialVersionUID = 6335140491154854116L;
0N/A
0N/A /**
0N/A * Constructs a persistent search non-critical control.
0N/A * The original entries, any changed entries (additions,
0N/A * deletions, modifications or renames) and entry change
0N/A * controls are requested.
0N/A *
0N/A * @exception IOException If a BER encoding error occurs.
0N/A */
0N/A public PersistentSearchControl() throws IOException {
0N/A super(OID);
0N/A super.value = setEncodedValue();
0N/A }
0N/A
0N/A /**
0N/A * Constructs a persistent search control.
0N/A *
0N/A * @param changeTypes The change types of interest.
0N/A * @param changesOnly Return original entries and changed entries
0N/A * or only the changed entries.
0N/A * @param returnControls Return entry change controls.
0N/A * @param criticality The control's criticality.
0N/A * @exception IOException If a BER encoding error occurs.
0N/A */
0N/A public PersistentSearchControl(int changeTypes, boolean changesOnly,
0N/A boolean returnControls, boolean criticality) throws IOException {
0N/A
0N/A super(OID, criticality, null);
0N/A this.changeTypes = changeTypes;
0N/A this.changesOnly = changesOnly;
0N/A this.returnControls = returnControls;
0N/A super.value = setEncodedValue();
0N/A }
0N/A
0N/A /*
0N/A * Sets the ASN.1 BER encoded value of the persistent search control.
0N/A * The result is the raw BER bytes including the tag and length of
0N/A * the control's value. It does not include the controls OID or criticality.
0N/A *
0N/A * @return A possibly null byte array representing the ASN.1 BER encoded
0N/A * value of the LDAP persistent search control.
0N/A * @exception IOException If a BER encoding error occurs.
0N/A */
0N/A private byte[] setEncodedValue() throws IOException {
0N/A
0N/A // build the ASN.1 encoding
0N/A BerEncoder ber = new BerEncoder(32);
0N/A
0N/A ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
0N/A ber.encodeInt(changeTypes);
0N/A ber.encodeBoolean(changesOnly);
0N/A ber.encodeBoolean(returnControls);
0N/A ber.endSeq();
0N/A
0N/A return ber.getTrimmedBuf();
0N/A }
0N/A}