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/Aimport javax.naming.*;
0N/Aimport javax.naming.directory.*;
0N/A
0N/A/**
0N/A * This class implements the LDAPv3 Response Control for entry-change
0N/A * notification 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 * EntryChangeNotification ::= SEQUENCE {
0N/A * changeType ENUMERATED {
0N/A * add (1),
0N/A * delete (2),
0N/A * modify (4),
0N/A * modDN (8)
0N/A * },
0N/A * previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
0N/A * changeNumber INTEGER OPTIONAL, -- if supported
0N/A * }
0N/A *
0N/A * </pre>
0N/A *
0N/A * @see PersistentSearchControl
0N/A * @see com.sun.jndi.ldap.ctl.ResponseControlFactory ResponseControlFactory
0N/A * @author Vincent Ryan
0N/A */
0N/Afinal public class EntryChangeResponseControl extends BasicControl {
0N/A
0N/A /**
0N/A * The entry-change response control's assigned object identifier
0N/A * is 2.16.840.1.113730.3.4.7.
0N/A */
0N/A public static final String OID = "2.16.840.1.113730.3.4.7";
0N/A
0N/A /**
0N/A * Indicates an entry which has been added.
0N/A */
0N/A public static final int ADD = 1;
0N/A
0N/A /**
0N/A * Indicates an entry which has been deleted.
0N/A */
0N/A public static final int DELETE = 2;
0N/A
0N/A /**
0N/A * Indicates an entry which has been modified.
0N/A */
0N/A public static final int MODIFY = 4;
0N/A
0N/A /**
0N/A * Indicates an entry which has been renamed.
0N/A */
0N/A public static final int RENAME = 8;
0N/A
0N/A /**
0N/A * The type of change that occurred.
0N/A *
0N/A * @serial
0N/A */
0N/A private int changeType;
0N/A
0N/A /**
0N/A * The previous distinguished name (only applies to RENAME changes).
0N/A *
0N/A * @serial
0N/A */
0N/A private String previousDN = null;
0N/A
0N/A /**
0N/A * The change number (if supported by the server).
0N/A *
0N/A * @serial
0N/A */
0N/A private long changeNumber = -1L;
0N/A
0N/A private static final long serialVersionUID = -2087354136750180511L;
0N/A
0N/A /**
0N/A * Constructs a new instance of EntryChangeResponseControl.
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 * May be null.
0N/A * @exception IOException if an error is encountered
0N/A * while decoding the control's value.
0N/A */
0N/A public EntryChangeResponseControl(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 if ((value != null) && (value.length > 0)) {
0N/A BerDecoder ber = new BerDecoder(value, 0, value.length);
0N/A
0N/A ber.parseSeq(null);
0N/A changeType = ber.parseEnumeration();
0N/A
0N/A if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_OCTET_STR)){
0N/A previousDN = ber.parseString(true);
0N/A }
0N/A if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_INTEGER)) {
0N/A changeNumber = ber.parseInt();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the type of change that occurred.
0N/A *
0N/A * @return The type of change.
0N/A */
0N/A public int getChangeType() {
0N/A return changeType;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the previous distinguished name of the entry before it was
0N/A * renamed and/or moved. This method applies only to RENAME changes.
0N/A *
0N/A * @return The previous distinguished name or null if not applicable.
0N/A */
0N/A public String getPreviousDN() {
0N/A return previousDN;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the change number assigned by the server for this change.
0N/A * Returns -1 if this feature is not supported by the server.
0N/A *
0N/A * @return The change number or -1 if unsupported.
0N/A */
0N/A public long getChangeNumber() {
0N/A return changeNumber;
0N/A }
0N/A}