001: /*
002: * Copyright 1999-2002 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.jndi.ldap;
027:
028: import java.io.IOException;
029: import javax.naming.*;
030: import javax.naming.directory.*;
031:
032: /**
033: * This class implements the LDAPv3 Response Control for entry-change
034: * notification as defined in
035: * <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.
036: *
037: * The control's value has the following ASN.1 definition:
038: * <pre>
039: *
040: * EntryChangeNotification ::= SEQUENCE {
041: * changeType ENUMERATED {
042: * add (1),
043: * delete (2),
044: * modify (4),
045: * modDN (8)
046: * },
047: * previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
048: * changeNumber INTEGER OPTIONAL, -- if supported
049: * }
050: *
051: * </pre>
052: *
053: * @see PersistentSearchControl
054: * @see com.sun.jndi.ldap.ctl.ResponseControlFactory ResponseControlFactory
055: * @author Vincent Ryan
056: */
057: final public class EntryChangeResponseControl extends BasicControl {
058:
059: /**
060: * The entry-change response control's assigned object identifier
061: * is 2.16.840.1.113730.3.4.7.
062: */
063: public static final String OID = "2.16.840.1.113730.3.4.7";
064:
065: /**
066: * Indicates an entry which has been added.
067: */
068: public static final int ADD = 1;
069:
070: /**
071: * Indicates an entry which has been deleted.
072: */
073: public static final int DELETE = 2;
074:
075: /**
076: * Indicates an entry which has been modified.
077: */
078: public static final int MODIFY = 4;
079:
080: /**
081: * Indicates an entry which has been renamed.
082: */
083: public static final int RENAME = 8;
084:
085: /**
086: * The type of change that occurred.
087: *
088: * @serial
089: */
090: private int changeType;
091:
092: /**
093: * The previous distinguished name (only applies to RENAME changes).
094: *
095: * @serial
096: */
097: private String previousDN = null;
098:
099: /**
100: * The change number (if supported by the server).
101: *
102: * @serial
103: */
104: private long changeNumber = -1L;
105:
106: private static final long serialVersionUID = -2087354136750180511L;
107:
108: /**
109: * Constructs a new instance of EntryChangeResponseControl.
110: *
111: * @param id The control's object identifier string.
112: * @param criticality The control's criticality.
113: * @param value The control's ASN.1 BER encoded value.
114: * May be null.
115: * @exception IOException if an error is encountered
116: * while decoding the control's value.
117: */
118: public EntryChangeResponseControl(String id, boolean criticality,
119: byte[] value) throws IOException {
120:
121: super (id, criticality, value);
122:
123: // decode value
124: if ((value != null) && (value.length > 0)) {
125: BerDecoder ber = new BerDecoder(value, 0, value.length);
126:
127: ber.parseSeq(null);
128: changeType = ber.parseEnumeration();
129:
130: if ((ber.bytesLeft() > 0)
131: && (ber.peekByte() == Ber.ASN_OCTET_STR)) {
132: previousDN = ber.parseString(true);
133: }
134: if ((ber.bytesLeft() > 0)
135: && (ber.peekByte() == Ber.ASN_INTEGER)) {
136: changeNumber = ber.parseInt();
137: }
138: }
139: }
140:
141: /**
142: * Retrieves the type of change that occurred.
143: *
144: * @return The type of change.
145: */
146: public int getChangeType() {
147: return changeType;
148: }
149:
150: /**
151: * Retrieves the previous distinguished name of the entry before it was
152: * renamed and/or moved. This method applies only to RENAME changes.
153: *
154: * @return The previous distinguished name or null if not applicable.
155: */
156: public String getPreviousDN() {
157: return previousDN;
158: }
159:
160: /**
161: * Retrieves the change number assigned by the server for this change.
162: * Returns -1 if this feature is not supported by the server.
163: *
164: * @return The change number or -1 if unsupported.
165: */
166: public long getChangeNumber() {
167: return changeNumber;
168: }
169: }
|