Modified: directory/apacheds/branches/apacheds-schema/xdbm-tools/src/main/java/org/apache/directory/server/xdbm/tools/StoreUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/xdbm-tools/src/main/java/org/apache/directory/server/xdbm/tools/StoreUtils.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/xdbm-tools/src/main/java/org/apache/directory/server/xdbm/tools/StoreUtils.java (original)
+++ directory/apacheds/branches/apacheds-schema/xdbm-tools/src/main/java/org/apache/directory/server/xdbm/tools/StoreUtils.java Sat Nov 7 07:57:34 2009
@@ -37,9 +37,8 @@
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.schema.SchemaUtils;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
/**
@@ -65,19 +64,17 @@
* @param registries oid registries
* @throws Exception on access exceptions
*/
- public static void loadExampleData( Store<ServerEntry> store, Registries registries ) throws Exception
+ public static void loadExampleData( Store<ServerEntry> store, SchemaManager schemaManager ) throws Exception
{
store.setSuffixDn( "o=Good Times Co." );
LdapDN suffixDn = new LdapDN( "o=Good Times Co." );
- suffixDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ suffixDn.normalize( schemaManager.getNormalizerMapping() );
- AttributeTypeRegistry attributeRegistry = registries.getAttributeTypeRegistry();
-
- store.init( registries );
+ store.init( schemaManager );
// Entry #1
- DefaultServerEntry entry = new DefaultServerEntry( registries, suffixDn );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, suffixDn );
entry.add( "objectClass", "organization" );
entry.add( "o", "Good Times Co." );
entry.add( "postalCode", "1" );
@@ -87,8 +84,8 @@
// Entry #2
LdapDN dn = new LdapDN( "ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "organizationalUnit" );
entry.add( "ou", "Sales" );
entry.add( "postalCode", "1" );
@@ -97,8 +94,8 @@
// Entry #3
dn = new LdapDN( "ou=Board of Directors,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "organizationalUnit" );
entry.add( "ou", "Board of Directors" );
entry.add( "postalCode", "1" );
@@ -107,8 +104,8 @@
// Entry #4
dn = new LdapDN( "ou=Engineering,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "organizationalUnit" );
entry.add( "ou", "Engineering" );
entry.add( "postalCode", "2" );
@@ -117,8 +114,8 @@
// Entry #5
dn = new LdapDN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Sales" );
entry.add( "cn", "JOhnny WAlkeR");
@@ -129,8 +126,8 @@
// Entry #6
dn = new LdapDN( "cn=JIM BEAN,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Sales" );
entry.add( "cn", "JIM BEAN");
@@ -141,8 +138,8 @@
// Entry #7
dn = new LdapDN( "ou=Apache,ou=Board of Directors,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "organizationalUnit" );
entry.add( "ou", "Apache" );
entry.add( "postalCode", "5" );
@@ -151,8 +148,8 @@
// Entry #8
dn = new LdapDN( "cn=Jack Daniels,ou=Engineering,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Engineering" );
entry.add( "cn", "Jack Daniels");
@@ -165,8 +162,8 @@
// Entry #9
dn = new LdapDN( "commonName=Jim Bean,ou=Apache,ou=Board of Directors,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "alias", "extensibleObject" );
entry.add( "ou", "Apache" );
entry.add( "commonName", "Jim Bean");
@@ -175,8 +172,8 @@
// Entry #10
dn = new LdapDN( "commonName=Jim Bean,ou=Board of Directors,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "alias", "extensibleObject" );
entry.add( "commonName", "Jim Bean");
entry.add( "aliasedObjectName", "cn=Jim Bean,ou=Sales,o=Good Times Co." );
@@ -184,8 +181,8 @@
// Entry #11
dn = new LdapDN( "2.5.4.3=Johnny Walker,ou=Engineering,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "alias", "extensibleObject" );
entry.add( "ou", "Engineering" );
entry.add( "2.5.4.3", "Johnny Walker");
Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java (original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java Sat Nov 7 07:57:34 2009
@@ -46,6 +46,7 @@
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.schema.ObjectClass;
import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.schema.SchemaObject;
import org.apache.directory.shared.ldap.schema.SyntaxChecker;
import org.apache.directory.shared.ldap.schema.UsageEnum;
@@ -196,7 +197,6 @@
{
String msg = "The schema " + schemaName + " does not exists or is not loaded";
LOG.error( msg );
- throw new NullPointerException( msg );
}
return schema;
@@ -257,7 +257,7 @@
/**
* Class load a syntaxChecker instance
*/
- private SyntaxChecker classLoadSyntaxChecker( String oid, String className,
+ private SyntaxChecker classLoadSyntaxChecker( SchemaManager schemaManager, String oid, String className,
EntryAttribute byteCode, Registries targetRegistries ) throws Exception
{
// Try to class load the syntaxChecker
@@ -278,6 +278,9 @@
// Create the syntaxChecker instance
syntaxChecker = ( SyntaxChecker ) clazz.newInstance();
+
+ // Inject the SchemaManager
+ syntaxChecker.setSchemaManager( schemaManager );
// Update the common fields
syntaxChecker.setBytecode( byteCodeStr );
@@ -297,7 +300,7 @@
* @return the loaded SyntaxChecker
* @throws NamingException if anything fails during loading
*/
- public SyntaxChecker getSyntaxChecker( Entry entry, Registries targetRegistries, String schemaName ) throws Exception
+ public SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName ) throws Exception
{
checkEntry( entry, SchemaConstants.SYNTAX_CHECKER );
@@ -314,7 +317,7 @@
EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
// Class load the syntaxChecker
- SyntaxChecker syntaxChecker = classLoadSyntaxChecker( oid, className, byteCode, targetRegistries );
+ SyntaxChecker syntaxChecker = classLoadSyntaxChecker( schemaManager, oid, className, byteCode, targetRegistries );
// Update the common fields
setSchemaObjectProperties( syntaxChecker, entry, schema );
@@ -333,7 +336,7 @@
* @return A new instance of a syntaxChecker
* @throws Exception If the creation has failed
*/
- public SyntaxChecker getSyntaxChecker( SyntaxCheckerDescription syntaxCheckerDescription,
+ public SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription,
Registries targetRegistries, String schemaName ) throws Exception
{
checkDescription( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
@@ -351,7 +354,7 @@
EntryAttribute byteCode = getByteCode( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
// Class load the SyntaxChecker
- SyntaxChecker syntaxChecker = classLoadSyntaxChecker( oid,
+ SyntaxChecker syntaxChecker = classLoadSyntaxChecker( schemaManager, oid,
fqcn, byteCode, targetRegistries );
// Update the common fields
@@ -364,7 +367,7 @@
/**
* Class load a comparator instances
*/
- private LdapComparator<?> classLoadComparator( String oid, String className,
+ private LdapComparator<?> classLoadComparator( SchemaManager schemaManager, String oid, String className,
EntryAttribute byteCode, Registries targetRegistries ) throws Exception
{
// Try to class load the comparator
@@ -386,6 +389,9 @@
// Create the comparator instance
comparator = ( LdapComparator<?> ) clazz.newInstance();
+ // Inject the SchemaManager
+ comparator.setSchemaManager( schemaManager );
+
// Update the loadable fields
comparator.setBytecode( byteCodeStr );
comparator.setFqcn( className );
@@ -406,7 +412,7 @@
* @return A new instance of a LdapComparator
* @throws Exception If the creation has failed
*/
- public LdapComparator<?> getLdapComparator(
+ public LdapComparator<?> getLdapComparator( SchemaManager schemaManager,
LdapComparatorDescription comparatorDescription,
Registries targetRegistries, String schemaName ) throws Exception
{
@@ -425,7 +431,7 @@
EntryAttribute byteCode = getByteCode( comparatorDescription, SchemaConstants.COMPARATOR );
// Class load the comparator
- LdapComparator<?> comparator = classLoadComparator( oid,
+ LdapComparator<?> comparator = classLoadComparator( schemaManager, oid,
fqcn, byteCode, targetRegistries );
// Update the common fields
@@ -444,7 +450,7 @@
* @return the loaded Comparator
* @throws NamingException if anything fails during loading
*/
- public LdapComparator<?> getLdapComparator( Entry entry,
+ public LdapComparator<?> getLdapComparator( SchemaManager schemaManager, Entry entry,
Registries targetRegistries, String schemaName ) throws Exception
{
checkEntry( entry, SchemaConstants.COMPARATOR );
@@ -462,7 +468,7 @@
EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
// Class load the comparator
- LdapComparator<?> comparator = classLoadComparator( oid, fqcn, byteCode, targetRegistries );
+ LdapComparator<?> comparator = classLoadComparator( schemaManager, oid, fqcn, byteCode, targetRegistries );
// Update the common fields
setSchemaObjectProperties( comparator, entry, schema );
@@ -475,7 +481,7 @@
/**
* Class load a normalizer instances
*/
- private Normalizer classLoadNormalizer( String oid, String className,
+ private Normalizer classLoadNormalizer( SchemaManager schemaManager, String oid, String className,
EntryAttribute byteCode, Registries targetRegistries ) throws Exception
{
// Try to class load the normalizer
@@ -497,6 +503,9 @@
// Create the normalizer instance
normalizer = ( Normalizer ) clazz.newInstance();
+ // Inject the SchemaManager
+ normalizer.setSchemaManager( schemaManager );
+
// Update the common fields
normalizer.setBytecode( byteCodeStr );
normalizer.setFqcn( className );
@@ -517,7 +526,7 @@
* @return A new instance of a normalizer
* @throws Exception If the creation has failed
*/
- public Normalizer getNormalizer( NormalizerDescription normalizerDescription,
+ public Normalizer getNormalizer( SchemaManager schemaManager, NormalizerDescription normalizerDescription,
Registries targetRegistries, String schemaName ) throws Exception
{
checkDescription( normalizerDescription, SchemaConstants.NORMALIZER );
@@ -535,7 +544,7 @@
EntryAttribute byteCode = getByteCode( normalizerDescription, SchemaConstants.NORMALIZER );
// Class load the normalizer
- Normalizer normalizer = classLoadNormalizer( oid, fqcn, byteCode, targetRegistries );
+ Normalizer normalizer = classLoadNormalizer( schemaManager, oid, fqcn, byteCode, targetRegistries );
// Update the common fields
setSchemaObjectProperties( normalizer, normalizerDescription, schema );
@@ -551,7 +560,7 @@
* @return the loaded Normalizer
* @throws NamingException if anything fails during loading
*/
- public Normalizer getNormalizer( Entry entry, Registries targetRegistries, String schemaName )
+ public Normalizer getNormalizer( SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName )
throws Exception
{
checkEntry( entry, SchemaConstants.NORMALIZER );
@@ -569,7 +578,7 @@
EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
// Class load the Normalizer
- Normalizer normalizer = classLoadNormalizer( oid, className, byteCode, targetRegistries );
+ Normalizer normalizer = classLoadNormalizer( schemaManager, oid, className, byteCode, targetRegistries );
// Update the common fields
setSchemaObjectProperties( normalizer, entry, schema );
@@ -774,6 +783,12 @@
// Get the schema
Schema schema = getSchema( schemaName, targetRegistries );
+
+ if ( schema == null )
+ {
+ // The schema is not loaded. We can't create the requested AttributeType
+ return null;
+ }
// Create the new AttributeType
AttributeType attributeType = new AttributeType( oid );
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java Sat Nov 7 07:57:34 2009
@@ -21,7 +21,7 @@
* @return the loaded SyntaxChecker
* @throws NamingException if anything fails during loading
*/
- SyntaxChecker getSyntaxChecker( Entry entry, Registries targetRegistries, String schemaName ) throws Exception;
+ SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName ) throws Exception;
/**
@@ -33,7 +33,7 @@
* @return A new instance of a syntaxChecker
* @throws Exception If the creation has failed
*/
- SyntaxChecker getSyntaxChecker( SyntaxCheckerDescription syntaxCheckerDescription,
+ SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription,
Registries targetRegistries, String schemaName ) throws Exception;
@@ -46,7 +46,7 @@
* @return A new instance of a LdapComparator
* @throws Exception If the creation has failed
*/
- LdapComparator<?> getLdapComparator(
+ LdapComparator<?> getLdapComparator( SchemaManager schemaManager,
LdapComparatorDescription comparatorDescription,
Registries targetRegistries, String schemaName ) throws Exception;
@@ -60,7 +60,7 @@
* @return the loaded Comparator
* @throws NamingException if anything fails during loading
*/
- LdapComparator<?> getLdapComparator( Entry entry,
+ LdapComparator<?> getLdapComparator( SchemaManager schemaManager, Entry entry,
Registries targetRegistries, String schemaName ) throws Exception;
@@ -73,7 +73,7 @@
* @return A new instance of a normalizer
* @throws Exception If the creation has failed
*/
- Normalizer getNormalizer( NormalizerDescription normalizerDescription,
+ Normalizer getNormalizer( SchemaManager schemaManager, NormalizerDescription normalizerDescription,
Registries targetRegistries, String schemaName ) throws Exception;
@@ -84,7 +84,7 @@
* @return the loaded Normalizer
* @throws NamingException if anything fails during loading
*/
- Normalizer getNormalizer( Entry entry, Registries targetRegistries, String schemaName )
+ Normalizer getNormalizer( SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName )
throws Exception;
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java Sat Nov 7 07:57:34 2009
@@ -37,7 +37,6 @@
/** The base64 encoded bytecode for this schema */
private String bytecode;
-
/**
* Constructor to use when the OID is known in advance.
*
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=833647&r1=833646&r2=833647&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 Sat Nov 7 07:57:34 2009
@@ -106,6 +106,8 @@
/** A map containing the list of supported extensions */
protected Map<String, List<String>> extensions;
+ /** A reference to the SchemaManager */
+ protected transient SchemaManager schemaManager;
/**
* A constructor for a SchemaObject instance. It must be
@@ -742,4 +744,15 @@
return clone;
}
+
+
+ /**
+ * Sets the SchemaManager
+ *
+ * @param schemaManager The SchemaManager
+ */
+ public void setSchemaManager( SchemaManager schemaManager )
+ {
+ this.schemaManager = schemaManager;
+ }
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/DnComparator.java Sat Nov 7 07:57:34 2009
@@ -25,8 +25,6 @@
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.LdapComparator;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
/**
@@ -37,28 +35,9 @@
*/
public class DnComparator extends LdapComparator<Object>
{
- // @TODO you'll need this to fix the way normalization is done
- private AttributeTypeRegistry attrRegistry;
-
-
- public DnComparator( AttributeTypeRegistry attrRegistry )
- {
- this.attrRegistry = attrRegistry;
- }
-
-
public DnComparator()
{
}
-
-
- /**
- * {@inheritDoc}
- */
- public void applyRegistries( Registries registries )
- {
- attrRegistry = registries.getAttributeTypeRegistry();
- }
public int compare( Object obj0, Object obj1 )
@@ -89,17 +68,17 @@
{
dn = (LdapDN)obj;
- dn = ( dn.isNormalized() ? dn : LdapDN.normalize( dn, attrRegistry.getNormalizerMapping() ) );
+ dn = ( dn.isNormalized() ? dn : LdapDN.normalize( dn, schemaManager.getNormalizerMapping() ) );
}
else if ( obj instanceof Name )
{
dn = new LdapDN( ( Name ) obj );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
}
else if ( obj instanceof String )
{
dn = new LdapDN( ( String ) obj );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
}
else
{
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/IntegerOrderingComparator.java Sat Nov 7 07:57:34 2009
@@ -24,6 +24,7 @@
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,6 +55,7 @@
super( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
}
+
/**
* Implementation of the Compare method
*/
@@ -95,4 +97,15 @@
// are dealing with booleans.
return ( b1 > b2 ? 1 : -1 );
}
+
+
+ /**
+ * Sets the SchemaManager
+ *
+ * @param schemaManager The SchemaManager
+ */
+ public void setSchemaManager( SchemaManager schemaManager )
+ {
+ super.setSchemaManager( schemaManager );
+ }
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NameAndOptionalUIDComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NameAndOptionalUIDComparator.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NameAndOptionalUIDComparator.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NameAndOptionalUIDComparator.java Sat Nov 7 07:57:34 2009
@@ -25,8 +25,6 @@
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.LdapComparator;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
/**
@@ -37,30 +35,12 @@
*/
public class NameAndOptionalUIDComparator extends LdapComparator<Object>
{
- // @TODO you'll need this to fix the way normalization is done
- private AttributeTypeRegistry attrRegistry;
-
-
- public NameAndOptionalUIDComparator( AttributeTypeRegistry attrRegistry )
- {
- this.attrRegistry = attrRegistry;
- }
-
-
public NameAndOptionalUIDComparator()
{
}
/**
- * {@inheritDoc}
- */
- public void applyRegistries( Registries registries ) throws NamingException
- {
- attrRegistry = registries.getAttributeTypeRegistry();
- }
-
- /**
* Comparing two uniqueMember is a matter of following this algorithm:
* - if they are only DN, then the values should be equal
* - otherwise, both element should contain the same DN and
@@ -178,17 +158,17 @@
{
dn = (LdapDN)obj;
- dn = ( dn.isNormalized() ? dn : LdapDN.normalize( dn, attrRegistry.getNormalizerMapping() ) );
+ dn = ( dn.isNormalized() ? dn : LdapDN.normalize( dn, schemaManager.getNormalizerMapping() ) );
}
else if ( obj instanceof Name )
{
dn = new LdapDN( ( Name ) obj );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
}
else if ( obj instanceof String )
{
dn = new LdapDN( ( String ) obj );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
}
else
{
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SerializableComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SerializableComparator.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SerializableComparator.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SerializableComparator.java Sat Nov 7 07:57:34 2009
@@ -25,7 +25,7 @@
import javax.naming.NamingException;
import org.apache.directory.shared.ldap.schema.LdapComparator;
-import org.apache.directory.shared.ldap.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
/**
@@ -40,36 +40,15 @@
{
private static final long serialVersionUID = 3257566226288162870L;
- /** the system global Comparator registry */
- private static ComparatorRegistry registry;
-
/** the OID of the matchingRule for this comparator */
private String matchingRuleOid;
/** the transient wrapped comparator */
private transient Comparator<E> wrapped;
-
-
- // ------------------------------------------------------------------------
- // S T A T I C M E T H O D S
- // ------------------------------------------------------------------------
-
- /**
- * Sets the global Comparator registry for comparator lookups.
- *
- * @param registry the comparator registry to use for Comparator lookups
- */
- public static void setRegistry( ComparatorRegistry registry )
- {
- SerializableComparator.registry = registry;
- }
-
-
+
// ------------------------------------------------------------------------
// C O N T R U C T O R S
// ------------------------------------------------------------------------
-
-
public SerializableComparator( String matchingRuleOid )
{
this.matchingRuleOid = matchingRuleOid;
@@ -90,7 +69,7 @@
{
try
{
- wrapped = (Comparator<E>)registry.lookup( matchingRuleOid );
+ wrapped = (Comparator<E>)schemaManager.lookupComparatorRegistry( matchingRuleOid );
}
catch ( NamingException e )
{
@@ -100,4 +79,26 @@
return wrapped.compare( o1, o2 );
}
+
+
+ /**
+ * @param schemaManager the schemaManager to set
+ */
+ public void setSchemaManager( SchemaManager schemaManager )
+ {
+ if ( wrapped == null )
+ {
+ try
+ {
+ wrapped = (Comparator<E>)schemaManager.lookupComparatorRegistry( matchingRuleOid );
+ }
+ catch ( NamingException ne )
+ {
+
+ }
+ }
+
+ ((LdapComparator<E>)wrapped).setSchemaManager( schemaManager );
+ super.setSchemaManager( schemaManager );
+ }
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingNormalizer.java Sat Nov 7 07:57:34 2009
@@ -24,6 +24,7 @@
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.schema.registries.Registries;
import org.apache.directory.shared.ldap.util.SynchronizedLRUMap;
@@ -158,4 +159,15 @@
{
normalizer.applyRegistries( registries );
}
+
+
+ /**
+ * Sets the SchemaManager
+ *
+ * @param schemaManager The SchemaManager
+ */
+ public void setSchemaManager( SchemaManager schemaManager )
+ {
+ normalizer.setSchemaManager( schemaManager );
+ }
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/ConcreteNameComponentNormalizer.java Sat Nov 7 07:57:34 2009
@@ -20,7 +20,7 @@
package org.apache.directory.shared.ldap.schema.normalizers;
-import java.io.UnsupportedEncodingException;
+import java.io.UnsupportedEncodingException;
import javax.naming.NamingException;
@@ -29,7 +29,7 @@
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,8 +48,8 @@
/** The LoggerFactory used by this Interceptor */
private static Logger LOG = LoggerFactory.getLogger( ConcreteNameComponentNormalizer.class );
- /** the at registry used to dynamically resolve Normalizers */
- private final AttributeTypeRegistry attributeRegistry;
+ /** the schemaManager used to dynamically resolve Normalizers */
+ private final SchemaManager schemaManager;
/**
@@ -57,11 +57,11 @@
* registries to find the appropriate normalizer for the attribute of the
* name component with which to normalize the name component value.
*
- * @param registry the at registry used to dynamically resolve Normalizers
+ * @param schemaManager the schemaManager used to dynamically resolve Normalizers
*/
- public ConcreteNameComponentNormalizer( AttributeTypeRegistry registry )
+ public ConcreteNameComponentNormalizer( SchemaManager schemaManager )
{
- this.attributeRegistry = registry;
+ this.schemaManager = schemaManager;
}
@@ -110,7 +110,7 @@
*/
public Object normalizeByName( String name, String value ) throws NamingException
{
- AttributeType attributeType = attributeRegistry.lookup( name );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( name );
if ( attributeType.getSyntax().isHumanReadable() )
{
@@ -141,7 +141,7 @@
*/
public Object normalizeByName( String name, byte[] value ) throws NamingException
{
- AttributeType attributeType = attributeRegistry.lookup( name );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( name );
if ( !attributeType.getSyntax().isHumanReadable() )
{
@@ -195,7 +195,7 @@
*/
private Normalizer lookup( String id ) throws NamingException
{
- AttributeType type = attributeRegistry.lookup( id );
+ AttributeType type = schemaManager.lookupAttributeTypeRegistry( id );
MatchingRule mrule = type.getEquality();
if ( mrule == null )
@@ -212,12 +212,12 @@
*/
public boolean isDefined( String id )
{
- return attributeRegistry.contains( id );
+ return schemaManager.getAttributeTypeRegistry().contains( id );
}
public String normalizeName( String attributeName ) throws NamingException
{
- return attributeRegistry.getOidByName( attributeName );
+ return schemaManager.getAttributeTypeRegistry().getOidByName( attributeName );
}
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/DnNormalizer.java Sat Nov 7 07:57:34 2009
@@ -27,8 +27,7 @@
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.Normalizer;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
/**
@@ -42,20 +41,6 @@
// The serial UID
private static final long serialVersionUID = 1L;
- /** A static instance of this normalizer */
- public static final DnNormalizer INSTANCE = new DnNormalizer();
-
- // @TODO use this later for setting up normalization
- private AttributeTypeRegistry attrRegistry;
-
-
- public DnNormalizer( AttributeTypeRegistry attrRegistry )
- {
- super( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
- this.attrRegistry = attrRegistry;
- }
-
-
/**
* Empty constructor
*/
@@ -76,7 +61,7 @@
dn = new LdapDN( dnStr );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
return new ClientStringValue( dn.getNormName() );
}
@@ -90,7 +75,7 @@
dn = new LdapDN( value );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
return dn.getNormName();
}
@@ -107,7 +92,7 @@
dn = new LdapDN( value );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
return dn.getNormName();
}
@@ -115,8 +100,8 @@
/**
* {@inheritDoc}
*/
- public void applyRegistries( Registries registries )
+ public void applySchemaManager( SchemaManager schemaManager )
{
- attrRegistry = registries.getAttributeTypeRegistry();
+ this.schemaManager = schemaManager;
}
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameAndOptionalUIDNormalizer.java Sat Nov 7 07:57:34 2009
@@ -26,8 +26,6 @@
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.Normalizer;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -44,30 +42,13 @@
// The serial UID
private static final long serialVersionUID = 1L;
- private AttributeTypeRegistry attrRegistry;
-
- public final static NameAndOptionalUIDNormalizer INSTANCE = new NameAndOptionalUIDNormalizer();
+ //public final static NameAndOptionalUIDNormalizer INSTANCE = new NameAndOptionalUIDNormalizer();
public NameAndOptionalUIDNormalizer()
{
super( OID );
}
- public NameAndOptionalUIDNormalizer( AttributeTypeRegistry attrRegistry )
- {
- super( OID );
- this.attrRegistry = attrRegistry;
- }
-
-
- /**
- * {@inheritDoc}
- */
- public void applyRegistries( Registries registries )
- {
- this.attrRegistry = registries.getAttributeTypeRegistry();
- }
-
public Value<?> normalize( Value<?> value ) throws NamingException
{
@@ -100,7 +81,7 @@
{
LdapDN dn = new LdapDN( nameAndUid.substring( 0, sharpPos ) );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
return new ClientStringValue( dn.getNormName() + '#' + uid );
}
@@ -148,7 +129,7 @@
{
LdapDN dn = new LdapDN( value.substring( 0, sharpPos ) );
- dn.normalize( attrRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
return dn.getNormName() + '#' + uid;
}
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=833647&r1=833646&r2=833647&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 Sat Nov 7 07:57:34 2009
@@ -20,24 +20,13 @@
package org.apache.directory.shared.ldap.schema.registries;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
import javax.naming.NamingException;
-import javax.naming.directory.NoSuchAttributeException;
import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
-import org.apache.directory.shared.ldap.schema.SchemaObject;
-import org.apache.directory.shared.ldap.schema.SchemaObjectType;
-import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -46,42 +35,16 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class AttributeTypeRegistry extends SchemaObjectRegistry<AttributeType> implements Cloneable
+public interface AttributeTypeRegistry extends SchemaObjectRegistry<AttributeType>,
+ Iterable<AttributeType>, Cloneable
{
- /** static class logger */
- private static final Logger LOG = LoggerFactory.getLogger( AttributeTypeRegistry.class );
-
- /** Speedup for DEBUG mode */
- private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
- /** cached Oid/normalizer mapping */
- private transient Map<String, OidNormalizer> oidNormalizerMap;
-
- /** maps OIDs to a Set of descendants for that OID */
- private Map<String,Set<AttributeType>> oidToDescendantSet;
-
-
- /**
- * Creates a new default AttributeTypeRegistry instance.
- */
- public AttributeTypeRegistry( OidRegistry oidRegistry )
- {
- super( SchemaObjectType.ATTRIBUTE_TYPE, oidRegistry );
- oidNormalizerMap = new HashMap<String, OidNormalizer>();
- oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
- }
-
-
/**
* Gets an oid/name to normalizer mapping used to normalize distinguished
* names.
*
* @return a map of OID Strings to OidNormalizer instances
*/
- public Map<String, OidNormalizer> getNormalizerMapping()
- {
- return Collections.unmodifiableMap( oidNormalizerMap );
- }
+ Map<String, OidNormalizer> getNormalizerMapping();
/**
@@ -93,19 +56,7 @@
* @throws NamingException if the ancestor attributeType cannot be
* discerned from the ancestorId supplied
*/
- public boolean hasDescendants( String ancestorId ) throws NamingException
- {
- try
- {
- String oid = getOidByName( ancestorId );
- Set<AttributeType> descendants = oidToDescendantSet.get( oid );
- return (descendants != null) && !descendants.isEmpty();
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
+ boolean hasDescendants( String ancestorId ) throws NamingException;
/**
@@ -118,93 +69,17 @@
* @throws NamingException if the ancestor attributeType cannot be
* discerned from the ancestorId supplied
*/
- @SuppressWarnings("unchecked")
- public Iterator<AttributeType> descendants( String ancestorId ) throws NamingException
- {
- try
- {
- String oid = getOidByName( ancestorId );
- Set<AttributeType> descendants = oidToDescendantSet.get( oid );
-
- if ( descendants == null )
- {
- return Collections.EMPTY_SET.iterator();
- }
-
- return descendants.iterator();
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
+ Iterator<AttributeType> descendants( String ancestorId ) throws NamingException;
/**
- * Registers a new AttributeType with this registry.
- *
- * @param attributeType the AttributeType to register
- * @throws NamingException if the AttributeType is already registered or
- * the registration operation is not supported
- */
- public void register( AttributeType attributeType ) throws NamingException
- {
- try
- {
- super.register( attributeType );
-
- // Internally associate the OID to the registered AttributeType
- if ( IS_DEBUG )
- {
- LOG.debug( "registred attributeType: {}", attributeType );
- }
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
-
-
- /**
* Store the AttributeType into a map associating an AttributeType to its
* descendants.
*
* @param attributeType The attributeType to register
* @throws NamingException If something went wrong
*/
- public void registerDescendants( AttributeType attributeType, AttributeType ancestor )
- throws NamingException
- {
- // add this attribute to descendant list of other attributes in superior chain
- if ( ancestor == null )
- {
- return;
- }
-
- // Get the ancestor's descendant, if any
- Set<AttributeType> descendants = oidToDescendantSet.get( ancestor.getOid() );
-
- // Initialize the descendant Set to store the descendants for the attributeType
- if ( descendants == null )
- {
- descendants = new HashSet<AttributeType>( 1 );
- oidToDescendantSet.put( ancestor.getOid(), descendants );
- }
-
- // Add the current type as a descendant
- descendants.add( attributeType );
-
- try
- {
- // And recurse until we reach the top of the hierarchy
- registerDescendants( attributeType, ancestor.getSuperior() );
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
+ public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws NamingException;
/**
@@ -215,166 +90,11 @@
* @param ancestor its ancestor
* @throws NamingException If something went wrong
*/
- public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor )
- throws NamingException
- {
- // add this attribute to descendant list of other attributes in superior chain
- if ( ancestor == null )
- {
- return;
- }
-
- // Get the ancestor's descendant, if any
- Set<AttributeType> descendants = oidToDescendantSet.get( ancestor.getOid() );
-
- if ( descendants != null )
- {
- descendants.remove( attributeType );
-
- if ( descendants.size() == 0 )
- {
- oidToDescendantSet.remove( descendants );
- }
- }
-
- try
- {
- // And recurse until we reach the top of the hierarchy
- unregisterDescendants( attributeType, ancestor.getSuperior() );
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
+ void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws NamingException;
/**
- * Removes the AttributeType registered with this registry.
- *
- * @param numericOid the numeric identifier
- * @throws NamingException if the numeric identifier is invalid
- */
- public AttributeType unregister( String numericOid ) throws NamingException
- {
- try
- {
- AttributeType removed = super.unregister( numericOid );
-
- removeMappingFor( removed );
-
- // Deleting an AT which might be used as a superior means we have
- // to recursively update the descendant map. We also have to remove
- // the at.oid -> descendant relation
- oidToDescendantSet.remove( numericOid );
-
- // Now recurse if needed
- unregisterDescendants( removed, removed.getSuperior() );
-
- return removed;
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
-
-
- /**
* Add a new Oid/Normalizer couple in the OidNormalizer map
*/
- public void addMappingFor( AttributeType attributeType ) throws NamingException
- {
- MatchingRule matchingRule = attributeType.getEquality();
- OidNormalizer oidNormalizer;
- String oid = attributeType.getOid();
-
- if ( matchingRule == null )
- {
- LOG.debug( "Attribute {} does not have normalizer : using NoopNormalizer", attributeType.getName() );
- oidNormalizer = new OidNormalizer( oid, new NoOpNormalizer( attributeType.getOid() ) );
- }
- else
- {
- oidNormalizer = new OidNormalizer( oid, matchingRule.getNormalizer() );
- }
-
- oidNormalizerMap.put( oid, oidNormalizer );
-
- // Also inject the attributeType's short names in the map
- for ( String name : attributeType.getNames() )
- {
- oidNormalizerMap.put( name.toLowerCase(), oidNormalizer );
- }
- }
-
-
- /**
- * Remove the AttributeType normalizer from the OidNormalizer map
- */
- private void removeMappingFor( SchemaObject attributeType )
- {
- if ( attributeType == null )
- {
- return;
- }
-
- oidNormalizerMap.remove( attributeType.getOid() );
-
- // We also have to remove all the short names for this attribute
- for ( String name : attributeType.getNames() )
- {
- oidNormalizerMap.remove( name.toLowerCase() );
- }
- }
-
-
- /**
- * {@inheritDoc}
- */
- public AttributeType lookup( String oid ) throws NamingException
- {
- try
- {
- return super.lookup( oid );
- }
- catch ( NamingException ne )
- {
- throw new NoSuchAttributeException( ne.getMessage() );
- }
- }
-
- /**
- * @see Object#toString()
- */
- public String toString()
- {
- return byName.toString();
- }
-
-
- /**
- * Clone the AttributeTypeRegistry
- */
- public AttributeTypeRegistry clone() throws CloneNotSupportedException
- {
- AttributeTypeRegistry clone = (AttributeTypeRegistry)super.clone();
-
- // Clone the oidNormalizerMap (will be empty)
- clone.oidNormalizerMap = new HashMap<String, OidNormalizer>();
-
- // Clone the oidToDescendant map (will be empty)
- clone.oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
-
- return clone;
- }
-
-
- /**
- * @return The number of AttributeType stored
- */
- public int size()
- {
- return oidRegistry.size();
- }
+ public void addMappingFor( AttributeType attributeType ) throws NamingException;
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/ComparatorRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/ComparatorRegistry.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/ComparatorRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/ComparatorRegistry.java Sat Nov 7 07:57:34 2009
@@ -22,13 +22,7 @@
import javax.naming.NamingException;
-import org.apache.directory.shared.asn1.primitives.OID;
import org.apache.directory.shared.ldap.schema.LdapComparator;
-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;
/**
@@ -37,25 +31,9 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class ComparatorRegistry extends SchemaObjectRegistry<LdapComparator<?>>
+public interface ComparatorRegistry extends SchemaObjectRegistry<LdapComparator<?>>,
+ Iterable<LdapComparator<?>>, Cloneable
{
- /** static class logger */
- private static final Logger LOG = LoggerFactory.getLogger( ComparatorRegistry.class );
-
- /** A speedup for debug */
- private static final boolean DEBUG = LOG.isDebugEnabled();
-
- /**
- * Creates a new default ComparatorRegistry instance.
- *
- * @param oidRegistry The global OID registry
- */
- public ComparatorRegistry( OidRegistry oidRegistry )
- {
- super( SchemaObjectType.COMPARATOR, oidRegistry );
- }
-
-
/**
* Registers a new LdapComparator with this registry.
*
@@ -63,33 +41,7 @@
* @throws NamingException if the LdapComparator is already registered or
* the registration operation is not supported
*/
- public void register( LdapComparator<?> comparator ) throws NamingException
- {
- String oid = comparator.getOid();
-
- if ( byName.containsKey( oid ) )
- {
- String msg = type.name() + " with OID " + oid + " already registered!";
- LOG.warn( msg );
- throw new NamingException( msg );
- }
-
- byName.put( oid, comparator );
-
- /*
- * add the aliases/names to the name map along with their toLowerCase
- * versions of the name: this is used to make sure name lookups work
- */
- for ( String name : comparator.getNames() )
- {
- byName.put( StringTools.trim( StringTools.toLowerCase( name ) ), comparator );
- }
-
- if ( LOG.isDebugEnabled() )
- {
- LOG.debug( "registered " + comparator.getName() + " for OID {}", oid );
- }
- }
+ void register( LdapComparator<?> comparator ) throws NamingException;
/**
@@ -99,29 +51,7 @@
* @param numericOid the numeric identifier
* @throws NamingException if the numeric identifier is invalid
*/
- public LdapComparator<?> unregister( String numericOid ) throws NamingException
- {
- if ( !OID.isOID( numericOid ) )
- {
- String msg = "OID " + numericOid + " is not a numeric OID";
- LOG.error( msg );
- throw new NamingException( msg );
- }
-
- LdapComparator<?> comparator = byName.remove( numericOid );
-
- for ( String name : comparator.getNames() )
- {
- byName.remove( name );
- }
-
- if ( DEBUG )
- {
- LOG.debug( "Removed {} with oid {} from the registry", comparator, numericOid );
- }
-
- return comparator;
- }
+ LdapComparator<?> unregister( String numericOid ) throws NamingException;
/**
@@ -130,47 +60,17 @@
*
* @param schemaName the name of the schema whose LdapComparators will be removed from
*/
- public void unregisterSchemaElements( String schemaName ) throws NamingException
- {
- if ( schemaName == null )
- {
- return;
- }
-
- // Loop on all the SchemaObjects stored and remove those associated
- // with the give schemaName
- for ( LdapComparator<?> comparator : this )
- {
- if ( schemaName.equalsIgnoreCase( comparator.getSchemaName() ) )
- {
- String oid = comparator.getOid();
- SchemaObject removed = unregister( oid );
-
- if ( DEBUG )
- {
- LOG.debug( "Removed {} with oid {} from the registry", removed, oid );
- }
- }
- }
- }
+ void unregisterSchemaElements( String schemaName ) throws NamingException;
/**
* Clone the ComparatorRegistry
*/
- public ComparatorRegistry clone() throws CloneNotSupportedException
- {
- ComparatorRegistry clone = (ComparatorRegistry)super.clone();
-
- return clone;
- }
+ ComparatorRegistry clone() throws CloneNotSupportedException;
/**
* @return The number of Comparators stored
*/
- public int size()
- {
- return byName.values().size();
- }
+ int size();
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITContentRuleRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITContentRuleRegistry.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITContentRuleRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITContentRuleRegistry.java Sat Nov 7 07:57:34 2009
@@ -21,7 +21,6 @@
import org.apache.directory.shared.ldap.schema.DITContentRule;
-import org.apache.directory.shared.ldap.schema.SchemaObjectType;
/**
@@ -30,35 +29,17 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class DITContentRuleRegistry extends SchemaObjectRegistry<DITContentRule>
+public interface DITContentRuleRegistry extends SchemaObjectRegistry<DITContentRule>,
+ Iterable<DITContentRule>, Cloneable
{
/**
- * Creates a new default NormalizerRegistry instance.
- *
- * @param oidRegistry The global OID registry
- */
- public DITContentRuleRegistry( OidRegistry oidRegistry )
- {
- super( SchemaObjectType.DIT_CONTENT_RULE, oidRegistry );
- }
-
-
- /**
* Clone the DITContentRuleRegistry
*/
- public DITContentRuleRegistry clone() throws CloneNotSupportedException
- {
- DITContentRuleRegistry clone = (DITContentRuleRegistry)super.clone();
-
- return clone;
- }
+ DITContentRuleRegistry clone() throws CloneNotSupportedException;
/**
* @return The number of DITContentRule stored
*/
- public int size()
- {
- return oidRegistry.size();
- }
+ int size();
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DITStructureRuleRegistry.java Sat Nov 7 07:57:34 2009
@@ -20,17 +20,11 @@
package org.apache.directory.shared.ldap.schema.registries;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
import javax.naming.NamingException;
import org.apache.directory.shared.ldap.schema.DITStructureRule;
-import org.apache.directory.shared.ldap.schema.SchemaObject;
-import org.apache.directory.shared.ldap.schema.SchemaObjectType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -39,29 +33,9 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class DITStructureRuleRegistry extends SchemaObjectRegistry<DITStructureRule>
+public interface DITStructureRuleRegistry extends SchemaObjectRegistry<DITStructureRule>,
+ Iterable<DITStructureRule>, Cloneable
{
- /** static class logger */
- private static final Logger LOG = LoggerFactory.getLogger( DITStructureRuleRegistry.class );
-
- /** A speedup for debug */
- private static final boolean DEBUG = LOG.isDebugEnabled();
-
- /** a map of DITStructureRule looked up by RuleId */
- protected Map<Integer, DITStructureRule> byRuleId;
-
- /**
- * Creates a new default NormalizerRegistry instance.
- *
- * @param oidRegistry The global OID registry
- */
- public DITStructureRuleRegistry( OidRegistry oidRegistry )
- {
- super( SchemaObjectType.DIT_STRUCTURE_RULE, oidRegistry );
- byRuleId = new HashMap<Integer, DITStructureRule>();
- }
-
-
/**
* Checks to see if an DITStructureRule exists in the registry, by its
* ruleId.
@@ -70,10 +44,7 @@
* @return true if a DITStructureRule definition exists for the ruleId, false
* otherwise
*/
- public boolean contains( int ruleId )
- {
- return byRuleId.containsKey( ruleId );
- }
+ boolean contains( int ruleId );
/**
@@ -81,10 +52,7 @@
*
* @return an Iterator of descriptions
*/
- public Iterator<DITStructureRule> iterator()
- {
- return byRuleId.values().iterator();
- }
+ Iterator<DITStructureRule> iterator();
/**
@@ -92,10 +60,7 @@
*
* @return an Iterator of ruleId
*/
- public Iterator<Integer> ruleIdIterator()
- {
- return byRuleId.keySet().iterator();
- }
+ Iterator<Integer> ruleIdIterator();
/**
@@ -105,19 +70,7 @@
* @return the schema name
* @throws NamingException if the schema object does not exist
*/
- public String getSchemaName( int ruleId ) throws NamingException
- {
- DITStructureRule ditStructureRule = byRuleId.get( ruleId );
-
- if ( ditStructureRule != null )
- {
- return ditStructureRule.getSchemaName();
- }
-
- String msg = "RuleId " + ruleId + " not found in ruleId to schema name map!";
- LOG.warn( msg );
- throw new NamingException( msg );
- }
+ String getSchemaName( int ruleId ) throws NamingException;
/**
@@ -127,24 +80,7 @@
* @throws NamingException if the DITStructureRule is already registered or
* the registration operation is not supported
*/
- public void register( DITStructureRule ditStructureRule ) throws NamingException
- {
- int ruleId = ditStructureRule.getRuleId();
-
- if ( byRuleId.containsKey( ruleId ) )
- {
- String msg = "DITStructureRule with RuleId " + ruleId + " already registered!";
- LOG.warn( msg );
- throw new NamingException( msg );
- }
-
- byRuleId.put( ruleId, ditStructureRule );
-
- if ( LOG.isDebugEnabled() )
- {
- LOG.debug( "registered {} for OID {}", ditStructureRule, ruleId );
- }
- }
+ void register( DITStructureRule ditStructureRule ) throws NamingException;
/**
@@ -155,24 +91,7 @@
* @return the DITStructureRule instance for rule identifier
* @throws NamingException if the DITStructureRule does not exist
*/
- public DITStructureRule lookup( int ruleId ) throws NamingException
- {
- DITStructureRule ditStructureRule = byRuleId.get( ruleId );
-
- if ( ditStructureRule == null )
- {
- String msg = "DITStructureRule for ruleId " + ruleId + " does not exist!";
- LOG.debug( msg );
- throw new NamingException( msg );
- }
-
- if ( DEBUG )
- {
- LOG.debug( "Found {} with ruleId: {}", ditStructureRule, ruleId );
- }
-
- return ditStructureRule;
- }
+ DITStructureRule lookup( int ruleId ) throws NamingException;
/**
@@ -181,15 +100,7 @@
* @param ruleId the rule identifier for the DITStructureRule to unregister
* @throws NamingException if no such DITStructureRule exists
*/
- public void unregister( int ruleId ) throws NamingException
- {
- DITStructureRule ditStructureRule = byRuleId.remove( ruleId );
-
- if ( DEBUG )
- {
- LOG.debug( "Removed {} with ruleId {} from the registry", ditStructureRule, ruleId );
- }
- }
+ void unregister( int ruleId ) throws NamingException;
/**
@@ -197,30 +108,9 @@
* this registry.
*
* @param schemaName the name of the schema whose syntaxCheckers will be removed from
+ * @throws NamingException if no such SchemaElement exists
*/
- public void unregisterSchemaElements( String schemaName )
- {
- if ( schemaName == null )
- {
- return;
- }
-
- // Loop on all the SchemaObjects stored and remove those associated
- // with the give schemaName
- for ( DITStructureRule ditStructureRule : this )
- {
- if ( schemaName.equalsIgnoreCase( ditStructureRule.getSchemaName() ) )
- {
- int ruleId = ditStructureRule.getRuleId();
- SchemaObject removed = byRuleId.remove( ruleId );
-
- if ( DEBUG )
- {
- LOG.debug( "Removed {} with ruleId {} from the registry", removed, ruleId );
- }
- }
- }
- }
+ void unregisterSchemaElements( String schemaName ) throws NamingException;
/**
@@ -228,45 +118,19 @@
*
* @param originalSchemaName The original Schema name
* @param newSchemaName The new Schema name
+ * @throws NamingException if the schema can't be renamed
*/
- public void renameSchema( String originalSchemaName, String newSchemaName )
- {
- // Loop on all the SchemaObjects stored and remove those associated
- // with the give schemaName
- for ( DITStructureRule ditStructureRule : this )
- {
- if ( originalSchemaName.equalsIgnoreCase( ditStructureRule.getSchemaName() ) )
- {
- ditStructureRule.setSchemaName( newSchemaName );
-
- if ( DEBUG )
- {
- LOG.debug( "Renamed {} schemaName to {}", ditStructureRule, newSchemaName );
- }
- }
- }
- }
+ void renameSchema( String originalSchemaName, String newSchemaName ) throws NamingException;
/**
* Clone the DITStructureRuleRegistry
*/
- public DITStructureRuleRegistry clone() throws CloneNotSupportedException
- {
- DITStructureRuleRegistry clone = (DITStructureRuleRegistry)super.clone();
-
- // Clone the RuleId map
- clone.byRuleId = new HashMap<Integer, DITStructureRule>();
-
- return clone;
- }
+ DITStructureRuleRegistry clone() throws CloneNotSupportedException;
/**
* @return The number of DITStructureRule stored
*/
- public int size()
- {
- return byRuleId.values().size();
- }
+ int size();
}
Added: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java?rev=833647&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java (added)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultAttributeTypeRegistry.java Sat Nov 7 07:57:34 2009
@@ -0,0 +1,369 @@
+/*
+ * 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.schema.registries;
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.directory.NoSuchAttributeException;
+
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.shared.ldap.schema.SchemaObjectType;
+import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
+import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An AttributeType registry service default implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 828111 $
+ */
+public class DefaultAttributeTypeRegistry extends DefaultSchemaObjectRegistry<AttributeType>
+ implements AttributeTypeRegistry
+{
+ /** static class logger */
+ private static final Logger LOG = LoggerFactory.getLogger( DefaultAttributeTypeRegistry.class );
+
+ /** Speedup for DEBUG mode */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** cached Oid/normalizer mapping */
+ private transient Map<String, OidNormalizer> oidNormalizerMap;
+
+ /** maps OIDs to a Set of descendants for that OID */
+ private Map<String,Set<AttributeType>> oidToDescendantSet;
+
+
+ /**
+ * Creates a new default AttributeTypeRegistry instance.
+ *
+ * @param oidRegistry The global OID registry
+ */
+ public DefaultAttributeTypeRegistry( OidRegistry oidRegistry )
+ {
+ super( SchemaObjectType.ATTRIBUTE_TYPE, oidRegistry );
+ oidNormalizerMap = new HashMap<String, OidNormalizer>();
+ oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Map<String, OidNormalizer> getNormalizerMapping()
+ {
+ return Collections.unmodifiableMap( oidNormalizerMap );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasDescendants( String ancestorId ) throws NamingException
+ {
+ try
+ {
+ String oid = getOidByName( ancestorId );
+ Set<AttributeType> descendants = oidToDescendantSet.get( oid );
+ return (descendants != null) && !descendants.isEmpty();
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public Iterator<AttributeType> descendants( String ancestorId ) throws NamingException
+ {
+ try
+ {
+ String oid = getOidByName( ancestorId );
+ Set<AttributeType> descendants = oidToDescendantSet.get( oid );
+
+ if ( descendants == null )
+ {
+ return Collections.EMPTY_SET.iterator();
+ }
+
+ return descendants.iterator();
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void register( AttributeType attributeType ) throws NamingException
+ {
+ try
+ {
+ super.register( attributeType );
+
+ // Internally associate the OID to the registered AttributeType
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "registred attributeType: {}", attributeType );
+ }
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerDescendants( AttributeType attributeType, AttributeType ancestor )
+ throws NamingException
+ {
+ // add this attribute to descendant list of other attributes in superior chain
+ if ( ancestor == null )
+ {
+ return;
+ }
+
+ // Get the ancestor's descendant, if any
+ Set<AttributeType> descendants = oidToDescendantSet.get( ancestor.getOid() );
+
+ // Initialize the descendant Set to store the descendants for the attributeType
+ if ( descendants == null )
+ {
+ descendants = new HashSet<AttributeType>( 1 );
+ oidToDescendantSet.put( ancestor.getOid(), descendants );
+ }
+
+ // Add the current type as a descendant
+ descendants.add( attributeType );
+
+ try
+ {
+ // And recurse until we reach the top of the hierarchy
+ registerDescendants( attributeType, ancestor.getSuperior() );
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor )
+ throws NamingException
+ {
+ // add this attribute to descendant list of other attributes in superior chain
+ if ( ancestor == null )
+ {
+ return;
+ }
+
+ // Get the ancestor's descendant, if any
+ Set<AttributeType> descendants = oidToDescendantSet.get( ancestor.getOid() );
+
+ if ( descendants != null )
+ {
+ descendants.remove( attributeType );
+
+ if ( descendants.size() == 0 )
+ {
+ oidToDescendantSet.remove( descendants );
+ }
+ }
+
+ try
+ {
+ // And recurse until we reach the top of the hierarchy
+ unregisterDescendants( attributeType, ancestor.getSuperior() );
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public AttributeType unregister( String numericOid ) throws NamingException
+ {
+ try
+ {
+ AttributeType removed = super.unregister( numericOid );
+
+ removeMappingFor( removed );
+
+ // Deleting an AT which might be used as a superior means we have
+ // to recursively update the descendant map. We also have to remove
+ // the at.oid -> descendant relation
+ oidToDescendantSet.remove( numericOid );
+
+ // Now recurse if needed
+ unregisterDescendants( removed, removed.getSuperior() );
+
+ return removed;
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addMappingFor( AttributeType attributeType ) throws NamingException
+ {
+ MatchingRule matchingRule = attributeType.getEquality();
+ OidNormalizer oidNormalizer;
+ String oid = attributeType.getOid();
+
+ if ( matchingRule == null )
+ {
+ LOG.debug( "Attribute {} does not have normalizer : using NoopNormalizer", attributeType.getName() );
+ oidNormalizer = new OidNormalizer( oid, new NoOpNormalizer( attributeType.getOid() ) );
+ }
+ else
+ {
+ oidNormalizer = new OidNormalizer( oid, matchingRule.getNormalizer() );
+ }
+
+ oidNormalizerMap.put( oid, oidNormalizer );
+
+ // Also inject the attributeType's short names in the map
+ for ( String name : attributeType.getNames() )
+ {
+ oidNormalizerMap.put( name.toLowerCase(), oidNormalizer );
+ }
+ }
+
+
+ /**
+ * Remove the AttributeType normalizer from the OidNormalizer map
+ */
+ private void removeMappingFor( SchemaObject attributeType )
+ {
+ if ( attributeType == null )
+ {
+ return;
+ }
+
+ oidNormalizerMap.remove( attributeType.getOid() );
+
+ // We also have to remove all the short names for this attribute
+ for ( String name : attributeType.getNames() )
+ {
+ oidNormalizerMap.remove( name.toLowerCase() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public AttributeType lookup( String oid ) throws NamingException
+ {
+ try
+ {
+ return super.lookup( oid );
+ }
+ catch ( NamingException ne )
+ {
+ throw new NoSuchAttributeException( ne.getMessage() );
+ }
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ boolean isFirst = true;
+
+ for ( String name:byName.keySet() )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ", " );
+ }
+
+ sb.append( name );
+ }
+
+ return sb.toString();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public DefaultAttributeTypeRegistry clone() throws CloneNotSupportedException
+ {
+ DefaultAttributeTypeRegistry clone = (DefaultAttributeTypeRegistry)super.clone();
+
+ // Clone the oidNormalizerMap (will be empty)
+ clone.oidNormalizerMap = new HashMap<String, OidNormalizer>();
+
+ // Clone the oidToDescendant map (will be empty)
+ clone.oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
+
+ return clone;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int size()
+ {
+ return oidRegistry.size();
+ }
+}
|