You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/11/21 08:58:21 UTC
svn commit: r596975 - in /harmony/enhanced/classlib/trunk/modules/jndi/src:
main/java/org/apache/harmony/jndi/provider/ldap/
main/java/org/apache/harmony/jndi/provider/ldap/asn1/
main/java/org/apache/harmony/jndi/provider/ldap/event/ test/java/org/apac...
Author: pyang
Date: Tue Nov 20 23:58:19 2007
New Revision: 596975
URL: http://svn.apache.org/viewvc?rev=596975&view=rev
Log:
Apply patch for HARMONY-5118 ([classlib][jndi][ldap] implements UnsolicitedNotification, EntryChangeNotification and PersistentSearch control)
Added:
harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/
harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/ECNotificationControl.java
harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControl.java
harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/event/
harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControlTest.java
Modified:
harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java?rev=596975&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java Tue Nov 20 23:58:19 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.jndi.provider.ldap;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.UnsolicitedNotification;
+
+import org.apache.harmony.jndi.internal.Util;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+public class UnsolicitedNotificationImpl implements UnsolicitedNotification,
+ ASN1Decodable {
+
+ private static final long serialVersionUID = 3063973693971731355L;
+
+ private LdapResult result;
+
+ private String oid;
+
+ private byte[] encodedValue;
+
+ private Control[] controls;
+
+ public void decodeValues(Object[] values) {
+ result = new LdapResult();
+ result.decodeValues(values);
+ oid = Utils.getString(values[4]);
+ if (values[5] != null) {
+ encodedValue = (byte[]) values[5];
+ }
+ }
+
+ public NamingException getException() {
+ return Util.getExceptionFromErrorCode(result.getResultCode());
+ }
+
+ public String[] getReferrals() {
+ return result.getReferrals();
+ }
+
+ public byte[] getEncodedValue() {
+ return encodedValue;
+ }
+
+ public String getID() {
+ return oid;
+ }
+
+ public Control[] getControls() throws NamingException {
+ return controls;
+ }
+
+ public void setControls(Control[] controls) {
+ this.controls = controls;
+ }
+
+}
Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java?rev=596975&r1=596974&r2=596975&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java Tue Nov 20 23:58:19 2007
@@ -355,4 +355,19 @@
setOptional(2);
}
};
+
+ public static final ASN1Type PersistentSearchControl = new ASN1SequenceWrap(
+ new ASN1Type[] { new ASN1Integer(), // changeTypes
+ new ASN1Boolean(), // changesOnly
+ new ASN1Boolean() }); // returnECs
+
+ public static final ASN1Type EntryChangeNotificationControl = new ASN1SequenceWrap(
+ new ASN1Type[] { new ASN1Enumerated(), // changeType
+ new ASN1OctetString(), // previousDN
+ new ASN1Integer() }) { // changeNumber
+ {
+ setOptional(1);
+ setOptional(2);
+ }
+ };
}
Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/ECNotificationControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/ECNotificationControl.java?rev=596975&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/ECNotificationControl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/ECNotificationControl.java Tue Nov 20 23:58:19 2007
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.jndi.provider.ldap.event;
+
+import java.io.IOException;
+
+import javax.naming.event.NamingEvent;
+import javax.naming.ldap.BasicControl;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+import org.apache.harmony.security.asn1.ASN1Integer;
+
+/**
+ * This class implements EntryChangeNotification control which defined in
+ * {@link http://www3.ietf.org/proceedings/01mar/I-D/ldapext-psearch-03.txt}.
+ *
+ *
+ */
+public class ECNotificationControl extends BasicControl implements
+ ASN1Decodable {
+
+ private int changeType;
+
+ private String previousDN;
+
+ private int changeNumber;
+
+ private static final long serialVersionUID = -1540666440189313315L;
+
+ public static final String OID = "2.16.840.1.113730.3.4.7"; //$NON-NLS-1$
+
+ public static final int ADD = 1;
+
+ public static final int DELETE = 2;
+
+ public static final int MODIFY = 4;
+
+ public static final int MODIFY_DN = 8;
+
+ public ECNotificationControl(byte[] encoded) {
+ super(OID, true, encoded);
+
+ decodeContend();
+ }
+
+ private void decodeContend() {
+ try {
+ Object[] values = (Object[]) LdapASN1Constant.EntryChangeNotificationControl
+ .decode(value);
+ decodeValues(values);
+ } catch (IOException e) {
+ // FIXME how to deal with the exception
+ }
+ }
+
+ public int getChangeNumber() {
+ return changeNumber;
+ }
+
+ /**
+ * get enumerated change type value defined in
+ * {@link http://www3.ietf.org/proceedings/01mar/I-D/ldapext-psearch-03.txt}
+ *
+ * @return change type value
+ */
+ public int getChangeType() {
+ return changeType;
+ }
+
+ /**
+ * get JNDI defined change type value which is different with
+ * <code>getChangeType()</code>
+ *
+ * @return JNDI defined change type value
+ */
+ public int getJNDIChangeType() {
+ switch (changeType) {
+ case ADD:
+ return NamingEvent.OBJECT_ADDED;
+ case DELETE:
+ return NamingEvent.OBJECT_REMOVED;
+ case MODIFY:
+ return NamingEvent.OBJECT_CHANGED;
+ case MODIFY_DN:
+ return NamingEvent.OBJECT_RENAMED;
+ default:
+ // never reach
+ return -1;
+ }
+
+ }
+
+ public String getPreviousDN() {
+ return previousDN;
+ }
+
+ public void decodeValues(Object[] values) {
+ changeType = ASN1Integer.toIntValue(values[0]);
+ if (values[1] != null) {
+ previousDN = Utils.getString(values[1]);
+ }
+
+ if (values[2] != null) {
+ changeNumber = ASN1Integer.toIntValue(values[2]);
+ }
+ }
+
+}
Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControl.java?rev=596975&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControl.java Tue Nov 20 23:58:19 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.jndi.provider.ldap.event;
+
+import javax.naming.ldap.BasicControl;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.security.asn1.ASN1Integer;
+
+/**
+ * This class implements PersistentSearch control defined in
+ * {@link http://www3.ietf.org/proceedings/01mar/I-D/ldapext-psearch-03.txt}.
+ *
+ * This control extend LDAPv3 search operation, so client can receive
+ * notifications of changes from server.
+ */
+public class PersistentSearchControl extends BasicControl implements
+ ASN1Encodable {
+
+ private static final long serialVersionUID = -524784347976291935L;
+
+ public static final String OID = "2.16.840.1.113730.3.4.3"; //$NON-NLS-1$
+
+ private int changeTypes;
+
+ private boolean changesOnly;
+
+ private boolean returnECs;
+
+ public PersistentSearchControl() {
+ // register all types of changes
+ this(1 | 2 | 4 | 8, true, true);
+ }
+
+ public PersistentSearchControl(int types, boolean changesOnly,
+ boolean returnECs) {
+ super(OID, true, null);
+ this.changesOnly = changesOnly;
+ this.returnECs = returnECs;
+ this.changeTypes = types;
+ value = getValue();
+ }
+
+ /**
+ * Get encoded content of persistent search control, which not include
+ * <code>OID</code>
+ *
+ * @return encoded content
+ */
+ private byte[] getValue() {
+ return LdapASN1Constant.PersistentSearchControl.encode(this);
+ }
+
+ public void encodeValues(Object[] values) {
+ values[0] = ASN1Integer.fromIntValue(changeTypes);
+ values[1] = Boolean.valueOf(changesOnly);
+ values[2] = Boolean.valueOf(returnECs);
+
+ }
+
+ public boolean isChangesOnly() {
+ return changesOnly;
+ }
+
+ public int getChangeTypes() {
+ return changeTypes;
+ }
+
+ public boolean isReturnECs() {
+ return returnECs;
+ }
+
+}
Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControlTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControlTest.java?rev=596975&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControlTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/event/PersistentSearchControlTest.java Tue Nov 20 23:58:19 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.jndi.provider.ldap.event;
+
+import org.apache.harmony.jndi.provider.ldap.LdapControl;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+
+import junit.framework.TestCase;
+
+public class PersistentSearchControlTest extends TestCase {
+
+ public void test_encodeValues_$LObject() {
+ PersistentSearchControl controls = new PersistentSearchControl();
+
+ ASN1TestUtils.checkEncode(controls,
+ LdapASN1Constant.PersistentSearchControl);
+
+ ASN1TestUtils.checkEncode(new LdapControl(controls),
+ LdapASN1Constant.Control);
+ }
+
+ public void test_constructor() {
+ PersistentSearchControl controls = new PersistentSearchControl();
+ assertTrue(controls.isChangesOnly());
+ assertEquals(1 | 2 | 4 | 8, controls.getChangeTypes());
+ assertEquals(PersistentSearchControl.OID, controls.getID());
+ assertTrue(controls.isCritical());
+ assertTrue(controls.isReturnECs());
+ }
+}