directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r777177 - in /directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries: DefaultAttributeTypeRegistry.java DefaultObjectClassRegistry.java DefaultSyntaxRegistry.java
Date Thu, 21 May 2009 17:01:43 GMT
Author: elecharny
Date: Thu May 21 17:01:43 2009
New Revision: 777177

URL: http://svn.apache.org/viewvc?rev=777177&view=rev
Log:
o SyntaxRegistry cleanup (+javadoc, +logs, some minor improvements)
o Used OID.isValid( oid ) instead of some other technics to validate OIDs

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/DefaultSyntaxRegistry.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=777177&r1=777176&r2=777177&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 17:01:43 2009
@@ -30,6 +30,7 @@
 import javax.naming.NamingException;
 import javax.naming.directory.NoSuchAttributeException;
 
+import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
@@ -348,9 +349,9 @@
      */
     public void unregister( String numericOid ) throws NamingException
     {
-        if ( ! Character.isDigit( numericOid.charAt( 0 ) ) )
+        if ( ! OID.isOID( numericOid ) )
         {
-        	String msg = "Looks like the arg (" + numericOid + ") is not a numeric OID";
+        	String msg = "Looks like the arg " + numericOid + " is not a numeric OID";
         	LOG.error(msg );
             throw new NamingException( msg );
         }

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=777177&r1=777176&r2=777177&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 17:01:43 2009
@@ -26,6 +26,7 @@
 
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -207,16 +208,9 @@
      */
     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 ) ) )
+        if ( ! OID.isOID( numericOid ) )
         {
-        	String msg = "Looks like the arg is not a numeric OID";
+        	String msg = "Looks like the arg " + numericOid + " is not a numeric OID";
         	LOG.warn( msg );
             throw new NamingException( msg );
         }

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java?rev=777177&r1=777176&r2=777177&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java
(original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java
Thu May 21 17:01:43 2009
@@ -20,12 +20,13 @@
 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;
 
+import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.schema.Syntax;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,7 +48,8 @@
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
     
     /** a map of entries using an OID for the key and a Syntax for the value */
-    private final Map<String,Syntax> byOid;
+    private final Map<String,Syntax> byOidSyntax;
+    
     /** the OID oidRegistry this oidRegistry uses to register new syntax OIDs */
     private final OidRegistry oidRegistry;
 
@@ -65,110 +67,139 @@
     public DefaultSyntaxRegistry( OidRegistry registry )
     {
         this.oidRegistry = registry;
-        this.byOid = new HashMap<String,Syntax>();
+        byOidSyntax = new ConcurrentHashMap<String,Syntax>();
     }
 
 
     // ------------------------------------------------------------------------
     // SyntaxRegistry interface methods
     // ------------------------------------------------------------------------
-
-    
+    /**
+     * {@inheritDoc}
+     */
     public Syntax lookup( String id ) throws NamingException
     {
         id = oidRegistry.getOid( id );
+        Syntax syntax = byOidSyntax.get( id );
 
-        if ( byOid.containsKey( id ) )
+        if ( syntax != null )
         {
-            Syntax syntax = byOid.get( id );
-            
             if ( IS_DEBUG )
             {
-                LOG.debug( "looked up using id '" + id + "': " + syntax );
+                LOG.debug( "looked up using id '{}' : {}", id, syntax );
             }
             
             return syntax;
         }
 
-        throw new NamingException( "Unknown syntax OID " + id );
+        String msg = "Unknown syntax OID " + id;
+        LOG.error( msg );
+        throw new NamingException( msg );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void register( Syntax syntax ) throws NamingException
     {
-        if ( byOid.containsKey( syntax.getOid() ) )
+    	String oid = syntax.getOid();
+    	
+        if ( byOidSyntax.containsKey( oid ) )
         {
-            throw new NamingException( "syntax w/ OID " + syntax.getOid()
-                + " has already been registered!" );
+        	String msg = "syntax " + syntax + " w/ OID " + oid
+            	+ " has already been registered!";
+        	LOG.warn( msg );
+            throw new NamingException( msg );
         }
 
+        // Register the new Syntax's oid/name relation into the global oidRegistry
         if ( syntax.getName() != null )
         {
-            oidRegistry.register( syntax.getName(), syntax.getOid() );
-        }
-        else
-        {
-            oidRegistry.register( syntax.getOid(), syntax.getOid() );
+            oidRegistry.register( syntax.getName(), oid );
         }
 
-        byOid.put( syntax.getOid(), syntax );
+        // Also register the oid/oid relation
+        oidRegistry.register( oid, oid );
+        byOidSyntax.put( oid, syntax );
         
         if ( IS_DEBUG )
         {
-            LOG.debug( "registered syntax: " + syntax );
+            LOG.debug( "registered syntax: {}", syntax );
         }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasSyntax( 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 byOidSyntax.containsKey( oid );
+        	}
+        	
+        	return false;
+        }
+        catch ( NamingException e )
+        {
+            return false;
         }
-
-        return false;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getSchemaName( String id ) throws NamingException
     {
-        if ( ! Character.isDigit( id.charAt( 0 ) ) )
+        if ( ! OID.isOID( id ) )
         {
-            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 );
         }
 
-        id = oidRegistry.getOid( id );
-        Syntax syntax = byOid.get( id );
+        String oid = oidRegistry.getOid( id );
+        Syntax syntax = byOidSyntax.get( oid );
+       
         if ( syntax != null )
         {
             return syntax.getSchema();
         }
 
-        throw new NamingException( "OID " + id + " not found in oid to " + "Syntax map!"
);
+        String msg = "OID " + oid + " not found in oid to Syntax map!";
+        LOG.error( msg );
+        throw new NamingException( msg );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<Syntax> iterator()
     {
-        return byOid.values().iterator();
+        return byOidSyntax.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 " + numericOid + " is not a numeric OID";
+    		LOG.error( msg );
+    		throw new NamingException( msg );
         }
 
-        byOid.remove( numericOid );
+        byOidSyntax.remove( numericOid );
     }
 }



Mime
View raw message