harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r599679 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/asn1/
Date Fri, 30 Nov 2007 02:49:30 GMT
Author: pyang
Date: Thu Nov 29 18:49:29 2007
New Revision: 599679

URL: http://svn.apache.org/viewvc?rev=599679&view=rev
Log:
Apply patch for HARMONY-5220 ([classlib][jndi][ldap] refactor LdapContextImpl using LdapUtils.parseFilter
to parse filter and some misc changeds)

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/UtilsTest.java
Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapUtils.java
    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/ldapURLContext.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapUtilsTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=599679&r1=599678&r2=599679&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Thu Nov 29 18:49:29 2007
@@ -1216,13 +1216,6 @@
         /*
          * there is only one ldap ns
          */
-        if (filter == null) {
-            throw new NullPointerException(Messages.getString("ldap.28")); //$NON-NLS-1$
-        }
-
-        if (objs == null) {
-            objs = new Object[0];
-        }
 
         if (searchControls == null) {
             searchControls = new SearchControls();
@@ -1230,17 +1223,8 @@
 
         // get absolute dn name
         String targetDN = getTargetDN(name, contextDn);
-        FilterParser filterParser = new FilterParser(filter);
-        filterParser.setArgs(objs);
-        Filter f = null;
-        try {
-            f = filterParser.parse();
-        } catch (ParseException e) {
-            InvalidSearchFilterException ex = new InvalidSearchFilterException(
-                    Messages.getString("ldap.29")); //$NON-NLS-1$
-            ex.setRootCause(e);
-            throw ex;
-        }
+        
+        Filter f = LdapUtils.parseFilter(filter, objs);
 
         LdapSearchResult result = doSearch(targetDN, f, searchControls);
 
@@ -2115,29 +2099,11 @@
             }
         }
 
-        if (filter == null) {
-            throw new NullPointerException(Messages.getString("ldap.28")); //$NON-NLS-1$
-        }
-
-        if (filterArgs == null) {
-            filterArgs = new Object[0];
-        }
-
         if (searchControls == null) {
             searchControls = new SearchControls();
         }
 
-        FilterParser filterParser = new FilterParser(filter);
-        filterParser.setArgs(filterArgs);
-        Filter f = null;
-        try {
-            f = filterParser.parse();
-        } catch (ParseException e) {
-            InvalidSearchFilterException ex = new InvalidSearchFilterException(
-                    Messages.getString("ldap.29")); //$NON-NLS-1$
-            ex.setRootCause(e);
-            throw ex;
-        }
+        Filter f = LdapUtils.parseFilter(filter, filterArgs);
 
         String targetDN = getTargetDN(name, contextDn);
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java?rev=599679&r1=599678&r2=599679&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
Thu Nov 29 18:49:29 2007
@@ -149,22 +149,6 @@
         return referrals;
     }
 
-    public void setErrorMessage(String errorMessage) {
-        this.errorMessage = errorMessage;
-    }
-
-    public void setMachedDN(String machedDN) {
-        this.machedDN = machedDN;
-    }
-
-    public void setReferrals(String[] referrals) {
-        this.referrals = referrals;
-    }
-
-    public void setResultCode(int resultCode) {
-        this.resultCode = resultCode;
-    }
-
     public int getResultCode() {
         return resultCode;
     }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapUtils.java?rev=599679&r1=599678&r2=599679&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapUtils.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapUtils.java
Thu Nov 29 18:49:29 2007
@@ -89,7 +89,7 @@
         errorCodesMap.put(80, NamingException.class);
     }
 
-    public static Filter parseFilter(String filter)
+    public static Filter parseFilter(String filter, Object[] args)
             throws InvalidSearchFilterException {
         if (filter == null) {
             // ldap.28=Parameter of filter should not be null
@@ -97,6 +97,13 @@
         }
 
         FilterParser parser = new FilterParser(filter);
+        
+        if (args == null) {
+            args = new Object[0];
+        }
+        
+        parser.setArgs(args);
+        
         try {
             return parser.parse();
         } catch (ParseException e) {

Modified: 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=599679&r1=599678&r2=599679&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
Thu Nov 29 18:49:29 2007
@@ -21,7 +21,6 @@
 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;
 
@@ -48,7 +47,7 @@
     }
 
     public NamingException getException() {
-        return Util.getExceptionFromErrorCode(result.getResultCode());
+        return LdapUtils.getExceptionFromResult(result);
     }
 
     public String[] getReferrals() {

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java?rev=599679&r1=599678&r2=599679&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
Thu Nov 29 18:49:29 2007
@@ -571,13 +571,9 @@
             context = new LdapContextImpl(client,
                     (Hashtable<Object, Object>) environment, dn);
 
-            if (objs == null) {
-                objs = new Object[0];
-            }
-
             Filter f = parser.getFilter();
             if (f == null) {
-                f = LdapUtils.parseFilter(filter);
+                f = LdapUtils.parseFilter(filter, objs);
             }
 
             if (searchControls == null) {

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapUtilsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapUtilsTest.java?rev=599679&r1=599678&r2=599679&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapUtilsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapUtilsTest.java
Thu Nov 29 18:49:29 2007
@@ -20,9 +20,11 @@
 import javax.naming.CommunicationException;
 import javax.naming.NamingException;
 import javax.naming.TimeLimitExceededException;
+import javax.naming.directory.InvalidSearchFilterException;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
 import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
 import org.apache.harmony.security.asn1.ASN1Integer;
 
@@ -50,6 +52,37 @@
         ex = LdapUtils.getExceptionFromResult(result);
         assertTrue(ex instanceof TimeLimitExceededException);
         assertEquals("[LDAP: error code 3]", ex.getMessage());
+    }
+
+    public void test_parseFilter() throws Exception {
+        try {
+            LdapUtils.parseFilter(null, new Object[0]);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            LdapUtils.parseFilter("object=*", null);
+            fail("Should throw InvalidSearchFilterException");
+        } catch (InvalidSearchFilterException e) {
+            // expected
+        }
+        
+
+        Filter filter = LdapUtils.parseFilter("(cn={0})", new Object[] { "value" });
+        assertEquals(Filter.EQUALITY_MATCH_FILTER, filter.getType());
+        assertTrue(filter.getValue() instanceof AttributeTypeAndValuePair);
+        AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) filter.getValue();
+        assertEquals("cn", pair.getType());
+        assertEquals("value", pair.getValue());
+
+        filter = LdapUtils.parseFilter("(cn=test)", null);
+        assertEquals(Filter.EQUALITY_MATCH_FILTER, filter.getType());
+        assertTrue(filter.getValue() instanceof AttributeTypeAndValuePair);
+        pair = (AttributeTypeAndValuePair) filter.getValue();
+        assertEquals("cn", pair.getType());
+        assertEquals("test", pair.getValue());
     }
 
     private LdapResult getLdapResult(int errorCode, String message) {

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/UtilsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/UtilsTest.java?rev=599679&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/UtilsTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/UtilsTest.java
Thu Nov 29 18:49:29 2007
@@ -0,0 +1,150 @@
+/* 
+ *  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.asn1;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.asn1.ASN1Boolean;
+import org.apache.harmony.security.asn1.ASN1Enumerated;
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1OctetString;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1Type;
+
+public class UtilsTest extends TestCase {
+
+	private final String testStr = "test123";
+
+	private final char[] testCharArray = testStr.toCharArray();
+
+	private byte[] testByteArray;
+
+	public UtilsTest() {
+		super();
+
+		try {
+			testByteArray = testStr.getBytes(Utils.CODING_CHARSET);
+		} catch (UnsupportedEncodingException e) {
+			// never reached, because UTF-8 is supported by all java
+			// platform
+		}
+	}
+	
+    public void test_conjoinSequence() {
+        ASN1Sequence first = new ASN1Sequence(new ASN1Type[] {
+                ASN1OctetString.getInstance(), ASN1Integer.getInstance(),
+                ASN1Boolean.getInstance() }) {
+            {
+                setDefault(Boolean.FALSE, 2);
+                setOptional(1);
+            }
+        };
+        ASN1Sequence second = new ASN1Sequence(new ASN1Type[] {
+                ASN1Integer.getInstance(), ASN1Enumerated.getInstance(),
+                ASN1OctetString.getInstance() }) {
+            {
+                setOptional(2);
+            }
+
+        };
+        ASN1Sequence result = Utils.conjoinSequence(first, second);
+
+        assertEquals(first.type.length + second.type.length, result.type.length);
+
+        for (int i = 0; i < first.type.length; i++) {
+            assertEquals(first.type[i], result.type[i]);
+            assertEquals(first.OPTIONAL[i], result.OPTIONAL[i]);
+            assertEquals(first.DEFAULT[i], result.DEFAULT[i]);
+        }
+
+        int index = first.type.length;
+        for (int i = 0; i < second.type.length; i++) {
+            assertEquals(second.type[i], result.type[i + index]);
+            assertEquals(second.OPTIONAL[i], result.OPTIONAL[i + index]);
+            assertEquals(second.DEFAULT[i], result.DEFAULT[i + index]);
+        }
+
+        result = Utils.conjoinSequence(first, null);
+
+        assertEquals(first.type.length, result.type.length);
+        for (int i = 0; i < first.type.length; i++) {
+            assertEquals(first.type[i], result.type[i]);
+            assertEquals(first.OPTIONAL[i], result.OPTIONAL[i]);
+            assertEquals(first.DEFAULT[i], result.DEFAULT[i]);
+        }
+
+        result = Utils.conjoinSequence(null, second);
+        assertEquals(second.type.length, result.type.length);
+        for (int i = 0; i < second.type.length; i++) {
+            assertEquals(second.type[i], result.type[i]);
+            assertEquals(second.OPTIONAL[i], result.OPTIONAL[i]);
+            assertEquals(second.DEFAULT[i], result.DEFAULT[i]);
+        }
+    }
+    
+    public void test_getString(){
+    	assertEquals("",Utils.getString(null));
+    	
+    	assertEquals(testStr,Utils.getString(testStr));
+    	assertEquals(testStr,Utils.getString(testByteArray));
+    	assertEquals(testStr,Utils.getString(testCharArray));
+    	
+    	try{
+    		Utils.getString(new Object());
+    		fail("ClassCastException expected here.");
+    	}catch (ClassCastException e){
+    		//expected
+    	}
+    }
+    
+    public void test_getBytes(){
+    	byte[] bytes = Utils.getBytes(null);
+    	assertTrue((bytes instanceof byte[]) && (bytes.length == 0));
+
+    	assertTrue(Arrays.equals(testByteArray,Utils.getBytes(testStr)));
+    	assertEquals(testByteArray,Utils.getBytes(testByteArray));
+    	assertTrue(Arrays.equals(testByteArray,Utils.getBytes(testCharArray)));
+    	
+    	try{
+    		Utils.getBytes(new Object());
+    		fail("ClassCastException expected here.");
+    	}catch (ClassCastException e){
+    		//expected
+    	}
+    }
+    
+    public void test_getCharArray(){
+    	char[] chars = Utils.getCharArray(null);
+    	assertTrue((chars instanceof char[]) && (chars.length == 0));
+
+    	assertTrue(Arrays.equals(testCharArray,Utils.getCharArray(testStr)));
+    	assertTrue(Arrays.equals(testCharArray,Utils.getCharArray(testByteArray)));
+    	assertEquals(testCharArray,Utils.getCharArray(testCharArray));
+    	
+    	try{
+    		Utils.getCharArray(new Object());
+    		fail("ClassCastException expected here.");
+    	}catch (ClassCastException e){
+    		//expected
+    	}
+    }
+    
+}



Mime
View raw message