You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/12/19 00:17:08 UTC
svn commit: r357545 - in
/directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema:
GlobalOidRegistry.java OidRegistry.java bootstrap/BootstrapOidRegistry.java
Author: elecharny
Date: Sun Dec 18 15:17:00 2005
New Revision: 357545
URL: http://svn.apache.org/viewcvs?rev=357545&view=rev
Log:
- changed the inheritance schema (using AbstractOidRegistry=
- added da toString() method
- deleted the reference to Monitor
- fixed a bug in the registry : if an OID has more than one name,
the first one was not stored
Modified:
directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/GlobalOidRegistry.java
directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/OidRegistry.java
directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapOidRegistry.java
Modified: directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/GlobalOidRegistry.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/GlobalOidRegistry.java?rev=357545&r1=357544&r2=357545&view=diff
==============================================================================
--- directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/GlobalOidRegistry.java (original)
+++ directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/GlobalOidRegistry.java Sun Dec 18 15:17:00 2005
@@ -17,16 +17,15 @@
package org.apache.ldap.server.schema;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import javax.naming.NamingException;
+import org.apache.asn1new.primitives.OID;
+import org.apache.commons.lang.StringUtils;
import org.apache.ldap.server.schema.bootstrap.BootstrapOidRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -36,16 +35,10 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class GlobalOidRegistry implements OidRegistry
+public class GlobalOidRegistry extends AbstractOidRegistry
{
- /** Maps OID to a name or a list of names if more than one name exists */
- private Hashtable byOid = new Hashtable();
-
- /** Maps several names to an OID */
- private Hashtable byName = new Hashtable();
-
- /** Default OidRegistryMonitor */
- private OidRegistryMonitor monitor = new OidRegistryMonitorAdapter();
+ /** The LoggerFactory used by this Interceptor */
+ private static Logger log = LoggerFactory.getLogger( GlobalOidRegistry.class );
/** the underlying bootstrap registry to delegate on misses to */
private BootstrapOidRegistry bootstrap;
@@ -61,39 +54,14 @@
*/
public GlobalOidRegistry( BootstrapOidRegistry bootstrap )
{
- this.bootstrap = bootstrap;
-
- if ( this.bootstrap == null )
+ if ( bootstrap == null )
{
throw new NullPointerException( "the bootstrap registry cannot be null" ) ;
}
- }
-
-
-
- /**
- * Gets the monitor.
- *
- * @return the monitor
- */
- OidRegistryMonitor getMonitor()
- {
- return monitor;
- }
-
-
- /**
- * Sets the monitor.
- *
- * @param monitor monitor to set.
- */
- void setMonitor( OidRegistryMonitor monitor )
- {
- this.monitor = monitor;
+ this.bootstrap = bootstrap;
}
-
// ------------------------------------------------------------------------
// Service Methods
// ------------------------------------------------------------------------
@@ -104,8 +72,9 @@
*/
public String getOid( String name ) throws NamingException
{
- if ( name == null )
+ if ( StringUtils.isEmpty( name ) )
{
+ log.error( "The name to be looked at should not be null" );
throw new NamingException( "name should not be null" );
}
@@ -113,9 +82,8 @@
* OID is another name for the object referred to by OID and the
* caller does not know that the argument is an OID String.
*/
- if ( Character.isDigit( name.charAt( 0 ) ) )
+ if ( OID.isOID( name ) )
{
- monitor.getOidWithOid( name );
return name;
}
@@ -124,14 +92,12 @@
if ( byName.containsKey( name ) )
{
String oid = ( String ) byName.get( name );
- monitor.oidResolved( name, oid );
return oid;
}
if ( bootstrap.hasOid( name ) )
{
String oid = bootstrap.getOid( name );
- monitor.oidResolved( name, oid );
return oid;
}
@@ -142,13 +108,13 @@
* byName lookup. BTW these normalized versions of the key are not
* returned on a getNameSet.
*/
- String lowerCase = name.trim().toLowerCase();
+ String lowerCase = StringUtils.lowerCase( StringUtils.trim( name ) );
+
if ( ! name.equals( lowerCase ) )
{
if ( byName.containsKey( lowerCase ) )
{
String oid = ( String ) byName.get( lowerCase );
- monitor.oidResolved( name, lowerCase, oid );
// We expect to see this version of the key again so we add it
byName.put( name, oid );
@@ -164,7 +130,6 @@
if ( bootstrap.hasOid( lowerCase) )
{
String oid = bootstrap.getOid( name );
- monitor.oidResolved( name, oid );
// We expect to see this version of the key again so we add it
byName.put( name, oid );
@@ -172,10 +137,9 @@
}
}
- String msg = "OID for name '" + name + "' was not " + "found within the OID registry";
- NamingException fault = new NamingException ( msg );
- monitor.oidResolutionFailed( name, fault );
- throw fault;
+ String msg = "OID for name '" + name + "' was not found within the OID registry";
+ log.error( msg );
+ throw new NamingException ( msg );
}
@@ -184,14 +148,19 @@
*/
public boolean hasOid( String name )
{
+ if ( StringUtils.isEmpty( name ) )
+ {
+ return false;
+ }
+
// check first with non-normalized name
- if ( this.byName.containsKey( name ) || this.byOid.containsKey( name ) )
+ if ( byName.containsKey( name ) || byOid.containsKey( name ) )
{
return true;
}
// check next with non-normalized name on the bootstrap registry
- if ( this.bootstrap.hasOid( name ) )
+ if ( bootstrap.hasOid( name ) )
{
return true;
}
@@ -203,13 +172,20 @@
* byName lookup. BTW these normalized versions of the key are not
* returned on a getNameSet.
*/
- String lowerCase = name.trim().toLowerCase();
+ String trimedName = StringUtils.trim( name );
+
+ if ( StringUtils.isEmpty( trimedName ) )
+ {
+ return false;
+ }
+
+ String lowerCase = StringUtils.lowerCase( trimedName );
+
if ( ! name.equals( lowerCase ) )
{
if ( byName.containsKey( lowerCase ) )
{
String oid = ( String ) byName.get( lowerCase );
- monitor.oidResolved( name, lowerCase, oid );
// We expect to see this version of the key again so we add it
byName.put( name, oid );
@@ -230,190 +206,45 @@
return false;
}
-
- /**
- * @see OidRegistry#getPrimaryName(String)
- */
- public String getPrimaryName( String oid ) throws NamingException
- {
- Object value = byOid.get( oid );
-
- if ( null == value )
- {
- String msg = "OID '" + oid + "' was not found within the OID registry";
-
- NamingException fault = new NamingException ( msg );
-
- monitor.oidDoesNotExist( oid, fault );
-
- throw fault;
- }
-
- if ( value instanceof String )
- {
- monitor.nameResolved( oid, ( String ) value );
-
- return ( String ) value;
- }
-
- String name = ( String ) ( ( List ) value ).get( 0 );
-
- monitor.nameResolved( oid, name );
-
- return name;
- }
-
-
/**
* @see OidRegistry#getNameSet(String)
*/
public List getNameSet( String oid ) throws NamingException
{
- Object value = this.byOid.get( oid );
+ List value = super.getNameSet( oid );
if ( null == value )
{
- value = this.bootstrap.getNameSet( oid );
+ return bootstrap.getNameSet( oid );
}
-
- if ( null == value )
+ else
{
- String msg = "OID '" + oid + "' was not found within the OID registry";
-
- NamingException fault = new NamingException ( msg );
-
- monitor.oidDoesNotExist( oid, fault );
-
- throw fault;
- }
-
- if ( value instanceof String )
- {
- List list = Collections.singletonList( value );
-
- monitor.namesResolved( oid, list );
-
- return list;
- }
-
- monitor.namesResolved( oid, ( List ) value );
-
- return ( List ) value;
- }
-
-
- /**
- * @see OidRegistry#list()
- */
- public Iterator list()
- {
- return Collections.unmodifiableSet( byOid.keySet() ).iterator();
- }
-
-
- /**
- * @see OidRegistry#register(String, String)
- */
- public void register( String name, String oid )
- {
- if ( ! Character.isDigit( oid.charAt( 0 ) ) )
- {
- throw new RuntimeException( "Swap the parameter order: the oid " +
- "does not start with a digit!" );
- }
-
- /*
- * Add the entry for the given name as is and its lowercased version if
- * the lower cased name is different from the given name name.
- */
- String lowerCase = name.toLowerCase();
-
- if ( ! lowerCase.equals( name ) )
- {
- byName.put( lowerCase, oid );
- }
-
- // Put both the name and the oid as names
- byName.put( name, oid );
-
- byName.put( oid, oid );
-
- /*
- * Update OID Map
- *
- * 1). Check if we already have a value[s] stored
- * 1a). Value is a single value and is a String
- * Replace value with list containing old and new values
- * 1b). More than one value stored in a list
- * Add new value to the list
- * 2). If we do not have a value then we just add it as a String
- */
- Object value = null;
-
- if ( ! byOid.containsKey( oid ) )
- {
- value = name;
+ return value;
}
- else
- {
- ArrayList list = null;
-
- value = byOid.get( oid );
-
- if ( value instanceof String )
- {
- String existingName = ( String ) value;
-
- // if the existing name is already there we don't readd it
- if ( existingName.equalsIgnoreCase( name ) )
- {
- return;
- }
-
- list = new ArrayList();
-
- list.add( value );
-
- value = list;
- }
- else if ( value instanceof ArrayList )
- {
- list = ( ArrayList ) value;
-
- for ( int ii = 0; ii < list.size(); ii++ )
- {
- // One form or another of the name already exists in list
- if ( ! name.equalsIgnoreCase( ( String ) list.get( ii ) ) )
- {
- return;
- }
- }
-
- list.add( name );
- }
- }
-
- byOid.put( oid, value );
-
- monitor.registered( name, oid );
}
-
+
/**
- * Get the map of all the oids by their name
- * @return The Map that contains all the oids
+ * A String representation of the class
*/
- public Map getOidByName()
+ public String toString( String tabs )
{
- return byName;
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( tabs ).append( "GlobalOidRegistry :\n" );
+
+ sb.append( super.toString( tabs + " " ) );
+
+ sb.append( tabs ).append( bootstrap == null ? "no bootstrap" : bootstrap.toString() );
+
+ return sb.toString();
}
/**
- * Get the map of all the oids by their name
- * @return The Map that contains all the oids
+ * A String representation of the class
*/
- public Map getNameByOid()
+ public String toString()
{
- return byOid;
+ return toString( "" );
}
}
Modified: directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/OidRegistry.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/OidRegistry.java?rev=357545&r1=357544&r2=357545&view=diff
==============================================================================
--- directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/OidRegistry.java (original)
+++ directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/OidRegistry.java Sun Dec 18 15:17:00 2005
@@ -100,4 +100,8 @@
* @return The Map that contains all the oids
*/
public Map getNameByOid();
+
+ public String toString( String tabs );
+
+ public String toString();
}
Modified: directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapOidRegistry.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapOidRegistry.java?rev=357545&r1=357544&r2=357545&view=diff
==============================================================================
--- directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapOidRegistry.java (original)
+++ directory/apacheds/branches/DN-refactoring/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapOidRegistry.java Sun Dec 18 15:17:00 2005
@@ -17,19 +17,15 @@
package org.apache.ldap.server.schema.bootstrap;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import javax.naming.NamingException;
-import org.apache.ldap.server.schema.OidRegistry;
-import org.apache.ldap.server.schema.OidRegistryMonitor;
-import org.apache.ldap.server.schema.OidRegistryMonitorAdapter;
+import org.apache.asn1new.primitives.OID;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ldap.server.schema.AbstractOidRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -37,36 +33,29 @@
* to a name and vice-versa.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
*/
-public class BootstrapOidRegistry implements OidRegistry
+public class BootstrapOidRegistry extends AbstractOidRegistry
{
- /** Maps OID to a name or a list of names if more than one name exists */
- private Map byOid = new HashMap();
-
- /** Maps several names to an OID */
- private Map byName = new HashMap();
-
- /** Default OidRegistryMonitor */
- private OidRegistryMonitor monitor = new OidRegistryMonitorAdapter();
-
-
+ /** The LoggerFactory used by this class */
+ private static Logger log = LoggerFactory.getLogger( BootstrapOidRegistry.class );
+
/**
* @see org.apache.ldap.server.schema.OidRegistry#getOid(java.lang.String)
*/
public String getOid( String name ) throws NamingException
{
- if ( name == null )
+ if ( StringUtils.isEmpty( name ) )
{
+ log.error( "The name to be looked at should not be null" );
throw new NamingException( "name should not be null" );
}
+
/* If name is an OID than we return it back since inherently the
* OID is another name for the object referred to by OID and the
* caller does not know that the argument is an OID String.
*/
- if ( Character.isDigit( name.charAt( 0 ) ) )
+ if ( OID.isOID( name ) )
{
- monitor.getOidWithOid( name );
return name;
}
@@ -74,7 +63,6 @@
if ( byName.containsKey( name ) )
{
String oid = ( String ) byName.get( name );
- monitor.oidResolved( name, oid );
return oid;
}
@@ -85,22 +73,21 @@
* byName lookup. BTW these normalized versions of the key are not
* returned on a getNameSet.
*/
- String lowerCase = name.trim().toLowerCase();
+ String lowerCase = StringUtils.lowerCase( StringUtils.trim( name ) );
+
if ( ! name.equals( lowerCase )
&& byName.containsKey( lowerCase ) )
{
String oid = ( String ) byName.get( lowerCase );
- monitor.oidResolved( name, lowerCase, oid );
// We expect to see this version of the key again so we add it
byName.put( name, oid );
return oid;
}
- NamingException fault = new NamingException ( "OID for name '"
- + name + "' was not " + "found within the OID registry" );
- monitor.oidResolutionFailed( name, fault );
- throw fault;
+ String msg = "OID for name '" + name + "' was not found within the OID registry";
+ log.error( msg );
+ throw new NamingException ( msg );
}
@@ -109,40 +96,26 @@
*/
public boolean hasOid( String name )
{
- if ( this.byName.containsKey( name ) || this.byOid.containsKey( name ) )
+ if ( StringUtils.isEmpty( name ) )
+ {
+ return false;
+ }
+
+ if ( byName.containsKey( name ) || byOid.containsKey( name ) )
{
return true;
}
- String normalized = name.toLowerCase();
- return this.byName.containsKey( normalized ) || this.byOid.containsKey( normalized );
- }
-
+ String trimedName = StringUtils.trim( name );
+
+ if ( StringUtils.isEmpty( trimedName ) )
+ {
+ return false;
+ }
+
+ String lowerCase = StringUtils.lowerCase( trimedName );
- /**
- * @see org.apache.ldap.server.schema.OidRegistry#getPrimaryName(java.lang.String)
- */
- public String getPrimaryName( String oid ) throws NamingException
- {
- Object value = byOid.get( oid );
-
- if ( null == value )
- {
- NamingException fault = new NamingException ( "OID '" + oid
- + "' was not found within the OID registry" );
- monitor.oidDoesNotExist( oid, fault );
- throw fault;
- }
-
- if ( value instanceof String )
- {
- monitor.nameResolved( oid, ( String ) value );
- return ( String ) value;
- }
-
- String name = ( String ) ( ( List ) value ).get( 0 );
- monitor.nameResolved( oid, name );
- return name;
+ return byName.containsKey( lowerCase ) || byOid.containsKey( lowerCase );
}
@@ -151,154 +124,43 @@
*/
public List getNameSet( String oid ) throws NamingException
{
- Object value = byOid.get( oid );
+ List value = super.getNameSet( oid );
if ( null == value )
{
NamingException fault = new NamingException ( "OID '" + oid
+ "' was not found within the OID registry" );
- monitor.oidDoesNotExist( oid, fault );
throw fault;
}
-
- if ( value instanceof String )
+ else
{
- List list = Collections.singletonList( value );
- monitor.namesResolved( oid, list );
- return list;
+ return value;
}
-
- monitor.namesResolved( oid, ( List ) value );
- return ( List ) value;
- }
-
-
- /**
- * @see org.apache.ldap.server.schema.OidRegistry#list()
- */
- public Iterator list()
- {
- return Collections.unmodifiableSet( byOid.keySet() ).iterator();
}
/**
- * Get the map of all the oids by their name
- * @return The Map that contains all the oids
+ * A String representation of the class
*/
- public Map getOidByName()
+ public String toString( String tabs )
{
- return byName;
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( tabs ).append( "BootstrapOidRegistry : {\n" );
+
+ sb.append( super.toString( tabs + " " ) );
+
+ sb.append( tabs ).append( "}\n" );
+
+ return sb.toString();
}
/**
- * Get the map of all the oids by their name
- * @return The Map that contains all the oids
+ * A String representation of the class
*/
- public Map getNameByOid()
+ public String toString()
{
- return byOid;
- }
-
- /**
- * @see org.apache.ldap.server.schema.OidRegistry#register(String, String)
- */
- public void register( String name, String oid )
- {
- if ( ! Character.isDigit( oid.charAt( 0 ) ) )
- {
- throw new RuntimeException( "Swap the parameter order: the oid " +
- "does not start with a digit!" );
- }
-
- /*
- * Add the entry for the given name as is and its lowercased version if
- * the lower cased name is different from the given name name.
- */
- String lowerCase = name.toLowerCase();
- if ( ! lowerCase.equals( name ) )
- {
- byName.put( lowerCase, oid );
- }
-
- // Put both the name and the oid as names
- byName.put( name, oid );
- byName.put( oid, oid );
-
- /*
- * Update OID Map
- *
- * 1). Check if we already have a value[s] stored
- * 1a). Value is a single value and is a String
- * Replace value with list containing old and new values
- * 1b). More than one value stored in a list
- * Add new value to the list
- * 2). If we do not have a value then we just add it as a String
- */
- Object value;
- if ( ! byOid.containsKey( oid ) )
- {
- value = name;
- }
- else
- {
- ArrayList list;
- value = byOid.get( oid );
-
- if ( value instanceof String )
- {
- String existingName = ( String ) value;
-
- // if the existing name is already there we don't readd it
- if ( existingName.equalsIgnoreCase( name ) )
- {
- return;
- }
-
- list = new ArrayList();
- list.add( value );
- value = list;
- }
- else if ( value instanceof ArrayList )
- {
- list = ( ArrayList ) value;
-
- for ( int ii = 0; ii < list.size(); ii++ )
- {
- // One form or another of the name already exists in list
- if ( ! name.equalsIgnoreCase( ( String ) list.get( ii ) ) )
- {
- return;
- }
- }
-
- list.add( name );
- }
- }
-
- byOid.put( oid, value );
- monitor.registered( name, oid );
+ return toString( "" );
}
-
- /**
- * Gets the monitor.
- *
- * @return the monitor
- */
- OidRegistryMonitor getMonitor()
- {
- return monitor;
- }
-
-
- /**
- * Sets the monitor.
- *
- * @param monitor monitor to set.
- */
- void setMonitor( OidRegistryMonitor monitor )
- {
- this.monitor = monitor;
- }
}