directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r888189 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/...
Date Mon, 07 Dec 2009 23:35:35 GMT
Author: elecharny
Date: Mon Dec  7 23:35:34 2009
New Revision: 888189

URL: http://svn.apache.org/viewvc?rev=888189&view=rev
Log:
o Added an isEnabled() and isDisabled() method in schemaManager
o Fixed the enable( Schema...) method
o Added a test for the enable(Schema...) method
o Improved the loadAllEnabled() method 

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=888189&r1=888188&r2=888189&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Mon Dec  7 23:35:34 2009
@@ -88,32 +88,32 @@
 public class DefaultSchemaManager implements SchemaManager
 {
     /** static class logger */
-    private static final Logger LOG = LoggerFactory.getLogger( DefaultSchemaManager.class
);
+    private static final Logger   LOG       = LoggerFactory.getLogger( DefaultSchemaManager.class
);
 
     /** The NamingContext this SchemaManager is associated with */
-    private LdapDN namingContext;
+    private LdapDN                namingContext;
 
     /** The global registries for this namingContext */
-    private volatile Registries registries;
+    private volatile Registries   registries;
 
     /** The list of errors produced when loading some schema elements */
-    private List<Throwable> errors;
+    private List<Throwable>       errors;
 
     /** The Schema schemaLoader used by this SchemaManager */
-    private SchemaLoader schemaLoader;
+    private SchemaLoader          schemaLoader;
 
     /** the factory that generates respective SchemaObjects from LDIF entries */
     protected final EntityFactory factory;
 
     /** the normalized name for the schema modification attributes */
-    private LdapDN schemaModificationAttributesDN;
+    private LdapDN                schemaModificationAttributesDN;
 
     /** A flag indicating that the SchemaManager is relaxed or not */
-    private boolean isRelaxed = STRICT;
+    private boolean               isRelaxed = STRICT;
 
     /** Two flags for RELAXED and STRUCT */
-    public static final boolean STRICT = false;
-    public static final boolean RELAXED = true;
+    public static final boolean   STRICT    = false;
+    public static final boolean   RELAXED   = true;
 
 
     /**
@@ -312,8 +312,17 @@
      */
     public boolean enable( Schema... schemas ) throws Exception
     {
+        boolean enabled = false;
+
+        // Reset the errors if not null
+        if ( errors != null )
+        {
+            errors.clear();
+        }
+
         // Work on a cloned and relaxed registries
         Registries clonedRegistries = cloneRegistries();
+        clonedRegistries.setRelaxed();
 
         for ( Schema schema : schemas )
         {
@@ -321,27 +330,38 @@
             load( clonedRegistries, schema );
         }
 
-        List<Throwable> errors = clonedRegistries.checkRefInteg();
+        // Build the cross references
+        errors = clonedRegistries.buildReferences();
 
         // Destroy the clonedRegistry
         clonedRegistries.clear();
 
         if ( errors.isEmpty() )
         {
-            // No error, inject the schema in the current registries 
-            for ( Schema schema : schemas )
+            // Ok no errors. Check the registries now
+            errors = clonedRegistries.checkRefInteg();
+
+            if ( errors.isEmpty() )
             {
-                schema.enable();
-                load( registries, schema );
-            }
+                // We are golden : let's apply the schemas in the real registries
+                for ( Schema schema : schemas )
+                {
+                    schema.enable();
+                    load( registries, schema );
+                }
+
+                // Build the cross references
+                errors = registries.buildReferences();
+                registries.setStrict();
 
-            errors = registries.checkRefInteg();
+                enabled = true;
+            }
         }
 
-        return errors.isEmpty();
+        // clear the cloned registries
+        clonedRegistries.clear();
 
-        // Swap the registries if it is consistent
-        //return swapRegistries( clonedRegistries );
+        return enabled;
     }
 
 
@@ -701,7 +721,6 @@
             if ( registries.isDisabledAccepted() || ( schema.isEnabled() && schemaObject.isEnabled()
) )
             {
                 registries.add( errors, schemaObject );
-
             }
             else
             {
@@ -1618,4 +1637,44 @@
     {
         isRelaxed = STRICT;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDisabled( String schemaName )
+    {
+        Schema schema = registries.getLoadedSchema( schemaName );
+
+        return ( schema != null ) && schema.isDisabled();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDisabled( Schema schema )
+    {
+        return ( schema != null ) && schema.isDisabled();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled( String schemaName )
+    {
+        Schema schema = registries.getLoadedSchema( schemaName );
+
+        return ( schema != null ) && schema.isEnabled();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled( Schema schema )
+    {
+        return ( schema != null ) && schema.isEnabled();
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java?rev=888189&r1=888188&r2=888189&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerEnableDisableLoadTest.java
Mon Dec  7 23:35:34 2009
@@ -21,6 +21,8 @@
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -52,21 +54,22 @@
     private static String workingDirectory;
 
     // The schema repository
-    private static File schemaRepository;
+    private static File   schemaRepository;
 
     // The schemaManager
     private SchemaManager schemaManager;
 
     // List of all the available schemas, enabled or disabled
-    private List<String> allSchemas = Arrays.asList( "system", "core", "cosine", "inetorgperson",
"apache",
-        "apachemeta", "collective", "java", "krb5kdc", "other", "nis", "autofs", "apachedns",
"dhcp", "samba", "corba" );
+    private List<String>  allSchemas      = Arrays.asList( "system", "core", "cosine",
"inetorgperson", "apache",
+                                              "apachemeta", "collective", "java", "krb5kdc",
"other", "nis", "autofs",
+                                              "apachedns", "dhcp", "samba", "corba" );
 
     // List of all the enabled schemas
-    private List<String> enabledSchemas = Arrays.asList( "system", "core", "cosine",
"inetorgperson", "apache",
-        "apachemeta", "collective", "java", "krb5kdc", "other" );
+    private List<String>  enabledSchemas  = Arrays.asList( "system", "core", "cosine",
"inetorgperson", "apache",
+                                              "apachemeta", "collective", "java", "krb5kdc",
"other" );
 
     // List of all the disabled schemas
-    private List<String> disabledSchemas = Arrays.asList( "nis", "autofs", "apachedns",
"dhcp", "samba", "corba" );
+    private List<String>  disabledSchemas = Arrays.asList( "nis", "autofs", "apachedns",
"dhcp", "samba", "corba" );
 
 
     @BeforeClass
@@ -138,6 +141,19 @@
         List<Schema> disabled = schemaManager.getDisabled();
 
         assertEquals( 0, disabled.size() );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 261, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 48, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 48, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 50, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 88, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 66, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 71, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 468, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 10, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
     }
 
 
@@ -145,21 +161,44 @@
     // Test the enable( String... schemaName) method
     //-------------------------------------------------------------------------
     /**
-     * Enable a schema which is alread enabled
+     * Enable a schema which is already enabled
      */
     @Test
     public void testEnableAlreadyEnabled() throws Exception
     {
         schemaManager.loadAllEnabled();
 
+        assertTrue( schemaManager.isEnabled( "core" ) );
         assertTrue( schemaManager.enable( "core" ) );
+        assertTrue( schemaManager.isEnabled( "core" ) );
     }
 
 
+    /**
+     * Enable a disabled schema
+     */
     @Test
-    public void testEnableDisabled()
+    public void testEnableDisabled() throws Exception
     {
+        schemaManager.loadAllEnabled();
+
+        assertTrue( schemaManager.enable( "nis" ) );
+        assertTrue( schemaManager.isEnabled( "nis" ) );
+
+        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "gecos" ) );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 288, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 49, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 49, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 51, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 101, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 68, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 73, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 511, schemaManager.getOidRegistry().size() );
 
+        assertEquals( 11, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
     }
 
 
@@ -171,7 +210,7 @@
 
 
     /**
-     * Enable multiple schemas, some are enabled, sme are disabled, some are not existing
+     * Enable multiple schemas, some are enabled, some are disabled, some are not existing
      */
     @Test
     public void testEnableMultipleSchemas()

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=888189&r1=888188&r2=888189&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
Mon Dec  7 23:35:34 2009
@@ -310,6 +310,24 @@
 
 
     /**
+     * Tells if the given Schema is enabled
+     *
+     * @param schemaName The schema name
+     * @return true if the schema is enabled
+     */
+    boolean isEnabled( String schemaName );
+
+
+    /**
+     * Tells if the given Schema is enabled
+     *
+     * @param schema The schema
+     * @return true if the schema is enabled
+     */
+    boolean isEnabled( Schema schema );
+
+
+    /**
      * Disables a set of Schemas, and returns true if all the schema have been
      * disabled, with all the dependent schemas, and if the registries is 
      * still consistent.
@@ -368,6 +386,24 @@
 
 
     /**
+     * Tells if the given Schema is disabled
+     *
+     * @param schemaName The schema name
+     * @return true if the schema is disabled
+     */
+    boolean isDisabled( String schemaName );
+
+
+    /**
+     * Tells if the given Schema is disabled
+     *
+     * @param schema The schema
+     * @return true if the schema is disabled
+     */
+    boolean isDisabled( Schema schema );
+
+
+    /**
      * Check that the Schemas are consistent regarding the current Registries.
      * 
      * @param schemas The schemas to check



Mime
View raw message