directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r777169 - in /directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries: DefaultAttributeTypeRegistry.java DefaultObjectClassRegistry.java DefaultRegistries.java
Date Thu, 21 May 2009 16:36:13 GMT
Author: elecharny
Date: Thu May 21 16:36:13 2009
New Revision: 777169

URL: http://svn.apache.org/viewvc?rev=777169&view=rev
Log:
Reviewed the ObjectClassRegistry classes.
o Added some Javadoc
o Switched to ConncurrentHashMap
o The OC oid is now injected in the byOid internal structure
o Added some logs
o Added some checks

Modified:
    directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
    directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultObjectClassRegistry.java
    directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java?rev=777169&r1=777168&r2=777169&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
(original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
Thu May 21 16:36:13 2009
@@ -103,13 +103,15 @@
         // First, register the AttributeType names and oid in the global
         // OidRegistry
         String[] names = attributeType.getNamesRef();
+        String oid = attributeType.getOid();
         
         for ( String name : names )
         {
-            oidRegistry.register( name, attributeType.getOid() );
+            oidRegistry.register( name, oid );
         }
         
-        oidRegistry.register( attributeType.getOid(), attributeType.getOid() );
+        // Also register the oid/oid relation
+        oidRegistry.register( oid, oid );
 
         // Inject the attributeType into the oid/normalizer map
         addMappingFor( attributeType );

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultObjectClassRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultObjectClassRegistry.java?rev=777169&r1=777168&r2=777169&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultObjectClassRegistry.java
(original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultObjectClassRegistry.java
Thu May 21 16:36:13 2009
@@ -20,9 +20,9 @@
 package org.apache.directory.server.schema.registries;
 
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 
@@ -47,7 +47,8 @@
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
     
     /** maps an OID to an ObjectClass */
-    private final Map<String,ObjectClass> byOid;
+    private final Map<String,ObjectClass> byOidOC;
+    
     /** the registry used to resolve names to OIDs */
     private final OidRegistry oidRegistry;
 
@@ -64,7 +65,7 @@
      */
     public DefaultObjectClassRegistry( OidRegistry oidRegistry )
     {
-        this.byOid = new HashMap<String,ObjectClass>();
+        byOidOC = new ConcurrentHashMap<String,ObjectClass>();
         this.oidRegistry = oidRegistry;
     }
 
@@ -72,102 +73,154 @@
     // ------------------------------------------------------------------------
     // Service Methods
     // ------------------------------------------------------------------------
-
-    
+    /**
+     * {@inheritDoc}
+     */
     public void register( ObjectClass objectClass ) throws NamingException
     {
-        if ( byOid.containsKey( objectClass.getOid() ) )
-        {
-            throw new NamingException( "objectClass w/ OID " + objectClass.getOid()
-                + " has already been registered!" );
+    	String oid = objectClass.getOid();
+    	
+        if ( byOidOC.containsKey( oid ) )
+        {
+        	String msg = "objectClass " + objectClass.getName() + " w/ OID " + oid
+            	+ " has already been registered!";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
 
-        if ( objectClass.getNamesRef() != null && objectClass.getNamesRef().length
> 0 )
-        {
-            oidRegistry.register( objectClass.getName(), objectClass.getOid() );
-        }
-        else
+        // Register the name/oid relation
+        String name = objectClass.getName();
+        
+        if ( !StringTools.isEmpty( name ) )
         {
-            oidRegistry.register( objectClass.getOid(), objectClass.getOid() );
+            oidRegistry.register( name, oid );
         }
         
-        byOid.put( objectClass.getOid(), objectClass );
+        // Also register the oid/oid relation
+        oidRegistry.register( oid, oid );
+        
+        // Stores the OC in the internal map
+        byOidOC.put( oid, objectClass );
         
         if ( IS_DEBUG )
         {
-            LOG.debug( "registered objectClass: " + objectClass );
+            LOG.debug( "registered objectClass: {}", objectClass );
         }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public ObjectClass lookup( String id ) throws NamingException
     {
-        if ( StringTools.isEmpty( id ) )
-        {
-            throw new NamingException( "name should not be empty" );
+    	String ocId = StringTools.trim( id ).toLowerCase();
+    	
+        if ( StringTools.isEmpty( ocId ) )
+        {
+        	String msg = "Lookup in the OC registry : name should not be empty";
+        	LOG.error( msg );
+            throw new NamingException( msg );
         }
         
-        String oid = oidRegistry.getOid( id.toLowerCase() );
+        String oid = oidRegistry.getOid( ocId );
+
+        ObjectClass objectClass = byOidOC.get( oid );
 
-        if ( !byOid.containsKey( oid ) )
+        if ( objectClass == null )
         {
-            throw new NamingException( "objectClass w/ OID " + oid + " not registered!" );
+        	String msg = "objectClass " + id + " w/ OID " + oid + " not registered!";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
-
-        ObjectClass objectClass = byOid.get( oid );
         
         if ( IS_DEBUG )
         {
-            LOG.debug( "looked objectClass with OID '" + oid + "' and got back " + objectClass
);
+            LOG.debug( "looked objectClass with OID '{}' and got back {}", oid, objectClass
);
         }
+        
         return objectClass;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasObjectClass( String id )
     {
-        if ( oidRegistry.hasOid( id ) )
+        try
         {
-            try
-            {
-                return byOid.containsKey( oidRegistry.getOid( id ) );
-            }
-            catch ( NamingException e )
-            {
-                return false;
-            }
+        	String oid = oidRegistry.getOid( id );
+        	
+        	if ( oid == null )
+        	{
+        		return false;
+        	}
+        	
+            return byOidOC.containsKey( oid );
+        }
+        catch ( NamingException e )
+        {
+            return false;
         }
-
-        return false;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getSchemaName( String id ) throws NamingException
     {
-        id = oidRegistry.getOid( id );
-        ObjectClass oc = byOid.get( id );
+        String ocOid = oidRegistry.getOid( id );
+        
+        if ( ocOid == null )
+        {
+        	String msg = "Element " + id + " not found in the OID registry !";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
+        }
+
+        ObjectClass oc = byOidOC.get( ocOid );
+        
         if ( oc != null )
         {
             return oc.getSchema();
         }
 
-        throw new NamingException( "OID " + id + " not found in oid to " + "ObjectClass map!"
);
+        String msg = "OID " + id + " not found in oid to " + "ObjectClass map!";
+        LOG.warn( msg );
+        throw new NamingException( msg );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<ObjectClass> iterator()
     {
-        return byOid.values().iterator();
+        return byOidOC.values().iterator();
     }
     
     
+    /**
+     * {@inheritDoc}
+     */
     public void unregister( String numericOid ) throws NamingException
     {
+    	if ( StringTools.isEmpty( numericOid ) )
+    	{
+    		String msg = "Can't unregister an empty element";
+    		LOG.warn( msg );
+    		throw new NamingException( msg );
+    	}
+    	
         if ( ! Character.isDigit( numericOid.charAt( 0 ) ) )
         {
-            throw new NamingException( "Looks like the arg is not a numeric OID" );
+        	String msg = "Looks like the arg is not a numeric OID";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
 
-        byOid.remove( numericOid );
+        byOidOC.remove( numericOid );
     }
 }

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java?rev=777169&r1=777168&r2=777169&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
(original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
Thu May 21 16:36:13 2009
@@ -43,7 +43,12 @@
  */
 public class DefaultRegistries implements Registries
 {
-    private DefaultAttributeTypeRegistry attributeTypeRegistry;
+	/** The AttributeType registry */
+    private AttributeTypeRegistry attributeTypeRegistry;
+    
+    /** The ObjectClass registry */
+    private DefaultObjectClassRegistry objectClassRegistry;
+
     private DefaultComparatorRegistry comparatorRegistry;
     private DefaultDitContentRuleRegistry ditContentRuleRegistry;
     private DefaultDitStructureRuleRegistry ditStructureRuleRegistry;
@@ -51,7 +56,6 @@
     private DefaultMatchingRuleUseRegistry matchingRuleUseRegistry;
     private DefaultNameFormRegistry nameFormRegistry;
     private DefaultNormalizerRegistry normalizerRegistry;
-    private DefaultObjectClassRegistry objectClassRegistry;
     private OidRegistry oidRegistry;
     private DefaultSyntaxCheckerRegistry syntaxCheckerRegistry;
     private DefaultSyntaxRegistry syntaxRegistry;
@@ -64,12 +68,14 @@
     {
         this.name = name;
         this.schemaLoader = schemaLoader;
+        
         this.schemaLoader.setListener( new SchemaLoaderListener() {
             public void schemaLoaded( Schema schema )
             {
                 loadedByName.put( schema.getSchemaName(), schema );
             }
         });
+        
         oidRegistry = registry;
         normalizerRegistry = new DefaultNormalizerRegistry();
         comparatorRegistry = new DefaultComparatorRegistry();



Mime
View raw message