directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r823360 [5/6] - in /directory: apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/ apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/syn...
Date Fri, 09 Oct 2009 00:03:51 GMT
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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -28,15 +28,19 @@
 
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.schema.LoadableSchemaObject;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
@@ -51,6 +55,7 @@
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.apache.directory.shared.ldap.util.Base64;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -83,6 +88,118 @@
     {
         this.classLoader = new AttributeClassLoader();
     }
+    
+    
+    /**
+     * Get an OID from an entry. Handles the bad cases (null OID, 
+     * not a valid OID, ...)
+     */
+    private String getOid( Entry entry, String objectType ) throws NamingException
+    {
+        // The OID
+        EntryAttribute mOid = entry.get( MetaSchemaConstants.M_OID_AT );
+        
+        if ( mOid == null )
+        {
+            String msg = objectType + " entry must have a valid " 
+                + MetaSchemaConstants.M_OID_AT + " attribute, it's null";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
+        }
+
+        String oid = mOid.getString();
+        
+        if ( !OID.isOID( oid ) )
+        {
+            String msg = "Comparator OID " + oid + " is not a valid OID "; 
+            LOG.warn( msg );
+            throw new LdapInvalidAttributeValueException( msg,
+                ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+        }
+        
+        return oid;
+    }
+    
+    
+    /**
+     * Get an OID from an entry. Handles the bad cases (null OID, 
+     * not a valid OID, ...)
+     */
+    private String getOid( SchemaObject description, String objectType ) throws NamingException
+    {
+        // The OID
+        String oid = description.getOid();
+        
+        if ( oid == null )
+        {
+            String msg = objectType + " entry must have a valid " 
+                + MetaSchemaConstants.M_OID_AT + " attribute, it's null";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
+        }
+
+        if ( !OID.isOID( oid ) )
+        {
+            String msg = "Comparator OID " + oid + " is not a valid OID "; 
+            LOG.warn( msg );
+            throw new LdapInvalidAttributeValueException( msg,
+                ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+        }
+        
+        return oid;
+    }
+
+    
+    /**
+     * Check that the Entry is not null
+     */
+    private void checkEntry( Entry entry, String schemaEntity )
+    {
+        if ( entry == null )
+        {
+            String msg = schemaEntity + " entry cannot be null";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
+        }
+    }
+
+    
+    /**
+     * Check that the Description is not null
+     */
+    private void checkDescription( SchemaObject description, String schemaEntity )
+    {
+        if ( description == null )
+        {
+            String msg = schemaEntity + " Schema description cannot be null";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
+        }
+    }
+
+    
+    /**
+     * Get the schema from its name. Return the Other reference if there
+     * is no schema name. Throws a NPE if the schema is not loaded.
+     */
+    private Schema getSchema( String schemaName, Registries registries )
+    {
+        if ( StringTools.isEmpty( schemaName ) )
+        {
+            schemaName = MetaSchemaConstants.SCHEMA_OTHER;
+        }
+
+        Schema schema = registries.getLoadedSchema( schemaName );
+        
+        if ( schema == null )
+        {
+            String msg = "The schema " + schemaName + " does not exists or is not loaded";
+            LOG.error( msg );
+            throw new NullPointerException( msg );
+        }
+        
+        return schema;
+    }
 
     
     public Schema getSchema( Entry entry ) throws Exception
@@ -136,28 +253,38 @@
     }
     
     
-    private SyntaxChecker getSyntaxChecker( String syntaxOid, String className, 
-        EntryAttribute bytecode, Registries targetRegistries ) throws Exception
+    /**
+     * Class load a syntaxChecker instance
+     */
+    private SyntaxChecker classLoadSyntaxChecker( String oid, String className, 
+        EntryAttribute byteCode, Registries targetRegistries ) throws Exception
     {
+        // Try to class load the syntaxChecker
         Class<?> clazz = null;
         SyntaxChecker syntaxChecker = null;
-        
-        if ( bytecode == null )
+        String byteCodeStr = StringTools.EMPTY;
+
+        if ( byteCode == null )
         {
             clazz = Class.forName( className );
         }
         else
         {
-            classLoader.setAttribute( bytecode );
+            classLoader.setAttribute( byteCode );
             clazz = classLoader.loadClass( className );
+            byteCodeStr = new String( Base64.encode( byteCode.getBytes() ) );
         }
         
+        // Create the syntaxChecker instance
         syntaxChecker = ( SyntaxChecker ) clazz.newInstance();
 
-        // try now before returning to check if we can inject a Registries object
-        syntaxChecker.setOid( syntaxOid );
-        injectRegistries( syntaxChecker, targetRegistries );
+        // Update the common fields
+        syntaxChecker.setBytecode( byteCodeStr );
         syntaxChecker.setFqcn( className );
+        
+        // Inject the new OID, as the loaded syntaxChecker might have its own
+        syntaxChecker.setOid( oid );
+
         return syntaxChecker;
     }
     
@@ -169,89 +296,141 @@
      * @return the loaded SyntaxChecker
      * @throws NamingException if anything fails during loading
      */
-    public SyntaxChecker getSyntaxChecker( Entry entry, Registries targetRegistries ) throws Exception
+    public SyntaxChecker getSyntaxChecker( Entry entry, Registries targetRegistries, String schemaName ) throws Exception
     {
-        if ( entry == null )
-        {
-            throw new NullPointerException( "entry cannot be null" );
-        }
+        checkEntry( entry, SchemaConstants.SYNTAX_CHECKER );
         
-        if ( entry.get( MetaSchemaConstants.M_FQCN_AT ) == null )
-        {
-            throw new NullPointerException( "entry must have a valid "
-                + MetaSchemaConstants.M_FQCN_AT + " attribute" );
-        }
+        // The SyntaxChecker OID
+        String oid = getOid( entry, SchemaConstants.SYNTAX_CHECKER );
+
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
 
-        String className = entry.get( MetaSchemaConstants.M_FQCN_AT ).get().getString();
-        String syntaxOid = entry.get( MetaSchemaConstants.M_OID_AT ).get().getString();
+        // The FQCN
+        String className = getFqcn( entry, SchemaConstants.SYNTAX_CHECKER );
+        
+        // The ByteCode
         EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
+            
+        // Class load the syntaxChecker
+        SyntaxChecker syntaxChecker = classLoadSyntaxChecker( oid, className, byteCode, targetRegistries );
+        
+        // Update the common fields
+        setSchemaObjectProperties( syntaxChecker, entry, schema );
         
-        return getSyntaxChecker( syntaxOid, className, byteCode, targetRegistries );
+        // return the resulting syntaxChecker
+        return syntaxChecker;
     }
     
     
+    /**
+     * Create a new instance of a SyntaxChecker 
+     *
+     * @param syntaxCheckerDescription
+     * @param targetRegistries
+     * @param schemaName
+     * @return A new instance of a syntaxChecker
+     * @throws Exception If the creation has failed
+     */
     public SyntaxChecker getSyntaxChecker( SyntaxCheckerDescription syntaxCheckerDescription, 
-        Registries targetRegistries ) throws Exception
+        Registries targetRegistries, String schemaName ) throws Exception
     {
-        EntryAttribute attr = null;
+        checkDescription( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
         
-        if ( syntaxCheckerDescription.getBytecode() != null )
-        {
-            byte[] bytecode = Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() );
-            attr = new DefaultClientAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
-        }
+        // The Comparator OID
+        String oid = getOid( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
+        
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // The FQCN
+        String fqcn = getFqcn( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
+        
+        // get the byteCode
+        EntryAttribute byteCode = getByteCode( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
+        
+        // Class load the SyntaxChecker
+        SyntaxChecker syntaxChecker = classLoadSyntaxChecker( oid, 
+            fqcn, byteCode, targetRegistries );
         
-        return getSyntaxChecker( syntaxCheckerDescription.getOid(), 
-            syntaxCheckerDescription.getFqcn(), attr, targetRegistries );
+        // Update the common fields
+        setSchemaObjectProperties( syntaxChecker, syntaxCheckerDescription, schema );
+        
+        return syntaxChecker;
     }
     
     
-    private LdapComparator<?> getLdapComparator( String oid, String className, 
-        EntryAttribute bytecode, Registries targetRegistries ) throws Exception
+    /**
+     * Class load a comparator instances
+     */
+    private LdapComparator<?> classLoadComparator( String oid, String className, 
+        EntryAttribute byteCode, Registries targetRegistries ) throws Exception
     {
+        // Try to class load the comparator
         LdapComparator<?> comparator = null;
         Class<?> clazz = null;
-         
-        try
+        String byteCodeStr = StringTools.EMPTY;
+
+        if ( byteCode == null ) 
         {
-	        if ( bytecode == null ) 
-	        {
-	            clazz = Class.forName( className );
-	        }
-	        else
-	        {
-	            classLoader.setAttribute( bytecode );
-	            clazz = classLoader.loadClass( className );
-	        }
+            clazz = Class.forName( className );
         }
-        catch ( Exception e )
+        else
         {
-        	LOG.error( "Failed to load class from LDIF bytecode from schemaObject {}", oid, e );
-        	throw e;
+            classLoader.setAttribute( byteCode );
+            clazz = classLoader.loadClass( className );
+            byteCodeStr = new String( Base64.encode( byteCode.getBytes() ) );
         }
         
+        // Create the comparator instance
         comparator = ( LdapComparator<?> ) clazz.newInstance();
-        comparator.setOid( oid );
-        injectRegistries( comparator, targetRegistries );
+
+        // Update the loadable fields
+        comparator.setBytecode( byteCodeStr );
         comparator.setFqcn( className );
+        
+        // Inject the new OID, as the loaded comparator might have its own
+        comparator.setOid( oid );
+        
         return comparator;
     }
     
     
+    /**
+     * Create a new instance of a LdapComparator 
+     *
+     * @param comparatorDescription
+     * @param targetRegistries
+     * @param schemaName
+     * @return A new instance of a LdapComparator
+     * @throws Exception If the creation has failed
+     */
     public LdapComparator<?> getLdapComparator( 
         LdapComparatorDescription comparatorDescription, 
-        Registries targetRegistries ) throws Exception
+        Registries targetRegistries, String schemaName ) throws Exception
     {
-        EntryAttribute attr = null;
+        checkDescription( comparatorDescription, SchemaConstants.COMPARATOR );
         
-        if ( comparatorDescription.getBytecode() != null )
-        { 
-            byte[] bytecode = Base64.decode( comparatorDescription.getBytecode().toCharArray() );
-            attr = new DefaultClientAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
-        }
+        // The Comparator OID
+        String oid = getOid( comparatorDescription, SchemaConstants.COMPARATOR );
+        
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // The FQCN
+        String fqcn = getFqcn( comparatorDescription, SchemaConstants.COMPARATOR );
         
-        return getLdapComparator( comparatorDescription.getOid(), 
-            comparatorDescription.getFqcn(), attr, targetRegistries );
+        // get the byteCode
+        EntryAttribute byteCode = getByteCode( comparatorDescription, SchemaConstants.COMPARATOR );
+        
+        // Class load the comparator
+        LdapComparator<?> comparator = classLoadComparator( oid, 
+            fqcn, byteCode, targetRegistries );
+        
+        // Update the common fields
+        setSchemaObjectProperties( comparator, comparatorDescription, schema );
+        
+        return comparator;
     }
     
     
@@ -259,68 +438,108 @@
      * Retrieve and load a Comparator class from the DIT.
      * 
      * @param entry the entry to load the Comparator from
+     * @param targetRegistries The registries
+     * @param schemaName The schema this SchemaObject will be part of
      * @return the loaded Comparator
      * @throws NamingException if anything fails during loading
      */
     public LdapComparator<?> getLdapComparator( Entry entry, 
-        Registries targetRegistries ) throws Exception
+        Registries targetRegistries, String schemaName ) throws Exception
     {
-        if ( entry == null )
-        {
-            throw new NullPointerException( "entry cannot be null" );
-        }
+        checkEntry( entry, SchemaConstants.COMPARATOR );
         
-        if ( entry.get( MetaSchemaConstants.M_FQCN_AT ) == null )
-        {
-            throw new NullPointerException( "entry must have a valid " 
-                + MetaSchemaConstants.M_FQCN_AT + " attribute" );
-        }
+        // The Comparator OID
+        String oid = getOid( entry, SchemaConstants.COMPARATOR );
+        
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // The FQCN
+        String fqcn = getFqcn( entry, SchemaConstants.COMPARATOR );
         
-        String className = entry.get( MetaSchemaConstants.M_FQCN_AT ).get().getString();
-        String oid = entry.get( MetaSchemaConstants.M_OID_AT ).getString();
-        EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT ); 
-        return getLdapComparator( oid, className, byteCode, targetRegistries );
+        // The ByteCode
+        EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
+            
+        // Class load the comparator
+        LdapComparator<?> comparator = classLoadComparator( oid, fqcn, byteCode, targetRegistries );
+        
+        // Update the common fields
+        setSchemaObjectProperties( comparator, entry, schema );
+        
+        // return the resulting comparator
+        return comparator;
     }
     
     
-    private Normalizer getNormalizer( String oid, String className, 
-        EntryAttribute bytecode, Registries targetRegistries ) throws Exception
+    /**
+     * Class load a normalizer instances
+     */
+    private Normalizer classLoadNormalizer( String oid, String className, 
+        EntryAttribute byteCode, Registries targetRegistries ) throws Exception
     {
+        // Try to class load the normalizer
         Class<?> clazz = null;
         Normalizer normalizer = null;
+        String byteCodeStr = StringTools.EMPTY;
         
-        if ( bytecode == null )
+        if ( byteCode == null )
         {
             clazz = Class.forName( className );
         }
         else
         {
-            classLoader.setAttribute( bytecode );
+            classLoader.setAttribute( byteCode );
             clazz = classLoader.loadClass( className );
+            byteCodeStr = new String( Base64.encode( byteCode.getBytes() ) );
         }
 
+        // Create the normalizer instance
         normalizer = ( Normalizer ) clazz.newInstance();
-        normalizer.setOid( oid );
-        injectRegistries( normalizer, targetRegistries );
+
+        // Update the common fields
+        normalizer.setBytecode( byteCodeStr );
         normalizer.setFqcn( className );
         
+        // Inject the new OID, as the loaded normalizer might have its own
+        normalizer.setOid( oid );
+        
         return normalizer;
     }
 
     
+    /**
+     * Create a new instance of a Normalizer 
+     *
+     * @param normalizerDescription
+     * @param targetRegistries
+     * @param schemaName
+     * @return A new instance of a normalizer
+     * @throws Exception If the creation has failed
+     */
     public Normalizer getNormalizer( NormalizerDescription normalizerDescription, 
-        Registries targetRegistries ) throws Exception
+        Registries targetRegistries, String schemaName ) throws Exception
     {
-        EntryAttribute attr = null;
+        checkDescription( normalizerDescription, SchemaConstants.NORMALIZER );
         
-        if ( normalizerDescription.getBytecode() != null )
-        {
-            byte[] bytecode = Base64.decode( normalizerDescription.getBytecode().toCharArray() );
-            attr = new DefaultClientAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
-        }
+        // The Comparator OID
+        String oid = getOid( normalizerDescription, SchemaConstants.NORMALIZER );
+        
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // The FQCN
+        String fqcn = getFqcn( normalizerDescription, SchemaConstants.NORMALIZER );
         
-        return getNormalizer( normalizerDescription.getOid(), 
-            normalizerDescription.getFqcn(), attr, targetRegistries );
+        // get the byteCode
+        EntryAttribute byteCode = getByteCode( normalizerDescription, SchemaConstants.NORMALIZER );
+
+        // Class load the normalizer
+        Normalizer normalizer = classLoadNormalizer( oid, fqcn, byteCode, targetRegistries );
+        
+        // Update the common fields
+        setSchemaObjectProperties( normalizer, normalizerDescription, schema );
+        
+        return normalizer;
     }
     
     
@@ -331,24 +550,31 @@
      * @return the loaded Normalizer
      * @throws NamingException if anything fails during loading
      */
-    public Normalizer getNormalizer( Entry entry, Registries targetRegistries ) 
+    public Normalizer getNormalizer( Entry entry, Registries targetRegistries, String schemaName ) 
         throws Exception
     {
-        if ( entry == null )
-        {
-            throw new NullPointerException( "entry cannot be null" );
-        }
+        checkEntry( entry, SchemaConstants.NORMALIZER );
         
-        if ( entry.get( MetaSchemaConstants.M_FQCN_AT ) == null )
-        {
-            throw new NullPointerException( "entry must have a valid " 
-                + MetaSchemaConstants.M_FQCN_AT + " attribute" );
-        }
+        // The Normalizer OID
+        String oid = getOid( entry, SchemaConstants.NORMALIZER );
+
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // The FQCN
+        String className = getFqcn( entry, SchemaConstants.NORMALIZER );
+        
+        // The ByteCode
+        EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
+            
+        // Class load the Normalizer
+        Normalizer normalizer = classLoadNormalizer( oid, className, byteCode, targetRegistries );
+        
+        // Update the common fields
+        setSchemaObjectProperties( normalizer, entry, schema );
         
-        String className = entry.get( MetaSchemaConstants.M_FQCN_AT ).getString();
-        String oid = entry.get( MetaSchemaConstants.M_OID_AT ).getString();
-        EntryAttribute bytecode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
-        return getNormalizer( oid, className, bytecode, targetRegistries );
+        // return the resulting Normalizer
+        return normalizer;
     }
     
     
@@ -387,41 +613,77 @@
     }
 
 
-    public LdapSyntax getSyntax( Entry entry, Registries targetRegistries, String schema ) throws NamingException
+    public LdapSyntax getSyntax( Entry entry, Registries targetRegistries, String schemaName ) throws NamingException
     {
-        String oid = entry.get( MetaSchemaConstants.M_OID_AT ).getString();
+        checkEntry( entry, SchemaConstants.SYNTAX );
+
+        // The Syntax OID
+        String oid = getOid( entry, SchemaConstants.SYNTAX );
+
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // Create the new LdapSyntax instance
         LdapSyntax syntax = new LdapSyntax( oid );
-        syntax.setSchemaName( schema );
-        syntax.applyRegistries( targetRegistries );
         
-        if ( entry.get( MetaSchemaConstants.X_HUMAN_READABLE_AT ) != null )
-        {
-            String val = entry.get( MetaSchemaConstants.X_HUMAN_READABLE_AT ).getString();
-            syntax.setHumanReadable( val.toUpperCase().equals( "TRUE" ) );
-        }
+        // The isHumanReadable field
+        EntryAttribute mHumanReadable = entry.get( MetaSchemaConstants.X_HUMAN_READABLE_AT );
         
-        if ( entry.get( MetaSchemaConstants.M_DESCRIPTION_AT ) != null )
+        if ( mHumanReadable != null )
         {
-            syntax.setDescription( entry.get( MetaSchemaConstants.M_DESCRIPTION_AT ).getString() ); 
+            String val = mHumanReadable.getString();
+            syntax.setHumanReadable( val.toUpperCase().equals( "TRUE" ) );
         }
+
+        // Common properties
+        setSchemaObjectProperties( syntax, entry, schema );
         
         return syntax;
     }
 
     
-    public MatchingRule getMatchingRule( Entry entry, Registries targetRegistries, String schema ) throws NamingException
+    /**
+     * Construct an MatchingRule from an entry get from the Dit
+     *
+     * @param entry The entry containing all the informations to build a MatchingRule
+     * @param targetRegistries The registries containing all the enabled SchemaObjects
+     * @param schemaName The schema containing this MatchingRule
+     * @return A MatchingRule SchemaObject
+     * @throws NamingException If the MatchingRule is invalid
+     */
+    public MatchingRule getMatchingRule( Entry entry, Registries targetRegistries, String schemaName ) throws NamingException
     {
-        String oid = entry.get( MetaSchemaConstants.M_OID_AT ).getString();
-        String syntaxOid = entry.get( MetaSchemaConstants.M_SYNTAX_AT ).getString();
-        MatchingRule mr = new MatchingRule( oid );
-        mr.setSyntaxOid( syntaxOid );
-        mr.setSchemaName( schema );
-        setSchemaObjectProperties( mr, entry );
-    	mr.applyRegistries( targetRegistries );
-        return mr;
+        checkEntry( entry, SchemaConstants.MATCHING_RULE );
+
+        // The MatchingRule OID
+        String oid = getOid( entry, SchemaConstants.MATCHING_RULE );
+
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        MatchingRule matchingRule = new MatchingRule( oid );
+
+        // The syntax field
+        EntryAttribute mSyntax = entry.get( MetaSchemaConstants.M_SYNTAX_AT );
+        
+        if ( mSyntax != null )
+        {
+            matchingRule.setSyntaxOid( mSyntax.getString() );
+        }
+
+        // The normalizer and comparator fields will be updated when we will
+        // apply the registry 
+
+        // Common properties
+        setSchemaObjectProperties( matchingRule, entry, schema );
+        
+        return matchingRule;
     }
     
     
+    /**
+     * Create a list of string from a multivalued attribute's values
+     */
     private List<String> getStrings( EntryAttribute attr ) throws NamingException
     {
         if ( attr == null )
@@ -440,126 +702,275 @@
     }
     
     
-    public ObjectClass getObjectClass( Entry entry, Registries targetRegistries, String schema ) throws Exception
+    public ObjectClass getObjectClass( Entry entry, Registries targetRegistries, String schemaName ) throws Exception
     {
-        String oid = entry.get( MetaSchemaConstants.M_OID_AT ).getString();
+        checkEntry( entry, SchemaConstants.OBJECT_CLASS );
+
+        // The ObjectClass OID
+        String oid = getOid( entry, SchemaConstants.OBJECT_CLASS );
+
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // Create the ObjectClass instance
         ObjectClass oc = new ObjectClass( oid );
-        oc.setSchemaName( schema );
         
-        if ( entry.get( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT ) != null )
+        // The Sup field
+        EntryAttribute mSuperiors = entry.get( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT );
+        
+        if ( mSuperiors != null )
         {
-            oc.setSuperiorOids( getStrings( entry.get( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT ) ) );
+            oc.setSuperiorOids( getStrings( mSuperiors ) );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_MAY_AT ) != null )
+        // The May field
+        EntryAttribute mMay = entry.get( MetaSchemaConstants.M_MAY_AT );
+            
+        if ( mMay != null )
         {
-            oc.setMayAttributeTypeOids( getStrings( entry.get( MetaSchemaConstants.M_MAY_AT ) ) );
+            oc.setMayAttributeTypeOids( getStrings( mMay ) );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_MUST_AT ) != null )
+        // The Must field
+        EntryAttribute mMust = entry.get( MetaSchemaConstants.M_MUST_AT );
+        
+        if ( mMust != null )
         {
-            oc.setMustAttributeTypeOids( getStrings( entry.get( MetaSchemaConstants.M_MUST_AT ) ) );
+            oc.setMustAttributeTypeOids( getStrings( mMust ) );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT ) != null )
+        // The objectClassType field
+        EntryAttribute mTypeObjectClass = entry.get( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT );
+            
+        if ( mTypeObjectClass != null )
         {
-            String type = entry.get( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT ).getString();
+            String type = mTypeObjectClass.getString();
             oc.setType( ObjectClassTypeEnum.getClassType( type ) );
         }
-        else
-        {
-            oc.setType( ObjectClassTypeEnum.STRUCTURAL );
-        }
         
-        setSchemaObjectProperties( oc, entry );
-        oc.applyRegistries( targetRegistries );
+        // Common properties
+        setSchemaObjectProperties( oc, entry, schema );
         
         return oc;
     }
     
     
-    public AttributeType getAttributeType( Entry entry, Registries targetRegistries, String schema ) throws NamingException
+    /**
+     * Construct an AttributeType from an entry representing an AttributeType.
+     *
+     * @param entry The entry containing all the informations to build an AttributeType
+     * @param targetRegistries The registries containing all the enabled SchemaObjects
+     * @param schemaName The schema containing this AttributeType
+     * @return An AttributeType SchemaObject
+     * @throws NamingException If the AttributeType is invalid
+     */
+    public AttributeType getAttributeType( Entry entry, Registries targetRegistries, String schemaName ) throws NamingException
     {
-        String oid = entry.get( MetaSchemaConstants.M_OID_AT ).getString();
-        AttributeType at = new AttributeType( oid );
+        checkEntry( entry, SchemaConstants.ATTRIBUTE_TYPE );
+        
+        // The AttributeType OID
+        String oid = getOid( entry, SchemaConstants.ATTRIBUTE_TYPE );
+
+        // Get the schema
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        // Create the new AttributeType
+        AttributeType attributeType = new AttributeType( oid );
+        
+        // Syntax
+        EntryAttribute mSyntax = entry.get( MetaSchemaConstants.M_SYNTAX_AT );
+        
+        if ( mSyntax != null )
+        {
+            attributeType.setSyntaxOid( mSyntax.getString() );
+        }
+        
+        // Equality
+        EntryAttribute mEquality = entry.get( MetaSchemaConstants.M_EQUALITY_AT );
         
-        at.setSchemaName( schema );
-        setSchemaObjectProperties( at, entry );
+        if ( mEquality != null )
+        {
+        	attributeType.setEqualityOid( mEquality.getString() );
+        }
         
-        if ( entry.get( MetaSchemaConstants.M_SYNTAX_AT ) != null )
+        // Ordering
+        EntryAttribute mOrdering = entry.get( MetaSchemaConstants.M_ORDERING_AT ); 
+            
+        if ( mOrdering != null )
         {
-            at.setSyntaxOid( entry.get( MetaSchemaConstants.M_SYNTAX_AT ).getString() );
+            attributeType.setOrderingOid( mOrdering.getString() );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_EQUALITY_AT ) != null )
+        // Substr
+        EntryAttribute mSubstr = entry.get( MetaSchemaConstants.M_SUBSTR_AT );
+        
+        if ( mSubstr != null )
         {
-        	String mrName = entry.get( MetaSchemaConstants.M_EQUALITY_AT ).getString();
-        	String mrOid = targetRegistries.getMatchingRuleRegistry().getOidByName( mrName );
-            at.setEqualityOid( mrOid );
+            attributeType.setSubstringOid( mSubstr.getString() );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_ORDERING_AT ) != null )
+        EntryAttribute mSupAttributeType = entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT );
+        
+        // Sup
+        if ( mSupAttributeType != null )
         {
-        	String mrName = entry.get( MetaSchemaConstants.M_ORDERING_AT ).getString();
-        	String mrOid = targetRegistries.getMatchingRuleRegistry().getOidByName( mrName );
-            at.setOrderingOid( mrOid );
+        	attributeType.setSuperiorOid( mSupAttributeType.getString() );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_SUBSTR_AT ) != null )
+        // isCollective
+        EntryAttribute mCollective = entry.get( MetaSchemaConstants.M_COLLECTIVE_AT );
+        
+        if ( mCollective != null )
         {
-        	String mrName = entry.get( MetaSchemaConstants.M_SUBSTR_AT ).getString();
-        	String mrOid = targetRegistries.getMatchingRuleRegistry().getOidByName( mrName );
-            at.setSubstringOid( mrOid );
+            String val = mCollective.getString();
+            attributeType.setCollective( val.equalsIgnoreCase( "TRUE" ) );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT ) != null )
+        // isSingleValued
+        EntryAttribute mSingleValued = entry.get( MetaSchemaConstants.M_SINGLE_VALUE_AT );
+        
+        if ( mSingleValued != null )
         {
-        	String supName = entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT ).getString();
-            String supOid = targetRegistries.getAttributeTypeRegistry().getOidByName( supName );
-        	at.setSuperiorOid( supOid );
+            String val = mSingleValued.getString();
+            attributeType.setSingleValued( val.equalsIgnoreCase( "TRUE" ) );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_COLLECTIVE_AT ) != null )
+        // isReadOnly
+        EntryAttribute mNoUserModification = entry.get( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT );
+        
+        if ( mNoUserModification != null )
+        {
+            String val = mNoUserModification.getString();
+            attributeType.setUserModifiable( ! val.equalsIgnoreCase( "TRUE" ) );
+        }
+        
+        // Usage
+        EntryAttribute mUsage = entry.get( MetaSchemaConstants.M_USAGE_AT );
+        
+        if ( mUsage != null )
+        {
+            attributeType.setUsage( UsageEnum.getUsage( mUsage.getString() ) );
+        }
+        
+        // Common properties
+        setSchemaObjectProperties( attributeType, entry, schema );
+        
+        return attributeType;
+    }
+    
+    
+    /**
+     * Process the FQCN attribute
+     */
+    private String getFqcn( Entry entry, String objectType ) throws NamingException
+    {
+        // The FQCN
+        EntryAttribute mFqcn = entry.get( MetaSchemaConstants.M_FQCN_AT );
+        
+        if ( mFqcn == null )
         {
-            String val = entry.get( MetaSchemaConstants.M_COLLECTIVE_AT ).getString();
-            at.setCollective( val.equalsIgnoreCase( "TRUE" ) );
+            String msg = objectType + " entry must have a valid " 
+                + MetaSchemaConstants.M_FQCN_AT + " attribute";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_SINGLE_VALUE_AT ) != null )
+        return mFqcn.getString();
+    }
+    
+    
+    /**
+     * Process the FQCN attribute
+     */
+    private String getFqcn( LoadableSchemaObject description, String objectType ) throws NamingException
+    {
+        // The FQCN
+        String mFqcn = description.getFqcn();
+        
+        if ( mFqcn == null )
         {
-            String val = entry.get( MetaSchemaConstants.M_SINGLE_VALUE_AT ).getString();
-            at.setSingleValued( val.equalsIgnoreCase( "TRUE" ) );
+            String msg = objectType + " entry must have a valid " 
+                + MetaSchemaConstants.M_FQCN_AT + " attribute";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT ) != null )
+        return mFqcn;
+    }
+    
+    
+    /**
+     * Process the ByteCode attribute
+     */
+    private EntryAttribute getByteCode( Entry entry, String objectType ) throws NamingException
+    {
+        EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT );
+        
+        if ( byteCode == null )
         {
-            String val = entry.get( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT ).getString();
-            at.setUserModifiable( ! val.equalsIgnoreCase( "TRUE" ) );
+            String msg = objectType + " entry must have a valid " 
+                + MetaSchemaConstants.M_BYTECODE_AT + " attribute";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_USAGE_AT ) != null )
+        return byteCode;
+    }
+    
+
+    /**
+     * Process the ByteCode attribute
+     */
+    private EntryAttribute getByteCode( LoadableSchemaObject description, String objectType ) throws NamingException
+    {
+        String byteCodeString = description.getBytecode();
+        
+        if ( byteCodeString == null )
         {
-            at.setUsage( UsageEnum.getUsage( entry.get( MetaSchemaConstants.M_USAGE_AT ).getString() ) );
+            String msg = objectType + " entry must have a valid " 
+                + MetaSchemaConstants.M_BYTECODE_AT + " attribute";
+            LOG.warn( msg );
+            throw new NullPointerException( msg );
         }
+
+        byte[] bytecode = Base64.decode( byteCodeString.toCharArray() );
+        EntryAttribute attr = new DefaultClientAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
         
-        at.applyRegistries( targetRegistries );
-        return at;
+        return attr;
     }
     
 
-    private void setSchemaObjectProperties( SchemaObject so, Entry entry ) throws NamingException
+    /**
+     * Process the common attributes to all SchemaObjects :
+     *  - obsolete
+     *  - description
+     *  - names
+     *  - schemaName
+     *  - specification (if any)
+     *  - extensions
+     *  - isReadOnly
+     *  - isEnabled
+     */
+    private void setSchemaObjectProperties( SchemaObject schemaObject, Entry entry, Schema schema ) throws NamingException
     {
-        if ( entry.get( MetaSchemaConstants.M_OBSOLETE_AT ) != null )
+        // The isObsolete field
+        EntryAttribute mObsolete = entry.get( MetaSchemaConstants.M_OBSOLETE_AT );
+        
+        if ( mObsolete != null )
         {
-            String val = entry.get( MetaSchemaConstants.M_OBSOLETE_AT ).getString();
-            so.setObsolete( val.equalsIgnoreCase( "TRUE" ) );
+            String val = mObsolete.getString();
+            schemaObject.setObsolete( val.equalsIgnoreCase( "TRUE" ) );
         }
         
-        if ( entry.get( MetaSchemaConstants.M_DESCRIPTION_AT ) != null )
+        // The description field
+        EntryAttribute mDescription = entry.get( MetaSchemaConstants.M_DESCRIPTION_AT );
+        
+        if ( mDescription != null )
         {
-            so.setDescription( entry.get( MetaSchemaConstants.M_DESCRIPTION_AT ).getString() ); 
+            schemaObject.setDescription( mDescription.getString() ); 
         }
 
+        // The names field
         EntryAttribute names = entry.get( MetaSchemaConstants.M_NAME_AT );
         
         if ( names != null )
@@ -571,7 +982,105 @@
                 values.add( name.getString() );
             }
             
-            so.setNames( values );
+            schemaObject.setNames( values );
         }
+        
+        // The isEnabled field
+        EntryAttribute mDisabled = entry.get( MetaSchemaConstants.M_DISABLED_AT );
+        
+        // If the SchemaObject has an explicit m-disabled attribute, then use it.
+        // Otherwise, inherit it from the schema
+        if ( mDisabled != null )
+        {
+            String val = mDisabled.getString();
+            schemaObject.setEnabled( ! val.equalsIgnoreCase( "TRUE" ) );
+        }
+        else
+        {
+            schemaObject.setEnabled( schema.isEnabled() );
+        }
+        
+        // The isReadOnly field
+        EntryAttribute mIsReadOnly = entry.get( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT );
+
+        if ( mIsReadOnly != null )
+        {
+            String val = mIsReadOnly.getString();
+            schemaObject.setReadOnly( val.equalsIgnoreCase( "TRUE" ) );
+        }
+        
+        // The specification field
+        /*
+         * TODO : create the M_SPECIFICATION_ATAT
+        EntryAttribute mSpecification = entry.get( MetaSchemaConstants.M_SPECIFICATION_AT );
+        
+        if ( mSpecification != null )
+        {
+            so.setSpecification( mSpecification.getString() ); 
+        }
+        */
+        
+        // The schemaName field
+        schemaObject.setSchemaName( schema.getSchemaName() );
+        
+        // The extensions field
+        /*
+         * TODO create the M_EXTENSION_AT AT
+        EntryAttribute extensions = entry.get( MetaSchemaConstants.M_EXTENSION_AT );
+        
+        if ( extensions != null )
+        {
+            List<String> extensions = new ArrayList<String>();
+            
+            for ( Value<?> extension:extensions )
+            {
+                values.add( extension() );
+            }
+            
+            so.setExtensions( values );
+        }
+        */
+    }
+
+
+    /**
+     * Process the common attributes to all SchemaObjects :
+     *  - obsolete
+     *  - description
+     *  - names
+     *  - schemaName
+     *  - specification (if any)
+     *  - extensions
+     *  - isReadOnly
+     *  - isEnabled
+     */
+    private void setSchemaObjectProperties( SchemaObject schemaObject, SchemaObject description, Schema schema ) throws NamingException
+    {
+        // The isObsolete field
+        schemaObject.setObsolete( description.isObsolete() );
+        
+        // The description field
+        schemaObject.setDescription( description.getDescription() );
+
+        // The names field
+        schemaObject.setNames( description.getNames() );
+        
+        // The isEnabled field. Has the description does not hold a 
+        // Disable field, we will inherit from the schema enable field
+        schemaObject.setEnabled( schema.isEnabled() );
+        
+        // The isReadOnly field. We don't have this data in the description,
+        // so set it to false
+        // TODO : should it be a X-READONLY extension ?
+        schemaObject.setReadOnly( false );
+
+        // The specification field
+        schemaObject.setSpecification( description.getSpecification() );
+        
+        // The schemaName field
+        schemaObject.setSchemaName( schema.getSchemaName() );
+        
+        // The extensions field
+        schemaObject.setExtensions( description.getExtensions() );
     }
 }

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=nis/ou=syntaxcheckers/m-oid=1.3.6.1.1.1.0.0.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dnis/ou%3Dsyntaxcheckers/m-oid%3D1.3.6.1.1.1.0.0.ldif?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=nis/ou=syntaxcheckers/m-oid=1.3.6.1.1.1.0.0.ldif (original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=nis/ou=syntaxcheckers/m-oid=1.3.6.1.1.1.0.0.ldif Fri Oct  9 00:03:45 2009
@@ -3,8 +3,8 @@
 entryuuid:: WoQyjBBbRF20wqCBTAvpiQ==
 m-oid: 1.3.6.1.1.1.0.0
 entrycsn: 20090818052726.864000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxCh
- ecker
+m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntax
+ Checker
 objectclass: metaSyntaxChecker
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=nis/ou=syntaxcheckers/m-oid=1.3.6.1.1.1.0.1.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dnis/ou%3Dsyntaxcheckers/m-oid%3D1.3.6.1.1.1.0.1.ldif?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=nis/ou=syntaxcheckers/m-oid=1.3.6.1.1.1.0.1.ldif (original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=nis/ou=syntaxcheckers/m-oid=1.3.6.1.1.1.0.1.ldif Fri Oct  9 00:03:45 2009
@@ -3,8 +3,8 @@
 entryuuid:: jSqpuKHcT6Stdr4GKEO5Fw==
 m-oid: 1.3.6.1.1.1.0.1
 entrycsn: 20090818052726.604000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxCh
- ecker
+m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntax
+ Checker
 objectclass: metaSyntaxChecker
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.55.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dsystem/ou%3Dsyntaxcheckers/m-oid%3D1.3.6.1.4.1.1466.115.121.1.55.ldif?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.55.ldif (original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.55.ldif Fri Oct  9 00:03:45 2009
@@ -3,8 +3,8 @@
 entryuuid:: BiVWTonXSvuB4A+EyFeK9g==
 m-oid: 1.3.6.1.4.1.1466.115.121.1.55
 entrycsn: 20090818052726.656000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxCh
- ecker
+m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntax
+ Checker
 objectclass: metaSyntaxChecker
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.56.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dsystem/ou%3Dsyntaxcheckers/m-oid%3D1.3.6.1.4.1.1466.115.121.1.56.ldif?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.56.ldif (original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.56.ldif Fri Oct  9 00:03:45 2009
@@ -3,8 +3,8 @@
 entryuuid:: 5rBWuVarSVy7ai0VcnqRDA==
 m-oid: 1.3.6.1.4.1.1466.115.121.1.56
 entrycsn: 20090818052726.587000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxCh
- ecker
+m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntax
+ Checker
 objectclass: metaSyntaxChecker
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.57.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dsystem/ou%3Dsyntaxcheckers/m-oid%3D1.3.6.1.4.1.1466.115.121.1.57.ldif?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.57.ldif (original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.57.ldif Fri Oct  9 00:03:45 2009
@@ -3,8 +3,8 @@
 entryuuid:: 6d22usemTou/+JkTfLkboA==
 m-oid: 1.3.6.1.4.1.1466.115.121.1.57
 entrycsn: 20090818052726.934000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxCh
- ecker
+m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntax
+ Checker
 objectclass: metaSyntaxChecker
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.59.ldif
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou%3Dschema/cn%3Dsystem/ou%3Dsyntaxcheckers/m-oid%3D1.3.6.1.4.1.1466.115.121.1.59.ldif?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.59.ldif (original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/resources/schema/ou=schema/cn=system/ou=syntaxcheckers/m-oid=1.3.6.1.4.1.1466.115.121.1.59.ldif Fri Oct  9 00:03:45 2009
@@ -3,8 +3,8 @@
 entryuuid:: EgQD634PQWeT2ddb2c5RhA==
 m-oid: 1.3.6.1.4.1.1466.115.121.1.59
 entrycsn: 20090818052726.851000Z#000000#000#000000
-m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxCh
- ecker
+m-fqcn: org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntax
+ Checker
 objectclass: metaSyntaxChecker
 objectclass: metaTop
 objectclass: top

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AttributeType.java Fri Oct  9 00:03:45 2009
@@ -22,6 +22,8 @@
 
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.schema.registries.LdapSyntaxRegistry;
 import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
@@ -197,9 +199,13 @@
     
     /**
      * Inject the registries into this Object, updating the references to
-     * other SchemaObject
+     * other SchemaObject.
+     * 
+     * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX), 
+     * an exception is thrown.
      *
      * @param registries The Registries
+     * @exception If the AttributeType is not valid 
      */
     public void applyRegistries( Registries registries ) throws NamingException
     {
@@ -218,20 +224,55 @@
             {
                 equality = mrRegistry.lookup( equalityOid );
             }
+            else if ( superior != null )
+            {
+                // We may have a superior with an EQUALITY MR 
+                equality = superior.getEquality();
+            }
             
             if ( orderingOid != null )
             {
                 ordering = mrRegistry.lookup( orderingOid );
             }
+            else if ( superior != null )
+            {
+                // We may have a superior with an ORDERING MR 
+                ordering = superior.getOrdering();
+            }
             
             if ( substringOid != null )
             {
                 substring = mrRegistry.lookup( substringOid );
             }
+            else if ( superior != null )
+            {
+                // We may have a superior with an SUBSTR MR 
+                substring = superior.getSubstring();
+            }
             
             LdapSyntaxRegistry lsRegistry = registries.getLdapSyntaxRegistry();
             
-            syntax = lsRegistry.lookup( syntaxOid );
+            if ( syntaxOid != null )
+            {
+                syntax = lsRegistry.lookup( syntaxOid );
+            }
+            else  if ( superior != null )
+            {
+                syntax = superior.getSyntax();
+            }
+            else
+            {
+                // This is an error: an AttributeType must have at least a SYNTAX or a SUP
+                throw new LdapSchemaViolationException( "The created AttributeType must have a SUP or a SYNTAX element", 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+            
+            // Inject the attributeType into the oid/normalizer map
+            atRegistry.addMappingFor( this );
+    
+            // Register this AttributeType into the Descendant map
+            atRegistry.registerDescendants( this, this.getSuperior() );
+            
         }
     }
     

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java Fri Oct  9 00:03:45 2009
@@ -23,7 +23,7 @@
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.syntaxCheckers.AcceptAllSyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntaxChecker;
 
 
 /**
@@ -193,7 +193,7 @@
             }
             catch ( NamingException ne )
             {
-                syntaxChecker = new  AcceptAllSyntaxChecker( oid );
+                syntaxChecker = new OctetStringSyntaxChecker();
             }
         }
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java Fri Oct  9 00:03:45 2009
@@ -22,6 +22,8 @@
 
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.comparators.ComparableComparator;
 import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
@@ -144,7 +146,9 @@
             }
             catch ( NamingException ne )
             {
-                ldapSyntax = new LdapSyntax( oid );
+                // The Syntax is a mandatory element, it must exist.
+                throw new LdapSchemaViolationException( "The created MatchingRule must refers to an existing SYNTAX element", 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
             }
         }
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java Fri Oct  9 00:03:45 2009
@@ -83,7 +83,7 @@
      *
      * @param registries The Registries
      */
-    public void setRegistries( Registries registries )
+    public void applyRegistries( Registries registries )
     {
         // Do nothing. The extended class will store the Registries if needed
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java Fri Oct  9 00:03:45 2009
@@ -115,6 +115,7 @@
         mayAttributeTypes = new ArrayList<AttributeType>();
         mustAttributeTypes = new ArrayList<AttributeType>();
         superiors = new ArrayList<ObjectClass>();
+        objectClassType = ObjectClassTypeEnum.STRUCTURAL;
     }
     
     
@@ -126,7 +127,7 @@
      * @throws Exception on failure
      *
      */
-    public void applyRegistries( Registries registries ) throws Exception
+    public void applyRegistries( Registries registries ) throws NamingException
     {
         if ( registries != null )
         {
@@ -143,6 +144,7 @@
                 	{
                 		continue;
                 	}
+                	
                     superiors.add( ocRegistry.lookup( ocRegistry.getOidByName( superiorName ) ) );
                 }
             }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -28,6 +28,9 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -68,7 +71,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SchemaObject implements Serializable
+public abstract class SchemaObject implements Serializable
 {
     /** The serialVersionUID */
     public static final long serialVersionUID = 1L;
@@ -204,6 +207,18 @@
 
     
     /**
+     * Inject the registries into this Object, updating the references to
+     * other SchemaObject
+     *
+     * @param registries The Registries
+     */
+    public void applyRegistries( Registries registries ) throws NamingException
+    {
+        // Do nothing
+    }
+    
+    
+    /**
      * Add a new name to the list of names for this SchemaObject. The name
      * is lowercased and trimmed.
      *  
@@ -254,7 +269,7 @@
         if ( ! isReadOnly )
         {
             this.names = new ArrayList<String>( names.size() );
-            
+
             for ( String name:names )
             {
             	if ( name != null )
@@ -319,7 +334,9 @@
     /**
      * Tells if this SchemaObject is enabled.
      *  
-     * @return true if the SchemaObject is enabled
+     * @param schemaEnabled the associated schema status
+     * @return true if the SchemaObject is enabled, or if it depends on 
+     * an enabled schema
      */
     public boolean isEnabled()
     {
@@ -426,15 +443,29 @@
 
     
     /**
-     * Add an extensions with their values
+     * Add an extensions with their values. (Actually do a copy)
+     * 
      * @param key The extension key
      * @param values The associated values
      */
     public void setExtensions( Map<String, List<String>> extensions )
     {
-        if ( !isReadOnly )
+        if ( !isReadOnly && ( extensions != null ) )
         {
-            this.extensions = extensions;
+            this.extensions = new HashMap<String, List<String>>();
+
+            for ( String key : extensions.keySet() )
+            {
+                List<String> values = new ArrayList<String>();
+
+                for ( String value : extensions.get( key ) )
+                {
+                    values.add( value );
+                }
+
+                this.extensions.put( key, values );
+            }
+            
         }
     }
 

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObjectType.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObjectType.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObjectType.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaObjectType.java Fri Oct  9 00:03:45 2009
@@ -19,6 +19,8 @@
  */
 package org.apache.directory.shared.ldap.schema;
 
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+
 /**
  * The SchemaObject types
  *
@@ -57,4 +59,65 @@
     {
         return value;
     }
+    
+    
+    /**
+     * Get the RDN associated with a schemaObjectType
+     *
+     * @param schemaObjectType The type we want the RDN for
+     * @return The associated RDN
+     */
+    public String getRdn()
+    {
+        String schemaObjectPath = null;
+        
+        switch ( this )
+        {
+            case ATTRIBUTE_TYPE :
+                schemaObjectPath = SchemaConstants.ATTRIBUTES_TYPE_PATH;
+                break;
+                
+            case COMPARATOR :
+                schemaObjectPath = SchemaConstants.COMPARATORS_PATH;
+                break;
+                
+            case DIT_CONTENT_RULE :
+                schemaObjectPath = SchemaConstants.DIT_CONTENT_RULES_PATH;
+                break;
+                
+            case DIT_STRUCTURE_RULE :
+                schemaObjectPath = SchemaConstants.DIT_STRUCTURE_RULES_PATH;
+                break;
+                
+            case LDAP_SYNTAX :
+                schemaObjectPath = SchemaConstants.SYNTAXES_PATH;
+                break;
+                
+            case MATCHING_RULE :
+                schemaObjectPath = SchemaConstants.MATCHING_RULES_PATH;
+                break;
+                
+            case MATCHING_RULE_USE :
+                schemaObjectPath = SchemaConstants.MATCHING_RULE_USE_PATH;
+                break;
+                
+            case NAME_FORM :
+                schemaObjectPath = SchemaConstants.NAME_FORMS_PATH;
+                break;
+                
+            case NORMALIZER :
+                schemaObjectPath = SchemaConstants.NORMALIZERS_PATH;
+                break;
+                
+            case OBJECT_CLASS :
+                schemaObjectPath = SchemaConstants.OBJECT_CLASSES_PATH;
+                break;
+                
+            case SYNTAX_CHECKER :
+                schemaObjectPath = SchemaConstants.SYNTAX_CHECKERS_PATH;
+                break;
+        }
+        
+        return schemaObjectPath;
+    }
 }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -52,7 +52,10 @@
     }
 
     
-    public void setRegistries( Registries registries )
+    /**
+     * {@inheritDoc}
+     */
+    public void applyRegistries( Registries registries )
     {
         attrRegistry = registries.getAttributeTypeRegistry();
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimNormalizer.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimNormalizer.java Fri Oct  9 00:03:45 2009
@@ -46,8 +46,8 @@
     /**
      * {@inheritDoc}
      */
-    public void setRegistries( Registries registries )
+    public void applyRegistries( Registries registries )
     {
-        super.setRegistries( registries );
+        super.applyRegistries( registries );
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimToLowerNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimToLowerNormalizer.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimToLowerNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDeepTrimToLowerNormalizer.java Fri Oct  9 00:03:45 2009
@@ -46,8 +46,8 @@
     /**
      * {@inheritDoc}
      */
-    public void setRegistries( Registries registries )
+    public void applyRegistries( Registries registries )
     {
-        super.setRegistries( registries );
+        super.applyRegistries( registries );
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDnNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDnNormalizer.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDnNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/CachingDnNormalizer.java Fri Oct  9 00:03:45 2009
@@ -46,8 +46,8 @@
     /**
      * {@inheritDoc}
      */
-    public void setRegistries( Registries registries )
+    public void applyRegistries( Registries registries )
     {
-        super.setRegistries( registries );
+        super.applyRegistries( registries );
     }
 }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -154,8 +154,8 @@
     /**
      * {@inheritDoc}
      */
-    public void setRegistries( Registries registries )
+    public void applyRegistries( Registries registries )
     {
-        normalizer.setRegistries( registries );
+        normalizer.applyRegistries( registries );
     }
 }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -68,15 +68,6 @@
     /**
      * {@inheritDoc}
      */
-    public void setRegistries( Registries registries )
-    {
-        this.attrRegistry = registries.getAttributeTypeRegistry();
-    }
-    
-
-    /**
-     * {@inheritDoc}
-     */
     public Value<?> normalize( Value<?> value ) throws NamingException
     {
         LdapDN dn = null;
@@ -119,4 +110,13 @@
         dn.normalize( attrRegistry.getNormalizerMapping() );
         return dn.getNormName();
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void applyRegistries( Registries registries )
+    {
+        attrRegistry = registries.getAttributeTypeRegistry();
+    }
 }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -20,6 +20,8 @@
 package org.apache.directory.shared.ldap.schema.normalizers;
 
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -28,8 +30,6 @@
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.util.StringTools;
 
-import javax.naming.NamingException;
-
 
 /**
  * A noirmalizer for UniqueMember
@@ -60,7 +60,10 @@
     }
     
     
-    public void setRegistries( Registries registries )
+    /**
+     * {@inheritDoc}
+     */
+    public void applyRegistries( Registries registries )
     {
         this.attrRegistry = registries.getAttributeTypeRegistry();
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameOrNumericIdNormalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameOrNumericIdNormalizer.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameOrNumericIdNormalizer.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/normalizers/NameOrNumericIdNormalizer.java Fri Oct  9 00:03:45 2009
@@ -143,7 +143,10 @@
     }
     
     
-    public void setRegistries( Registries registries )
+    /**
+     * {@inheritDoc}
+     */
+    public void applyRegistries( Registries registries )
     {
         this.registries = registries;
     }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -153,12 +153,6 @@
         {
             super.register( attributeType );
             
-            // Inject the attributeType into the oid/normalizer map
-            addMappingFor( attributeType );
-    
-            // Register this AttributeType into the Descendant map
-            registerDescendants( attributeType, attributeType.getSuperior() );
-            
             // Internally associate the OID to the registered AttributeType
             if ( IS_DEBUG )
             {
@@ -289,7 +283,7 @@
     /**
      * Add a new Oid/Normalizer couple in the OidNormalizer map
      */
-    private void addMappingFor( AttributeType attributeType ) throws NamingException
+    public void addMappingFor( AttributeType attributeType ) throws NamingException
     {
         MatchingRule matchingRule = attributeType.getEquality();
         OidNormalizer oidNormalizer;

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java Fri Oct  9 00:03:45 2009
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 
@@ -98,6 +99,18 @@
     /** A map storing all the schema objects associated with a schema */
     private Map<String, Set<SchemaWrapper>> schemaObjectsBySchemaName;
     
+    /**
+     *  A map storing a relation between a SchemaObject and all the 
+     *  referencing SchemaObjects.
+     */
+    protected Map<SchemaWrapper, Set<SchemaObject>> usedBy;
+    
+    /**
+     *  A map storing a relation between a SchemaObject and all the 
+     *  SchemaObjects it uses.
+     */
+    protected Map<SchemaWrapper, Set<SchemaObject>> using;
+    
 
     /**
      * Creates a new instance of Registries.
@@ -119,6 +132,8 @@
         objectClassRegistry = new ObjectClassRegistry( oidRegistry );
         syntaxCheckerRegistry = new SyntaxCheckerRegistry( oidRegistry );
         schemaObjectsBySchemaName = new HashMap<String, Set<SchemaWrapper>>();
+        usedBy = new ConcurrentHashMap<SchemaWrapper, Set<SchemaObject>>();
+        using = new ConcurrentHashMap<SchemaWrapper, Set<SchemaObject>>();
     }
 
     
@@ -433,7 +448,7 @@
 
 
     /**
-     * Check if the Normalizer and Comparator are existing for a matchingRule
+     * Check if the Comparator and the syntax are existing for a matchingRule
      */
     private boolean resolve( MatchingRule mr, List<Throwable> errors )
     {
@@ -462,22 +477,6 @@
 
         try
         {
-            if ( mr.getNormalizer() == null )
-            {
-                String schema = matchingRuleRegistry.getSchemaName( mr.getOid() );
-                errors.add( new NullPointerException( "matchingRule " + mr.getName() + " in schema " + schema
-                    + " with OID " + mr.getOid() + " has a null normalizer" ) );
-                isSuccess = false;
-            }
-        }
-        catch ( Exception e )
-        {
-            errors.add( e );
-            isSuccess = false;
-        }
-
-        try
-        {
             isSuccess &= resolve( mr.getSyntax(), errors );
 
             if ( mr.getSyntax() == null )
@@ -668,7 +667,7 @@
 	 * @return Gets a reference to the Map associating a schemaName to
 	 * its contained SchemaObjects
 	 */
-	public Map<String, Set<SchemaWrapper>> getObjectBySchemaname()
+	public Map<String, Set<SchemaWrapper>> getObjectBySchemaName()
 	{
 	    return schemaObjectsBySchemaName;
 	}
@@ -764,6 +763,12 @@
 	}
 
 
+	/**
+	 * Unregister a SchemaObject from the registries
+	 *
+	 * @param schemaObject The SchemaObject we want to deregister
+	 * @throws NamingException If the removal failed
+	 */
     public void unregister( SchemaObject schemaObject ) throws NamingException
     {
         String oid = schemaObject.getOid();
@@ -831,4 +836,193 @@
             // Not present !!
         }
     }
+    
+    
+    /**
+     * Checks if a specific SchemaObject is referenced by any other SchemaObject.
+     *
+     * @param schemaObject The SchemaObject we are looking for
+     * @return true if there is at least one SchemaObjetc referencing the given one
+     */
+    public boolean isReferenced( SchemaObject schemaObject )
+    {
+        SchemaWrapper wrapper = new SchemaWrapper( schemaObject );
+        
+        Set<SchemaObject> set = using.get( wrapper );
+        
+        return ( set != null ) && ( set.size() != 0 );
+    }
+
+    
+    /**
+     * Gets the Set of SchemaObjects referencing the given SchemaObject
+     *
+     * @param schemaObject The SchemaObject we are looking for
+     * @return The Set of referencing SchemaObject, or null 
+     */
+    public Set<SchemaObject> getUsedBy( SchemaObject schemaObject )
+    {
+        SchemaWrapper wrapper = new SchemaWrapper( schemaObject );
+        
+        return usedBy.get( wrapper );
+    }
+
+    
+    /**
+     * Gets the Set of SchemaObjects referenced by the given SchemaObject
+     *
+     * @param schemaObject The SchemaObject we are looking for
+     * @return The Set of referenced SchemaObject, or null 
+     */
+    public Set<SchemaObject> getUsing( SchemaObject schemaObject )
+    {
+        SchemaWrapper wrapper = new SchemaWrapper( schemaObject );
+        
+        return using.get( wrapper );
+    }
+    
+    
+    /**
+     * Add an association between a SchemaObject an the SchemaObject it refers
+     *
+     * @param reference The base SchemaObject
+     * @param referee The SchemaObject pointing on the reference
+     */
+    private void addUsing( SchemaObject reference, SchemaObject referee )
+    {
+        if ( ( reference == null ) || ( referee == null ) )
+        {
+            return;
+        }
+        
+        SchemaWrapper wrapper = new SchemaWrapper( reference );
+        
+        Set<SchemaObject> usedBy = getUsedBy( reference );
+        
+        if ( usedBy == null )
+        {
+            usedBy = new HashSet<SchemaObject>();
+            using.put( wrapper, usedBy );
+        }
+        
+        usedBy.add( referee );
+    }
+    
+    
+    /**
+     * Add an association between a SchemaObject an the SchemaObject it refers
+     *
+     * @param reference The base SchemaObject
+     * @param referee The SchemaObject pointing on the reference
+     */
+    public void addReference( SchemaObject reference, SchemaObject referee )
+    {
+        addUsing( reference, referee );
+        addUsedBy( referee, reference );
+    }
+
+
+    /**
+     * Add an association between a SchemaObject an the SchemaObject that refers it
+     *
+     * @param reference The base SchemaObject
+     * @param referee The SchemaObject pointing on the reference
+     */
+    private void addUsedBy( SchemaObject referee, SchemaObject reference )
+    {
+        if ( ( reference == null ) || ( referee == null ) )
+        {
+            return;
+        }
+        SchemaWrapper wrapper = new SchemaWrapper( referee );
+        
+        Set<SchemaObject> using = getUsing( referee );
+        
+        if ( using == null )
+        {
+            using = new HashSet<SchemaObject>();
+            usedBy.put( wrapper, using );
+        }
+        
+        using.add( reference );
+    }
+    
+    
+    /**
+     * Del an association between a SchemaObject an the SchemaObject it refers
+     *
+     * @param reference The base SchemaObject
+     * @param referee The SchemaObject pointing on the reference
+     */
+    private void delUsing( SchemaObject reference, SchemaObject referee )
+    {
+        if ( ( reference == null ) || ( referee == null ) )
+        {
+            return;
+        }
+        
+        Set<SchemaObject> usedBy = getUsedBy( reference );
+        
+        if ( usedBy == null )
+        {
+            return;
+        }
+        
+        usedBy.remove( referee );
+        
+        if ( usedBy.size() == 0 )
+        {
+            SchemaWrapper wrapper = new SchemaWrapper( reference );
+            
+            using.remove( wrapper );
+        }
+        
+        return;
+    }
+
+
+    /**
+     * Del an association between a SchemaObject an the SchemaObject that refers it
+     *
+     * @param reference The base SchemaObject
+     * @param referee The SchemaObject pointing on the reference
+     */
+    private void delUsedBy( SchemaObject referee, SchemaObject reference )
+    {
+        if ( ( reference == null ) || ( referee == null ) )
+        {
+            return;
+        }
+
+        Set<SchemaObject> using = getUsing( referee );
+        
+        if ( using == null )
+        {
+            return;
+        }
+        
+        using.remove( reference );
+        
+        if ( using.size() == 0 )
+        {
+            SchemaWrapper wrapper = new SchemaWrapper( referee );
+            
+            usedBy.remove( wrapper );
+        }
+        
+        return;
+    }
+    
+    
+    /**
+     * Delete an association between a SchemaObject an the SchemaObject it refers
+     *
+     * @param reference The base SchemaObject
+     * @param referee The SchemaObject pointing on the reference
+     */
+    public void delReference( SchemaObject reference, SchemaObject referee )
+    {
+        delUsing( reference, referee );
+        delUsedBy( referee, reference );
+    }
 }

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=823360&r1=823359&r2=823360&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 Fri Oct  9 00:03:45 2009
@@ -213,22 +213,25 @@
     {
         String oid = schemaObject.getOid();
         
-        if ( byName.containsKey( oid ) )
+        if ( schemaObject.isEnabled() )
         {
-            String msg = type.name() + " with OID " + oid + " already registered!";
-            LOG.warn( msg );
-            throw new NamingException( msg );
-        }
-
-        byName.put( oid, schemaObject );
-        
-        /*
-         * 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 : schemaObject.getNames() )
-        {
-        	byName.put( StringTools.trim( StringTools.toLowerCase( name ) ), schemaObject );
+            if ( byName.containsKey( oid ) )
+            {
+                String msg = type.name() + " with OID " + oid + " already registered!";
+                LOG.warn( msg );
+                throw new NamingException( msg );
+            }
+    
+            byName.put( oid, schemaObject );
+            
+            /*
+             * 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 : schemaObject.getNames() )
+            {
+            	byName.put( StringTools.trim( StringTools.toLowerCase( name ) ), schemaObject );
+            }
         }
         
         if ( LOG.isDebugEnabled() )

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SyntaxCheckerRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SyntaxCheckerRegistry.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SyntaxCheckerRegistry.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SyntaxCheckerRegistry.java Fri Oct  9 00:03:45 2009
@@ -71,7 +71,7 @@
         {
             String msg = type.name() + " with OID " + oid + " already registered!";
             LOG.warn( msg );
-            throw new NamingException( msg );
+            //throw new NamingException( msg );
         }
 
         byName.put( oid, syntaxChecker );

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/OctetStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/OctetStringSyntaxChecker.java?rev=823360&r1=823359&r2=823360&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/OctetStringSyntaxChecker.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/OctetStringSyntaxChecker.java Fri Oct  9 00:03:45 2009
@@ -59,18 +59,6 @@
      */
     public boolean isValidSyntax( Object value )
     {
-        // It must be a byte[]
-        boolean result = value instanceof byte[];
-        
-        if ( result )
-        {
-            LOG.debug( "Syntax valid for '{}'", value );
-        }
-        else
-        {
-            LOG.debug( "Syntax invalid for '{}'", value );
-        }
-        
-        return result;
+        return ( value != null );
     }
 }



Mime
View raw message