You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/12/19 01:01:18 UTC

svn commit: r357577 - /directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java

Author: elecharny
Date: Sun Dec 18 16:01:13 2005
New Revision: 357577

URL: http://svn.apache.org/viewcvs?rev=357577&view=rev
Log:
- Replaced LdapName by LdapDN
- Deleted a commemnted method
- Cleaned the imports

Modified:
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java?rev=357577&r1=357576&r2=357577&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java Sun Dec 18 16:01:13 2005
@@ -26,11 +26,15 @@
 package org.apache.ldap.common.util ;
 
 
-import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.name.LdapDN;
 
-import javax.naming.*;
 import java.util.ArrayList;
 
+import javax.naming.CompositeName;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
 
 /**
  * Tools dealing with common Naming operations.
@@ -104,109 +108,6 @@
 
 
     /**
-     * Parses an LDAP relative distinguished name to create a Name instance.
-     *
-     * @param a_rdn string representing the LDAP relative distinguished name.
-     * @return the parsed Name of a_rdn.
-     * @throws  InvalidNameException if <tt>a_dn</tt> is not a valid name,
-     *      or if the dn violates the syntax rules of this name
-     *
-    public static Name parse(String a_rdn)
-        throws InvalidNameException
-    {
-        ArrayList l_list ;
-
-        if (a_rdn == null || a_rdn.equals("")) {
-            return new LdapName(new ArrayList()) ;
-        } else if (a_rdn.indexOf(',') == -1) {
-            if (a_rdn.indexOf('=') == -1) {
-                throw new InvalidNameException(a_rdn +
-                    " is not a valid distinguished name component.") ;
-            }
-
-            l_list = new ArrayList() ;
-            l_list.add(a_rdn) ;
-            return new LdapName(l_list) ;
-        }
-
-        l_list = new ArrayList() ;
-        String l_rest = a_rdn ;
-        String l_token = null ;
-        int l_index = -1 ;
-
-        while ((l_index = l_rest.indexOf(',')) != -1) {
-            l_token = l_rest.substring(0, l_index) ;
-            l_rest = l_rest.substring(l_index + 1) ;
-
-            if (l_token.indexOf('=') == -1) {
-                throw new InvalidNameException(a_rdn
-                    + " is not a valid relative DN component.") ;
-            }
-
-            l_list.add(l_token) ;
-        }
-
-        if (l_rest.indexOf('=') == -1) {
-            throw new InvalidNameException(l_rest
-                + " is not a valid relative DN component.") ;
-        }
-
-        l_list.add(l_rest) ;
-
-        return new LdapName(l_list) ;
-    }
-    */
-
-
-    /**
-     * Gets a DN parser.
-     *
-     * @return the distinguished name parser.
-     *
-    public static NameParser getNameParser()
-    {
-        return new NameParser() {
-            public Name parse(String a_rdn)
-                throws InvalidNameException
-            {
-                return NamespaceTools.parse(a_rdn) ;
-            }
-        } ;
-    }
-    */
-
-
-    /**
-     * @task What is this method for??? It does not make sense out of a Context
-     * implementation.
-     *
-     * @param a_name the potentially federated name to get this namespaces
-     * component from.
-     * @return this namespaces name component.
-     * @throws InvalidNameException when a_name is a CompositeName greater than
-     * size 1.
-     *
-    public static Name getNamespaceName(Name a_name)
-        throws InvalidNameException
-    {
-        if (a_name instanceof CompositeName) {
-            // We do not federate!
-            if (a_name.size() > 1) {
-                throw new InvalidNameException(a_name.toString() +
-                " has more components than namespace can handle") ;
-            }
-
-            // Turn component that belongs to you into a compound name
-            return parse(a_name.get(0));
-        } else {
-            // Already parsed
-            return a_name ;
-        }
-    }
-    */
-
-
-    /**
      * Generates the string representation of a name.
      *
      * @task what the hell are these functions for if toString on a Name returns
@@ -421,13 +322,13 @@
      */
     public static Name getRelativeName( Name ancestor, Name descendant ) throws NamingException
     {
-        LdapName rdn = new LdapName( descendant.toString() );
+        LdapDN dn = (LdapDN)descendant;
 
-        if ( rdn.startsWith( ancestor ) )
+        if ( dn.startsWith( ancestor ) )
         {
-            for ( int ii = 0; ii < ancestor.size(); ii++ )
+            for ( int i = 0; i < ancestor.size(); i++ )
             {
-                rdn.remove( 0 );
+                dn.remove( 0 );
             }
         }
         else
@@ -437,7 +338,7 @@
             throw e;
         }
 
-        return rdn;
+        return dn;
     }