directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r831372 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/ ldap/src/main/java/org/...
Date Fri, 30 Oct 2009 16:19:27 GMT
Author: elecharny
Date: Fri Oct 30 16:19:26 2009
New Revision: 831372

URL: http://svn.apache.org/viewvc?rev=831372&view=rev
Log:
Refactored the SchemaLoader and Registries

Modified:
    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/test/java/org/apache/directory/server/schema/loader/ldif/JarLdifSchemaLoaderTest.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java

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=831372&r1=831371&r2=831372&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 Fri Oct 30 16:19:26 2009
@@ -23,19 +23,17 @@
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
-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.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 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;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,7 +74,6 @@
      */
     public JarLdifSchemaLoader() throws Exception
     {
-        super( new SchemaEntityFactory() );
         initializeSchemas();
     }
 
@@ -119,7 +116,7 @@
                 {
                     LdifReader reader = new LdifReader( resource.openStream() );
                     LdifEntry entry = reader.next();
-                    Schema schema = factory.getSchema( entry.getEntry() );
+                    Schema schema = getSchema( entry.getEntry() );
                     schemaMap.put( schema.getSchemaName(), schema );
                     
                     if ( IS_DEBUG )
@@ -139,8 +136,8 @@
 
     /**
      * {@inheritDoc}
-     */
-    public List<Throwable> loadWithDependencies( Schema schema, Registries registries, boolean check ) throws Exception
+     *
+    public List<Throwable> loadWithDependencies( Registries registries, boolean check, Schema... schemas ) throws Exception
     {
         // Relax the controls at first
         List<Throwable> errors = new ArrayList<Throwable>();
@@ -181,7 +178,7 @@
      * the schema has been loaded.
      * 
      * {@inheritDoc}
-     */
+     *
     public void load( Schema schema, Registries registries, boolean isDepLoad ) throws Exception
     {
         // if we're loading a dependency and it has not been enabled on 
@@ -205,17 +202,17 @@
         
         // We set the registries to Permissive, so that we don't care about the order
         // the SchemaObjects are loaded.
-        loadComparators( schema, registries );
-        loadNormalizers( schema, registries );
-        loadSyntaxCheckers( schema, registries );
-        loadSyntaxes( schema, registries );
-        loadMatchingRules( schema, registries );
-        loadAttributeTypes( schema, registries );
-        loadObjectClasses( schema, registries );
-        loadMatchingRuleUses( schema, registries );
-        loadDitContentRules( schema, registries );
-        loadNameForms( schema, registries );
-        loadDitStructureRules( schema, registries );
+        loadComparators( schema );
+        loadNormalizers( schema );
+        loadSyntaxCheckers( schema );
+        loadSyntaxes( schema );
+        loadMatchingRules( schema );
+        loadAttributeTypes( schema );
+        loadObjectClasses( schema );
+        loadMatchingRuleUses( schema );
+        loadDitContentRules( schema );
+        loadNameForms( schema );
+        loadDitStructureRules( schema );
 
         notifyListenerOrRegistries( schema, registries );
     }
@@ -234,19 +231,15 @@
     
     
     /**
-     * Loads the Comparators from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which comparators are loaded
-     * @param registries the registries which are loaded with comparators
-     * @throws Exception if there are failures accessing comparator information
-     * stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadComparators( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadComparators( Schema schema ) throws Exception
     {
         String comparatorsDirectory = getSchemaDirectory( schema ) 
             + "/" + SchemaConstants.COMPARATORS_PATH;
         
+        List<Entry> comparatorList = new ArrayList<Entry>();
+        
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + comparatorsDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -257,9 +250,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
 
-                registerComparator( registries, entry, schema );
+                comparatorList.add( entry.getEntry() );
             }
         }
+        
+        return comparatorList;
     }
     
     
@@ -268,15 +263,16 @@
      * supplied registries.
      *
      * @param schema the schema for which syntaxCheckers are loaded
-     * @param targetRegistries the registries which are loaded with syntaxCheckers
      * @throws Exception if there are failures accessing syntaxChecker 
      * information stored in LDIF files
      */
-    private void loadSyntaxCheckers( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadSyntaxCheckers( Schema schema ) throws Exception
     {
         String syntaxCheckersDirectory = getSchemaDirectory( schema ) 
             +  "/" + SchemaConstants.SYNTAX_CHECKERS_PATH;
 
+        List<Entry> syntaxCheckerList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + syntaxCheckersDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -287,9 +283,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
                 
-                registerSyntaxChecker( registries, entry, schema );
+                syntaxCheckerList.add( entry.getEntry() );
             }
         }
+        
+        return syntaxCheckerList;
     }
     
     
@@ -298,15 +296,16 @@
      * supplied registries.
      *
      * @param schema the schema for which normalizers are loaded
-     * @param registries the registries which are loaded with normalizers
      * @throws Exception if there are failures accessing normalizer information
      * stored in LDIF files
      */
-    private void loadNormalizers( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadNormalizers( Schema schema ) throws Exception
     {
         String normalizersDirectory = getSchemaDirectory( schema )
             + "/" + SchemaConstants.NORMALIZERS_PATH;
 
+        List<Entry> normalizerList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + normalizersDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -317,9 +316,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
                 
-                registerNormalizer( registries, entry, schema );
+                normalizerList.add( entry.getEntry() );
             }
         }
+        
+        return normalizerList;
     }
     
     
@@ -328,15 +329,16 @@
      * supplied registries.
      *
      * @param schema the schema for which matchingRules are loaded
-     * @param registries the registries which are loaded with matchingRules
      * @throws Exception if there are failures accessing matchingRule 
      * information stored in LDIF files
      */
-    private void loadMatchingRules( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadMatchingRules( Schema schema ) throws Exception
     {
         String matchingRulesDirectory = getSchemaDirectory( schema )
             + "/" + SchemaConstants.MATCHING_RULES_PATH;
         
+        List<Entry> matchingRuleList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + matchingRulesDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -347,9 +349,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
 
-                registerMatchingRule( registries, entry, schema );
+                matchingRuleList.add( entry.getEntry() );
             }
         }
+        
+        return matchingRuleList;
     }
     
     
@@ -358,15 +362,16 @@
      * supplied registries.
      *
      * @param schema the schema for which syntaxes are loaded
-     * @param registries the registries which are loaded with syntaxes
      * @throws Exception if there are failures accessing comparator information
      * stored in LDIF files
      */
-    private void loadSyntaxes( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadSyntaxes( Schema schema ) throws Exception
     {
         String syntaxesDirectory = getSchemaDirectory( schema )
             + "/" + SchemaConstants.SYNTAXES_PATH;
 
+        List<Entry> syntaxList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + syntaxesDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -377,9 +382,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
                 
-                registerSyntax( registries, entry, schema );
+                syntaxList.add( entry.getEntry() );
             }
         }
+        
+        return syntaxList;
     }
 
     
@@ -388,16 +395,17 @@
      * supplied registries.
      *
      * @param schema the schema for which attributeTypes are loaded
-     * @param registries the registries which are loaded with attributeTypes
      * @throws Exception if there are failures accessing attributeTypes 
      * information stored in LDIF files
      */
-    private void loadAttributeTypes( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadAttributeTypes( Schema schema ) throws Exception
     {
     	// check that the attributeTypes directory exists for the schema
         String attributeTypesDirectory = getSchemaDirectory( schema )
             + "/" + SchemaConstants.ATTRIBUTES_TYPE_PATH;
         
+        List<Entry> attributeTypeList = new ArrayList<Entry>();
+
         // get list of attributeType LDIF schema files in attributeTypes
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
@@ -409,9 +417,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
 
-                registerAttributeType( registries, entry, schema );
+                attributeTypeList.add( entry.getEntry() );
             }
         }
+        
+        return attributeTypeList;
     }
 
 
@@ -420,15 +430,16 @@
      * supplied registries.
      *
      * @param schema the schema for which matchingRuleUses are loaded
-     * @param registries the registries which are loaded with matchingRuleUses
      * @throws Exception if there are failures accessing matchingRuleUse 
      * information stored in LDIF files
      */
-    private void loadMatchingRuleUses( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadMatchingRuleUses( Schema schema ) throws Exception
     {
         String matchingRuleUsesDirectory = getSchemaDirectory( schema )
             + "/" + SchemaConstants.MATCHING_RULE_USE_PATH;
         
+        List<Entry> matchingRuleUseList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + matchingRuleUsesDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -439,9 +450,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
 
-                registerMatchingRuleUse( registries, entry, schema );
+                matchingRuleUseList.add( entry.getEntry() );
             }
         }
+        
+        return matchingRuleUseList;
     }
 
 
@@ -450,14 +463,15 @@
      * supplied registries.
      *
      * @param schema the schema for which nameForms are loaded
-     * @param registries the registries which are loaded with nameForms
      * @throws Exception if there are failures accessing nameForm information
      * stored in LDIF files
      */
-    private void loadNameForms( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadNameForms( Schema schema ) throws Exception
     {
         String nameFormsDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.NAME_FORMS_PATH;
 
+        List<Entry> nameFormList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + nameFormsDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -468,9 +482,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
 
-                registerNameForm( registries, entry, schema );
+                nameFormList.add( entry.getEntry() );
             }
         }
+        
+        return nameFormList;
     }
 
 
@@ -479,15 +495,16 @@
      * supplied registries.
      *
      * @param schema the schema for which ditContentRules are loaded
-     * @param registries the registries which are loaded with ditContentRules
      * @throws Exception if there are failures accessing ditContentRules 
      * information stored in LDIF files
      */
-    private void loadDitContentRules( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadDitContentRules( Schema schema ) throws Exception
     {
         String ditContentRulesDirectory = getSchemaDirectory( schema ) + "/" + 
             SchemaConstants.DIT_CONTENT_RULES_PATH;
 
+        List<Entry> ditContentRulesList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + ditContentRulesDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -498,9 +515,11 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
                 
-                registerDitContentRule( registries, entry, schema );
+                ditContentRulesList.add( entry.getEntry() );
             }
         }
+        
+        return ditContentRulesList;
     }
 
 
@@ -509,15 +528,16 @@
      * the supplied registries.
      *
      * @param schema the schema for which ditStructureRules are loaded
-     * @param registries the registries which are loaded with ditStructureRules
      * @throws Exception if there are failures accessing ditStructureRule 
      * information stored in LDIF files
      */
-    private void loadDitStructureRules( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadDitStructureRules( Schema schema ) throws Exception
     {
         String ditStructureRulesDirectory = getSchemaDirectory( schema )
             + "/" + SchemaConstants.DIT_STRUCTURE_RULES_PATH;
 
+        List<Entry> ditStructureRuleList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + ditStructureRulesDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -529,9 +549,11 @@
             
                 LdifEntry entry = reader.next();
                 
-                registerDitStructureRule( registries, entry, schema );
+                ditStructureRuleList.add( entry.getEntry() );
             }
         }
+        
+        return ditStructureRuleList;
     }
 
 
@@ -540,15 +562,16 @@
      * supplied registries.
      *
      * @param schema the schema for which objectClasses are loaded
-     * @param registries the registries which are loaded with objectClasses
      * @throws Exception if there are failures accessing objectClass information
      * stored in LDIF files
      */
-    private void loadObjectClasses( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadObjectClasses( Schema schema ) throws Exception
     {
     	// get objectClasses directory, check if exists, return if not
     	String objectClassesDirectory = getSchemaDirectory( schema ) + "/" + SchemaConstants.OBJECT_CLASSES_PATH;
 
+        List<Entry> objectClassList = new ArrayList<Entry>();
+
         for ( String resourcePath : RESOURCE_MAP.keySet() )
         {
             Pattern regex = Pattern.compile( ".*" + objectClassesDirectory + "/m-oid=.*\\." + LDIF_EXT );
@@ -559,8 +582,10 @@
                 LdifReader reader = new LdifReader( resource.openStream() );
                 LdifEntry entry = reader.next();
 
-                registerObjectClass( registries, entry, schema );
+                objectClassList.add( entry.getEntry() );
             }
         }
+        
+        return objectClassList;
     }
 }

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=831372&r1=831371&r2=831372&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 Fri Oct 30 16:19:26 2009
@@ -25,10 +25,7 @@
 import java.io.FileWriter;
 import java.io.FilenameFilter;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Stack;
 
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -37,7 +34,6 @@
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 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;
 import org.apache.directory.shared.ldap.util.DateUtils;
 import org.slf4j.Logger;
@@ -98,8 +94,6 @@
      */
     public LdifSchemaLoader( File baseDirectory ) throws Exception
     {
-        super( new SchemaEntityFactory() );
-
         this.baseDirectory = baseDirectory;
 
         if ( ! baseDirectory.exists() )
@@ -151,7 +145,7 @@
             {
                 LdifReader reader = new LdifReader( new File( schemaDirectory, ldifFile ) );
                 LdifEntry entry = reader.next();
-                Schema schema = factory.getSchema( entry.getEntry() );
+                Schema schema = getSchema( entry.getEntry() );
                 schemaMap.put( schema.getSchemaName(), schema );
                 
                 if ( IS_DEBUG )
@@ -170,7 +164,7 @@
 
     /**
      * {@inheritDoc}
-     */
+     *
     public List<Throwable> loadWithDependencies( Schema schema, Registries registries, boolean check ) throws Exception
     {
         // Relax the controls at first
@@ -204,7 +198,7 @@
      * the schema has been loaded.
      * 
      * {@inheritDoc}
-     */
+     *
     public void load( Schema schema, Registries registries, boolean isDepLoad ) throws Exception
     {
         // if we're loading a dependency and it has not been enabled on 
@@ -225,7 +219,7 @@
         
         registries.schemaLoaded( schema );
         
-        loadComparators( schema, registries );
+        loadComparators( schema );
         loadNormalizers( schema, registries );
         loadSyntaxCheckers( schema, registries );
         loadSyntaxes( schema, registries );
@@ -318,22 +312,18 @@
     
     
     /**
-     * Loads the Comparators from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which comparators are loaded
-     * @param registries the registries which are loaded with comparators
-     * @throws Exception if there are failures accessing comparator information
-     * stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadComparators( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadComparators( Schema schema ) throws Exception
     {
         File comparatorsDirectory = new File( getSchemaDirectory( schema ), 
             SchemaConstants.COMPARATORS_PATH );
         
+        List<Entry> comparatorList = new ArrayList<Entry>();
+        
         if ( ! comparatorsDirectory.exists() )
         {
-            return;
+            return comparatorList;
         }
         
         File[] comparators = comparatorsDirectory.listFiles( ldifFilter );
@@ -343,28 +333,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerComparator( registries, entry, schema );
+            comparatorList.add( entry.getEntry() );
         }
+        
+        return comparatorList;
     }
     
     
     /**
-     * Loads the SyntaxCheckers from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which syntaxCheckers are loaded
-     * @param targetRegistries the registries which are loaded with syntaxCheckers
-     * @throws Exception if there are failures accessing syntaxChecker 
-     * information stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadSyntaxCheckers( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadSyntaxCheckers( Schema schema ) throws Exception
     {
         File syntaxCheckersDirectory = new File( getSchemaDirectory( schema ), 
             SchemaConstants.SYNTAX_CHECKERS_PATH );
         
+        List<Entry> syntaxCheckerList = new ArrayList<Entry>();
+
         if ( ! syntaxCheckersDirectory.exists() )
         {
-            return;
+            return syntaxCheckerList;
         }
         
         File[] syntaxCheckerFiles = syntaxCheckersDirectory.listFiles( ldifFilter );
@@ -374,28 +362,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerSyntaxChecker( registries, entry, schema );
+            syntaxCheckerList.add( entry.getEntry() );
         }
+        
+        return syntaxCheckerList;
     }
     
     
     /**
-     * Loads the Normalizers from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which normalizers are loaded
-     * @param registries the registries which are loaded with normalizers
-     * @throws Exception if there are failures accessing normalizer information
-     * stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadNormalizers( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadNormalizers( Schema schema ) throws Exception
     {
         File normalizersDirectory = new File( getSchemaDirectory( schema ), 
             SchemaConstants.NORMALIZERS_PATH );
         
+        List<Entry> normalizerList = new ArrayList<Entry>();
+
         if ( ! normalizersDirectory.exists() )
         {
-            return;
+            return normalizerList;
         }
         
         File[] normalizerFiles = normalizersDirectory.listFiles( ldifFilter );
@@ -405,28 +391,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerNormalizer( registries, entry, schema );
+            normalizerList.add( entry.getEntry() );
         }
+        
+        return normalizerList;
     }
     
     
     /**
-     * Loads the MatchingRules from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which matchingRules are loaded
-     * @param registries the registries which are loaded with matchingRules
-     * @throws Exception if there are failures accessing matchingRule 
-     * information stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadMatchingRules( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadMatchingRules( Schema schema ) throws Exception
     {
         File matchingRulesDirectory = new File( getSchemaDirectory( schema ), 
             SchemaConstants.MATCHING_RULES_PATH );
         
+        List<Entry> matchingRuleList = new ArrayList<Entry>();
+
         if ( ! matchingRulesDirectory.exists() )
         {
-            return;
+            return matchingRuleList;
         }
         
         File[] matchingRuleFiles = matchingRulesDirectory.listFiles( ldifFilter );
@@ -436,28 +420,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
 
-            registerMatchingRule( registries, entry, schema );
+            matchingRuleList.add( entry.getEntry() );
         }
+        
+        return matchingRuleList;
     }
     
     
     /**
-     * Loads the Syntaxes from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which syntaxes are loaded
-     * @param registries the registries which are loaded with syntaxes
-     * @throws Exception if there are failures accessing comparator information
-     * stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadSyntaxes( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadSyntaxes( Schema schema ) throws Exception
     {
         File syntaxesDirectory = new File( getSchemaDirectory( schema ), 
             SchemaConstants.SYNTAXES_PATH );
         
+        List<Entry> syntaxList = new ArrayList<Entry>();
+
         if ( ! syntaxesDirectory.exists() )
         {
-            return;
+            return syntaxList;
         }
         
         File[] syntaxFiles = syntaxesDirectory.listFiles( ldifFilter );
@@ -467,28 +449,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
 
-            registerSyntax( registries, entry, schema );
+            syntaxList.add( entry.getEntry() );
         }
+        
+        return syntaxList;
     }
 
     
     /**
-     * Loads the AttributeTypes from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which attributeTypes are loaded
-     * @param registries the registries which are loaded with attributeTypes
-     * @throws Exception if there are failures accessing attributeTypes 
-     * information stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadAttributeTypes( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadAttributeTypes( Schema schema ) throws Exception
     {
     	// check that the attributeTypes directory exists for the schema
         File attributeTypesDirectory = new File ( getSchemaDirectory( schema ), SchemaConstants.ATTRIBUTES_TYPE_PATH );
         
+        List<Entry> attributeTypeList = new ArrayList<Entry>();
+
         if ( ! attributeTypesDirectory.exists() )
         {
-            return;
+            return attributeTypeList;
         }
         
         // get list of attributeType LDIF schema files in attributeTypes
@@ -499,28 +479,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerAttributeType( registries, entry, schema );
+            attributeTypeList.add( entry.getEntry() );
         }
+        
+        return attributeTypeList;
     }
     
     
     /**
-     * Loads the MatchingRuleUses from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which matchingRuleUses are loaded
-     * @param registries the registries which are loaded with matchingRuleUses
-     * @throws Exception if there are failures accessing matchingRuleUse 
-     * information stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadMatchingRuleUses( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadMatchingRuleUses( Schema schema ) throws Exception
     {
         File matchingRuleUsesDirectory = new File( getSchemaDirectory( schema ),
             SchemaConstants.MATCHING_RULE_USE_PATH );
         
+        List<Entry> matchingRuleUseList = new ArrayList<Entry>();
+
         if ( ! matchingRuleUsesDirectory.exists() )
         {
-            return;
+            return matchingRuleUseList;
         }
         
         File[] matchingRuleUseFiles = matchingRuleUsesDirectory.listFiles( ldifFilter );
@@ -530,28 +508,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerMatchingRuleUse( registries, entry, schema );
+            matchingRuleUseList.add( entry.getEntry() );
         }
+        
+        return matchingRuleUseList;
     }
 
 
     /**
-     * Loads the NameForms from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which nameForms are loaded
-     * @param registries the registries which are loaded with nameForms
-     * @throws Exception if there are failures accessing nameForm information
-     * stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadNameForms( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadNameForms( Schema schema ) throws Exception
     {
         File nameFormsDirectory = new File( getSchemaDirectory( schema ),
             SchemaConstants.NAME_FORMS_PATH );
         
+        List<Entry> nameFormList = new ArrayList<Entry>();
+
         if ( ! nameFormsDirectory.exists() )
         {
-            return;
+            return nameFormList;
         }
         
         File[] nameFormFiles = nameFormsDirectory.listFiles( ldifFilter );
@@ -561,28 +537,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerNameForm( registries, entry, schema );
+            nameFormList.add( entry.getEntry() );
         }
+        
+        return nameFormList;
     }
 
 
     /**
-     * Loads the DitContentRules from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which ditContentRules are loaded
-     * @param registries the registries which are loaded with ditContentRules
-     * @throws Exception if there are failures accessing ditContentRules 
-     * information stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadDitContentRules( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadDitContentRules( Schema schema ) throws Exception
     {
         File ditContentRulesDirectory = new File( getSchemaDirectory( schema ),
             SchemaConstants.DIT_CONTENT_RULES_PATH );
         
+        List<Entry> ditContentRuleList = new ArrayList<Entry>();
+        
         if ( ! ditContentRulesDirectory.exists() )
         {
-            return;
+            return ditContentRuleList;
         }
         
         File[] ditContentRuleFiles = ditContentRulesDirectory.listFiles( ldifFilter );
@@ -592,28 +566,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerDitContentRule( registries, entry, schema );
+            ditContentRuleList.add( entry.getEntry() );
         }
+        
+        return ditContentRuleList;
     }
 
 
     /**
-     * Loads the ditStructureRules from LDIF files in the supplied schema into 
-     * the supplied registries.
-     *
-     * @param schema the schema for which ditStructureRules are loaded
-     * @param registries the registries which are loaded with ditStructureRules
-     * @throws Exception if there are failures accessing ditStructureRule 
-     * information stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadDitStructureRules( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadDitStructureRules( Schema schema ) throws Exception
     {
         File ditStructureRulesDirectory = new File( getSchemaDirectory( schema ),
             SchemaConstants.DIT_STRUCTURE_RULES_PATH );
+
+        List<Entry> ditStructureRuleList = new ArrayList<Entry>();
         
         if ( ! ditStructureRulesDirectory.exists() )
         {
-            return;
+            return ditStructureRuleList;
         }
         
         File[] ditStructureRuleFiles = ditStructureRulesDirectory.listFiles( ldifFilter );
@@ -623,28 +595,26 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerDitStructureRule( registries, entry, schema );
+            ditStructureRuleList.add( entry.getEntry() );
         }
+        
+        return ditStructureRuleList;
     }
 
 
     /**
-     * Loads the ObjectClasses from LDIF files in the supplied schema into the 
-     * supplied registries.
-     *
-     * @param schema the schema for which objectClasses are loaded
-     * @param registries the registries which are loaded with objectClasses
-     * @throws Exception if there are failures accessing objectClass information
-     * stored in LDIF files
+     * {@inheritDoc}
      */
-    private void loadObjectClasses( Schema schema, Registries registries ) throws Exception
+    public List<Entry> loadObjectClasses( Schema schema ) throws Exception
     {
     	// get objectClasses directory, check if exists, return if not
     	File objectClassesDirectory = new File( getSchemaDirectory( schema ), SchemaConstants.OBJECT_CLASSES_PATH );
         
-    	if ( ! objectClassesDirectory.exists() )
+        List<Entry> objectClassList = new ArrayList<Entry>();
+
+        if ( ! objectClassesDirectory.exists() )
         {
-            return;
+            return objectClassList;
         }
         
         // get list of objectClass LDIF files from directory and load
@@ -655,7 +625,9 @@
             LdifReader reader = new LdifReader( ldifFile );
             LdifEntry entry = reader.next();
             
-            registerObjectClass( registries, entry, schema );
+            objectClassList.add( entry.getEntry() );
         }
+        
+        return objectClassList;
     }
 }

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/JarLdifSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/JarLdifSchemaLoaderTest.java?rev=831372&r1=831371&r2=831372&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/JarLdifSchemaLoaderTest.java (original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/JarLdifSchemaLoaderTest.java Fri Oct 30 16:19:26 2009
@@ -23,7 +23,8 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.JarLdifSchemaLoader;
 import org.junit.Test;
 
@@ -39,15 +40,16 @@
     @Test
     public void testJarLdifSchemaLoader() throws Exception
     {
-        Registries registries = new Registries();
         JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
-        loader.loadWithDependencies( loader.getSchema( "system" ), registries, true );
+        SchemaManager sm = new DefaultSchemaManager( loader );
+
+        sm.loadWithDeps( "system" );
         
-        assertTrue( registries.getAttributeTypeRegistry().contains( "cn" ) );
-        assertFalse( registries.getAttributeTypeRegistry().contains( "m-aux" ) );
+        assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) );
+        assertFalse( sm.getRegistries().getAttributeTypeRegistry().contains( "m-aux" ) );
         
-        loader.loadWithDependencies( loader.getSchema( "apachemeta" ), registries, true );
+        sm.loadWithDeps( "apachemeta" );
 
-        assertTrue( registries.getAttributeTypeRegistry().contains( "m-aux" ) );
+        assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "m-aux" ) );
     }
 }

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java?rev=831372&r1=831371&r2=831372&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java (original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java Fri Oct 30 16:19:26 2009
@@ -25,12 +25,12 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.List;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -80,15 +80,15 @@
         extractor.extractOrCopy();
         
         LdifSchemaLoader loader = new LdifSchemaLoader( new File( workingDirectory, "schema" ) );
-        Registries registries = new Registries();
-        
-        List<Throwable> errors = loader.loadAllEnabled( registries, true );
+        SchemaManager sm = new DefaultSchemaManager( loader );
+
+        boolean loaded = sm.loadAllEnabled();
         
-        if ( errors.size() != 0 )
+        if ( !loaded )
         {
-            fail( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( sm.getErrors() ) );
         }
         
-        assertTrue( registries.getAttributeTypeRegistry().contains( "cn" ) );
+        assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) );
     }
 }

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=831372&r1=831371&r2=831372&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 Fri Oct 30 16:19:26 2009
@@ -20,31 +20,18 @@
 package org.apache.directory.shared.ldap.schema.registries;
 
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
+import java.util.HashSet;
 import java.util.Map;
-import java.util.Stack;
+import java.util.Set;
 
-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;
-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.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,15 +50,6 @@
 
     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 
      * populated when this class is created with all the schemas present in
@@ -107,39 +85,9 @@
     /**
      * {@inheritDoc}
      */
-    public final List<Throwable> loadAllEnabled( Registries registries, boolean check ) throws Exception
+    public final Collection<Schema> getAllEnabled() throws Exception
     {
-        // Relax the controls at first
-        List<Throwable> errors = new ArrayList<Throwable>();
-        boolean wasRelaxed = registries.isRelaxed();
-        registries.setRelaxed( true );
-
-        Map<String,Schema> notloaded = new HashMap<String,Schema>( schemaMap );
-        
-        for ( String schemaName : schemaMap.keySet() )
-        {
-            if ( registries.isSchemaLoaded( schemaName ) )
-            {
-                notloaded.remove( schemaName );
-            }
-        }
-         
-        for ( Schema schema : schemaMap.values() )
-        {
-            loadDepsFirst( schema, new Stack<String>(), 
-                notloaded, schema, registries );
-        }
-
-        // At the end, check the registries if required
-        if ( check )
-        {
-            errors = registries.checkRefInteg();
-        }
-        
-        // Restore the Registries isRelaxed flag
-        registries.setRelaxed( wasRelaxed );
-        
-        return errors;
+        return schemaMap.values();
     }
     
     
@@ -156,7 +104,7 @@
      * @param props to use while trying to resolve other schemas
      * @throws Exception if there is a cycle detected and/or another
      * failure results while loading, producing and or registering schema objects
-     */
+     *
     protected final void loadDepsFirst( Schema rootAncestor, Stack<String> beenthere, Map<String, Schema> notLoaded,
                                         Schema schema, Registries registries ) throws Exception
     {
@@ -190,7 +138,7 @@
          * We got deps and need to load them before this schema.  We go through
          * all deps loading them with their deps first if they have not been
          * loaded.
-         */
+         *
         for ( String depName : deps )
         {
             // @todo if a dependency is not loaded it's not in this list
@@ -247,11 +195,62 @@
         return this.schemaMap.get( schemaName );
     }
 
+    
+    protected Schema getSchema( Entry entry ) throws Exception
+    {
+        String name;
+        String owner;
+        String[] dependencies = StringTools.EMPTY_STRINGS;
+        boolean isDisabled = false;
+        
+        if ( entry == null )
+        {
+            throw new NullPointerException( "entry cannot be null" );
+        }
+        
+        if ( entry.get( SchemaConstants.CN_AT ) == null )
+        {
+            throw new NullPointerException( "entry must have a valid cn attribute" );
+        }
+        
+        name = entry.get( SchemaConstants.CN_AT ).getString();
+        
+        if ( entry.get( SchemaConstants.CREATORS_NAME_AT ) == null )
+        {
+            throw new NullPointerException( "entry must have a valid " 
+                + SchemaConstants.CREATORS_NAME_AT + " attribute" );
+        }
+        
+        owner = entry.get( SchemaConstants.CREATORS_NAME_AT ).getString();
+        
+        if ( entry.get( MetaSchemaConstants.M_DISABLED_AT ) != null )
+        {
+            String value = entry.get( MetaSchemaConstants.M_DISABLED_AT ).getString();
+            value = value.toUpperCase();
+            isDisabled = value.equals( "TRUE" );
+        }
+        
+        if ( entry.get( MetaSchemaConstants.M_DEPENDENCIES_AT ) != null )
+        {
+            Set<String> depsSet = new HashSet<String>();
+            EntryAttribute depsAttr = entry.get( MetaSchemaConstants.M_DEPENDENCIES_AT );
+            
+            for ( Value<?> value:depsAttr )
+            {
+                depsSet.add( value.getString() );
+            }
+
+            dependencies = depsSet.toArray( StringTools.EMPTY_STRINGS );
+        }
+        
+        return new DefaultSchema( name, owner, dependencies, isDisabled ){};
+    }
+    
 
     /**
      * {@inheritDoc}
-     */
-    public List<Throwable> loadWithDependencies( Collection<Schema> schemas, Registries registries, boolean check ) throws Exception
+     *
+    public List<Throwable> loadWithDependencies( Registries registries, boolean check, Schema... schemas ) throws Exception
     {
         // Relax the controls at first
         List<Throwable> errors = new ArrayList<Throwable>();
@@ -294,7 +293,7 @@
      * @param entry The LdifEntry containing the comparator description
      * @param schema The associated schema
      * @throws Exception If the registering failed
-     */
+     *
     protected LdapComparator<?> registerComparator( Registries registries, LdifEntry entry, Schema schema ) 
         throws Exception
     {
@@ -309,7 +308,7 @@
      * @param entry The Entry containing the comparator description
      * @param schema The associated schema
      * @throws Exception If the registering failed
-     */
+     *
     protected LdapComparator<?> registerComparator( Registries registries, Entry entry, Schema schema ) 
         throws Exception
     {
@@ -348,7 +347,7 @@
      * @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
     {
@@ -387,7 +386,7 @@
      * @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
     {
@@ -425,7 +424,7 @@
      * @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
     {
@@ -463,7 +462,7 @@
      * @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
     {
@@ -501,7 +500,7 @@
      * @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
     {
@@ -538,7 +537,7 @@
      * @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
     {
@@ -555,7 +554,7 @@
      * @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
     {
@@ -572,7 +571,7 @@
      * @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
     {
@@ -589,7 +588,7 @@
      * @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
     {
@@ -606,7 +605,7 @@
      * @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
     {
@@ -622,7 +621,7 @@
      * @param schema The associated schema
      * @return the created ObjectClass instance
      * @throws Exception If the registering failed
-     */
+     *
     protected ObjectClass registerObjectClass( Registries registries, Entry entry, Schema schema) 
         throws Exception
     {
@@ -649,4 +648,16 @@
         
         return objectClass;
     }
+    
+    
+    public EntityFactory getFactory()
+    {
+        return factory;
+    }
+    */
+
+    public Object getDao()
+    {
+        return null;
+    }
 }

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=831372&r1=831371&r2=831372&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 30 16:19:26 2009
@@ -26,7 +26,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 
@@ -45,6 +44,7 @@
 import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.SchemaWrapper;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,12 +61,6 @@
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( Registries.class );
 
-    /** A flag indicating if this Registries is relaxed or not */
-    private boolean isRelaxed;
-    
-    /** A flag indicating if this Registries should accept only enabled elements */
-    private boolean acceptDisabled;
-    
     /**
      * A String name to Schema object map for those schemas loaded into this
      * registry.
@@ -112,6 +106,16 @@
     /** A map storing all the schema objects associated with a schema */
     private Map<String, Set<SchemaWrapper>> schemaObjectsBySchemaName;
     
+    /** A flag indicating that the Registries is relaxed or not */
+    private boolean isRelaxed;
+    
+    /** A flag indicating that disabled SchemaObject are accepted */
+    private boolean disabledAccepted;
+    
+    /** Two flags for RELAXED and STRUCT */
+    public static final boolean STRICT = false;
+    public static final boolean RELAXED = true;
+    
     /**
      *  A map storing a relation between a SchemaObject and all the 
      *  referencing SchemaObjects.
@@ -144,15 +148,12 @@
         normalizerRegistry = new NormalizerRegistry( oidRegistry );
         objectClassRegistry = new ObjectClassRegistry( oidRegistry );
         syntaxCheckerRegistry = new SyntaxCheckerRegistry( oidRegistry );
-        schemaObjectsBySchemaName = new ConcurrentHashMap<String, Set<SchemaWrapper>>();
-        usedBy = new ConcurrentHashMap<SchemaWrapper, Set<SchemaWrapper>>();
-        using = new ConcurrentHashMap<SchemaWrapper, Set<SchemaWrapper>>();
-        
-        // Default to not permissive
-        isRelaxed = false;
+        schemaObjectsBySchemaName = new HashMap<String, Set<SchemaWrapper>>();
+        usedBy = new HashMap<SchemaWrapper, Set<SchemaWrapper>>();
+        using = new HashMap<SchemaWrapper, Set<SchemaWrapper>>();
         
-        // Default to not allow disabled element
-        acceptDisabled = false;
+        isRelaxed = STRICT;
+        disabledAccepted = false;
     }
 
     
@@ -475,6 +476,49 @@
         // Step 6-9 aren't yet defined
         return errors;
     }
+    
+    
+    /**
+     * Build the usedBy and using references from the stored elements.
+     */
+    public void buildReferences()
+    {
+        // First start with the Syntaxes
+        for ( LdapSyntax syntax : ldapSyntaxRegistry )
+        {
+            SyntaxChecker syntaxChecker = null;
+            
+            // Each syntax should reference a SyntaxChecker with the same OID
+            try
+            {
+                syntaxChecker = syntaxCheckerRegistry.lookup( syntax.getOid() );
+            }
+            catch ( NamingException ne )
+            {
+                // There is no SyntaxChecker : default to the OctetString SyntaxChecker
+                syntaxChecker = new OctetStringSyntaxChecker( syntax.getOid() );
+            }
+            
+            addReference( syntax, syntaxChecker );
+        }
+
+        // Then the MatchingRules
+        for ( MatchingRule matchingRule : matchingRuleRegistry )
+        {
+            // each matching rule references a Syntax, a Comparator and a Normalizer
+            // If we don't have a Syntax, this is an error
+            LdapSyntax syntax = null;
+            
+            try
+            {
+                syntax = ldapSyntaxRegistry.lookup( matchingRule.getSyntaxOid() );
+            }
+            catch ( NamingException ne )
+            {
+                
+            }
+        }
+    }
 
     
     /**
@@ -867,7 +911,63 @@
 	    return content;
 	}
 	
+
+	/**
+	 * Add the given AttributeTtpe into the Registries
+	 *
+	 * @param attributeType The AttributeType to register
+	 * @throws NamingException If the registering failed
+	 */
+    public void register( AttributeType attributeType ) throws NamingException
+    {
+        LOG.debug( "Registering AttributeType: {}:{}", attributeType.getOid(), attributeType.getName() );
+        
+        String schemaName = StringTools.toLowerCase( attributeType.getSchemaName() );
+
+        // First, clone the Registries so that we don't mess with the 
+        // current registries if something goes wrong
+        // Register the new AT into the cloned ATRegistry
+        attributeTypeRegistry.register( attributeType );
+        
+        if ( isStrict() )
+        {
+            // Update the AT with the cloned registries
+            attributeType.applyRegistries( this );
+            
+            // Update the referenced objects (Using/UsedBy)
+            // The Syntax,
+            addReference( attributeType, attributeType.getSyntax() );
+    
+            // The Superior if any
+            addReference( attributeType, attributeType.getSuperior() );
+    
+            // The MatchingRules
+            addReference( attributeType, attributeType.getEquality() );
+            addReference( attributeType, attributeType.getOrdering() );
+            addReference( attributeType, attributeType.getSubstring() );
+        }        
+    }
+    
 	
+    /**
+     * Add the given LdapComparator into the Registries
+     *
+     * @param comparator The LdapComparator to register
+     * @throws NamingException If the registering failed
+     */
+    public void register( LdapComparator<?> comparator ) throws NamingException
+    {
+        LOG.debug( "Registering Comparator: {}:{}", comparator.getOid(), comparator.getName() );
+
+        comparatorRegistry.register( comparator );
+        
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( "registered " + comparator.getName() + " for OID {}", comparator.getOid() );
+        }
+    }
+    
+        
 	public void register( SchemaObject schemaObject ) throws NamingException
 	{
 	    LOG.debug( "Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid() );
@@ -877,14 +977,6 @@
 	    // First call the specific registry's register method
 	    switch ( schemaObject.getObjectType() )
 	    {
-	        case ATTRIBUTE_TYPE : 
-	            attributeTypeRegistry.register( (AttributeType)schemaObject );
-	            break;
-	            
-            case COMPARATOR : 
-                comparatorRegistry.register( (LdapComparator<?>)schemaObject );
-                break;
-                
             case DIT_CONTENT_RULE : 
                 ditContentRuleRegistry.register( (DITContentRule)schemaObject );
                 break;
@@ -1679,6 +1771,54 @@
     
     
     /**
+     * Clone the Registries
+     */
+    public Registries clone() throws CloneNotSupportedException
+    {
+        // First clone the structure
+        Registries clone = (Registries)super.clone();
+        
+        // We have to clone every SchemaObject registries now
+        clone.attributeTypeRegistry = attributeTypeRegistry.clone();
+        clone.comparatorRegistry = comparatorRegistry.clone();
+        clone.ditContentRuleRegistry = ditContentRuleRegistry.clone();
+        clone.ditStructureRuleRegistry = ditStructureRuleRegistry.clone();
+        clone.ldapSyntaxRegistry = ldapSyntaxRegistry.clone();
+        clone.matchingRuleRegistry = matchingRuleRegistry.clone();
+        clone.matchingRuleUseRegistry = matchingRuleUseRegistry.clone();
+        clone.nameFormRegistry = nameFormRegistry.clone();
+        clone.normalizerRegistry = normalizerRegistry.clone();
+        clone.objectClassRegistry = objectClassRegistry.clone();
+        clone.syntaxCheckerRegistry = syntaxCheckerRegistry.clone();
+        
+        // Now, clone the oidRegistry
+        clone.oidRegistry = oidRegistry.clone();
+        
+        // Clone the schema list
+        clone.loadedSchemas = new HashMap<String, Schema>();
+        
+        for ( String schemaName : loadedSchemas.keySet() )
+        {
+            // We don't cone the schemas
+            clone.loadedSchemas.put( schemaName, loadedSchemas.get( schemaName ) );
+        }
+        
+        // Last, not least, clone the Using and usedBy structures
+        // They will be empty
+        clone.using = new HashMap<SchemaWrapper, Set<SchemaWrapper>>();
+        clone.usedBy = new HashMap<SchemaWrapper, Set<SchemaWrapper>>();
+        
+        // Now, check the registries. We don"t care about errors
+        checkRefInteg();
+        
+        // Last, rebuild the using and usedBy references
+        buildReferences();
+        
+        return clone;
+    }
+
+    
+    /**
      * Tells if the Registries is permissive or if it must be checked 
      * against inconsistencies.
      *
@@ -1688,28 +1828,47 @@
     {
         return isRelaxed;
     }
-    
+
     
     /**
-     * Change the Registries behavior regarding consistency.
+     * Tells if the Registries is strict.
      *
-     * @param isRelaxed If <code>false</code>, then the Registries won't allow modifications that 
-     * leave the Registries to be inconsistent
+     * @return True if SchemaObjects cannot be added if they break the consistency 
      */
-    public void setRelaxed( boolean isRelaxed )
+    public boolean isStrict()
     {
-        this.isRelaxed = isRelaxed;
+        return !isRelaxed;
     }
+
     
+    /**
+     * Change the Registries to a relaxed mode, where invalid SchemaObjects
+     * can be registered.
+     */
+    public void setRelaxed()
+    {
+        isRelaxed = RELAXED;
+    }
+
     
     /**
+     * Change the Registries to a strict mode, where invalid SchemaObjects
+     * cannot be registered.
+     */
+    public void setStrict()
+    {
+        isRelaxed = STRICT;
+    }
+
+
+    /**
      * Tells if the Registries accept disabled elements.
      *
-     * @return True if disbaled SchemaObjects can be added 
+     * @return True if disabled SchemaObjects can be added 
      */
-    public boolean acceptDisabled()
+    public boolean isDisabledAccepted()
     {
-        return acceptDisabled;
+        return disabledAccepted;
     }
     
     
@@ -1719,50 +1878,72 @@
      * @param acceptDisabled If <code>false</code>, then the Registries won't accept
      * disabled SchemaObject or enabled SchemaObject from disabled schema 
      */
-    public void setAcceptDisabled( boolean acceptDisabled )
+    public void setDisabledAccepted( boolean disabledAccepted )
     {
-        this.acceptDisabled = acceptDisabled;
+        this.disabledAccepted = disabledAccepted;
     }
     
     
     /**
-     * Clone the Registries
+     * @see Object#toString()
      */
-    public Registries clone() throws CloneNotSupportedException
+    public String toString()
     {
-        // First clone the structure
-        Registries clone = (Registries)super.clone();
+        StringBuilder sb = new StringBuilder();
         
-        // We have to clone every SchemaObject registries now
-        clone.attributeTypeRegistry = attributeTypeRegistry.clone();
-        clone.comparatorRegistry = comparatorRegistry.clone();
-        clone.ditContentRuleRegistry = ditContentRuleRegistry.clone();
-        clone.ditStructureRuleRegistry = ditStructureRuleRegistry.clone();
-        clone.ldapSyntaxRegistry = ldapSyntaxRegistry.clone();
-        clone.matchingRuleRegistry = matchingRuleRegistry.clone();
-        clone.matchingRuleUseRegistry = matchingRuleUseRegistry.clone();
-        clone.nameFormRegistry = nameFormRegistry.clone();
-        clone.normalizerRegistry = normalizerRegistry.clone();
-        clone.objectClassRegistry = objectClassRegistry.clone();
-        clone.syntaxCheckerRegistry = syntaxCheckerRegistry.clone();
+        sb.append( "Registries [" );
         
-        // Now, clone the oidRegistry
-        clone.oidRegistry = oidRegistry.clone();
+        if ( isRelaxed )
+        {
+            sb.append( "RELAXED," );
+        }
+        else
+        {
+            sb.append( "STRICT," );
+        }
         
-        // Clone the schema list
-        clone.loadedSchemas = new HashMap<String, Schema>();
+        if ( disabledAccepted )
+        {
+            sb.append( " Disabled accepted] :\n" );
+        }
+        else
+        {
+            sb.append( " Disabled forbidden] :\n" );
+        }
         
-        for ( String schemaName : loadedSchemas.keySet() )
+        sb.append( "loaded schemas [" );
+        boolean isFirst = true;
+        
+        for ( String schema:loadedSchemas.keySet() )
         {
-            // We don't cone the schemas
-            clone.loadedSchemas.put( schemaName, loadedSchemas.get( schemaName ) );
+            if ( isFirst )
+            {
+                isFirst = false;
+            }
+            else
+            {
+                sb.append( ", " );
+            }
+            
+            sb.append( schema );
         }
         
-        // Last, not least, clone the Using and usedBy structures
-        // They will be empty
-        clone.using = new HashMap<SchemaWrapper, Set<SchemaWrapper>>();
-        clone.usedBy = new HashMap<SchemaWrapper, Set<SchemaWrapper>>();
+        sb.append( "]\n" );
         
-        return clone;
+        sb.append( "AttributeTypes : " ).append( attributeTypeRegistry.size() ).append( "\n" );
+        sb.append( "Comparators : " ).append( comparatorRegistry.size() ).append( "\n" );
+        sb.append( "DitContentRules : " ).append( ditContentRuleRegistry.size() ).append( "\n" );
+        sb.append( "DitStructureRules : " ).append( ditStructureRuleRegistry.size() ).append( "\n" );
+        sb.append( "MatchingRules : " ).append( matchingRuleRegistry.size() ).append( "\n" );
+        sb.append( "MatchingRuleUses : " ).append( matchingRuleUseRegistry.size() ).append( "\n" );
+        sb.append( "NameForms : " ).append( nameFormRegistry.size() ).append( "\n" );
+        sb.append( "Normalizers : " ).append( normalizerRegistry.size() ).append( "\n" );
+        sb.append( "ObjectClasses : " ).append( objectClassRegistry.size() ).append( "\n" );
+        sb.append( "Syntaxes : " ).append( ldapSyntaxRegistry.size() ).append( "\n" );
+        sb.append( "SyntaxCheckers : " ).append( syntaxCheckerRegistry.size() ).append( "\n" );
+        
+        sb.append( "OidRegistry : " ).append( oidRegistry.size() ).append( '\n' );
+        
+        return sb.toString();
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java?rev=831372&r1=831371&r2=831372&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java Fri Oct 30 16:19:26 2009
@@ -23,6 +23,8 @@
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.directory.shared.ldap.entry.Entry;
+
 
 /**
  * Loads schemas into registres.
@@ -51,28 +53,16 @@
     
     
     /**
-     * Loads a collection of schemas.  A best effort should be made to load the dependended 
+     * Loads a set of schemas.  A best effort should be made to load the dependended 
      * schemas that these schemas may rely on even if they are not included in the collection.
      * 
-     * @param schemas the collection of schemas to load
-     * @param registries the registries to populate with these schemas
-     * @param check tells if the Registries must be checked after having been loaded
-     * @return the list of erros we met during the loading of schemas
-     * @throws Exception if any kind of problems are encountered during the load
-     */
-    List<Throwable> loadWithDependencies( Collection<Schema> schemas, Registries registries, boolean check ) throws Exception;
-    
-    
-    /**
-     * Loads a single schema at least and possibly it's dependencies.  
-     * 
-     * @param schema the schema to load
      * @param registries the registries to populate with these schemas
      * @param check tells if the Registries must be checked after having been loaded
+     * @param schemas the set of schemas to load
      * @return the list of erros we met during the loading of schemas
      * @throws Exception if any kind of problems are encountered during the load
-     */
-    List<Throwable> loadWithDependencies( Schema schema, Registries registries, boolean check ) throws Exception;
+     *
+    List<Throwable> loadWithDependencies( Registries registries, boolean check, Schema... schemas ) throws Exception;
     
     
     /**
@@ -82,7 +72,7 @@
      * @param check tells if the Registries must be checked after having been loaded
      * @return the list of erros we met during the loading of schemas
      * @throws Exception if there are any failures
-     */
+     *
     List<Throwable> loadAllEnabled( Registries registries, boolean check ) throws Exception;
     
     
@@ -93,6 +83,119 @@
      * @param registries the registries to populate with these schemas
      * @param isDepLoad tells the loader if this load request is to satisfy a dependency
      * @throws Exception if any kind of problems are encountered during the load
-     */
+     *
     void load( Schema schema, Registries registries, boolean isDepLoad ) throws Exception;
+    
+    
+    /**
+     * Build a list of AttributeTypes read from the underlying storage
+     *
+     * @param schema the schema from which AttributeTypes are loaded
+     * @throws Exception if there are failures accessing AttributeType information
+     */
+    List<Entry> loadAttributeTypes( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of Comparators read from the underlying storage
+     *
+     * @param schema the schema from which Comparators are loaded
+     * @throws Exception if there are failures accessing Comparator information
+     */
+    List<Entry> loadComparators( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of DitContentRules read from the underlying storage
+     *
+     * @param schema the schema from which DitContentRules are loaded
+     * @throws Exception if there are failures accessing DitContentRule information
+     */
+    List<Entry> loadDitContentRules( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of DitStructureRules read from the underlying storage
+     *
+     * @param schema the schema from which DitStructureRules are loaded
+     * @throws Exception if there are failures accessing DitStructureRule information
+     */
+    List<Entry> loadDitStructureRules( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of MatchingRules read from the underlying storage
+     *
+     * @param schema the schema from which MatchingRules are loaded
+     * @throws Exception if there are failures accessing MatchingRule information
+     */
+    List<Entry> loadMatchingRules( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of MatchingRuleUses read from the underlying storage
+     *
+     * @param schema the schema from which MatchingRuleUses are loaded
+     * @throws Exception if there are failures accessing MatchingRuleUse information
+     */
+    List<Entry> loadMatchingRuleUses( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of NameForms read from the underlying storage
+     *
+     * @param schema the schema from which NameForms are loaded
+     * @throws Exception if there are failures accessing NameForm information
+     */
+    List<Entry> loadNameForms( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of Normalizers read from the underlying storage
+     *
+     * @param schema the schema from which Normalizers are loaded
+     * @throws Exception if there are failures accessing Normalizer information
+     */
+    List<Entry> loadNormalizers( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of ObjectClasses read from the underlying storage
+     *
+     * @param schema the schema from which ObjectClasses are loaded
+     * @throws Exception if there are failures accessing ObjectClass information
+     */
+    List<Entry> loadObjectClasses( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of Syntaxes read from the underlying storage
+     *
+     * @param schema the schema from which Syntaxes are loaded
+     * @throws Exception if there are failures accessing Syntax information
+     */
+    List<Entry> loadSyntaxes( Schema schema ) throws Exception;
+    
+    
+    /**
+     * Build a list of SyntaxCheckers read from the underlying storage
+     *
+     * @param schema the schema from which SyntaxCheckers are loaded
+     * @throws Exception if there are failures accessing SyntaxChecker information
+     */
+    List<Entry> loadSyntaxCheckers( Schema schema ) throws Exception;
+
+
+    /**
+     * @return the list of enabled schemas
+     * @throws Exception TODO
+     */
+    Collection<Schema> getAllEnabled() throws Exception;
+
+
+    /**
+     * TODO : get rid of this here !
+     * @dao the DAO
+     */
+    Object getDao();
 }



Mime
View raw message