directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r809333 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/ ldap/src/main/java/org/...
Date Sun, 30 Aug 2009 13:29:01 GMT
Author: akarasulu
Date: Sun Aug 30 13:28:59 2009
New Revision: 809333

URL: http://svn.apache.org/viewvc?rev=809333&view=rev
Log:
fixing various bugs and issues in schema api code - i.e. added new byName lookup hash for
aliases without using byOid for names now

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/AcceptAllSyntaxChecker.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
Sun Aug 30 13:28:59 2009
@@ -49,7 +49,6 @@
 import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.FilenameFilter;
-import java.io.IOException;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -428,7 +427,14 @@
             LdifEntry entry = reader.next();
             SyntaxChecker syntaxChecker = 
                 factory.getSyntaxChecker( entry.getEntry(), registries );
-            registries.getSyntaxCheckerRegistry().register( syntaxChecker );
+            try
+            {
+            	registries.getSyntaxCheckerRegistry().register( syntaxChecker );
+            }
+            catch ( Exception e )
+            {
+            	e.printStackTrace();
+            }
         }
     }
     

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
Sun Aug 30 13:28:59 2009
@@ -410,7 +410,7 @@
         mr.setSyntaxOid( syntaxOid );
         mr.setSchemaName( schema );
         setSchemaObjectProperties( mr, entry );
-        mr.applyRegistries( targetRegistries );
+    	mr.applyRegistries( targetRegistries );
         return mr;
     }
     
@@ -486,22 +486,30 @@
         
         if ( entry.get( MetaSchemaConstants.M_EQUALITY_AT ) != null )
         {
-            at.setEqualityOid( entry.get( MetaSchemaConstants.M_EQUALITY_AT ).getString()
);
+        	String mrName = entry.get( MetaSchemaConstants.M_EQUALITY_AT ).getString();
+        	String mrOid = targetRegistries.getMatchingRuleRegistry().getOidByName( mrName );
+            at.setEqualityOid( mrOid );
         }
         
         if ( entry.get( MetaSchemaConstants.M_ORDERING_AT ) != null )
         {
-            at.setOrderingOid( entry.get( MetaSchemaConstants.M_ORDERING_AT ).getString()
);
+        	String mrName = entry.get( MetaSchemaConstants.M_ORDERING_AT ).getString();
+        	String mrOid = targetRegistries.getMatchingRuleRegistry().getOidByName( mrName );
+            at.setEqualityOid( mrOid );
         }
         
         if ( entry.get( MetaSchemaConstants.M_SUBSTR_AT ) != null )
         {
-            at.setSubstrOid( entry.get( MetaSchemaConstants.M_SUBSTR_AT ).getString() );
+        	String mrName = entry.get( MetaSchemaConstants.M_SUBSTR_AT ).getString();
+        	String mrOid = targetRegistries.getMatchingRuleRegistry().getOidByName( mrName );
+            at.setEqualityOid( mrOid );
         }
         
         if ( entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT ) != null )
         {
-            at.setSuperiorOid( entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT ).getString()
);
+        	String supName = entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT ).getString();
+            String supOid = targetRegistries.getAttributeTypeRegistry().getOidByName( supName
);
+        	at.setSuperiorOid( supOid );
         }
         
         if ( entry.get( MetaSchemaConstants.M_COLLECTIVE_AT ) != null )

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
Sun Aug 30 13:28:59 2009
@@ -28,7 +28,7 @@
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
 
- 
+
 /**
  * Tests the LdifSchemaLoader.
  *

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
Sun Aug 30 13:28:59 2009
@@ -122,7 +122,7 @@
             normalizer = registries.getNormalizerRegistry().lookup( oid );
 
             // Gets the associated SC 
-            ldapSyntax = registries.getLdapSyntaxRegistry().lookup( oid );
+            ldapSyntax = registries.getLdapSyntaxRegistry().lookup( ldapSyntaxOid );
         }
     }
     
@@ -232,6 +232,4 @@
             this.normalizer = normalizer;
         }
     }
-
-
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
Sun Aug 30 13:28:59 2009
@@ -116,11 +116,6 @@
         isReadOnly = false;
         extensions = new HashMap<String, List<String>>();
         names = new ArrayList<String>();
-        
-        if ( oid != null )
-        {
-        	names.add( oid );
-        }
     }
     
     
@@ -181,7 +176,7 @@
         }
         else
         {
-            return new ArrayList<String>();
+            return Collections.emptyList();
         }
     }
 

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
Sun Aug 30 13:28:59 2009
@@ -41,7 +41,6 @@
 
     /**
      * The SyntaxChecker base constructor
-     * @param objectType
      * @param oid The associated OID
      */
     protected SyntaxChecker( String oid )
@@ -51,6 +50,16 @@
 
 
     /**
+     * The SyntaxChecker default constructor where the oid is set after 
+     * instantiation.
+     */
+    protected SyntaxChecker()
+    {
+        super( SchemaObjectType.SYNTAX_CHECKER );
+    }
+
+
+    /**
      * Determines if the attribute's value conforms to the attribute syntax.
      * 
      * @param value the value of some attribute with the syntax

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java
Sun Aug 30 13:28:59 2009
@@ -99,6 +99,7 @@
     @Override
     public void setOid( String oid )
     {
+    	super.setOid( oid );
         normalizer.setOid( oid );
     }
     

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=809333&r1=809332&r2=809333&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
Sun Aug 30 13:28:59 2009
@@ -218,6 +218,6 @@
 
     public String normalizeName( String attributeName ) throws NamingException
     {
-        return attributeRegistry.getOid( attributeName );
+        return attributeRegistry.getOidByName( attributeName );
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
Sun Aug 30 13:28:59 2009
@@ -94,7 +94,7 @@
      */
     public boolean hasDescendants( String ancestorId ) throws NamingException
     {
-        String oid = getOid( ancestorId );
+        String oid = getOidByName( ancestorId );
         Set<AttributeType> descendants = oidToDescendantSet.get( oid );
         return (descendants != null) && !descendants.isEmpty();
     }
@@ -113,7 +113,7 @@
     @SuppressWarnings("unchecked")
     public Iterator<AttributeType> descendants( String ancestorId ) throws NamingException
     {
-        String oid = getOid( ancestorId );
+        String oid = getOidByName( ancestorId );
         Set<AttributeType> descendants = oidToDescendantSet.get( oid );
         
         if ( descendants == null )

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
Sun Aug 30 13:28:59 2009
@@ -20,8 +20,11 @@
 package org.apache.directory.shared.ldap.schema.registries;
 
 
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
@@ -47,9 +50,12 @@
     /** A speedup for debug */
     private static final boolean DEBUG = LOG.isDebugEnabled();
     
-    /** a map of SchemaObject looked up by OID or Name */
+    /** a map of SchemaObject looked up by OID */
     protected final Map<String, T> byOid;
     
+    /** a map of SchemaObject looked up by name */
+    protected final Map<String, T> byName;
+    
     /** The SchemaObject type */
     protected SchemaObjectType type;
 
@@ -63,6 +69,7 @@
     protected SchemaObjectRegistry( SchemaObjectType schemaObjectType, OidRegistry oidRegistry
)
     {
         byOid = new ConcurrentHashMap<String, T>();
+        byName = new ConcurrentHashMap<String, T>();
         type = schemaObjectType;
         this.oidRegistry = oidRegistry;
     }
@@ -183,7 +190,7 @@
 
         if ( DEBUG )
         {
-            LOG.debug( "Found {} with oid: {}", schemaObject, oid );
+    		LOG.debug( "Found {} with oid: {}", schemaObject, oid );
         }
         
         return schemaObject;
@@ -210,6 +217,16 @@
 
         byOid.put( oid, schemaObject );
         
+        /*
+         * add the aliases/names to the name map along with their toLowerCase
+         * versions of the name: this is used to make sure name lookups work
+         */
+        for ( String name : schemaObject.getNames() )
+        {
+        	byName.put( name, schemaObject );
+        	byName.put( name.toLowerCase(), schemaObject );
+        }
+        
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( "registered " + schemaObject.getName() + " for OID {}", oid );
@@ -238,6 +255,37 @@
 
         SchemaObject schemaObject = byOid.remove( numericOid );
         
+        /* byName Cleanup
+         * --------------
+         * 
+         * We iterate throw all the Entry objects in the byName hash.  This
+         * costs a bit since it is a full scan of the hash but it's in memory
+         * and can up to 10K objects (well within our range) work reasonably.
+         * As we iterate we push keys to remove into the keysToRemove list to
+         * be removed later after this first iteration to prevent concurrent
+         * modification issues during iteration.
+         * 
+         * Next we loop again on the keysToRemove list and remove the entries
+         * from the byName map.  This seems elaborate however note that 
+         * because we cash different case varying permutations of the name so
+         * lookups work properly, we cannot just rely on removing entry by 
+         * key as they are in the names list.  This is why we have to scan the
+         * entire entry set and check to see if it is in fact the schema 
+         * object in question.
+         */
+        List<String> keysToRemove = new ArrayList<String>(); 
+        for ( Entry<String, T> entry : byName.entrySet() )
+        {
+        	if ( entry.getValue().equals( schemaObject ) )
+        	{
+        		keysToRemove.add( entry.getKey() );
+        	}
+        }
+        for ( String key : keysToRemove )
+        {
+        	byName.remove( key );
+        }
+        
         // And remove the SchemaObject from the oidRegistry
         oidRegistry.unregister( numericOid );
         
@@ -281,21 +329,40 @@
     
     
     /**
-     * Gets the numericOid associated to a name, if any
-     *
+     * Gets the numericOid for a name/alias if one is associated.  To prevent
+     * lookup failures due to case variance in the name, a failure to lookup the
+     * OID, will trigger a lookup using a lower cased version of the name and 
+     * the name that failed to match will automatically be associated with the
+     * OID.
+     * 
      * @param name The name we are looking the oid for
      * @return The numericOID associated with this name
      * @throws NamingException If the OID can't be found
      */
-    public String getOid( String name ) throws NamingException
+    public String getOidByName( String name ) throws NamingException
     {
-        T schemaObject = byOid.get( name );
-        
-        if ( schemaObject != null )
-        {
-            return schemaObject.getOid();
-        }
-        
-        throw new NamingException( "Can't find an OID for the name " + name );
+    	if ( ! byName.containsKey( name ) )
+    	{
+    		// last resort before giving up check with lower cased version
+        	String lowerCased = name.toLowerCase();
+    		
+        	// ok this name is not for a schema object in the registry
+    		if ( ! byName.containsKey( lowerCased ) )
+    		{
+    	        throw new NamingException( "Can't find an OID for the name " + name );
+    		}
+
+    		// we found the schema object using lower cased name
+			T schemaObject = byName.get( name );
+			
+        	// provided name argument has case variance so we add it to 
+			// map in case the same lookup is attempted again in future
+			byName.put( name, schemaObject );
+			return schemaObject.getOid();
+    	}
+    	
+    	// we found the schema object by key on the first lookup attempt
+        T schemaObject = byName.get( name );
+        return schemaObject.getOid();
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/AcceptAllSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/AcceptAllSyntaxChecker.java?rev=809333&r1=809332&r2=809333&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/AcceptAllSyntaxChecker.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/AcceptAllSyntaxChecker.java
Sun Aug 30 13:28:59 2009
@@ -39,6 +39,7 @@
     /** The serialVersionUID */
     private static final long serialVersionUID = 1L;
 
+
     /**
      * Creates a SyntaxChecker which accepts all values.
      * 
@@ -51,6 +52,15 @@
 
     
     /**
+     * Creates a default SyntaxChecker which accepts all values deferring 
+     * setup of the OID until after instantiation.
+     */
+    public AcceptAllSyntaxChecker()
+    {
+    }
+
+    
+    /**
      * {@inheritDoc}
      */
     public boolean isValidSyntax( Object value )



Mime
View raw message