directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1729391 - in /directory/shared/trunk/ldap: model/src/main/java/org/apache/directory/api/ldap/model/schema/ model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/ schema/data/src/main/java/org/apache/directory/api/ldap/s...
Date Tue, 09 Feb 2016 14:26:12 GMT
Author: elecharny
Date: Tue Feb  9 14:26:12 2016
New Revision: 1729391

URL: http://svn.apache.org/viewvc?rev=1729391&view=rev
Log:
o Made the LowerCaseKayMap a separate class
o The SchemaManager has a new getAllSchemas() method, and the setSchemaLoader()/ getLoader()
methods have been removed
o The SM also holds the list of Schema it knows about, it does not use anymore the SchemaLoader
for that
o Each Schema has a reference to the SchemaLoader used to load it
o 

Added:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/LowerCaseKeyMap.java
Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaManager.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/AbstractSchemaLoader.java
    directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
    directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SingleLdifSchemaLoader.java
    directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/manager/impl/DefaultSchemaManager.java
    directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerEnableDisableLoadTest.java
    directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadTest.java
    directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadWithDepsTest.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaManager.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaManager.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaManager.java
Tue Feb  9 14:26:12 2016
@@ -20,6 +20,7 @@
 package org.apache.directory.api.ldap.model.schema;
 
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -40,7 +41,6 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.registries.OidRegistry;
 import org.apache.directory.api.ldap.model.schema.registries.Registries;
 import org.apache.directory.api.ldap.model.schema.registries.Schema;
-import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader;
 import org.apache.directory.api.ldap.model.schema.registries.SyntaxCheckerRegistry;
 
 
@@ -313,7 +313,13 @@ public interface SchemaManager
     /**
      * @return the list of all the enabled schema
      */
-    List<Schema> getEnabled();
+    Collection<Schema> getEnabled();
+
+
+    /**
+     * @return the list of all schemas
+     */
+    Collection<Schema> getAllSchemas();
 
 
     /**
@@ -655,14 +661,6 @@ public interface SchemaManager
 
 
     /**
-     * Associate a Schema loader to this SchemaManager
-     *
-     * @param schemaLoader The schema loader to use
-     */
-    void setSchemaLoader( SchemaLoader schemaLoader );
-
-
-    /**
      * @return the namingContext
      */
     Dn getNamingContext();
@@ -677,12 +675,6 @@ public interface SchemaManager
 
 
     /**
-     * @return The used loader
-     */
-    SchemaLoader getLoader();
-
-
-    /**
      * Registers a new SchemaObject. The registries will be updated only if it's
      * consistent after this addition, if the SchemaManager is in Strict mode.
      * If something went wrong during this operation, the 
@@ -694,6 +686,34 @@ public interface SchemaManager
      * the registration operation is not supported
      */
     boolean add( SchemaObject schemaObject ) throws LdapException;
+    
+    
+    /**
+     * Add a new Schema into the SchemaManager.
+     *
+     * @param schema The schema to add
+     * @return <tt>true</tt> if the Shcema has been correctly loaded, <tt>false</tt>
if we had some errors 
+     */
+    //boolean add( Schema schema ) throws LdapException;
+    
+    
+    /**
+     * Add a new Schema from a file into the SchemaManager. We will use the default schemaLoader.
+     *
+     * @param schemaFile The file containing the schema to add
+     * @return <tt>true</tt> if the Shcema has been correctly loaded, <tt>false</tt>
if we had some errors 
+     */
+    //boolean add( String schemaFile ) throws LdapException;
+
+    
+    /**
+     * Add a new Schema into the SchemaManager, using a new SchemaLoader.
+     *
+     * @param schemaFile The file containing the schema to add
+     * @param schemaLoader The SchemaLoader to use to load this new schema
+     * @return <tt>true</tt> if the Shcema has been correctly loaded, <tt>false</tt>
if we had some errors 
+     */
+    //boolean add( String schemaFile, SchemaLoader schemaLoader ) throws LdapException;
 
 
     /**

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/AbstractSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/AbstractSchemaLoader.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/AbstractSchemaLoader.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/AbstractSchemaLoader.java
Tue Feb  9 14:26:12 2016
@@ -22,7 +22,6 @@ package org.apache.directory.api.ldap.mo
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -57,32 +56,6 @@ public abstract class AbstractSchemaLoad
     private boolean relaxed;
 
     /**
-     * a map implementation which converts the keys to lower case before inserting
-     */
-    private static class LowerCaseKeyMap extends HashMap<String, Schema>
-    {
-        private static final long serialVersionUID = 1L;
-
-
-        @Override
-        public Schema put( String key, Schema value )
-        {
-            return super.put( Strings.toLowerCaseAscii( key ), value );
-        }
-
-
-        @Override
-        public void putAll( Map<? extends String, ? extends Schema> map )
-        {
-            for ( Map.Entry<? extends String, ? extends Schema> e : map.entrySet()
)
-            {
-                put( e.getKey(), e.getValue() );
-            }
-        }
-    }
-
-
-    /**
      * {@inheritDoc}
      */
     public final Collection<Schema> getAllEnabled() throws Exception

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/LowerCaseKeyMap.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/LowerCaseKeyMap.java?rev=1729391&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/LowerCaseKeyMap.java
(added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/registries/LowerCaseKeyMap.java
Tue Feb  9 14:26:12 2016
@@ -0,0 +1,89 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.api.ldap.model.schema.registries;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.api.util.Strings;
+
+/**
+ * a map implementation which converts the keys to lower case before inserting
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class LowerCaseKeyMap extends HashMap<String, Schema>
+{
+    private static final long serialVersionUID = 1L;
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Schema get( Object key )
+    {
+        return super.get( Strings.toLowerCaseAscii( ( String ) key ) );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Schema remove( Object key )
+    {
+        return super.remove( Strings.toLowerCaseAscii( ( String ) key ) );
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean containsKey( Object key )
+    {
+        return super.containsKey( Strings.toLowerCaseAscii( ( String ) key ) );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Schema put( String key, Schema value )
+    {
+        return super.put( Strings.toLowerCaseAscii( key ), value );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void putAll( Map<? extends String, ? extends Schema> map )
+    {
+        for ( Map.Entry<? extends String, ? extends Schema> e : map.entrySet() )
+        {
+            super.put( Strings.toLowerCaseAscii( e.getKey() ), e.getValue() );
+        }
+    }
+}

Modified: directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
(original)
+++ directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
Tue Feb  9 14:26:12 2016
@@ -261,7 +261,7 @@ public class SchemaEntityFactory impleme
             dependencies = depsSet.toArray( EMPTY_ARRAY );
         }
 
-        return new DefaultSchema( name, owner, dependencies, isDisabled );
+        return new DefaultSchema( null, name, owner, dependencies, isDisabled );
     }
 
 

Modified: directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SingleLdifSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SingleLdifSchemaLoader.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SingleLdifSchemaLoader.java
(original)
+++ directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SingleLdifSchemaLoader.java
Tue Feb  9 14:26:12 2016
@@ -21,6 +21,7 @@
 package org.apache.directory.api.ldap.schema.loader;
 
 
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -94,7 +95,32 @@ public class SingleLdifSchemaLoader exte
         }
     }
 
+    /**
+     * Instantiates a new single LDIF schema loader.
+     */
+    public SingleLdifSchemaLoader( String schemaFile )
+    {
+        try
+        {
+            for ( String s : schemaObjectTypeRdns )
+            {
+                scObjEntryMap.put( s, new HashMap<String, List<Entry>>() );
+            }
 
+            InputStream in = new FileInputStream( schemaFile );
+
+            initializeSchemas( in );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    /**
+     * Initialize the Schema object from a Single LDIF file
+     */
     private void initializeSchemas( InputStream in ) throws Exception
     {
         LdifReader ldifReader = new LdifReader( in );
@@ -105,7 +131,7 @@ public class SingleLdifSchemaLoader exte
         {
             LdifEntry ldifEntry = ldifReader.next();
             String dn = ldifEntry.getDn().getName();
-
+            
             if ( SCHEMA_START_PATTERN.matcher( dn ).matches() )
             {
                 Schema schema = getSchema( ldifEntry.getEntry() );
@@ -122,6 +148,9 @@ public class SingleLdifSchemaLoader exte
     }
 
 
+    /**
+     * Load all the schemaObjects
+     */
     private void loadSchemaObject( String schemaName, LdifEntry ldifEntry ) throws Exception
     {
         for ( String scObjTypeRdn : schemaObjectTypeRdns )
@@ -136,6 +165,7 @@ public class SingleLdifSchemaLoader exte
             {
                 Map<String, List<Entry>> m = scObjEntryMap.get( scObjTypeRdn
);
                 List<Entry> entryList = m.get( schemaName );
+                
                 if ( entryList == null )
                 {
                     entryList = new ArrayList<Entry>();
@@ -162,6 +192,7 @@ public class SingleLdifSchemaLoader exte
         for ( Schema s : schemas )
         {
             List<Entry> preLoaded = m.get( s.getSchemaName() );
+            
             if ( preLoaded != null )
             {
                 atList.addAll( preLoaded );

Modified: directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/manager/impl/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/manager/impl/DefaultSchemaManager.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/manager/impl/DefaultSchemaManager.java
(original)
+++ directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/manager/impl/DefaultSchemaManager.java
Tue Feb  9 14:26:12 2016
@@ -22,6 +22,7 @@ package org.apache.directory.api.ldap.sc
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -68,6 +69,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.registries.ImmutableObjectClassRegistry;
 import org.apache.directory.api.ldap.model.schema.registries.ImmutableSyntaxCheckerRegistry;
 import org.apache.directory.api.ldap.model.schema.registries.LdapSyntaxRegistry;
+import org.apache.directory.api.ldap.model.schema.registries.LowerCaseKeyMap;
 import org.apache.directory.api.ldap.model.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.api.ldap.model.schema.registries.MatchingRuleUseRegistry;
 import org.apache.directory.api.ldap.model.schema.registries.NameFormRegistry;
@@ -106,14 +108,18 @@ public class DefaultSchemaManager implem
     /** The list of errors produced when loading some schema elements */
     private List<Throwable> errors;
 
-    /** The Schema schemaLoader used by this SchemaManager */
-    private SchemaLoader schemaLoader;
-
     /** the factory that generates respective SchemaObjects from LDIF entries */
     private final EntityFactory factory;
 
     /** A Map containing all the schema being dependent from a schema */
-    private Map<String, Set<String>> schemaDependences = new HashMap<String,
Set<String>>();
+    private Map<String, Set<String>> schemaDependencies = new HashMap<String,
Set<String>>();
+    
+    /**
+     * 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
+     * the LDIF based schema repository.
+     */
+    private Map<String, Schema> schemaMap = new LowerCaseKeyMap();
 
     /** A flag indicating that the SchemaManager is relaxed or not */
     private boolean isRelaxed = STRICT;
@@ -125,7 +131,14 @@ public class DefaultSchemaManager implem
     {
         // Default to the the root (one schemaManager for all the entries
         namingContext = Dn.ROOT_DSE;
-        this.schemaLoader = new JarLdifSchemaLoader();
+        SchemaLoader schemaLoader = new JarLdifSchemaLoader();
+        
+        
+        for ( Schema schema : schemaLoader.getAllSchemas() )
+        {
+            schemaMap.put( schema.getSchemaName(), schema );
+        }
+        
         errors = new ArrayList<Throwable>();
         registries = new Registries();
         factory = new SchemaEntityFactory();
@@ -133,56 +146,74 @@ public class DefaultSchemaManager implem
         loadAllEnabled();
     }
 
+    
     /**
      * Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
-     *
-     * @param relaxed If teh schema  manager should be relaxed or not
+     * 
+     * @param schemas The list of schema to load
      */
-    public DefaultSchemaManager( boolean relaxed ) throws Exception
+    public DefaultSchemaManager( Collection<Schema> schemas ) throws Exception
     {
         // Default to the the root (one schemaManager for all the entries
         namingContext = Dn.ROOT_DSE;
-        this.schemaLoader = new JarLdifSchemaLoader();
+        
+        for ( Schema schema : schemas )
+        {
+            schemaMap.put( schema.getSchemaName(), schema );
+        }
+        
+        //this.schemaLoader = new JarLdifSchemaLoader();
         errors = new ArrayList<Throwable>();
         registries = new Registries();
         factory = new SchemaEntityFactory();
-        isRelaxed = relaxed;
-        loadAllEnabled();
+        isRelaxed = STRICT;
     }
 
-
+    
     /**
      * Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
-     *
-     * @param loader The schema loader to use
+     * 
+     * @param schemaLoader The schemaLoader containing the schemas to load
      */
-    public DefaultSchemaManager( SchemaLoader loader )
+    public DefaultSchemaManager( SchemaLoader schemaLoader ) throws Exception
     {
         // Default to the the root (one schemaManager for all the entries
         namingContext = Dn.ROOT_DSE;
-        this.schemaLoader = loader;
+        
+        for ( Schema schema : schemaLoader.getAllSchemas() )
+        {
+            schemaMap.put( schema.getSchemaName(), schema );
+        }
+        
+        //this.schemaLoader = new JarLdifSchemaLoader();
         errors = new ArrayList<Throwable>();
         registries = new Registries();
         factory = new SchemaEntityFactory();
-        isRelaxed = loader.isRelaxed();
+        isRelaxed = STRICT;
     }
-
+    
 
     /**
-     * Creates a new instance of DefaultSchemaManager, for a specific
-     * naming context
+     * Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
      *
-     * @param loader The schema loader to use
-     * @param namingContext The associated NamingContext
+     * @param relaxed If the schema  manager should be relaxed or not
+     * @param schemas The list of schema to load
      */
-    public DefaultSchemaManager( SchemaLoader loader, Dn namingContext )
+    public DefaultSchemaManager( boolean relaxed, Collection<Schema> schemas ) throws
Exception
     {
-        this.namingContext = namingContext;
-        this.schemaLoader = loader;
+        // Default to the the root (one schemaManager for all the entries
+        namingContext = Dn.ROOT_DSE;
+
+        for ( Schema schema : schemas )
+        {
+            schemaMap.put( schema.getSchemaName(), schema );
+        }
+        
+        //this.schemaLoader = new JarLdifSchemaLoader();
         errors = new ArrayList<Throwable>();
         registries = new Registries();
         factory = new SchemaEntityFactory();
-        isRelaxed = loader.isRelaxed();
+        isRelaxed = relaxed;
     }
 
 
@@ -229,7 +260,7 @@ public class DefaultSchemaManager implem
 
         for ( String schemaName : schemas )
         {
-            Schema schema = schemaLoader.getSchema( schemaName );
+            Schema schema = schemaMap.get( schemaName );
 
             if ( schema != null )
             {
@@ -250,6 +281,7 @@ public class DefaultSchemaManager implem
     {
         // Create a content container for this schema
         registries.addSchema( schema.getSchemaName() );
+        schemaMap.put( schema.getSchemaName(), schema );
 
         // And inject any existing SchemaObject into the registries
         try
@@ -434,7 +466,7 @@ public class DefaultSchemaManager implem
             {
                 for ( String dependency : schema.getDependencies() )
                 {
-                    Schema dependencySchema = schemaLoader.getSchema( dependency );
+                    Schema dependencySchema = schema.getSchemaLoader().getSchema( dependency
);
 
                     if ( dependencySchema.isDisabled() )
                     {
@@ -543,6 +575,25 @@ public class DefaultSchemaManager implem
     /**
      * {@inheritDoc}
      */
+    public List<Schema> getAllSchemas()
+    {
+        List<Schema> schemas = new ArrayList<Schema>();
+
+        for ( Schema schema : schemaMap.values() )
+        {
+            if ( schema.isEnabled() )
+            {
+                schemas.add( schema );
+            }
+        }
+
+        return schemas;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public List<Throwable> getErrors()
     {
         return errors;
@@ -621,12 +672,11 @@ public class DefaultSchemaManager implem
                     load( registries, schema );
 
                     // Update the schema dependences if needed
-
                     if ( schema.getDependencies() != null )
                     {
                         for ( String dep : schema.getDependencies() )
                         {
-                            Set<String> deps = schemaDependences.get( dep );
+                            Set<String> deps = schemaDependencies.get( dep );
 
                             if ( deps == null )
                             {
@@ -635,12 +685,12 @@ public class DefaultSchemaManager implem
                             }
 
                             // Replace the dependences
-                            schemaDependences.put( dep, deps );
+                            schemaDependencies.put( dep, deps );
                         }
                     }
 
-                    // add the schema to the schemaLoader
-                    schemaLoader.addSchema( schema );
+                    // add the schema to the SchemaMap
+                    schemaMap.put( schema.getSchemaName(), schema );
                 }
 
                 // Build the cross references
@@ -716,7 +766,7 @@ public class DefaultSchemaManager implem
             {
                 for ( String dependency : schema.getDependencies() )
                 {
-                    Schema dependencySchema = schemaLoader.getSchema( dependency );
+                    Schema dependencySchema = schemaMap.get( dependency );
 
                     if ( dependencySchema == null )
                     {
@@ -788,7 +838,12 @@ public class DefaultSchemaManager implem
      */
     private void addAttributeTypes( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadAttributeTypes( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+
+        for ( Entry entry : schema.getSchemaLoader().loadAttributeTypes( schema ) )
         {
             AttributeType attributeType = factory.getAttributeType( this, entry, registries,
schema.getSchemaName() );
 
@@ -802,7 +857,12 @@ public class DefaultSchemaManager implem
      */
     private void addComparators( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadComparators( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+        
+        for ( Entry entry : schema.getSchemaLoader().loadComparators( schema ) )
         {
             LdapComparator<?> comparator = factory.getLdapComparator( this, entry,
registries, schema.getSchemaName() );
 
@@ -818,7 +878,7 @@ public class DefaultSchemaManager implem
     //    @SuppressWarnings("PMD.UnusedFormalParameter")
     //    private void addDitContentRules( Schema schema, Registries registries ) throws
LdapException, IOException
     //    {
-    //        if ( !schemaLoader.loadDitContentRules( schema ).isEmpty() )
+    //        if ( !schema.getSchemaLoader().loadDitContentRules( schema ).isEmpty() )
     //        {
     //            throw new NotImplementedException( I18n.err( I18n.ERR_11003 ) );
     //        }
@@ -831,7 +891,7 @@ public class DefaultSchemaManager implem
     //    @SuppressWarnings("PMD.UnusedFormalParameter")
     //    private void addDitStructureRules( Schema schema, Registries registries ) throws
LdapException, IOException
     //    {
-    //        if ( !schemaLoader.loadDitStructureRules( schema ).isEmpty() )
+    //        if ( !schema.getSchemaLoader().loadDitStructureRules( schema ).isEmpty() )
     //        {
     //            throw new NotImplementedException( I18n.err( I18n.ERR_11004 ) );
     //        }
@@ -842,7 +902,12 @@ public class DefaultSchemaManager implem
      */
     private void addMatchingRules( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadMatchingRules( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+
+        for ( Entry entry : schema.getSchemaLoader().loadMatchingRules( schema ) )
         {
             MatchingRule matchingRule = factory.getMatchingRule( this, entry, registries,
schema.getSchemaName() );
 
@@ -858,11 +923,11 @@ public class DefaultSchemaManager implem
     //    @SuppressWarnings("PMD.UnusedFormalParameter")
     //    private void addMatchingRuleUses( Schema schema, Registries registries ) throws
LdapException, IOException
     //    {
-    //        if ( !schemaLoader.loadMatchingRuleUses( schema ).isEmpty() )
+    //        if ( !schema.getSchemaLoader().loadMatchingRuleUses( schema ).isEmpty() )
     //        {
     //            throw new NotImplementedException( I18n.err( I18n.ERR_11005 ) );
     //        }
-    //        // for ( Entry entry : schemaLoader.loadMatchingRuleUses( schema ) )
+    //        // for ( Entry entry : schema.getSchemaLoader().loadMatchingRuleUses( schema
) )
     //        // {
     //        //     throw new NotImplementedException( I18n.err( I18n.ERR_11005 ) );
     //        // }
@@ -875,7 +940,7 @@ public class DefaultSchemaManager implem
     //    @SuppressWarnings("PMD.UnusedFormalParameter")
     //    private void addNameForms( Schema schema, Registries registries ) throws LdapException,
IOException
     //    {
-    //        if ( !schemaLoader.loadNameForms( schema ).isEmpty() )
+    //        if ( !schema.getSchemaLoader().loadNameForms( schema ).isEmpty() )
     //        {
     //            throw new NotImplementedException( I18n.err( I18n.ERR_11006 ) );
     //        }
@@ -886,7 +951,12 @@ public class DefaultSchemaManager implem
      */
     private void addNormalizers( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadNormalizers( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+
+        for ( Entry entry : schema.getSchemaLoader().loadNormalizers( schema ) )
         {
             Normalizer normalizer = factory.getNormalizer( this, entry, registries, schema.getSchemaName()
);
 
@@ -900,7 +970,12 @@ public class DefaultSchemaManager implem
      */
     private void addObjectClasses( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadObjectClasses( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+
+        for ( Entry entry : schema.getSchemaLoader().loadObjectClasses( schema ) )
         {
             ObjectClass objectClass = factory.getObjectClass( this, entry, registries, schema.getSchemaName()
);
 
@@ -914,7 +989,12 @@ public class DefaultSchemaManager implem
      */
     private void addSyntaxes( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadSyntaxes( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+
+        for ( Entry entry : schema.getSchemaLoader().loadSyntaxes( schema ) )
         {
             LdapSyntax syntax = factory.getSyntax( this, entry, registries, schema.getSchemaName()
);
 
@@ -928,7 +1008,12 @@ public class DefaultSchemaManager implem
      */
     private void addSyntaxCheckers( Schema schema, Registries registries ) throws LdapException,
IOException
     {
-        for ( Entry entry : schemaLoader.loadSyntaxCheckers( schema ) )
+        if ( schema.getSchemaLoader() == null )
+        {
+            return;
+        }
+
+        for ( Entry entry : schema.getSchemaLoader().loadSyntaxCheckers( schema ) )
         {
             SyntaxChecker syntaxChecker = factory.getSyntaxChecker( this, entry, registries,
schema.getSchemaName() );
 
@@ -981,9 +1066,21 @@ public class DefaultSchemaManager implem
      */
     public boolean loadAllEnabled() throws Exception
     {
-        Schema[] schemas = schemaLoader.getAllEnabled().toArray( new Schema[0] );
-
-        return loadWithDeps( schemas );
+        Schema[] schemas = new Schema[schemaMap.size()];
+        int i = 0;
+        
+        for ( Schema schema : schemaMap.values() )
+        {
+            if ( schema.isEnabled() )
+            {
+                schemas[i++] = schema;
+            }
+        }
+        
+        Schema[] enabledSchemas = new Schema[i];
+        System.arraycopy( schemas, 0, enabledSchemas, 0, i );
+        
+        return loadWithDeps( enabledSchemas );
     }
 
 
@@ -992,9 +1089,18 @@ public class DefaultSchemaManager implem
      */
     public boolean loadAllEnabledRelaxed() throws Exception
     {
-        Schema[] schemas = schemaLoader.getAllEnabled().toArray( new Schema[0] );
-
-        return loadWithDepsRelaxed( schemas );
+        Schema[] enabledSchemas = new Schema[schemaMap.size()];
+        int i = 0;
+        
+        for ( Schema schema : schemaMap.values() )
+        {
+            if ( schema.isEnabled() )
+            {
+                enabledSchemas[i++] = schema;
+            }
+        }
+        
+        return loadWithDepsRelaxed( enabledSchemas );
     }
 
 
@@ -1195,7 +1301,7 @@ public class DefaultSchemaManager implem
             else
             {
                 // Call recursively this method
-                Schema schemaDep = schemaLoader.getSchema( depName );
+                Schema schemaDep = schemaMap.get( depName );
                 loadDepsFirst( registries, schemaDep );
             }
         }
@@ -1293,7 +1399,7 @@ public class DefaultSchemaManager implem
             else
             {
                 // Call recursively this method
-                Schema schemaDep = schemaLoader.getSchema( depName );
+                Schema schemaDep = schema.getSchemaLoader().getSchema( depName );
                 loadDepsFirstRelaxed( schemaDep );
             }
         }
@@ -1357,7 +1463,7 @@ public class DefaultSchemaManager implem
                     // Update the schema dependences
                     for ( String dep : schema.getDependencies() )
                     {
-                        Set<String> deps = schemaDependences.get( dep );
+                        Set<String> deps = schemaDependencies.get( dep );
 
                         if ( deps != null )
                         {
@@ -1365,7 +1471,7 @@ public class DefaultSchemaManager implem
                         }
                     }
 
-                    schemaLoader.removeSchema( schema );
+                    schemaMap.remove( schema.getSchemaName() );
                 }
 
                 // Build the cross references
@@ -1452,15 +1558,6 @@ public class DefaultSchemaManager implem
 
 
     /**
-     * {@inheritDoc}
-     */
-    public void setSchemaLoader( SchemaLoader schemaLoader )
-    {
-        this.schemaLoader = schemaLoader;
-    }
-
-
-    /**
      * @return the namingContext
      */
     public Dn getNamingContext()
@@ -1479,15 +1576,6 @@ public class DefaultSchemaManager implem
     }
 
 
-    /**
-     * {@inheritDoc}
-     */
-    public SchemaLoader getLoader()
-    {
-        return schemaLoader;
-    }
-
-
     //-----------------------------------------------------------------------------------
     // Immutable accessors
     //-----------------------------------------------------------------------------------
@@ -1750,7 +1838,7 @@ public class DefaultSchemaManager implem
             return MetaSchemaConstants.SCHEMA_OTHER;
         }
 
-        if ( schemaLoader.getSchema( schemaName ) == null )
+        if ( schemaMap.get( schemaName ) == null )
         {
             return null;
         }
@@ -2051,7 +2139,7 @@ public class DefaultSchemaManager implem
      */
     public Schema getLoadedSchema( String schemaName )
     {
-        return schemaLoader.getSchema( schemaName );
+        return schemaMap.get( schemaName );
     }
 
 
@@ -2062,7 +2150,8 @@ public class DefaultSchemaManager implem
     {
         try
         {
-            Schema schema = schemaLoader.getSchema( schemaName );
+            Schema schema = schemaMap.get( schemaName );
+            
             return schema != null;
         }
         catch ( Exception e )
@@ -2199,7 +2288,7 @@ public class DefaultSchemaManager implem
      */
     public Set<String> listDependentSchemaNames( String schemaName )
     {
-        return schemaDependences.get( schemaName );
+        return schemaDependencies.get( schemaName );
     }
 
 

Modified: directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerEnableDisableLoadTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerEnableDisableLoadTest.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerEnableDisableLoadTest.java
(original)
+++ directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerEnableDisableLoadTest.java
Tue Feb  9 14:26:12 2016
@@ -30,6 +30,7 @@ import static org.junit.Assert.fail;
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
@@ -141,7 +142,7 @@ public class SchemaManagerEnableDisableL
         }
 
         // The enabled schemas
-        List<Schema> enabled = schemaManager.getEnabled();
+        Collection<Schema> enabled = schemaManager.getEnabled();
 
         assertEquals( enabled.size(), enabledSchemas.size() );
 

Modified: directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadTest.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadTest.java
(original)
+++ directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadTest.java
Tue Feb  9 14:26:12 2016
@@ -214,7 +214,7 @@ public class SchemaManagerLoadTest
     // Test the load( String... schemaName) method
     //-------------------------------------------------------------------------
     /**
-     * test loading the "system" schema
+     * test loading the "system" schema amone
      */
     @Test
     public void testLoadSystem() throws Exception
@@ -705,7 +705,7 @@ public class SchemaManagerLoadTest
 
         Schema system = loader.getSchema( "system" );
         Schema core = loader.getSchema( "core" );
-        Schema empty = new DefaultSchema( "empty" );
+        Schema empty = new DefaultSchema( loader, "empty" );
         Schema cosine = loader.getSchema( "cosine" );
         Schema inetOrgPerson = loader.getSchema( "InetOrgPerson" );
 
@@ -739,7 +739,7 @@ public class SchemaManagerLoadTest
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        Schema dummy = new DefaultSchema( "dummy" );
+        Schema dummy = new DefaultSchema( loader, "dummy" );
 
         assertTrue( schemaManager.load( dummy ) );
 
@@ -767,7 +767,7 @@ public class SchemaManagerLoadTest
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        Schema dummy = new DefaultSchema( "dummy" );
+        Schema dummy = new DefaultSchema( loader, "dummy" );
         dummy.addDependencies( "bad" );
 
         assertFalse( schemaManager.load( dummy ) );
@@ -787,16 +787,14 @@ public class SchemaManagerLoadTest
     }
 
 
-    @Ignore("loadDisabled() method need to be fixed")
     @Test
     public void testLoadDisabled() throws Exception
     {
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+        SchemaManager schemaManager = new DefaultSchemaManager();
 
         assertTrue( schemaManager.loadDisabled( "nis" ) );
 
-        assertFalse( schemaManager.getErrors().isEmpty() );
+        assertTrue( schemaManager.getErrors().isEmpty() );
 
         AttributeType at = schemaManager.getAttributeType( "uidNumber" );
         // if nis schema was loaded then the at will not be null

Modified: directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadWithDepsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadWithDepsTest.java?rev=1729391&r1=1729390&r2=1729391&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadWithDepsTest.java
(original)
+++ directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/api/ldap/schema/loader/SchemaManagerLoadWithDepsTest.java
Tue Feb  9 14:26:12 2016
@@ -280,7 +280,7 @@ public class SchemaManagerLoadWithDepsTe
     public void testLoadCosine() throws Exception
     {
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader.getAllSchemas() );
 
         schemaManager.loadWithDeps( "cosine" );
 
@@ -585,7 +585,7 @@ public class SchemaManagerLoadWithDepsTe
 
         Schema system = loader.getSchema( "system" );
         Schema core = loader.getSchema( "core" );
-        Schema empty = new DefaultSchema( "empty" );
+        Schema empty = new DefaultSchema( loader, "empty" );
         Schema cosine = loader.getSchema( "cosine" );
         Schema inetOrgPerson = loader.getSchema( "InetOrgPerson" );
 




Mime
View raw message