directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r823854 - in /directory: apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/ shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/ shared...
Date Sat, 10 Oct 2009 13:31:47 GMT
Author: elecharny
Date: Sat Oct 10 13:31:47 2009
New Revision: 823854

URL: http://svn.apache.org/viewvc?rev=823854&view=rev
Log:
Moved the SchemaEntity registering into the Abstract class, to avoid duplication of code.

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/JarLdifSchemaLoader.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java?rev=823854&r1=823853&r2=823854&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
Sat Oct 10 13:31:47 2009
@@ -79,7 +79,6 @@
     private static final Logger LOG = LoggerFactory.getLogger( PartitionSchemaLoader.class
);
 
     private final SchemaPartitionDao dao;
-    private SchemaEntityFactory factory;
     private Partition partition;
     
     /** The attributeType registry */
@@ -103,7 +102,7 @@
     
     public PartitionSchemaLoader( Partition partition, Registries registries ) throws Exception
     {
-        this.factory = new SchemaEntityFactory();
+        super( new SchemaEntityFactory() );
         this.partition = partition;
         atRegistry = registries.getAttributeTypeRegistry();
         

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/JarLdifSchemaLoader.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/JarLdifSchemaLoader.java?rev=823854&r1=823853&r2=823854&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/JarLdifSchemaLoader.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/JarLdifSchemaLoader.java
Sat Oct 10 13:31:47 2009
@@ -23,14 +23,12 @@
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 import java.util.regex.Pattern;
 
-import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
@@ -38,16 +36,7 @@
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.DITContentRule;
-import org.apache.directory.shared.ldap.schema.DITStructureRule;
-import org.apache.directory.shared.ldap.schema.LdapComparator;
-import org.apache.directory.shared.ldap.schema.LdapSyntax;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
-import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
-import org.apache.directory.shared.ldap.schema.NameForm;
-import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
-import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.ResourceMap;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schema.registries.AbstractSchemaLoader;
@@ -75,9 +64,6 @@
     /** Speedup for DEBUG mode */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
-    /** the factory that generates respective SchemaObjects from LDIF entries */
-    private final SchemaEntityFactory factory = new SchemaEntityFactory();
-    
     /** a map of all the resources in this jar */
     private static final Map<String,Boolean> RESOURCE_MAP = ResourceMap.getResources(
Pattern.compile( ".*schema/ou=schema.*" ) );
 
@@ -93,6 +79,7 @@
      */
     public JarLdifSchemaLoader() throws Exception
     {
+        super( new SchemaEntityFactory() );
         initializeSchemas();
     }
 
@@ -156,38 +143,6 @@
     /**
      * {@inheritDoc}
      */
-    public Schema getSchema( String schemaName ) throws Exception
-    {
-        return this.schemaMap.get( schemaName );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void loadWithDependencies( Collection<Schema> schemas, Registries registries
) throws Exception
-    {
-        Map<String,Schema> notLoaded = new HashMap<String,Schema>();
-        
-        for ( Schema schema : schemas )
-        {
-            if ( ! registries.isSchemaLoaded( schema.getSchemaName() ) )
-            {
-                notLoaded.put( schema.getSchemaName(), schema );
-            }
-        }
-        
-        for ( Schema schema : notLoaded.values() )
-        {
-            Stack<String> beenthere = new Stack<String>();
-            super.loadDepsFirst( schema, beenthere, notLoaded, schema, registries );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     public void loadWithDependencies( Schema schema, Registries registries ) throws Exception
     {
         Stack<String> beenthere = new Stack<String>();
@@ -293,16 +248,8 @@
                 URL resource = getResource( resourcePath, "comparator LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                LdapComparator<?> comparator = 
-                    factory.getLdapComparator( entry.getEntry(), registries, schema.getSchemaName()
);
-                comparator.setOid( entry.get( MetaSchemaConstants.M_OID_AT ).getString()
);
 
-                if ( schema.isEnabled() && comparator.isEnabled() )
-                {
-                    comparator.applyRegistries( registries );
-                }
-
-                registries.register( comparator );
+                registerComparator( registries, entry, schema );
             }
         }
     }
@@ -331,15 +278,8 @@
                 URL resource = getResource( resourcePath, "syntaxChecker LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                SyntaxChecker syntaxChecker = 
-                    factory.getSyntaxChecker( entry.getEntry(), registries, schema.getSchemaName()
);
-
-                if ( schema.isEnabled() && syntaxChecker.isEnabled() )
-                {
-                    syntaxChecker.applyRegistries( registries );
-                }
-
-                registries.register( syntaxChecker );
+                
+                registerSyntaxChecker( registries, entry, schema );
             }
         }
     }
@@ -368,15 +308,8 @@
                 URL resource = getResource( resourcePath, "normalizer LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                Normalizer normalizer =
-                    factory.getNormalizer( entry.getEntry(), registries, schema.getSchemaName()
);
-
-                if ( schema.isEnabled() && normalizer.isEnabled() )
-                {
-                    normalizer.applyRegistries( registries );
-                }
-
-                registries.register( normalizer );
+                
+                registerNormalizer( registries, entry, schema );
             }
         }
     }
@@ -405,15 +338,8 @@
                 URL resource = getResource( resourcePath, "matchingRules LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                MatchingRule matchingRule = factory.getMatchingRule( 
-                    entry.getEntry(), registries, schema.getSchemaName() );
 
-                if ( matchingRule.isEnabled() )
-                {
-                    matchingRule.applyRegistries( registries );
-                }
-                
-                registries.register( matchingRule );
+                registerMatchingRule( registries, entry, schema );
             }
         }
     }
@@ -442,15 +368,8 @@
                 URL resource = getResource( resourcePath, "syntax LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                LdapSyntax syntax = factory.getSyntax( 
-                    entry.getEntry(), registries, schema.getSchemaName() );
-
-                if ( syntax.isEnabled() )
-                {
-                    syntax.applyRegistries( registries );
-                }
-
-                registries.register( syntax );
+                
+                registerSyntax( registries, entry, schema );
             }
         }
     }
@@ -569,15 +488,8 @@
         	}
         }
         
-        AttributeType attributeType = factory.getAttributeType( entry.getEntry(), registries,
schema.getSchemaName() );
-        
-        if ( attributeType.isEnabled() )
-        {
-            attributeType.applyRegistries( registries );
-        }
+        AttributeType attributeType = registerAttributeType( registries, entry, schema );
         
-        registries.register( attributeType );
-
         // after registering AT check if any deferred entries depend on it
         if ( attributeType.getNames() != null )
         {
@@ -631,16 +543,8 @@
                 URL resource = getResource( resourcePath, "matchingRuleUse LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                MatchingRuleUse matchingRuleUse = null;
-            
-                // TODO add factory method to generate the matchingRuleUse
-                if ( true )
-                {
-                    throw new NotImplementedException( "Need to implement factory " +
-                    		"method for creating a matchingRuleUse" );
-                }
-                
-                registries.register( matchingRuleUse );
+
+                registerMatchingRuleUse( registries, entry, schema );
             }
         }
     }
@@ -668,16 +572,8 @@
                 URL resource = getResource( resourcePath, "nameForm LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                NameForm nameForm = null;
 
-                // TODO add factory method to generate the nameForm
-                if ( true )
-                {
-                    throw new NotImplementedException( "Need to implement factory " +
-                            "method for creating a nameForm" );
-                }
-                
-                registries.register( nameForm );
+                registerNameForm( registries, entry, schema );
             }
         }
     }
@@ -706,16 +602,8 @@
                 URL resource = getResource( resourcePath, "ditContentRule LDIF file" );
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
-                DITContentRule ditContentRule = null;
-                
-                // TODO add factory method to generate the ditContentRule
-                if ( true )
-                {
-                    throw new NotImplementedException( "Need to implement factory " +
-                            "method for creating a ditContentRule" );
-                }
                 
-                registries.register( ditContentRule );
+                registerDitContentRule( registries, entry, schema );
             }
         }
     }
@@ -745,16 +633,8 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
             
                 LdifEntry entry = reader.next();
-                DITStructureRule ditStructureRule = null;
-            
-                // TODO add factory method to generate the ditContentRule
-                if ( true )
-                {
-                    throw new NotImplementedException( "Need to implement factory " +
-                            "method for creating a ditStructureRule" );
-                }
                 
-                registries.register( ditStructureRule );
+                registerDitStructureRule( registries, entry, schema );
             }
         }
     }
@@ -873,14 +753,7 @@
         	}
         }
         
-        ObjectClass objectClass = factory.getObjectClass( entry.getEntry(), registries, schema.getSchemaName()
);
-
-        if ( objectClass.isEnabled() )
-        {
-            objectClass.applyRegistries( registries );
-        }
-
-        registries.register( objectClass );
+        ObjectClass objectClass = registerObjectClass( registries, entry, schema );
 
         // after registering AT check if any deferred entries depend on it
         if ( objectClass.getNames() != null )

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.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/LdifSchemaLoader.java?rev=823854&r1=823853&r2=823854&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/LdifSchemaLoader.java
Sat Oct 10 13:31:47 2009
@@ -25,15 +25,11 @@
 import java.io.FileWriter;
 import java.io.FilenameFilter;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 
-import javax.naming.NamingException;
-
-import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.Entry;
@@ -43,16 +39,7 @@
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.DITContentRule;
-import org.apache.directory.shared.ldap.schema.DITStructureRule;
-import org.apache.directory.shared.ldap.schema.LdapComparator;
-import org.apache.directory.shared.ldap.schema.LdapSyntax;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
-import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
-import org.apache.directory.shared.ldap.schema.NameForm;
-import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
-import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.registries.AbstractSchemaLoader;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.schema.registries.Schema;
@@ -89,9 +76,6 @@
      */
     private static final String ADMIN_SYSTEM_DN = "uid=admin,ou=system";
 
-    /** the factory that generates respective SchemaObjects from LDIF entries */
-    private final SchemaEntityFactory factory = new SchemaEntityFactory();
-    
     /** directory containing the schema LDIF file for ou=schema */
     private final File baseDirectory;
     
@@ -116,6 +100,8 @@
      */
     public LdifSchemaLoader( File baseDirectory ) throws Exception
     {
+        super( new SchemaEntityFactory() );
+
         this.baseDirectory = baseDirectory;
 
         if ( ! baseDirectory.exists() )
@@ -187,38 +173,6 @@
     /**
      * {@inheritDoc}
      */
-    public Schema getSchema( String schemaName ) throws Exception
-    {
-        return this.schemaMap.get( schemaName );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void loadWithDependencies( Collection<Schema> schemas, Registries registries
) throws Exception
-    {
-        Map<String,Schema> notLoaded = new HashMap<String,Schema>();
-        
-        for ( Schema schema : schemas )
-        {
-            if ( ! registries.isSchemaLoaded( schema.getSchemaName() ) )
-            {
-                notLoaded.put( schema.getSchemaName(), schema );
-            }
-        }
-        
-        for ( Schema schema : notLoaded.values() )
-        {
-            Stack<String> beenthere = new Stack<String>();
-            super.loadDepsFirst( schema, beenthere, notLoaded, schema, registries );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     public void loadWithDependencies( Schema schema, Registries registries ) throws Exception
     {
         Stack<String> beenthere = new Stack<String>();
@@ -374,16 +328,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            LdapComparator<?> comparator = 
-                factory.getLdapComparator( entry.getEntry(), registries, schema.getSchemaName()
);
-            comparator.setOid( entry.get( MetaSchemaConstants.M_OID_AT ).getString() );
-
-            if ( schema.isEnabled() && comparator.isEnabled() )
-            {
-                comparator.applyRegistries( registries );
-            }
-
-            registries.getComparatorRegistry().register( comparator );
+            
+            registerComparator( registries, entry, schema );
         }
     }
     
@@ -413,17 +359,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            SyntaxChecker syntaxChecker = 
-                factory.getSyntaxChecker( entry.getEntry(), registries, schema.getSchemaName()
);
-            try
-            {
-            	registries.getSyntaxCheckerRegistry().register( syntaxChecker );
-            }
-            catch ( NamingException e )
-            {
-            	// Do nothing at this point. Just log the event
-                LOG.warn( e.getMessage() );
-            }
+            
+            registerSyntaxChecker( registries, entry, schema );
         }
     }
     
@@ -453,15 +390,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            Normalizer normalizer =
-                factory.getNormalizer( entry.getEntry(), registries, schema.getSchemaName()
);
             
-            if ( schema.isEnabled() && normalizer.isEnabled() )
-            {
-                normalizer.applyRegistries( registries );
-            }
-            
-            registries.getNormalizerRegistry().register( normalizer );
+            registerNormalizer( registries, entry, schema );
         }
     }
     
@@ -491,15 +421,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            MatchingRule matchingRule = factory.getMatchingRule( 
-                entry.getEntry(), registries, schema.getSchemaName() );
-
-            if ( schema.isEnabled() && matchingRule.isEnabled() )
-            {
-                matchingRule.applyRegistries( registries );
-            }
 
-            registries.getMatchingRuleRegistry().register( matchingRule );
+            registerMatchingRule( registries, entry, schema );
         }
     }
     
@@ -529,15 +452,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            LdapSyntax syntax = factory.getSyntax( 
-                entry.getEntry(), registries, schema.getSchemaName() );
-
-            if ( schema.isEnabled() && syntax.isEnabled() )
-            {
-                syntax.applyRegistries( registries );
-            }
 
-            registries.getLdapSyntaxRegistry().register( syntax );
+            registerSyntax( registries, entry, schema );
         }
     }
 
@@ -655,13 +571,7 @@
         	}
         }
         
-        AttributeType attributeType = factory.getAttributeType( entry.getEntry(), registries,
schema.getSchemaName() );
-        registries.getAttributeTypeRegistry().register( attributeType );
-        
-        if ( schema.isEnabled() && attributeType.isEnabled() )
-        {
-            attributeType.applyRegistries( registries );
-        }
+        AttributeType attributeType = registerAttributeType( registries, entry, schema );
 
         // after registering AT check if any deferred entries depend on it
         if ( attributeType.getNames() != null )
@@ -718,16 +628,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            MatchingRuleUse matchingRuleUse = null;
             
-            // TODO add factory method to generate the matchingRuleUse
-            if ( true )
-            {
-                throw new NotImplementedException( "Need to implement factory " +
-                		"method for creating a matchingRuleUse" );
-            }
-            
-            registries.getMatchingRuleUseRegistry().register( matchingRuleUse );
+            registerMatchingRuleUse( registries, entry, schema );
         }
     }
 
@@ -757,16 +659,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            NameForm nameForm = null;
-
-            // TODO add factory method to generate the nameForm
-            if ( true )
-            {
-                throw new NotImplementedException( "Need to implement factory " +
-                        "method for creating a nameForm" );
-            }
             
-            registries.getNameFormRegistry().register( nameForm );
+            registerNameForm( registries, entry, schema );
         }
     }
 
@@ -796,16 +690,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            DITContentRule ditContentRule = null;
-            
-            // TODO add factory method to generate the ditContentRule
-            if ( true )
-            {
-                throw new NotImplementedException( "Need to implement factory " +
-                        "method for creating a ditContentRule" );
-            }
             
-            registries.getDitContentRuleRegistry().register( ditContentRule );
+            registerDitContentRule( registries, entry, schema );
         }
     }
 
@@ -835,16 +721,8 @@
         {
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
-            DITStructureRule ditStructureRule = null;
-            
-            // TODO add factory method to generate the ditContentRule
-            if ( true )
-            {
-                throw new NotImplementedException( "Need to implement factory " +
-                        "method for creating a ditStructureRule" );
-            }
             
-            registries.getDitStructureRuleRegistry().register( ditStructureRule );
+            registerDitStructureRule( registries, entry, schema );
         }
     }
 
@@ -964,14 +842,7 @@
         	}
         }
         
-        ObjectClass objectClass = factory.getObjectClass( entry.getEntry(), registries, schema.getSchemaName()
);
-
-        if ( schema.isEnabled() && objectClass.isEnabled() )
-        {
-            objectClass.applyRegistries( registries );
-        }
-
-        registries.getObjectClassRegistry().register( objectClass );
+        ObjectClass objectClass = registerObjectClass( registries, entry, schema );
 
         // after registering AT check if any deferred entries depend on it
         if ( objectClass.getNames() != null )

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=823854&r1=823853&r2=823854&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 Oct 10 13:31:47 2009
@@ -38,6 +38,7 @@
 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.EntityFactory;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.LdapSyntax;
 import org.apache.directory.shared.ldap.schema.LoadableSchemaObject;
@@ -66,7 +67,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SchemaEntityFactory
+public class SchemaEntityFactory implements EntityFactory
 {
 	/** Slf4j logger */
 	private final static Logger LOG = LoggerFactory.getLogger( SchemaEntityFactory.class );

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java?rev=823854&r1=823853&r2=823854&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
Sat Oct 10 13:31:47 2009
@@ -20,16 +20,28 @@
 package org.apache.directory.shared.ldap.schema.registries;
 
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Stack;
 
 import javax.naming.NamingException;
 
-import org.apache.directory.shared.ldap.schema.registries.Schema;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
-import org.apache.directory.shared.ldap.schema.registries.SchemaLoaderListener;
+import org.apache.directory.shared.ldap.NotImplementedException;
+import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.DITContentRule;
+import org.apache.directory.shared.ldap.schema.DITStructureRule;
+import org.apache.directory.shared.ldap.schema.EntityFactory;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
+import org.apache.directory.shared.ldap.schema.NameForm;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,6 +60,14 @@
 
     protected SchemaLoaderListener listener;
     
+    /** the factory that generates respective SchemaObjects from LDIF entries */
+    protected final EntityFactory factory;
+    
+    
+    public AbstractSchemaLoader( EntityFactory factory )
+    {
+        this.factory = factory;
+    }
     
     /** 
      * A map of all available schema names to schema objects. This map is 
@@ -198,4 +218,276 @@
         notLoaded.remove( schema.getSchemaName() );
         beenthere.pop();
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Schema getSchema( String schemaName ) throws Exception
+    {
+        return this.schemaMap.get( schemaName );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void loadWithDependencies( Collection<Schema> schemas, Registries registries
) throws Exception
+    {
+        Map<String,Schema> notLoaded = new HashMap<String,Schema>();
+        
+        for ( Schema schema : schemas )
+        {
+            if ( ! registries.isSchemaLoaded( schema.getSchemaName() ) )
+            {
+                notLoaded.put( schema.getSchemaName(), schema );
+            }
+        }
+        
+        for ( Schema schema : notLoaded.values() )
+        {
+            Stack<String> beenthere = new Stack<String>();
+            loadDepsFirst( schema, beenthere, notLoaded, schema, registries );
+        }
+    }
+    
+    
+    /**
+     * Register the comparator contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the comparator description
+     * @param schema The associated schema
+     * @throws Exception If the registering failed
+     */
+    protected void registerComparator( Registries registries, LdifEntry entry, Schema schema)

+        throws Exception
+    {
+        LdapComparator<?> comparator = 
+            factory.getLdapComparator( entry.getEntry(), registries, schema.getSchemaName()
);
+        comparator.setOid( entry.get( MetaSchemaConstants.M_OID_AT ).getString() );
+
+        if ( schema.isEnabled() && comparator.isEnabled() )
+        {
+            comparator.applyRegistries( registries );
+            registries.register( comparator );
+        }
+    }
+    
+    
+    /**
+     * Register the SyntaxChecker contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the SyntaxChecker description
+     * @param schema The associated schema
+     * @return the created SyntaxChecker instance
+     * @throws Exception If the registering failed
+     */
+    protected SyntaxChecker registerSyntaxChecker( Registries registries, LdifEntry entry,
Schema schema) 
+        throws Exception
+    {
+        SyntaxChecker syntaxChecker = 
+            factory.getSyntaxChecker( entry.getEntry(), registries, schema.getSchemaName()
);
+        syntaxChecker.setOid( entry.get( MetaSchemaConstants.M_OID_AT ).getString() );
+
+        if ( schema.isEnabled() && syntaxChecker.isEnabled() )
+        {
+            syntaxChecker.applyRegistries( registries );
+            registries.register( syntaxChecker );
+        }
+        
+        return syntaxChecker;
+    }
+    
+    
+    /**
+     * Register the Normalizer contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the Normalizer description
+     * @param schema The associated schema
+     * @return the created Normalizer instance
+     * @throws Exception If the registering failed
+     */
+    protected Normalizer registerNormalizer( Registries registries, LdifEntry entry, Schema
schema) 
+        throws Exception
+    {
+        Normalizer normalizer =
+            factory.getNormalizer( entry.getEntry(), registries, schema.getSchemaName() );
+        
+        if ( schema.isEnabled() && normalizer.isEnabled() )
+        {
+            normalizer.applyRegistries( registries );
+            registries.register( normalizer );
+        }
+        
+        return normalizer;
+    }
+    
+    
+    /**
+     * Register the MatchingRule contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the MatchingRule description
+     * @param schema The associated schema
+     * @return the created MatchingRule instance
+     * @throws Exception If the registering failed
+     */
+    protected MatchingRule registerMatchingRule( Registries registries, LdifEntry entry,
Schema schema) 
+        throws Exception
+    {
+        MatchingRule matchingRule = factory.getMatchingRule( 
+            entry.getEntry(), registries, schema.getSchemaName() );
+
+        if ( schema.isEnabled() && matchingRule.isEnabled() )
+        {
+            matchingRule.applyRegistries( registries );
+            registries.register( matchingRule );
+        }
+        
+        return matchingRule;
+    }
+    
+    
+    /**
+     * Register the Syntax contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the Syntax description
+     * @param schema The associated schema
+     * @return the created Syntax instance
+     * @throws Exception If the registering failed
+     */
+    protected LdapSyntax registerSyntax( Registries registries, LdifEntry entry, Schema schema)

+        throws Exception
+    {
+        LdapSyntax syntax = factory.getSyntax( 
+            entry.getEntry(), registries, schema.getSchemaName() );
+
+        if ( schema.isEnabled() && syntax.isEnabled() )
+        {
+            syntax.applyRegistries( registries );
+            registries.register( syntax );
+        }
+        
+        return syntax;
+    }
+    
+    
+    /**
+     * Register the AttributeType contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the AttributeType description
+     * @param schema The associated schema
+     * @return the created AttributeType instance
+     * @throws Exception If the registering failed
+     */
+    protected AttributeType registerAttributeType( Registries registries, LdifEntry entry,
Schema schema) 
+        throws Exception
+    {
+        AttributeType attributeType = factory.getAttributeType( entry.getEntry(), registries,
schema.getSchemaName() );
+        
+        if ( schema.isEnabled() && attributeType.isEnabled() )
+        {
+            attributeType.applyRegistries( registries );
+            registries.register( attributeType );
+        }
+        
+        return attributeType;
+    }
+    
+    
+    /**
+     * Register the MatchingRuleUse contained in the given LdifEntry into the registries.

+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the MatchingRuleUse description
+     * @param schema The associated schema
+     * @return the created MatchingRuleUse instance
+     * @throws Exception If the registering failed
+     */
+    protected MatchingRuleUse registerMatchingRuleUse( Registries registries, LdifEntry entry,
Schema schema) 
+        throws Exception
+    {
+        throw new NotImplementedException( "Need to implement factory " +
+                "method for creating a MatchingRuleUse" );
+    }
+    
+    
+    /**
+     * Register the NameForm contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the NameForm description
+     * @param schema The associated schema
+     * @return the created NameForm instance
+     * @throws Exception If the registering failed
+     */
+    protected NameForm registerNameForm( Registries registries, LdifEntry entry, Schema schema)

+        throws Exception
+    {
+        throw new NotImplementedException( "Need to implement factory " +
+                "method for creating a NameForm" );
+    }
+    
+    
+    /**
+     * Register the DitContentRule contained in the given LdifEntry into the registries.

+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the DitContentRule description
+     * @param schema The associated schema
+     * @return the created DitContentRule instance
+     * @throws Exception If the registering failed
+     */
+    protected DITContentRule registerDitContentRule( Registries registries, LdifEntry entry,
Schema schema) 
+        throws Exception
+    {
+        throw new NotImplementedException( "Need to implement factory " +
+                "method for creating a DitContentRule" );
+    }
+    
+    
+    /**
+     * Register the DitStructureRule contained in the given LdifEntry into the registries.

+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the DitStructureRule description
+     * @param schema The associated schema
+     * @return the created DitStructureRule instance
+     * @throws Exception If the registering failed
+     */
+    protected DITStructureRule registerDitStructureRule( Registries registries, LdifEntry
entry, Schema schema) 
+        throws Exception
+    {
+        throw new NotImplementedException( "Need to implement factory " +
+                "method for creating a DitStructureRule" );
+    }
+
+
+    /**
+     * Register the ObjectClass contained in the given LdifEntry into the registries. 
+     *
+     * @param registries The Registries
+     * @param entry The LdifEntry containing the ObjectClass description
+     * @param schema The associated schema
+     * @return the created ObjectClass instance
+     * @throws Exception If the registering failed
+     */
+    protected ObjectClass registerObjectClass( Registries registries, LdifEntry entry, Schema
schema) 
+        throws Exception
+    {
+        ObjectClass objectClass = factory.getObjectClass( entry.getEntry(), registries, schema.getSchemaName()
);
+
+        if ( schema.isEnabled() && objectClass.isEnabled() )
+        {
+            objectClass.applyRegistries( registries );
+            registries.register( objectClass );
+        }
+        
+        return objectClass;
+    }
 }



Mime
View raw message