directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r355399 - in /directory/shared/ldap: branches/DN-refactoring/ branches/DN-refactoring/apache-provider/ branches/DN-refactoring/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/compare/ branches/DN-refactoring/apache2-prov...
Date Fri, 09 Dec 2005 07:21:46 GMT
Author: elecharny
Date: Thu Dec  8 23:21:16 2005
New Revision: 355399

URL: http://svn.apache.org/viewcvs?rev=355399&view=rev
Log:
Creating a branch to work on a refactored DN

Added:
    directory/shared/ldap/branches/DN-refactoring/
      - copied from r354930, directory/shared/ldap/trunk/
    directory/shared/ldap/branches/DN-refactoring/apache-provider/
      - copied from r355143, directory/shared/ldap/trunk/apache-provider/
    directory/shared/ldap/branches/DN-refactoring/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/compare/CompareRequestRuleTest.java
      - copied unchanged from r355237, directory/shared/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/compare/CompareRequestRuleTest.java
    directory/shared/ldap/branches/DN-refactoring/apache2-provider/
      - copied from r355143, directory/shared/ldap/trunk/apache2-provider/
    directory/shared/ldap/branches/DN-refactoring/common/
      - copied from r355144, directory/shared/ldap/trunk/common/
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/message/CompareRequest.java
      - copied unchanged from r355235, directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/message/CompareRequest.java
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/message/CompareRequestImpl.java
      - copied unchanged from r355235, directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/message/CompareRequestImpl.java
    directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/message/CompareRequestImplTest.java
      - copied unchanged from r355236, directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/message/CompareRequestImplTest.java
    directory/shared/ldap/branches/DN-refactoring/snacc-provider/
      - copied from r355144, directory/shared/ldap/trunk/snacc-provider/
    directory/shared/ldap/branches/DN-refactoring/snacc-provider/src/main/java/org/apache/ldap/common/berlib/snacc/CompareRequestTransform.java
      - copied unchanged from r355238, directory/shared/ldap/trunk/snacc-provider/src/main/java/org/apache/ldap/common/berlib/snacc/CompareRequestTransform.java
Modified:
    directory/shared/ldap/branches/DN-refactoring/common/src/antlr/dnparser.g
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapName.java
    directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
    directory/shared/ldap/trunk/common/src/antlr/dnparser.g
    directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/name/LdapName.java
    directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/antlr/dnparser.g
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/antlr/dnparser.g?rev=355399&r1=355144&r2=355399&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/antlr/dnparser.g (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/antlr/dnparser.g Thu Dec  8 23:21:16
2005
@@ -82,32 +82,39 @@
     ;
 
 
-attributeTypeAndValue returns [String l_tav]
+attributeTypeAndValue returns [String tav]
 {
-    l_tav = null ;
-    StringBuffer l_buf = new StringBuffer() ;
-    String l_lhs = null ;
+    tav = null ;
+    StringBuffer buf = new StringBuffer() ;
+    String lhs = null ;
 }
-	:	( l_attr:ATTRIBUTE 
+	:	( attr:ATTRIBUTE 
             {
-                l_lhs = l_attr.getText() ;
-                m_valueParser.setOid(false) ;
+                lhs = attr.getText() ;
+                Object oidName = DnOidContainer.getOidByName( lhs );
+                
+                if ( oidName != null )
+                {
+                	lhs = (java.lang.String) oidName;
+                }
+                
+				m_valueParser.setOid(false) ;
             }
-        | l_oiddn:OIDDN
+        | oiddn:OIDDN
             {
-                l_lhs = l_oiddn.getText().substring( "OID.".length() ) ;
+                lhs = oiddn.getText().substring( "OID.".length() ) ;
                 m_valueParser.setOid(true) ;
             }
-        | l_oid:OID
+        | oid:OID
             {
-                l_lhs = l_oid.getText() ;
+                lhs = oid.getText() ;
                 m_valueParser.setOid(true) ;
             }
         ) EQUAL
 		{
-            m_valueParser.setLhs(l_lhs) ;
-            l_buf.append(l_lhs) ;
-            l_buf.append('=').append(m_valueParser.value()) ;
-            l_tav = l_buf.toString() ;
+            m_valueParser.setLhs(lhs) ;
+            buf.append(lhs) ;
+            buf.append('=').append(m_valueParser.value()) ;
+            tav = buf.toString() ;
 		}
 	;

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapName.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapName.java?rev=355399&r1=355144&r2=355399&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapName.java
(original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapName.java
Thu Dec  8 23:21:16 2005
@@ -27,6 +27,7 @@
 package org.apache.ldap.common.name ;
 
 
+import org.apache.asn1.codec.util.StringUtils;
 import org.apache.ldap.common.util.NamespaceTools;
 
 import javax.naming.InvalidNameException;
@@ -57,7 +58,20 @@
     private String m_name ;
     /** Dirty bit used to determine whether the cached m_name is up to date */
     private boolean m_isClean = false ;
-
+    
+    public static LdapName EMPTY_LDAP_NAME = null;
+    
+    static
+    {
+    	try
+    	{
+    		EMPTY_LDAP_NAME = new LdapName( "" );
+    	}
+    	catch ( NamingException ne )
+    	{
+    		// Nothing to do...
+    	}
+    }
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -905,6 +919,68 @@
         }
         
         return a_dn.get( a_dn.size() - 1 ) ;
+    }
+    
+    private static String getRdn( String nameComponent, int start )
+    {
+    	return "";
+    }
+    
+    public static LdapName toOidName( LdapName dn, Map oids ) throws InvalidNameException
+    {
+    	if ( ( dn == null ) || ( dn.size() == 0 ) )
+    	{
+    		return dn;
+    	}
+    	
+    	LdapName newDn = new LdapName();
+    	
+    	Enumeration rdns = dn.getAll();
+    	
+    	while ( rdns.hasMoreElements() )
+    	{
+    		 String rdn = (String)rdns.nextElement();
+    		 
+    		 if ( rdn.indexOf( '+' ) != -1 )
+    		 {
+    			 
+    		 }
+    		 else
+    		 {
+    			 int posEqual = rdn.indexOf( '=' );
+    			 
+    			 if ( posEqual > 0 )
+    			 {
+    				 String name = StringUtils.trim( rdn.substring( 0, posEqual ) );
+    				 
+    				 if ( StringUtils.isEmpty( StringUtils.lowerCase( name ) ) == false )
+    				 {
+    					 String oid = (String)oids.get( name );
+    					 
+    					 if ( oid != null )
+    					 {
+        					 String newRdn = oid + rdn.substring( posEqual );
+        					 newDn.add( newRdn );
+    					 }
+    					 else
+    					 {
+    						 return null;
+    					 }
+    				 }
+    				 else
+    				 {
+    					 return null;
+    				 }
+    			 }
+    			 else
+    			 {
+    				 return  null;
+    			 }
+				 
+			 }
+    	}
+    	
+    	return newDn;
     }
 }
 

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapNameTest.java?rev=355399&r1=355144&r2=355399&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
(original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
Thu Dec  8 23:21:16 2005
@@ -21,6 +21,8 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.naming.Name;
 
@@ -1067,4 +1069,42 @@
         
         assertEquals( cn, name.toString() );
     }
+
+    /**
+     * Class to test for toOid( Name, Map)
+     */
+    public void testLdapNameToOid() throws Exception
+    {
+        ArrayList list = new ArrayList() ;
+        list.add( "ou=People" ) ;
+        list.add( "dc=example" ) ;
+        list.add( "dc=com" ) ;
+        LdapName name = new LdapName( list.iterator() ) ;
+        
+        Map oids = new HashMap();
+        
+        oids.put( "dc", "0.9.2342.19200300.100.1.25" );
+        oids.put( "ou", "2.5.4.11" );
+        
+        LdapName result = LdapName.toOidName( name, oids );
+        assertTrue( result.toString().equals( 
+            "2.5.4.11=People,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com"
) ) ;
+    }
+
+    /**
+     * Class to test for toOid( Name, Map)
+     */
+    public void testLdapNameToOidEmpty() throws Exception
+    {
+        LdapName name = new LdapName() ;
+        
+        Map oids = new HashMap();
+        
+        oids.put( "dc", "0.9.2342.19200300.100.1.25" );
+        oids.put( "ou", "2.5.4.11" );
+        
+        LdapName result = LdapName.toOidName( name, oids );
+        assertTrue( result.toString().equals( "" ) ) ;
+    }
+
 }

Modified: directory/shared/ldap/trunk/common/src/antlr/dnparser.g
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/antlr/dnparser.g?rev=355399&r1=355398&r2=355399&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/antlr/dnparser.g (original)
+++ directory/shared/ldap/trunk/common/src/antlr/dnparser.g Thu Dec  8 23:21:16 2005
@@ -82,32 +82,39 @@
     ;
 
 
-attributeTypeAndValue returns [String l_tav]
+attributeTypeAndValue returns [String tav]
 {
-    l_tav = null ;
-    StringBuffer l_buf = new StringBuffer() ;
-    String l_lhs = null ;
+    tav = null ;
+    StringBuffer buf = new StringBuffer() ;
+    String lhs = null ;
 }
-	:	( l_attr:ATTRIBUTE 
+	:	( attr:ATTRIBUTE 
             {
-                l_lhs = l_attr.getText() ;
-                m_valueParser.setOid(false) ;
+                lhs = attr.getText() ;
+                Object oidName = DnOidContainer.getOidByName( lhs );
+                
+                if ( oidName != null )
+                {
+                	lhs = (java.lang.String) oidName;
+                }
+                
+				m_valueParser.setOid(false) ;
             }
-        | l_oiddn:OIDDN
+        | oiddn:OIDDN
             {
-                l_lhs = l_oiddn.getText().substring( "OID.".length() ) ;
+                lhs = oiddn.getText().substring( "OID.".length() ) ;
                 m_valueParser.setOid(true) ;
             }
-        | l_oid:OID
+        | oid:OID
             {
-                l_lhs = l_oid.getText() ;
+                lhs = oid.getText() ;
                 m_valueParser.setOid(true) ;
             }
         ) EQUAL
 		{
-            m_valueParser.setLhs(l_lhs) ;
-            l_buf.append(l_lhs) ;
-            l_buf.append('=').append(m_valueParser.value()) ;
-            l_tav = l_buf.toString() ;
+            m_valueParser.setLhs(lhs) ;
+            buf.append(lhs) ;
+            buf.append('=').append(m_valueParser.value()) ;
+            tav = buf.toString() ;
 		}
 	;

Modified: directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/name/LdapName.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/name/LdapName.java?rev=355399&r1=355398&r2=355399&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/name/LdapName.java
(original)
+++ directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/name/LdapName.java
Thu Dec  8 23:21:16 2005
@@ -27,6 +27,7 @@
 package org.apache.ldap.common.name ;
 
 
+import org.apache.asn1.codec.util.StringUtils;
 import org.apache.ldap.common.util.NamespaceTools;
 
 import javax.naming.InvalidNameException;
@@ -57,7 +58,20 @@
     private String m_name ;
     /** Dirty bit used to determine whether the cached m_name is up to date */
     private boolean m_isClean = false ;
-
+    
+    public static LdapName EMPTY_LDAP_NAME = null;
+    
+    static
+    {
+    	try
+    	{
+    		EMPTY_LDAP_NAME = new LdapName( "" );
+    	}
+    	catch ( NamingException ne )
+    	{
+    		// Nothing to do...
+    	}
+    }
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -905,6 +919,68 @@
         }
         
         return a_dn.get( a_dn.size() - 1 ) ;
+    }
+    
+    private static String getRdn( String nameComponent, int start )
+    {
+    	return "";
+    }
+    
+    public static LdapName toOidName( LdapName dn, Map oids ) throws InvalidNameException
+    {
+    	if ( ( dn == null ) || ( dn.size() == 0 ) )
+    	{
+    		return dn;
+    	}
+    	
+    	LdapName newDn = new LdapName();
+    	
+    	Enumeration rdns = dn.getAll();
+    	
+    	while ( rdns.hasMoreElements() )
+    	{
+    		 String rdn = (String)rdns.nextElement();
+    		 
+    		 if ( rdn.indexOf( '+' ) != -1 )
+    		 {
+    			 
+    		 }
+    		 else
+    		 {
+    			 int posEqual = rdn.indexOf( '=' );
+    			 
+    			 if ( posEqual > 0 )
+    			 {
+    				 String name = StringUtils.trim( rdn.substring( 0, posEqual ) );
+    				 
+    				 if ( StringUtils.isEmpty( StringUtils.lowerCase( name ) ) == false )
+    				 {
+    					 String oid = (String)oids.get( name );
+    					 
+    					 if ( oid != null )
+    					 {
+        					 String newRdn = oid + rdn.substring( posEqual );
+        					 newDn.add( newRdn );
+    					 }
+    					 else
+    					 {
+    						 return null;
+    					 }
+    				 }
+    				 else
+    				 {
+    					 return null;
+    				 }
+    			 }
+    			 else
+    			 {
+    				 return  null;
+    			 }
+				 
+			 }
+    	}
+    	
+    	return newDn;
     }
 }
 

Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java?rev=355399&r1=355398&r2=355399&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
(original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/name/LdapNameTest.java
Thu Dec  8 23:21:16 2005
@@ -21,6 +21,8 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.naming.Name;
 
@@ -1067,4 +1069,42 @@
         
         assertEquals( cn, name.toString() );
     }
+
+    /**
+     * Class to test for toOid( Name, Map)
+     */
+    public void testLdapNameToOid() throws Exception
+    {
+        ArrayList list = new ArrayList() ;
+        list.add( "ou=People" ) ;
+        list.add( "dc=example" ) ;
+        list.add( "dc=com" ) ;
+        LdapName name = new LdapName( list.iterator() ) ;
+        
+        Map oids = new HashMap();
+        
+        oids.put( "dc", "0.9.2342.19200300.100.1.25" );
+        oids.put( "ou", "2.5.4.11" );
+        
+        LdapName result = LdapName.toOidName( name, oids );
+        assertTrue( result.toString().equals( 
+            "2.5.4.11=People,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com"
) ) ;
+    }
+
+    /**
+     * Class to test for toOid( Name, Map)
+     */
+    public void testLdapNameToOidEmpty() throws Exception
+    {
+        LdapName name = new LdapName() ;
+        
+        Map oids = new HashMap();
+        
+        oids.put( "dc", "0.9.2342.19200300.100.1.25" );
+        oids.put( "ou", "2.5.4.11" );
+        
+        LdapName result = LdapName.toOidName( name, oids );
+        assertTrue( result.toString().equals( "" ) ) ;
+    }
+
 }



Mime
View raw message