directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r550064 - in /directory/sandbox/szoerner/groovyldap/src/main: groovy/ java/org/apache/directory/groovyldap/
Date Sat, 23 Jun 2007 16:36:11 GMT
Author: szoerner
Date: Sat Jun 23 09:36:09 2007
New Revision: 550064

URL: http://svn.apache.org/viewvc?view=rev&rev=550064
Log:
Refactoring

Added:
    directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Util.java
Modified:
    directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearch.groovy
    directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearchClosure.groovy
    directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/DirContextToMapObjectFactory.java
    directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/LDAP.java

Modified: directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearch.groovy
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearch.groovy?view=diff&rev=550064&r1=550063&r2=550064
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearch.groovy (original)
+++ directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearch.groovy Sat Jun 23 09:36:09
2007
@@ -2,9 +2,8 @@
 
 ldap = LDAP.newInstance('ldap://zanzibar:10389/')
 
-// search op
 results = ldap.search('(objectClass=*)', 'dc=example,dc=com', SearchScope.ONE)
-println "${results.size} entries found:"
+println " ${results.size} entries found ".center(40,'-')
 for (entry in results) {
   println entry.dn
 }

Modified: directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearchClosure.groovy
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearchClosure.groovy?view=diff&rev=550064&r1=550063&r2=550064
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearchClosure.groovy (original)
+++ directory/sandbox/szoerner/groovyldap/src/main/groovy/demoSearchClosure.groovy Sat Jun
23 09:36:09 2007
@@ -3,6 +3,6 @@
 ldap = LDAP.newInstance('ldap://zanzibar:10389/dc=example,dc=com')
 
 ldap.eachEntry ('(objectClass=person)') { person ->  
-    println person.cn
+    println "${person.cn} (${person.dn})"
 }
 

Modified: directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/DirContextToMapObjectFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/DirContextToMapObjectFactory.java?view=diff&rev=550064&r1=550063&r2=550064
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/DirContextToMapObjectFactory.java
(original)
+++ directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/DirContextToMapObjectFactory.java
Sat Jun 23 09:36:09 2007
@@ -40,7 +40,6 @@
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
- *
  */
 public class DirContextToMapObjectFactory implements DirObjectFactory
 {

Modified: directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/LDAP.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/LDAP.java?view=diff&rev=550064&r1=550063&r2=550064
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/LDAP.java
(original)
+++ directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/LDAP.java
Sat Jun 23 09:36:09 2007
@@ -24,7 +24,6 @@
 import groovy.lang.Closure;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -33,7 +32,6 @@
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
-import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
@@ -43,7 +41,7 @@
 
 
 /**
- * A wrapper class which provides LDAP functionality to groovy.
+ * A wrapper class which provides LDAP functionality to Groovy.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -98,6 +96,9 @@
     }
 
 
+    /**
+     * Creates a new LDAP object with default parameters. It will anonymously connect to
localhost on port 389. 
+     */
     public static LDAP newInstance()
     {
         return new LDAP();
@@ -113,44 +114,18 @@
      * Search scope ONE (one level)
      */
     public static final SearchScope ONE = SearchScope.ONE;
-    
+
     /**
      * Search scope SUB (subtree)
      */
     public static final SearchScope SUB = SearchScope.SUB;
-    
+
     /**
      * Search scope BASE (only the search base itself)
      */
     public static final SearchScope BASE = SearchScope.BASE;
 
 
-    /** 
-     * Creates an attribute from the given parameters. If value is a collection, a multi-valued
attribute will be created.
-     * 
-     * @param name Name of the attribute
-     * @param value 
-     * @return a JNDI attribute object
-     */
-    protected Attribute createAttribute( String name, Object value )
-    {
-        Attribute attr = new BasicAttribute( name );
-        if ( value instanceof Collection )
-        {
-            Collection values = ( Collection ) value;
-            for ( Object val : values )
-            {
-                attr.add( val );
-            }
-        }
-        else
-        {
-            attr.add( value );
-        }
-        return attr;
-    }
-
-
     /**
      * LDAP add operation. Adds a new entry to the directory.
      * 
@@ -164,7 +139,7 @@
         BasicAttributes attrs = new BasicAttributes();
         for ( String key : attributes.keySet() )
         {
-            Attribute attr = createAttribute( key, attributes.get( key ) );
+            Attribute attr = Util.createAttribute( key, attributes.get( key ) );
             attrs.put( attr );
         }
 
@@ -230,7 +205,7 @@
         List<ModificationItem> mods = new ArrayList<ModificationItem>();
         for ( String key : attributes.keySet() )
         {
-            Attribute attr = createAttribute( key, attributes.get( key ) );
+            Attribute attr = Util.createAttribute( key, attributes.get( key ) );
             ModificationItem item = new ModificationItem( modType.getJndiValue(), attr );
             mods.add( item );
         }
@@ -288,7 +263,7 @@
             Map<String, Object> attributes = ( Map<String, Object> ) pair.get(
1 );
             for ( String key : attributes.keySet() )
             {
-                Attribute attr = createAttribute( key, attributes.get( key ) );
+                Attribute attr = Util.createAttribute( key, attributes.get( key ) );
                 ModificationItem item = new ModificationItem( modType.getJndiValue(), attr
);
                 mods.add( item );
             }

Added: directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Util.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Util.java?view=auto&rev=550064
==============================================================================
--- directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Util.java
(added)
+++ directory/sandbox/szoerner/groovyldap/src/main/java/org/apache/directory/groovyldap/Util.java
Sat Jun 23 09:36:09 2007
@@ -0,0 +1,66 @@
+/*
+ *  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.directory.groovyldap;
+
+
+import java.util.Collection;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+
+/**
+ * Utility methods.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class Util
+{
+    private Util()
+    {
+
+    }
+
+    /** 
+     * Creates an attribute from the given parameters. If value is a collection, a multi-valued
attribute will be created.
+     * 
+     * @param name Name of the attribute
+     * @param value 
+     * @return a JNDI attribute object
+     */
+    static Attribute createAttribute( String name, Object value )
+    {
+        Attribute attr = new BasicAttribute( name );
+        if ( value instanceof Collection )
+        {
+            Collection values = ( Collection ) value;
+            for ( Object val : values )
+            {
+                attr.add( val );
+            }
+        }
+        else
+        {
+            attr.add( value );
+        }
+        return attr;
+    }
+
+}



Mime
View raw message