directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 1428 - in incubator/directory/ldap/trunk/eve/backend/schema: api common/api common/api/src oid oid/api oid/api/src oid/api/src/java oid/api/src/java/org oid/api/src/java/org/apache oid/api/src/java/org/apache/eve oid/api/src/java/org/apache/eve/schema oid/impl oid/impl/src oid/impl/src/java oid/impl/src/java/org oid/impl/src/java/org/apache oid/impl/src/java/org/apache/eve oid/impl/src/java/org/apache/eve/schema
Date Tue, 16 Dec 2003 01:36:33 GMT
Author: akarasulu
Date: Mon Dec 15 17:36:33 2003
New Revision: 1428

Added:
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/   (props changed)
      - copied from rev 1426, incubator/directory/ldap/trunk/eve/backend/schema/api/
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/project.properties
      - copied unchanged from rev 1427, incubator/directory/ldap/trunk/eve/backend/schema/api/project.properties
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/project.xml
      - copied unchanged from rev 1427, incubator/directory/ldap/trunk/eve/backend/schema/api/project.xml
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/
      - copied from rev 1427, incubator/directory/ldap/trunk/eve/backend/schema/api/src/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistry.java
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistryMonitor.java
   incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistryMonitorAdapter.java
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/apache/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/apache/eve/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/apache/eve/schema/
   incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/apache/eve/schema/DefaultOidRegistry.java
Removed:
   incubator/directory/ldap/trunk/eve/backend/schema/api/
Log:
rearranging a few things


Added: incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistry.java
Mon Dec 15 17:36:33 2003
@@ -0,0 +1,118 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+    and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema ;
+
+
+import java.util.List ;
+import java.util.Iterator ;
+
+import javax.naming.NamingException ;
+
+
+/**
+ * Object identifier registry.
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $LastChangedBy$
+ * @version $LastChangedRevision$
+ */
+public interface OidRegistry
+{
+    /** Avalon service interface ROLE */
+    String ROLE = OidRegistry.class.toString() ;
+    
+    /**
+     * Gets the object identifier using a common name
+     * 
+     * @param a_name the name to lookup an OID for
+     * @return the OID string associated with a name
+     * @throws NamingException if a_name does not map to an OID
+     */
+    String getOid( String a_name ) throws NamingException ;
+    
+    /**
+     * Gets the primary name associated with an OID.  The primary name is the
+     * first name specified for the OID.
+     * 
+     * @param a_oid the object identifier
+     * @return the primary name
+     * @throws NamingException if a_oid does not exist
+     */
+    String getPrimaryName( String a_oid ) throws NamingException ;
+    
+    /**
+     * Gets the names associated with an OID.  An OID is unique however it may 
+     * have many names used to refer to it.  A good example is the cn and
+     * commonName attribute names for OID 2.5.4.3.  Within a server one name 
+     * within the set must be chosen as the primary name.  This is used to
+     * name certain things within the server internally.  If there is more than
+     * one name then the first name is taken to be the primary.
+     * 
+     * @param a_oid the OID for which we return the set of common names
+     * @return a sorted set of names
+     * @throws NamingException if a_oid does not exist
+     */
+    List getNameSet( String a_oid ) throws NamingException ;
+    
+    /**
+     * Lists all the OIDs within the registry.  This may be a really big list.
+     * 
+     * @return all the OIDs registered
+     */
+    Iterator list() ;
+    
+    /**
+     * Adds an OID name pair to the registry.
+     * 
+     * @param a_name the name to associate with the OID
+     * @param a_oid the OID to add or associate a new name with 
+     */
+    void register( String a_name, String a_oid ) ;
+}

Added: incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistryMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistryMonitor.java
Mon Dec 15 17:36:33 2003
@@ -0,0 +1,132 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+	and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema ;
+
+
+import java.util.List ;
+
+import javax.naming.NamingException ;
+
+
+/**
+ * Monitor used to track notable OidRegistry events.
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $LastChangedBy$
+ * @version $LastChangedRevision$
+ */
+public interface OidRegistryMonitor
+{
+    /**
+     * Monitors situations where an OID is used to resolve an OID.  The caller
+     * does not know that the argument is the same as the return value.
+     * 
+     * @param a_oid the OID argument and return value
+     */
+    void getOidWithOid( String a_oid ) ;
+    
+    /**
+     * Monitors when an OID is resolved successfully for a name.
+     *  
+     * @param a_name the name used to lookup an OID
+     * @param a_oid the OID returned for the name
+     */
+	void oidResolved( String a_name, String a_oid ) ;
+	
+	/**
+     * Monitors when an OID is resolved successfully by using a normalized form
+     * of the name.
+     *  
+     * @param a_name the name used to lookup an OID
+	 * @param a_normalized the normalized name that mapped to the OID
+     * @param a_oid the OID returned for the name
+	 */
+	void oidResolved( String a_name, String a_normalized, String a_oid ) ;
+	
+	/**
+	 * Monitors when resolution of an OID by name fails.
+	 * 
+	 * @param a_name the name used to lookup an OID
+	 * @param a_fault the exception thrown for the failure after this call
+	 */
+	void oidResolutionFailed( String a_name, NamingException a_fault ) ;
+	
+	/**
+	 * Monitors when a name lookups fail due to the use of an unknown OID.
+	 *  
+	 * @param a_oid the OID used to lookup object names
+	 * @param a_fault the exception thrown for the failure after this call
+	 */
+	void oidDoesNotExist( String a_oid, NamingException a_fault ) ;
+	
+	/**
+	 * Monitors situations where a primary name is resolved for a OID.
+	 * 
+	 * @param a_oid the OID used for the lookup
+	 * @param a_primaryName the primary name found for the OID
+	 */
+	void nameResolved( String a_oid, String a_primaryName ) ;
+
+	/**
+	 * Monitors situations where a names are resolved for a OID.
+	 * 
+	 * @param a_oid the OID used for the lookup
+	 * @param a_names the names found for the OID
+	 */
+	void namesResolved( String a_oid, List a_names ) ;
+	
+	/**
+	 * Monitors the successful registration of a name for an OID.
+	 * 
+	 * @param a_name the one of many names registered with an OID
+	 * @param a_oid the OID to be associated with the name
+	 */
+	void registered( String a_name, String a_oid ) ;
+}

Added: incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistryMonitorAdapter.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/oid/api/src/java/org/apache/eve/schema/OidRegistryMonitorAdapter.java
Mon Dec 15 17:36:33 2003
@@ -0,0 +1,141 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+	and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema;
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+/**
+ * $todo$ doc me
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $LastChangedBy$
+ * @version $LastChangedRevision$
+ */
+public class OidRegistryMonitorAdapter implements OidRegistryMonitor
+{
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#getOidWithOid(java.lang.String)
+     */
+    public void getOidWithOid(String a_a_oid)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#oidResolved(java.lang.String, java.lang.String)
+     */
+    public void oidResolved(String a_a_name, String a_a_oid)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#oidResolved(java.lang.String, java.lang.String,
java.lang.String)
+     */
+    public void oidResolved(
+        String a_a_name,
+        String a_a_normalized,
+        String a_a_oid)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#oidResolutionFailed(java.lang.String,
javax.naming.NamingException)
+     */
+    public void oidResolutionFailed(String a_a_name, NamingException a_a_fault)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#oidDoesNotExist(java.lang.String, javax.naming.NamingException)
+     */
+    public void oidDoesNotExist(String a_a_oid, NamingException a_a_fault)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#nameResolved(java.lang.String, java.lang.String)
+     */
+    public void nameResolved(String a_a_oid, String a_name)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#namesResolved(java.lang.String, java.util.List)
+     */
+    public void namesResolved(String a_a_oid, List a_a_names)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.schema.OidRegistryMonitor#registered(java.lang.String, java.lang.String)
+     */
+    public void registered(String a_a_name, String a_a_oid)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/apache/eve/schema/DefaultOidRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/oid/impl/src/java/org/apache/eve/schema/DefaultOidRegistry.java
Mon Dec 15 17:36:33 2003
@@ -0,0 +1,268 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+	and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema ;
+
+import java.util.List ;
+import java.util.Iterator ;
+import java.util.ArrayList ;
+import java.util.Hashtable ;
+import java.util.Collections ;
+
+import javax.naming.NamingException ;
+
+
+/**
+ * Default OID registry implementation used to resolve a schema object OID 
+ * to a name and vice-versa.
+ * 
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $LastChangedBy$
+ * @version $LastChangedRevision$
+ */
+public class DefaultOidRegistry
+{ 
+	/** Maps OID to a name or a list of names if more than one name exists */
+	private Hashtable m_byOid = new Hashtable() ;
+	/** Maps several names to an OID */
+	private Hashtable m_byName = new Hashtable() ;
+	/** Default OidRegistryMonitor */
+	private OidRegistryMonitor m_monitor = null ;
+    
+    
+	/**
+	 * @see org.apache.ldap.server.schema.OidRegistry#getOid(java.lang.String)
+	 */
+	public String getOid( String a_name ) throws NamingException
+	{
+		/* If a_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( a_name.charAt( 0 ) ) 
+			&& m_byOid.containsKey( a_name ) )
+		{
+		    m_monitor.getOidWithOid( a_name ) ;
+			return a_name ;
+		}
+
+		// If a_name is mapped to a OID already return OID
+		if ( m_byName.containsKey( a_name ) )
+		{
+		    String l_oid = ( String ) m_byName.get( a_name ) ; 
+		    m_monitor.oidResolved( a_name, l_oid ) ;
+			return l_oid ;
+		}
+        
+		/*
+		 * As a last resort we check if a_name is not normalized and if the 
+		 * normalized version used as a key returns an OID.  If the normalized
+		 * name works add the normalized name as a key with its OID to the 
+		 * byName lookup.  BTW these normalized versions of the key are not 
+		 * returned on a getNameSet.
+		 */
+		 String l_lowerCase = a_name.trim().toLowerCase() ;
+		 if ( ! a_name.equals( l_lowerCase ) 
+			&& m_byName.containsKey( l_lowerCase ) )
+		 {
+			 String l_oid = ( String ) m_byName.get( l_lowerCase ) ;
+			 m_monitor.oidResolved( a_name, l_lowerCase, l_oid ) ;
+			 
+			 // We expect to see this version of the key again so we add it 
+			 m_byName.put( a_name, l_oid ) ;
+			 return l_oid ;
+		 }
+         
+		 NamingException l_fault = new NamingException ( "OID for name '" 
+		         + a_name + "' was not " + "found within the OID registry" ) ; 
+		 m_monitor.oidResolutionFailed( a_name, l_fault ) ;
+		 throw l_fault ;
+	}
+
+
+	/**
+	 * @see org.apache.ldap.server.schema.OidRegistry#getPrimaryName(java.lang.String)
+	 */
+	public String getPrimaryName( String a_oid ) throws NamingException
+	{
+		Object l_value = m_byOid.get( a_oid ) ;
+        
+		if ( null == l_value )
+		{
+		    NamingException l_fault = new NamingException ( "OID '" + a_oid 
+		            + "' was not found within the OID registry" ) ; 
+		    m_monitor.oidDoesNotExist( a_oid, l_fault ) ;
+			throw l_fault ;
+		}
+        
+		if ( l_value instanceof String )
+		{
+		    m_monitor.nameResolved( a_oid, ( String ) l_value ) ;
+			return ( String ) l_value ;
+		}
+        
+		String l_name = ( String ) ( ( List ) l_value ).get( 0 ) ;
+		m_monitor.nameResolved( a_oid, l_name ) ;
+		return l_name ;
+	}
+
+
+	/**
+	 * @see org.apache.ldap.server.schema.OidRegistry#getNameSet(java.lang.String)
+	 */
+	public List getNameSet( String a_oid ) throws NamingException
+	{
+		Object l_value = m_byOid.get( a_oid ) ;
+        
+		if ( null == l_value )
+		{
+			NamingException l_fault = new NamingException ( "OID '" + a_oid 
+					+ "' was not found within the OID registry" ) ; 
+			m_monitor.oidDoesNotExist( a_oid, l_fault ) ;
+			throw l_fault ;
+		}
+        
+		if ( l_value instanceof String )
+		{
+		    List l_list = Collections.singletonList( l_value ) ;
+		    m_monitor.namesResolved( a_oid, l_list ) ;
+			return l_list ;
+		}
+        
+		m_monitor.namesResolved( a_oid, ( List ) l_value ) ;
+		return ( List ) l_value ;
+	}
+
+
+	/**
+	 * @see org.apache.ldap.server.schema.OidRegistry#listOids()
+	 */
+	public Iterator listOids()
+	{
+		return Collections.unmodifiableSet( m_byOid.keySet() ).iterator() ;
+	}
+
+
+	/**
+	 * @see org.apache.ldap.server.schema.OidRegistry#add(java.lang.String, 
+	 * java.lang.String)
+	 */
+	public void register( String a_name, String a_oid )
+	{
+		/*
+		 * 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 l_lowerCase = a_name.toLowerCase() ;
+		if ( ! l_lowerCase.equals( a_name ) )
+		{
+			m_byName.put( l_lowerCase, a_oid ) ;
+		}
+        
+		// Put both the name and the oid as names
+		m_byName.put( a_name, a_oid ) ;
+		m_byName.put( a_oid, a_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 l_value = null ;
+		if ( ! m_byOid.containsKey( a_oid ) )
+		{
+			l_value = a_name ;
+		}
+		else 
+		{
+			ArrayList l_list = null ;
+			l_value = m_byOid.get( a_oid ) ;
+            
+			if ( l_value instanceof String )
+			{
+				String l_existingName = ( String ) l_value ;
+                
+				// if the existing name is already there we don't readd it
+				if ( l_existingName.equalsIgnoreCase( a_name ) )
+				{
+					return ;
+				}
+                
+				l_list = new ArrayList() ;
+				l_list.add( l_value ) ;
+				l_value = l_list ;
+			}
+			else if ( l_value instanceof ArrayList )
+			{
+				l_list = ( ArrayList ) l_list ;
+                
+				for ( int ii = 0; ii < l_list.size(); ii++ )
+				{
+					// One form or another of the name already exists in list
+					if ( ! a_name.equalsIgnoreCase( ( String ) 
+						l_list.get( ii ) ) )
+					{
+						return ;
+					}
+				}
+                
+				l_list.add( a_name ) ;
+			}
+		}
+
+		m_byOid.put( a_oid, l_value ) ;
+		m_monitor.registered( a_name, a_oid ) ;
+	}
+}
+

Mime
View raw message