001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.jndi.provider.ldap.event;
019:
020: import java.io.IOException;
021:
022: import javax.naming.event.NamingEvent;
023: import javax.naming.ldap.BasicControl;
024:
025: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
026: import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
027: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
028: import org.apache.harmony.security.asn1.ASN1Integer;
029:
030: /**
031: * This class implements EntryChangeNotification control which defined in
032: * {@link http://www3.ietf.org/proceedings/01mar/I-D/ldapext-psearch-03.txt}.
033: *
034: *
035: */
036: public class ECNotificationControl extends BasicControl implements
037: ASN1Decodable {
038:
039: private int changeType;
040:
041: private String previousDN;
042:
043: private int changeNumber;
044:
045: private static final long serialVersionUID = -1540666440189313315L;
046:
047: public static final String OID = "2.16.840.1.113730.3.4.7"; //$NON-NLS-1$
048:
049: public static final int ADD = 1;
050:
051: public static final int DELETE = 2;
052:
053: public static final int MODIFY = 4;
054:
055: public static final int MODIFY_DN = 8;
056:
057: public ECNotificationControl(byte[] encoded) {
058: super (OID, true, encoded);
059:
060: decodeContend();
061: }
062:
063: private void decodeContend() {
064: try {
065: Object[] values = (Object[]) LdapASN1Constant.EntryChangeNotificationControl
066: .decode(value);
067: decodeValues(values);
068: } catch (IOException e) {
069: // FIXME how to deal with the exception
070: }
071: }
072:
073: public int getChangeNumber() {
074: return changeNumber;
075: }
076:
077: /**
078: * get enumerated change type value defined in
079: * {@link http://www3.ietf.org/proceedings/01mar/I-D/ldapext-psearch-03.txt}
080: *
081: * @return change type value
082: */
083: public int getChangeType() {
084: return changeType;
085: }
086:
087: /**
088: * get JNDI defined change type value which is different with
089: * <code>getChangeType()</code>
090: *
091: * @return JNDI defined change type value
092: */
093: public int getJNDIChangeType() {
094: switch (changeType) {
095: case ADD:
096: return NamingEvent.OBJECT_ADDED;
097: case DELETE:
098: return NamingEvent.OBJECT_REMOVED;
099: case MODIFY:
100: return NamingEvent.OBJECT_CHANGED;
101: case MODIFY_DN:
102: return NamingEvent.OBJECT_RENAMED;
103: default:
104: // never reach
105: return -1;
106: }
107:
108: }
109:
110: public String getPreviousDN() {
111: return previousDN;
112: }
113:
114: public void decodeValues(Object[] values) {
115: changeType = ASN1Integer.toIntValue(values[0]);
116: if (values[1] != null) {
117: previousDN = Utils.getString(values[1]);
118: }
119:
120: if (values[2] != null) {
121: changeNumber = ASN1Integer.toIntValue(values[2]);
122: }
123: }
124:
125: }
|