directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r777320 - in /directory/apacheds/trunk: schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxCheckerRegistry.java xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/BogusSyntax.java
Date Thu, 21 May 2009 23:32:59 GMT
Author: elecharny
Date: Thu May 21 23:32:56 2009
New Revision: 777320

URL: http://svn.apache.org/viewvc?rev=777320&view=rev
Log:
o Cleanup of the SyntaxChecker registry
o Fixed a test which was failing (NPE)

Modified:
    directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxCheckerRegistry.java
    directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/BogusSyntax.java

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxCheckerRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxCheckerRegistry.java?rev=777320&r1=777319&r2=777320&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxCheckerRegistry.java
(original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxCheckerRegistry.java
Thu May 21 23:32:56 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.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.parsers.SyntaxCheckerDescription;
 import org.slf4j.Logger;
@@ -44,8 +45,10 @@
 {
     /** static class logger */
     private static final Logger LOG = LoggerFactory.getLogger( DefaultSyntaxCheckerRegistry.class
);
+    
     /** a map by OID of SyntaxCheckers */
-    private final Map<String, SyntaxChecker> byOid;
+    private final Map<String, SyntaxChecker> byOidSyntaxChecker;
+    
     /** maps an OID to a syntaxCheckerDescription */
     private final Map<String, SyntaxCheckerDescription> oidToDescription;
 
@@ -53,75 +56,97 @@
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
     // ------------------------------------------------------------------------
-
-
     /**
      * Creates an instance of a DefaultSyntaxRegistry.
      */
     public DefaultSyntaxCheckerRegistry()
     {
-        this.byOid = new HashMap<String, SyntaxChecker>();
-        this.oidToDescription = new HashMap<String, SyntaxCheckerDescription>();
+        byOidSyntaxChecker = new ConcurrentHashMap<String, SyntaxChecker>();
+        oidToDescription = new ConcurrentHashMap<String, SyntaxCheckerDescription>();
     }
 
 
     // ------------------------------------------------------------------------
     // Service Methods
     // ------------------------------------------------------------------------
-
-    
+    /**
+     * {@inheritDoc}
+     */
     public void register( SyntaxCheckerDescription syntaxCheckerDescription, SyntaxChecker
syntaxChecker ) throws NamingException
     {
-        if ( byOid.containsKey( syntaxChecker.getSyntaxOid() ) )
+    	String oid = syntaxChecker.getSyntaxOid();
+    	
+        if ( byOidSyntaxChecker.containsKey( oid ) )
         {
-            throw new NamingException( "SyntaxChecker with OID " + syntaxChecker.getSyntaxOid()
-                + " already registered!" );
+        	String msg = "SyntaxChecker with OID " + oid + " already registered!";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
 
-        byOid.put( syntaxChecker.getSyntaxOid(), syntaxChecker );
-        oidToDescription.put( syntaxChecker.getSyntaxOid(), syntaxCheckerDescription );
+        byOidSyntaxChecker.put( oid, syntaxChecker );
+        oidToDescription.put( oid, syntaxCheckerDescription );
+        
         if ( LOG.isDebugEnabled() )
         {
-            LOG.debug( "registered syntaxChecher for OID " + syntaxChecker.getSyntaxOid()
);
+            LOG.debug( "registered syntaxChecher for OID {}", oid );
         }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public SyntaxChecker lookup( String oid ) throws NamingException
     {
-        if ( !byOid.containsKey( oid ) )
+        SyntaxChecker syntaxChecker = byOidSyntaxChecker.get( oid );
+
+        if ( syntaxChecker == null )
         {
-            throw new NamingException( "SyntaxChecker for OID " + oid + " not found!" );
+        	String msg = "SyntaxChecker for OID " + oid + " not found!";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
-
-        SyntaxChecker syntaxChecker = byOid.get( oid );
+        
         if ( LOG.isDebugEnabled() )
         {
-            LOG.debug( "looked up syntaxChecher with OID " + oid );
+            LOG.debug( "looked up syntaxChecher with OID {}", oid );
         }
+
         return syntaxChecker;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasSyntaxChecker( String oid )
     {
-        return byOid.containsKey( oid );
+        return byOidSyntaxChecker.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 = "Looks like the arg is not a numeric OID";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
 
-        if ( oidToDescription.containsKey( oid ) )
+        SyntaxCheckerDescription 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.warn( msg );
+        throw new NamingException( msg );
     }
     
     
@@ -129,7 +154,7 @@
     {
         List<String> ext = desc.getExtensions().get( "X-SCHEMA" );
         
-        if ( ext == null || ext.size() == 0 )
+        if ( ( ext == null ) || ( ext.size() == 0 ) )
         {
             return "other";
         }
@@ -138,47 +163,65 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<SyntaxChecker> iterator()
     {
-        return byOid.values().iterator();
+        return byOidSyntaxChecker.values().iterator();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void unregister( String numericOid ) throws NamingException
     {
-        if ( ! Character.isDigit( numericOid.charAt( 0 ) ) )
+        if ( ! OID.isOID( numericOid ) )
         {
-            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 );
+        byOidSyntaxChecker.remove( numericOid );
         oidToDescription.remove( numericOid );
     }
     
     
+    /**
+     * {@inheritDoc}
+     */
     public void unregisterSchemaElements( String schemaName )
     {
-        List<String> oids = new ArrayList<String>( byOid.keySet() );
+        List<String> oids = new ArrayList<String>( byOidSyntaxChecker.keySet()
);
+        
         for ( String oid : oids )
         {
             SyntaxCheckerDescription description = oidToDescription.get( oid );
             String schemaNameForOid = getSchema( description );
+            
             if ( schemaNameForOid.equalsIgnoreCase( schemaName ) )
             {
-                byOid.remove( oid );
+            	byOidSyntaxChecker.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>( byOidSyntaxChecker.keySet()
);
+        
         for ( String oid : oids )
         {
             SyntaxCheckerDescription description = oidToDescription.get( oid );
             String schemaNameForOid = getSchema( description );
+            
             if ( schemaNameForOid.equalsIgnoreCase( originalSchemaName ) )
             {
                 List<String> values = description.getExtensions().get( "X-SCHEMA" );
@@ -189,6 +232,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<SyntaxCheckerDescription> syntaxCheckerDescriptionIterator()
     {
         return oidToDescription.values().iterator();

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/BogusSyntax.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/BogusSyntax.java?rev=777320&r1=777319&r2=777320&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/BogusSyntax.java
(original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/BogusSyntax.java
Thu May 21 23:32:56 2009
@@ -46,7 +46,7 @@
 
     public SyntaxChecker getSyntaxChecker() throws NamingException
     {
-        return new AcceptAllSyntaxChecker();
+        return new AcceptAllSyntaxChecker( getOid() );
     }
 
 



Mime
View raw message