directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r991481 - in /directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap: Search.java jndi/DirContextToMapObjectFactory.java
Date Wed, 01 Sep 2010 08:53:30 GMT
Author: szoerner
Date: Wed Sep  1 08:53:29 2010
New Revision: 991481

URL: http://svn.apache.org/viewvc?rev=991481&view=rev
Log:
Applied patch from Grégory Joseph according to DIRGROOVY-7

Modified:
    directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Search.java
    directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/jndi/DirContextToMapObjectFactory.java

Modified: directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Search.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Search.java?rev=991481&r1=991480&r2=991481&view=diff
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Search.java
(original)
+++ directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Search.java
Wed Sep  1 08:53:29 2010
@@ -21,6 +21,7 @@
 package org.apache.directory.groovyldap;
 
 
+import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Map;
 
@@ -75,26 +76,11 @@ public class Search
             }
             else if ( key.equalsIgnoreCase( "filterArgs" ) )
             {
-                Object value = map.get( key );
-                Object[] values = null;
-                if ( value instanceof Object[] )
-                {
-                    values = ( Object[] ) value;
-                }
-                else if ( value instanceof Collection )
-                {
-
-                    @SuppressWarnings("unchecked")
-                    Collection<Object> c = ( Collection<Object> ) value;
-
-                    values = c.toArray();
-                }
-                else
-                {
-                    values = new Object[]
-                        { value };
-                }
-                this.setFilterArgs( values );
+                this.setFilterArgs( toArray(Object.class, map.get( key )) );
+            }
+            else if ( key.equalsIgnoreCase( "attrs" ) )
+            {
+                this.setAttrs( toArray(String.class, map.get( key )) );
             }
             else
             {
@@ -103,7 +89,6 @@ public class Search
         }
     }
 
-
     public String[] getAttrs()
     {
         return attrs;
@@ -163,4 +148,25 @@ public class Search
         this.scope = scope;
     }
 
+    @SuppressWarnings("unchecked")
+    private static <T> T[] toArray(Class<T> target, Object value) {
+        T[] values = null;
+        if ( value.getClass().isArray())
+        {
+            values = ( T[] ) value;
+        }
+        else if ( value instanceof Collection)
+        {
+
+            Collection<T> c = ( Collection<T> ) value;
+
+            values = c.toArray((T[]) Array.newInstance(target, c.size()));
+        }
+        else
+        {
+            values = (T[]) Array.newInstance(target, 1);
+            values[0] = (T) value;
+        }
+        return values;
+    }
 }

Modified: directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/jndi/DirContextToMapObjectFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/jndi/DirContextToMapObjectFactory.java?rev=991481&r1=991480&r2=991481&view=diff
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/jndi/DirContextToMapObjectFactory.java
(original)
+++ directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/jndi/DirContextToMapObjectFactory.java
Wed Sep  1 08:53:29 2010
@@ -21,10 +21,10 @@ package org.apache.directory.groovyldap.
 
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 import javax.naming.Context;
 import javax.naming.Name;
@@ -54,15 +54,14 @@ public class DirContextToMapObjectFactor
             DirContext dctx = ( DirContext ) obj;
 
             // add distinguished name (DN) of entry to the map
-            Map<String, Object> map = new HashMap<String, Object>();
+            Map<String, Object> map = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
             map.put( "dn", dctx.getNameInNamespace() );
 
-            Attributes as = dctx.getAttributes( "" );
-            NamingEnumeration<? extends Attribute> e = as.getAll();
+            NamingEnumeration<? extends Attribute> e = attrs.getAll();
             while ( e.hasMore() )
             {
                 Attribute attribute = e.next();
-                String attrName = attribute.getID().toLowerCase();
+                String attrName = attribute.getID(); //.toLowerCase();
 
                 if ( attribute.size() == 1 )
                 {



Mime
View raw message