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 2009/08/31 17:49:12 UTC
svn commit: r809635 - in /directory/shared/branches/shared-schema/ldap/src:
main/java/org/apache/directory/shared/ldap/ldif/
main/java/org/apache/directory/shared/ldap/schema/
main/java/org/apache/directory/shared/ldap/schema/registries/
test/java/org/...
Author: elecharny
Date: Mon Aug 31 15:49:11 2009
New Revision: 809635
URL: http://svn.apache.org/viewvc?rev=809635&view=rev
Log:
o Added a test for ATRegistry
o Fixed the SchemaObjectRegistry handling of the byName() structure
o Fixed the DescriptionUtils representation of SO
o Changed the LdifEntry.toString() method to produce a LDIF output
o Added some error logs in SchemaLoader
Added:
directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/registries/
directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/registries/AttributeTypeRegistryTest.java
Modified:
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java Mon Aug 31 15:49:11 2009
@@ -45,6 +45,7 @@
import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.util.DNUtils;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -632,65 +633,18 @@
/**
- * @return a String representing the Entry
+ * @return a String representing the Entry, as a LDIF
*/
public String toString()
{
- StringBuffer sb = new StringBuffer();
- sb.append( "Entry : " );
-
- if ( entry.getDn() == null )
+ try
{
- sb.append( "" );
+ return LdifUtils.convertToLdif( this );
}
- else
+ catch ( NamingException ne )
{
- sb.append( entry.getDn().getUpName() ).append( '\n' );
- }
-
- sb.append( '\n' );
-
- if ( control != null )
- {
- sb.append( " Control : " ).append( control ).append( '\n' );
- }
-
- switch ( changeType )
- {
- case Add :
- sb.append( " Change type is ADD\n" );
- sb.append( " Attributes : \n" );
- sb.append( dumpAttributes() );
- break;
-
- case Modify :
- sb.append( " Change type is MODIFY\n" );
- sb.append( " Modifications : \n" );
- sb.append( dumpModificationItems() );
- break;
-
- case Delete :
- sb.append( " Change type is DELETE\n" );
- break;
-
- case ModDn :
- case ModRdn :
- sb.append( " Change type is ").append( changeType == ChangeType.ModDn ? "MODDN\n" : "MODRDN\n" );
- sb.append( " Delete old RDN : " ).append( deleteOldRdn ? "true\n" : "false\n" );
- sb.append( " New RDN : " ).append( newRdn ).append( '\n' );
-
- if ( !StringTools.isEmpty( newSuperior ) )
- {
- sb.append( " New superior : " ).append( newSuperior ).append( '\n' );
- }
-
- break;
-
- default :
- break; // Do nothing
+ return null;
}
-
- return sb.toString();
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java Mon Aug 31 15:49:11 2009
@@ -83,57 +83,55 @@
buf.append( attributeType.getOid() );
buf.append( '\n' );
- if ( attributeType.getName() != null )
+ if ( attributeType.getNames() != null )
{
- buf.append( "NAME " );
- buf.append( attributeType.getName() );
- buf.append( '\n' );
+ buf.append( " NAME " );
+ getQDescrs( buf, attributeType.getNames() );
}
if ( attributeType.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( attributeType.getDescription() );
buf.append( '\n' );
}
if ( attributeType.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
if ( attributeType.getSuperior() != null )
{
- buf.append( "SUP " );
+ buf.append( " SUP " );
buf.append( attributeType.getSuperiorName() );
buf.append( '\n' );
}
if ( attributeType.getEquality() != null )
{
- buf.append( "EQUALITY " );
+ buf.append( " EQUALITY " );
buf.append( attributeType.getEqualityName() );
buf.append( '\n' );
}
if ( attributeType.getOrdering() != null )
{
- buf.append( "ORDERING " );
+ buf.append( " ORDERING " );
buf.append( attributeType.getOrderingName() );
buf.append( '\n' );
}
if ( attributeType.getSubstring() != null )
{
- buf.append( "SUBSTR " );
+ buf.append( " SUBSTR " );
buf.append( attributeType.getSubstringName() );
buf.append( '\n' );
}
if ( attributeType.getSyntax() != null )
{
- buf.append( "SYNTAX " );
+ buf.append( " SYNTAX " );
buf.append( attributeType.getSyntaxName() );
@@ -147,23 +145,20 @@
if ( attributeType.isSingleValued() )
{
- buf.append( "SINGLE-VALUE" );
- buf.append( '\n' );
+ buf.append( " SINGLE-VALUE\n" );
}
if ( attributeType.isCollective() )
{
- buf.append( "COLLECTIVE" );
- buf.append( '\n' );
+ buf.append( " COLLECTIVE\n" );
}
if ( attributeType.isUserModifiable() )
{
- buf.append( "NO-USER-MODIFICATION" );
- buf.append( '\n' );
+ buf.append( " NO-USER-MODIFICATION\n" );
}
- buf.append( "USAGE " );
+ buf.append( " USAGE " );
buf.append( UsageEnum.render( attributeType.getUsage() ) );
buf.append( '\n' );
@@ -208,24 +203,23 @@
buf.append( dITContentRule.getOid() );
buf.append( '\n' );
- if ( dITContentRule.getName() != null )
+ if ( dITContentRule.getNames() != null )
{
- buf.append( "NAME " );
- buf.append( dITContentRule.getName() );
+ buf.append( " NAME " );
+ getQDescrs( buf, dITContentRule.getNames() );
buf.append( '\n' );
}
if ( dITContentRule.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( dITContentRule.getDescription() );
buf.append( '\n' );
}
if ( dITContentRule.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
// print out all the auxiliary object class oids
@@ -233,7 +227,7 @@
if ( ( aux != null ) && ( aux.size() > 0 ) )
{
- buf.append( "AUX " );
+ buf.append( " AUX " );
getQDStrings( buf, aux );
}
@@ -241,7 +235,7 @@
if ( ( must != null ) && ( must.size() > 0 ) )
{
- buf.append( "MUST " );
+ buf.append( " MUST " );
getQDStrings( buf, must );
}
@@ -249,7 +243,7 @@
if ( ( may != null ) && ( may.size() > 0 ) )
{
- buf.append( "MAY " );
+ buf.append( " MAY " );
getQDStrings( buf, may );
}
@@ -257,7 +251,7 @@
if ( ( not != null ) && ( not.size() > 0 ) )
{
- buf.append( "NOT " );
+ buf.append( " NOT " );
getQDStrings( buf, not );
}
@@ -299,27 +293,25 @@
buf.append( matchingRule.getOid() );
buf.append( '\n' );
- if ( matchingRule.getName() != null )
+ if ( matchingRule.getNames() != null )
{
- buf.append( "NAME " );
- buf.append( matchingRule.getName() );
- buf.append( '\n' );
+ buf.append( " NAME " );
+ getQDescrs( buf, matchingRule.getNames() );
}
if ( matchingRule.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( matchingRule.getDescription() );
buf.append( '\n' );
}
if ( matchingRule.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
- buf.append( "SYNTAX " );
+ buf.append( " SYNTAX " );
buf.append( matchingRule.getSyntaxOid() );
buf.append( '\n' );
@@ -370,24 +362,22 @@
buf.append( matchingRuleUse.getOid() );
buf.append( '\n' );
- buf.append( "NAME " );
- buf.append( matchingRuleUse.getName() );
- buf.append( '\n' );
+ buf.append( " NAME " );
+ getQDescrs( buf, matchingRuleUse.getNames() );
if ( matchingRuleUse.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( matchingRuleUse.getDescription() );
buf.append( '\n' );
}
if ( matchingRuleUse.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
- buf.append( "APPLIES " );
+ buf.append( " APPLIES " );
List<AttributeType> attributeTypes = matchingRuleUse.getApplicableAttributes();
if ( attributeTypes.size() == 1 )
@@ -457,31 +447,29 @@
buf.append( nameForm.getOid() );
buf.append( '\n' );
- if ( nameForm.getName() != null )
+ if ( nameForm.getNames() != null )
{
- buf.append( "NAME " );
- buf.append( nameForm.getName() );
- buf.append( '\n' );
+ buf.append( " NAME " );
+ getQDescrs( buf, nameForm.getNames() );
}
if ( nameForm.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( nameForm.getDescription() );
buf.append( '\n' );
}
if ( nameForm.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
- buf.append( "OC " );
+ buf.append( " OC " );
buf.append( nameForm.getStructuralObjectClassOid() );
buf.append( '\n' );
- buf.append( "MUST\n" );
+ buf.append( " MUST\n" );
List<AttributeType> must = nameForm.getMustAttributeTypes();
getQDStrings( buf, must );
@@ -490,7 +478,7 @@
if ( ( may != null ) && ( may.size() > 0 ) )
{
- buf.append( "MAY\n" );
+ buf.append( " MAY\n" );
getQDStrings( buf, may );
}
@@ -534,36 +522,35 @@
buf.append( objectClass.getOid() );
buf.append( '\n' );
- if ( objectClass.getName() != null )
+ if ( objectClass.getNames() != null )
{
- buf.append( "NAME " );
- buf.append( objectClass.getName() );
- buf.append( '\n' );
+ buf.append( " NAME " );
+ getQDescrs( buf, objectClass.getNames() );
}
if ( objectClass.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( objectClass.getDescription() );
buf.append( '\n' );
}
if ( objectClass.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
List<ObjectClass> sups = objectClass.getSuperiors();
if ( ( sups != null ) && ( sups.size() > 0 ) )
{
- buf.append( "SUP\n" );
+ buf.append( " SUP\n" );
getQDStrings( buf, sups );
}
if ( objectClass.getType() != null )
{
+ buf.append( ' ' );
buf.append( objectClass.getType() );
buf.append( '\n' );
}
@@ -572,7 +559,7 @@
if ( ( must != null ) && ( must.size() > 0 ) )
{
- buf.append( "MUST\n" );
+ buf.append( " MUST\n" );
getQDStrings( buf, must );
}
@@ -580,7 +567,7 @@
if ( ( may != null ) && ( may.size() > 0 ) )
{
- buf.append( "MAY\n" );
+ buf.append( " MAY\n" );
getQDStrings( buf, may );
}
@@ -622,27 +609,25 @@
buf.append( dITStructureRule.getOid() );
buf.append( '\n' );
- if ( dITStructureRule.getName() != null )
+ if ( dITStructureRule.getNames() != null )
{
- buf.append( "NAME " );
- buf.append( dITStructureRule.getName() );
- buf.append( '\n' );
+ buf.append( " NAME " );
+ getQDescrs( buf, dITStructureRule.getNames() );
}
if ( dITStructureRule.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( dITStructureRule.getDescription() );
buf.append( '\n' );
}
if ( dITStructureRule.isObsolete() )
{
- buf.append( "OBSOLETE" );
- buf.append( '\n' );
+ buf.append( " OBSOLETE\n" );
}
- buf.append( "FORM " );
+ buf.append( " FORM " );
buf.append( dITStructureRule.getForm() );
buf.append( '\n' );
@@ -651,7 +636,7 @@
if ( ( sups != null ) && ( sups.size() > 0 ) )
{
- buf.append( "SUP\n" );
+ buf.append( " SUP\n" );
if ( sups.size() == 1 )
{
@@ -714,7 +699,7 @@
if ( syntax.getDescription() != null )
{
- buf.append( "DESC " );
+ buf.append( " DESC " );
buf.append( syntax.getDescription() );
buf.append( '\n' );
}
@@ -777,7 +762,7 @@
{
if ( schemaObjects.size() == 1 )
{
- sb.append( schemaObjects.get( 0 ).getName() );
+ sb.append( '\'' ).append( schemaObjects.get( 0 ).getName() ).append( '\'' );
}
else
{
@@ -795,7 +780,42 @@
sb.append( " " );
}
- sb.append( schemaObject.getName() );
+ sb.append( '\'' ).append( schemaObject.getName() ).append( '\'' );
+ }
+
+ sb.append( " )" );
+ }
+ }
+
+ sb.append( '\n' );
+ }
+
+
+ private static void getQDescrs( StringBuilder sb, List<String> names )
+ {
+ if ( ( names != null ) && ( names.size() != 0 ) )
+ {
+ if ( names.size() == 1 )
+ {
+ sb.append( '\'' ).append( names.get( 0 ) ).append( '\'' );
+ }
+ else
+ {
+ boolean isFirst = true;
+ sb.append( "( " );
+
+ for ( String name : names )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( " " );
+ }
+
+ sb.append( '\'' ).append( name ).append( '\'' );
}
sb.append( " )" );
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObject.java Mon Aug 31 15:49:11 2009
@@ -23,8 +23,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -211,11 +213,26 @@
{
if ( ! isReadOnly )
{
+ // We must avoid duplicated names, as names are case insensitive
+ Set<String> lowerNames = new HashSet<String>();
+
+ // Fills a set with all the existing names
+ for ( String name : this.names )
+ {
+ lowerNames.add( StringTools.toLowerCase( name ) );
+ }
+
for ( String name : names )
{
if ( name != null )
{
- this.names.add( name );
+ String lowerName = StringTools.toLowerCase( name );
+ // Check that the lower cased names is not already present
+ if ( ! lowerNames.contains( lowerName ) )
+ {
+ this.names.add( name );
+ lowerNames.add( lowerName );
+ }
}
}
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java Mon Aug 31 15:49:11 2009
@@ -22,7 +22,6 @@
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import java.util.Stack;
import javax.naming.NamingException;
@@ -88,6 +87,7 @@
public final void loadAllEnabled( Registries registries ) throws Exception
{
Map<String,Schema> notloaded = new HashMap<String,Schema>( schemaMap );
+
for ( String schemaName : schemaMap.keySet() )
{
if ( registries.isSchemaLoaded( schemaName ) )
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java Mon Aug 31 15:49:11 2009
@@ -190,12 +190,14 @@
* @param numericOid the numeric identifier
* @throws NamingException if the numeric identifier is invalid
*/
- public void unregister( String numericOid ) throws NamingException
+ public AttributeType unregister( String numericOid ) throws NamingException
{
- super.unregister( numericOid );
+ AttributeType removed = super.unregister( numericOid );
- removeMappingFor( oidRegistry.getSchemaObject( numericOid ) );
+ removeMappingFor( removed );
oidToDescendantSet.remove( numericOid );
+
+ return removed;
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java Mon Aug 31 15:49:11 2009
@@ -20,11 +20,8 @@
package org.apache.directory.shared.ldap.schema.registries;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import javax.naming.NamingException;
@@ -32,6 +29,7 @@
import org.apache.directory.shared.asn1.primitives.OID;
import org.apache.directory.shared.ldap.schema.SchemaObject;
import org.apache.directory.shared.ldap.schema.SchemaObjectType;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,9 +48,6 @@
/** A speedup for debug */
private static final boolean DEBUG = LOG.isDebugEnabled();
- /** a map of SchemaObject looked up by OID */
- protected final Map<String, T> byOid;
-
/** a map of SchemaObject looked up by name */
protected final Map<String, T> byName;
@@ -68,7 +63,6 @@
*/
protected SchemaObjectRegistry( SchemaObjectType schemaObjectType, OidRegistry oidRegistry )
{
- byOid = new ConcurrentHashMap<String, T>();
byName = new ConcurrentHashMap<String, T>();
type = schemaObjectType;
this.oidRegistry = oidRegistry;
@@ -85,7 +79,12 @@
*/
public boolean contains( String oid )
{
- return byOid.containsKey( oid );
+ if ( !byName.containsKey( oid ) )
+ {
+ return byName.containsKey( StringTools.toLowerCase( oid ) );
+ }
+
+ return true;
}
@@ -105,7 +104,7 @@
throw new NamingException( msg );
}
- SchemaObject schemaObject = byOid.get( oid );
+ SchemaObject schemaObject = byName.get( oid );
if ( schemaObject != null )
{
@@ -150,7 +149,7 @@
*/
public Iterator<T> iterator()
{
- return byOid.values().iterator();
+ return byName.values().iterator();
}
@@ -161,7 +160,7 @@
*/
public Iterator<String> oidsIterator()
{
- return byOid.keySet().iterator();
+ return byName.keySet().iterator();
}
@@ -184,7 +183,7 @@
oid = getOidByName( oid );
}
- T schemaObject = byOid.get( oid );
+ T schemaObject = byName.get( oid );
if ( schemaObject == null )
{
@@ -213,14 +212,14 @@
{
String oid = schemaObject.getOid();
- if ( byOid.containsKey( oid ) )
+ if ( byName.containsKey( oid ) )
{
String msg = type.name() + " with OID " + oid + " already registered!";
LOG.warn( msg );
throw new NamingException( msg );
}
- byOid.put( oid, schemaObject );
+ byName.put( oid, schemaObject );
/*
* add the aliases/names to the name map along with their toLowerCase
@@ -228,7 +227,6 @@
*/
for ( String name : schemaObject.getNames() )
{
- byName.put( name, schemaObject );
byName.put( name.toLowerCase(), schemaObject );
}
@@ -249,7 +247,7 @@
* @param numericOid the numeric identifier
* @throws NamingException if the numeric identifier is invalid
*/
- public void unregister( String numericOid ) throws NamingException
+ public T unregister( String numericOid ) throws NamingException
{
if ( !OID.isOID( numericOid ) )
{
@@ -258,37 +256,11 @@
throw new NamingException( msg );
}
- SchemaObject schemaObject = byOid.remove( numericOid );
+ T schemaObject = byName.remove( numericOid );
- /* byName Cleanup
- * --------------
- *
- * We iterate throw all the Entry objects in the byName hash. This
- * costs a bit since it is a full scan of the hash but it's in memory
- * and can up to 10K objects (well within our range) work reasonably.
- * As we iterate we push keys to remove into the keysToRemove list to
- * be removed later after this first iteration to prevent concurrent
- * modification issues during iteration.
- *
- * Next we loop again on the keysToRemove list and remove the entries
- * from the byName map. This seems elaborate however note that
- * because we cash different case varying permutations of the name so
- * lookups work properly, we cannot just rely on removing entry by
- * key as they are in the names list. This is why we have to scan the
- * entire entry set and check to see if it is in fact the schema
- * object in question.
- */
- List<String> keysToRemove = new ArrayList<String>();
- for ( Entry<String, T> entry : byName.entrySet() )
- {
- if ( entry.getValue().equals( schemaObject ) )
- {
- keysToRemove.add( entry.getKey() );
- }
- }
- for ( String key : keysToRemove )
+ for ( String name : schemaObject.getNames() )
{
- byName.remove( key );
+ byName.remove( name );
}
// And remove the SchemaObject from the oidRegistry
@@ -298,6 +270,8 @@
{
LOG.debug( "Removed {} with oid {} from the registry", schemaObject, numericOid );
}
+
+ return schemaObject;
}
@@ -321,7 +295,7 @@
if ( schemaName.equalsIgnoreCase( schemaObject.getSchemaName() ) )
{
String oid = schemaObject.getOid();
- SchemaObject removed = byOid.remove( oid );
+ SchemaObject removed = unregister( oid );
oidRegistry.unregister( oid );
if ( DEBUG )
@@ -346,28 +320,23 @@
*/
public String getOidByName( String name ) throws NamingException
{
- if ( ! byName.containsKey( name ) )
+ T schemaObject = byName.get( name );
+
+ if ( schemaObject == null )
{
// last resort before giving up check with lower cased version
String lowerCased = name.toLowerCase();
+ schemaObject = byName.get( lowerCased );
+
// ok this name is not for a schema object in the registry
- if ( ! byName.containsKey( lowerCased ) )
+ if ( schemaObject == null )
{
throw new NamingException( "Can't find an OID for the name " + name );
}
-
- // we found the schema object using lower cased name
- T schemaObject = byName.get( lowerCased );
-
- // provided name argument has case variance so we add it to
- // map in case the same lookup is attempted again in future
- byName.put( name, schemaObject );
- return schemaObject.getOid();
}
// we found the schema object by key on the first lookup attempt
- T schemaObject = byName.get( name );
return schemaObject.getOid();
}
Modified: directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=809635&r1=809634&r2=809635&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java Mon Aug 31 15:49:11 2009
@@ -372,13 +372,6 @@
@Test
public void testConvertAttributesfromLdif() throws NamingException
{
- String expected =
- "sn: test\n" +
- "cn: Saarbrucke\n n\n" +
- "objectClass: to\n p\n" +
- "objectClass: pe\n rson\n" +
- "objectClass: in\n etorgPerson\n\n";
-
Attributes attributes = new BasicAttributes( true );
Attribute oc = new BasicAttribute( "objectclass" );
Added: directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/registries/AttributeTypeRegistryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/registries/AttributeTypeRegistryTest.java?rev=809635&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/registries/AttributeTypeRegistryTest.java (added)
+++ directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/registries/AttributeTypeRegistryTest.java Mon Aug 31 15:49:11 2009
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.shared.ldap.registries;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.registries.OidRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Test the AttributeTypeRegistry
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeTypeRegistryTest
+{
+ AttributeTypeRegistry atRegistry;
+
+ @Before
+ public void setup()
+ {
+ atRegistry = new AttributeTypeRegistry( new OidRegistry() );
+ }
+
+
+ @Test
+ public void testUnregister() throws NamingException
+ {
+ AttributeType at0 = new AttributeType( "1.1" );
+ at0.addName( "t", "test", "Test", "T" );
+ atRegistry.register( at0 );
+
+ atRegistry.unregister( "1.1" );
+ assertFalse( atRegistry.contains( "1.1" ) );
+ assertFalse( atRegistry.contains( "t" ) );
+ assertFalse( atRegistry.contains( "T" ) );
+ assertFalse( atRegistry.contains( "tEsT" ) );
+
+ try
+ {
+ atRegistry.getOidByName( "T" );
+ fail();
+ }
+ catch ( NamingException ne )
+ {
+ assertTrue( true );
+ }
+ }
+
+
+ @Test
+ public void testRegister() throws NamingException
+ {
+ AttributeType at0 = new AttributeType( "1.1" );
+ at0.addName( "t", "test", "Test", "T" );
+ atRegistry.register( at0 );
+
+ assertTrue( atRegistry.contains( "1.1" ) );
+ assertTrue( atRegistry.contains( "t" ) );
+ assertTrue( atRegistry.contains( "T" ) );
+ assertTrue( atRegistry.contains( "tEsT" ) );
+ assertEquals( "1.1", atRegistry.getOidByName( "T" ) );
+
+ try
+ {
+ atRegistry.register( at0 );
+ fail();
+ }
+ catch ( NamingException ne )
+ {
+ assertTrue( true );
+ }
+ }
+}