directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r890966 - in /directory/shared/branches/shared-schema: ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=normalizers/ ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ ldap/src/main/java/org/apache/directory...
Date Tue, 15 Dec 2009 20:10:13 GMT
Author: elecharny
Date: Tue Dec 15 20:10:12 2009
New Revision: 890966

URL: http://svn.apache.org/viewvc?rev=890966&view=rev
Log:
o Modified the ldif Normalizer for UniqueMember
o Fixed the UniqueMember comparator which was expecting an OID instead of a DN 
o Renamed NameAndOptionalUIDNormalizer to UniqueMemberNormalizer

Added:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java
      - copied, changed from r890817, directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java
Removed:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java
Modified:
    directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=normalizers/m-oid=2.5.13.23.ldif
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=normalizers/m-oid=2.5.13.23.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dsystem/ou%3Dnormalizers/m-oid%3D2.5.13.23.ldif?rev=890966&r1=890965&r2=890966&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=normalizers/m-oid=2.5.13.23.ldif
(original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=normalizers/m-oid=2.5.13.23.ldif
Tue Dec 15 20:10:12 2009
@@ -3,8 +3,8 @@
 entryuuid:: 6EmWN528QkeZHE8Km2gqtA==
 m-oid: 2.5.13.23
 entrycsn: 20090818052727.714000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.normalizers.NameAndOptionalUIDNo
- rmalizer
+m-fqcn: org.apache.directory.shared.ldap.schema.normalizers.UniqueMemberNormaliz
+ er
 objectclass: metaNormalizer
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java?rev=890966&r1=890965&r2=890966&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/UniqueMemberComparator.java
Tue Dec 15 20:10:12 2009
@@ -20,11 +20,12 @@
 package org.apache.directory.shared.ldap.schema.comparators;
 
 
+import javax.naming.Name;
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,10 +46,10 @@
     /** The serialVersionUID */
     private static final long serialVersionUID = 1L;
 
-    /** A reference to the schema manager */ 
+    /** A reference to the schema manager */
     private transient SchemaManager schemaManager;
 
-    
+
     /**
      * The IntegerOrderingComparator constructor. Its OID is the IntegerOrderingMatch matching
      * rule OID.
@@ -57,169 +58,137 @@
     {
         super( oid );
     }
-    
-    
-    /**
-     * Implementation of the Compare method
-     */
-    public int compare( String o1, String o2 )
-    {
-        String s1 = getNumericIdString( o1 );
-        String s2 = getNumericIdString( o2 );
-
-        if ( s1 == null && s2 == null )
-        {
-            return 0;
-        }
-        
-        if ( s1 == null )
-        {
-            return -1;
-        }
-        
-        if ( s2 == null )
-        {
-            return 1;
-        }
-        
-        return s1.compareTo( s2 );
-    }
 
 
     /**
-     * {@inheritDoc}
+     * Implementation of the Compare method
      */
-    public void setSchemaManager( SchemaManager schemaManager )
-    {
-        this.schemaManager = schemaManager;
-    }
-
-    
-    private String getNumericIdString( Object obj )
+    public int compare( String dnstr0, String dnstr1 )
     {
-        String strValue;
+        int dash0 = dnstr0.lastIndexOf( '#' );
+        int dash1 = dnstr1.lastIndexOf( '#' );
 
-        if ( obj == null )
-        {
-            return null;
-        }
-        
-        if ( obj instanceof String )
-        {
-            strValue = ( String ) obj;
-        }
-        else if ( obj instanceof byte[] )
+        if ( ( dash0 == -1 ) && ( dash1 == -1 ) )
         {
-            strValue = StringTools.utf8ToString( ( byte[] ) obj ); 
-        }
-        else
-        {
-            strValue = obj.toString();
-        }
-        
-        if ( strValue.length() == 0 )
-        {
-            return "";
-        }
-
-        String oid = null;
-        
-        // First check in the global OID
-        if ( schemaManager.getOidRegistry().hasOid( oid ) )
-        {
-            oid = strValue;
-        }
-        else
-        {
-            // Now check in all the registries
-            // The AttributeType registry
+            // no UID part
             try
             {
-                oid = schemaManager.getAttributeTypeRegistry().getOidByName( strValue );
+                return getDn( dnstr0 ).compareTo( getDn( dnstr1 ) );
             }
             catch ( NamingException ne )
             {
-                // Not found...
+                return -1;
             }
-
-            // The DITContentRule registry
-            try
-            {
-                oid = schemaManager.getDITContentRuleRegistry().getOidByName( strValue );
-            }
-            catch ( NamingException ne )
+        }
+        else
+        {
+            // Now, check that we don't have another '#'
+            if ( dnstr0.indexOf( '#' ) != dash0 )
             {
-                // Not found...
+                // Yes, we have one : this is not allowed, it should have been
+                // escaped.
+                return -1;
             }
 
-            // The DITStructureRule registry
-            try
-            {
-                oid = schemaManager.getDITStructureRuleRegistry().getOidByName( strValue
);
-            }
-            catch ( NamingException ne )
+            if ( dnstr1.indexOf( '#' ) != dash0 )
             {
-                // Not found...
-            }
-        
-            // The MatchingRule registry
-            try
-            {
-                oid = schemaManager.getMatchingRuleRegistry().getOidByName( strValue );
-            }
-            catch ( NamingException ne )
-            {
-                // Not found...
+                // Yes, we have one : this is not allowed, it should have been
+                // escaped.
+                return 1;
             }
 
-            // The MatchingRuleUse registry
-            try
-            {
-                oid = schemaManager.getMatchingRuleUseRegistry().getOidByName( strValue );
-            }
-            catch ( NamingException ne )
-            {
-                // Not found...
-            }
+            LdapDN dn0 = null;
+            LdapDN dn1 = null;
 
-            // The NameForm registry
-            try
+            // This is an UID if the '#' is immediatly
+            // followed by a BitString, except if the '#' is
+            // on the last position
+            String uid0 = dnstr0.substring( dash0 + 1 );
+
+            if ( dash0 > 0 )
             {
-                oid = schemaManager.getNameFormRegistry().getOidByName( strValue );
+                try
+                {
+                    dn0 = new LdapDN( dnstr0.substring( 0, dash0 ) );
+                }
+                catch ( NamingException ne )
+                {
+                    return -1;
+                }
             }
-            catch ( NamingException ne )
+            else
             {
-                // Not found...
+                return -1;
             }
 
-            // The ObjectClass registry
-            try
+            // This is an UID if the '#' is immediatly
+            // followed by a BitString, except if the '#' is
+            // on the last position
+            String uid1 = dnstr1.substring( dash1 + 1 );
+
+            if ( dash1 > 0 )
             {
-                oid = schemaManager.getObjectClassRegistry().getOidByName( strValue );
+                try
+                {
+                    dn1 = new LdapDN( dnstr0.substring( 0, dash1 ) );
+                }
+                catch ( NamingException ne )
+                {
+                    return 1;
+                }
             }
-            catch ( NamingException ne )
+            else
             {
-                // Not found...
+                return 1;
             }
 
-            // The Syntax registry
-            try
-            {
-                oid = schemaManager.getLdapSyntaxRegistry().getOidByName( strValue );
-            }
-            catch ( NamingException ne )
+            int dnComp = dn0.compareTo( dn1 );
+
+            if ( dnComp != 0 )
             {
-                // Not found...
+                return dnComp;
             }
+
+            return uid0.compareTo( uid1 );
         }
-        
-        if ( oid != null )
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setSchemaManager( SchemaManager schemaManager )
+    {
+        this.schemaManager = schemaManager;
+    }
+
+
+    public LdapDN getDn( Object obj ) throws NamingException
+    {
+        LdapDN dn = null;
+
+        if ( obj instanceof LdapDN )
+        {
+            dn = ( LdapDN ) obj;
+
+            dn = ( dn.isNormalized() ? dn : LdapDN.normalize( dn, schemaManager.getNormalizerMapping()
) );
+        }
+        else if ( obj instanceof Name )
         {
-            return oid;
+            dn = new LdapDN( ( Name ) obj );
+            dn.normalize( schemaManager.getNormalizerMapping() );
         }
-        
-        String msg =  "Failed to lookup OID for " + strValue;
-        LOG.warn( msg );
-        throw new RuntimeException( msg );
+        else if ( obj instanceof String )
+        {
+            dn = new LdapDN( ( String ) obj );
+            dn.normalize( schemaManager.getNormalizerMapping() );
+        }
+        else
+        {
+            throw new IllegalStateException( "I do not know how to handle dn comparisons
with objects of class: "
+                + ( obj == null ? null : obj.getClass() ) );
+        }
+
+        return dn;
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java?rev=890966&r1=890965&r2=890966&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java
Tue Dec 15 20:10:12 2009
@@ -203,7 +203,7 @@
             return new NoOpNormalizer( id );
         }
         
-        return type.getEquality().getNormalizer();
+        return mrule.getNormalizer();
     }
 
 

Copied: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java
(from r890817, directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java)
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java?p2=directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java&p1=directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java&r1=890817&r2=890966&rev=890966&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/UniqueMemberNormalizer.java
Tue Dec 15 20:10:12 2009
@@ -37,7 +37,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class NameAndOptionalUIDNormalizer extends Normalizer
+public class UniqueMemberNormalizer extends Normalizer
 {
     // The serial UID
     private static final long serialVersionUID = 1L;
@@ -46,7 +46,7 @@
     private SchemaManager schemaManager;
     
     
-    public NameAndOptionalUIDNormalizer()
+    public UniqueMemberNormalizer()
     {
         super( SchemaConstants.UNIQUE_MEMBER_MATCH_MATCH_MR_OID );
     }
@@ -145,7 +145,7 @@
         {
             // No UID, the strValue is a DN
             // Return the normalized DN
-            return new LdapDN( value ).getNormName();
+            return new LdapDN( value ).normalize( schemaManager.getNormalizerMapping() ).getNormName();
         }
     }
 



Mime
View raw message