Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/EntryChangeResponseControl.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;28import javax.naming.*;29import javax.naming.directory.*;3031/**32* This class implements the LDAPv3 Response Control for entry-change33* notification as defined in34* <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.35*36* The control's value has the following ASN.1 definition:37* <pre>38*39* EntryChangeNotification ::= SEQUENCE {40* changeType ENUMERATED {41* add (1),42* delete (2),43* modify (4),44* modDN (8)45* },46* previousDN LDAPDN OPTIONAL, -- modifyDN ops. only47* changeNumber INTEGER OPTIONAL, -- if supported48* }49*50* </pre>51*52* @see PersistentSearchControl53* @see com.sun.jndi.ldap.ctl.ResponseControlFactory ResponseControlFactory54* @author Vincent Ryan55*/56public final class EntryChangeResponseControl extends BasicControl {5758/**59* The entry-change response control's assigned object identifier60* is 2.16.840.1.113730.3.4.7.61*/62public static final String OID = "2.16.840.1.113730.3.4.7";6364/**65* Indicates an entry which has been added.66*/67public static final int ADD = 1;6869/**70* Indicates an entry which has been deleted.71*/72public static final int DELETE = 2;7374/**75* Indicates an entry which has been modified.76*/77public static final int MODIFY = 4;7879/**80* Indicates an entry which has been renamed.81*/82public static final int RENAME = 8;8384/**85* The type of change that occurred.86*87* @serial88*/89private int changeType;9091/**92* The previous distinguished name (only applies to RENAME changes).93*94* @serial95*/96private String previousDN = null;9798/**99* The change number (if supported by the server).100*101* @serial102*/103private long changeNumber = -1L;104105private static final long serialVersionUID = -2087354136750180511L;106107/**108* Constructs a new instance of EntryChangeResponseControl.109*110* @param id The control's object identifier string.111* @param criticality The control's criticality.112* @param value The control's ASN.1 BER encoded value.113* May be null.114* @exception IOException if an error is encountered115* while decoding the control's value.116*/117public EntryChangeResponseControl(String id, boolean criticality,118byte[] value) throws IOException {119120super(id, criticality, value);121122// decode value123if ((value != null) && (value.length > 0)) {124BerDecoder ber = new BerDecoder(value, 0, value.length);125126ber.parseSeq(null);127changeType = ber.parseEnumeration();128129if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_OCTET_STR)){130previousDN = ber.parseString(true);131}132if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_INTEGER)) {133changeNumber = ber.parseInt();134}135}136}137138/**139* Retrieves the type of change that occurred.140*141* @return The type of change.142*/143public int getChangeType() {144return changeType;145}146147/**148* Retrieves the previous distinguished name of the entry before it was149* renamed and/or moved. This method applies only to RENAME changes.150*151* @return The previous distinguished name or null if not applicable.152*/153public String getPreviousDN() {154return previousDN;155}156157/**158* Retrieves the change number assigned by the server for this change.159* Returns -1 if this feature is not supported by the server.160*161* @return The change number or -1 if unsupported.162*/163public long getChangeNumber() {164return changeNumber;165}166}167168169