directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r777274 - /directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
Date Thu, 21 May 2009 21:36:30 GMT
Author: elecharny
Date: Thu May 21 21:36:30 2009
New Revision: 777274

URL: http://svn.apache.org/viewvc?rev=777274&view=rev
Log:
Cleanup of the NormalizerRegistry

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

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java?rev=777274&r1=777273&r2=777274&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
(original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
Thu May 21 21:36:30 2009
@@ -21,13 +21,14 @@
 
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.parsers.NormalizerDescription;
 
@@ -50,7 +51,7 @@
     private static final boolean DEBUG = LOG.isDebugEnabled();
     
     /** a map of Normalizers looked up by OID */
-    private final Map<String,Normalizer> byOid;
+    private final Map<String,Normalizer> byOidNormalizer;
     
     /** maps an OID to a normalizerDescription */
     private final Map<String,NormalizerDescription> oidToDescription;
@@ -66,128 +67,167 @@
      */
     public DefaultNormalizerRegistry()
     {
-        this.byOid = new HashMap<String, Normalizer>();
-        this.oidToDescription = new HashMap<String, NormalizerDescription>();
+    	byOidNormalizer = new ConcurrentHashMap<String, Normalizer>();
+        oidToDescription = new ConcurrentHashMap<String, NormalizerDescription>();
     }
 
 
     // ------------------------------------------------------------------------
     // Service Methods
     // ------------------------------------------------------------------------
-
-    
+    /**
+     * {@inheritDoc}
+     */
     public void register( NormalizerDescription description, Normalizer normalizer ) throws
NamingException
     {
         String oid = description.getNumericOid();
-        if ( byOid.containsKey( oid ) )
+        
+        if ( byOidNormalizer.containsKey( oid ) )
         {
-            throw new NamingException( "Normalizer already " + "registered for OID " + oid
);
+        	String msg = "Normalizer already registered for OID " + oid;
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
 
         oidToDescription.put( oid, description );
-        byOid.put( oid, normalizer );
+        byOidNormalizer.put( oid, normalizer );
         
         if ( DEBUG )
         {
-            LOG.debug( "registered normalizer with oid: " + oid );
+            LOG.debug( "registered normalizer with oid: {}", oid );
         }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Normalizer lookup( String oid ) throws NamingException
     {
-        if ( !byOid.containsKey( oid ) )
+        if ( !byOidNormalizer.containsKey( oid ) )
         {
-            throw new NamingException( "Normalizer for OID " + oid + " does not exist!" );
+        	String msg = "Normalizer for OID " + oid + " does not exist!";
+        	LOG.debug( msg );
+            throw new NamingException( msg );
         }
 
-        Normalizer normalizer = byOid.get( oid );
+        Normalizer normalizer = byOidNormalizer.get( oid );
         
         if ( DEBUG )
         {
-            LOG.debug( "registered normalizer with oid: " + oid );
+            LOG.debug( "registered normalizer with oid: {}", oid );
         }
         
         return normalizer;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasNormalizer( String oid )
     {
-        return byOid.containsKey( oid );
+        return byOidNormalizer.containsKey( oid );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getSchemaName( String oid ) throws NamingException
     {
-        if ( ! Character.isDigit( oid.charAt( 0 ) ) )
+        if ( !OID.isOID( oid ) )
         {
-            throw new NamingException( "Looks like the arg is not a numeric OID" );
+        	String msg = "OID " + oid + " is not a numeric OID";
+        	LOG.error( msg );
+            throw new NamingException( msg );
         }
 
-        if ( oidToDescription.containsKey( oid ) )
+        NormalizerDescription description = oidToDescription.get( oid );
+        
+        if ( description != null )
         {
-            return getSchema( oidToDescription.get( oid ) );
+            return getSchema( description );
         }
 
-        throw new NamingException( "OID " + oid + " not found in oid to " + "schema name
map!" );
+        String msg = "OID " + oid + " not found in oid to schema name map!";
+        LOG.error( msg );
+        throw new NamingException( msg );
     }
 
 
     private static String getSchema( NormalizerDescription desc )
     {
-        List values = desc.getExtensions().get( "X-SCHEMA" );
+        List<String> values = desc.getExtensions().get( "X-SCHEMA" );
         
-        if ( values == null || values.size() == 0 )
+        if ( ( values == null ) || ( values.size() == 0 ) )
         {
             return "other";
         }
         
-        return desc.getExtensions().get( "X-SCHEMA" ).get( 0 );
+        return values.get( 0 );
     }
     
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<String> oidIterator()
     {
-        return byOid.keySet().iterator();
+        return byOidNormalizer.keySet().iterator();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void unregister( String oid ) throws NamingException
     {
-        if ( ! Character.isDigit( oid.charAt( 0 ) ) )
+        if ( !OID.isOID( oid ) )
         {
-            throw new NamingException( "OID " + oid + " is not a numeric OID" );
+        	String msg = "OID " + oid + " is not a numeric OID";
+        	LOG.error( msg );
+            throw new NamingException( msg );
         }
 
-        this.byOid.remove( oid );
-        this.oidToDescription.remove( oid );
+        byOidNormalizer.remove( oid );
+        oidToDescription.remove( oid );
     }
     
     
+    /**
+     * {@inheritDoc}
+     */
     public void unregisterSchemaElements( String schemaName )
     {
-        List<String> oids = new ArrayList<String>( byOid.keySet() );
+        List<String> oids = new ArrayList<String>( byOidNormalizer.keySet() );
+        
         for ( String oid : oids )
         {
             NormalizerDescription description = oidToDescription.get( oid );
             String schemaNameForOid = getSchema( description );
+            
             if ( schemaNameForOid.equalsIgnoreCase( schemaName ) )
             {
-                byOid.remove( oid );
+            	byOidNormalizer.remove( oid );
                 oidToDescription.remove( oid );
             }
         }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void renameSchema( String originalSchemaName, String newSchemaName )
     {
-        List<String> oids = new ArrayList<String>( byOid.keySet() );
+        List<String> oids = new ArrayList<String>( byOidNormalizer.keySet() );
+        
         for ( String oid : oids )
         {
             NormalizerDescription description = oidToDescription.get( oid );
             String schemaNameForOid = getSchema( description );
+            
             if ( schemaNameForOid.equalsIgnoreCase( originalSchemaName ) )
             {
                 List<String> schemaExt = description.getExtensions().get( "X-SCHEMA"
);
@@ -198,6 +238,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<NormalizerDescription> normalizerDescriptionIterator()
     {
         return oidToDescription.values().iterator();



Mime
View raw message