You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/07/29 17:57:13 UTC
svn commit: r426819 - in
/directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default: ./
pom.xml
src/main/java/org/apache/directory/server2/schema/registries/oid/default/DefaultOidRegistry.java
Author: akarasulu
Date: Sat Jul 29 08:57:13 2006
New Revision: 426819
URL: http://svn.apache.org/viewvc?rev=426819&view=rev
Log:
brushing off old 1.x branch class
Added:
directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/src/main/java/org/apache/directory/server2/schema/registries/oid/default/DefaultOidRegistry.java
Modified:
directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/ (props changed)
directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/pom.xml
Propchange: directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Jul 29 08:57:13 2006
@@ -1,3 +1,4 @@
.classpath
+.settings
.project
target
Modified: directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/pom.xml?rev=426819&r1=426818&r2=426819&view=diff
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/pom.xml (original)
+++ directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/pom.xml Sat Jul 29 08:57:13 2006
@@ -6,8 +6,8 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>osgi-bundle</packaging>
- <name>ApacheDS 2.0: Default Oid Registry Service Implementation</name>
- <artifactId>oid-registry-service-default</artifactId>
+ <name>ApacheDS 2.0: Default Oid Registry Impl</name>
+ <artifactId>oid-registry-default</artifactId>
<dependencies>
</dependencies>
<build>
@@ -19,7 +19,7 @@
<extensions>true</extensions>
<configuration>
<osgiManifest>
- <bundleName>ApacheDS Oid Registry Service</bundleName>
+ <bundleName>ApacheDS Default Oid Registry Impl</bundleName>
<bundleVendor>Apache Software Foundation</bundleVendor>
<bundleDescription>
A bundle containing the OID registry interface.
Added: directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/src/main/java/org/apache/directory/server2/schema/registries/oid/default/DefaultOidRegistry.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/src/main/java/org/apache/directory/server2/schema/registries/oid/default/DefaultOidRegistry.java?rev=426819&view=auto
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/src/main/java/org/apache/directory/server2/schema/registries/oid/default/DefaultOidRegistry.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/schema/registries/oid/default/src/main/java/org/apache/directory/server2/schema/registries/oid/default/DefaultOidRegistry.java Sat Jul 29 08:57:13 2006
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.directory.server2.schema.registries.oid.default;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.schema.OidRegistry;
+import org.apache.directory.server.core.schema.OidRegistryMonitor;
+import org.apache.directory.server.core.schema.OidRegistryMonitorAdapter;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * Default OID registry implementation used to resolve a schema object OID
+ * to a name and vice-versa.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 420140 $
+ */
+public class DefaultOidRegistry implements OidRegistry
+{
+ /** 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();
+
+
+ /**
+ * @see org.apache.directory.server.core.schema.OidRegistry#getOid(java.lang.String)
+ */
+ public String getOid( String name ) throws NamingException
+ {
+ if ( name != null && name.length() > 0 )
+ {
+ throw new NamingException( "name should not be null or empty" );
+ }
+
+ /* 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.
+ */
+ char car = name.charAt( 0 );
+ if ( car >= '0' && car <= '9' )
+ {
+ //monitor.getOidWithOid( name );
+ return name;
+ }
+
+ // If name is mapped to a OID already return OID
+ if ( byName.containsKey( name ) )
+ {
+ String oid = ( String ) byName.get( name );
+ return oid;
+ }
+
+ /*
+ * As a last resort we check if 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 lowerCase = name.trim().toLowerCase();
+ if ( !name.equals( lowerCase ) && byName.containsKey( lowerCase ) )
+ {
+ String oid = ( String ) byName.get( lowerCase );
+
+ // 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" );
+ throw fault;
+ }
+
+
+ /**
+ * @see org.apache.directory.server.core.schema.OidRegistry#hasOid(java.lang.String)
+ */
+ public boolean hasOid( String name )
+ {
+ if ( this.byName.containsKey( name ) || this.byOid.containsKey( name ) )
+ {
+ return true;
+ }
+
+ String normalized = name.toLowerCase();
+ return this.byName.containsKey( normalized ) || this.byOid.containsKey( normalized );
+ }
+
+
+ /**
+ * @see org.apache.directory.server.core.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" );
+ throw fault;
+ }
+
+ if ( value instanceof String )
+ {
+ return ( String ) value;
+ }
+
+ String name = ( String ) ( ( List ) value ).get( 0 );
+ return name;
+ }
+
+
+ /**
+ * @see org.apache.directory.server.core.schema.OidRegistry#getNameSet(java.lang.String)
+ */
+ public List getNameSet( 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" );
+ throw fault;
+ }
+
+ if ( value instanceof String )
+ {
+ List list = Collections.singletonList( value );
+ return list;
+ }
+
+ return ( List ) value;
+ }
+
+
+ /**
+ * @see org.apache.directory.server.core.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
+ */
+ public Map getOidByName()
+ {
+ return byName;
+ }
+
+
+ /**
+ * Get the map of all the oids by their name
+ * @return The Map that contains all the oids
+ */
+ public Map getNameByOid()
+ {
+ return byOid;
+ }
+
+
+ /**
+ * @see org.apache.directory.server.core.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( name );
+ 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 );
+ }
+}