directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r888423 - 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 Tue, 08 Dec 2009 15:01:15 GMT
Author: elecharny
Date: Tue Dec  8 15:01:15 2009
New Revision: 888423

URL: http://svn.apache.org/viewvc?rev=888423&view=rev
Log:
o Implemented the disable( Schema... ) method
o Added some test for this method
o Fixed some methods signature

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=888423&r1=888422&r2=888423&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
Tue Dec  8 15:01:15 2009
@@ -212,6 +212,32 @@
     }
 
 
+    /**
+     * Delete all the schemaObjects for a given schema from the registries
+     */
+    private void deleteSchemaObjects( Schema schema, Registries registries ) throws Exception
+    {
+        Map<String, Set<SchemaObjectWrapper>> schemaObjects = registries.getObjectBySchemaName();
+        Set<SchemaObjectWrapper> content = schemaObjects.get( StringTools.toLowerCase(
schema.getSchemaName() ) );
+
+        List<SchemaObject> toBeDeleted = new ArrayList<SchemaObject>();
+
+        // Buid an intermediate list to avoid concurrent modifications
+        for ( SchemaObjectWrapper schemaObjectWrapper : content )
+        {
+            toBeDeleted.add( schemaObjectWrapper.get() );
+        }
+
+        for ( SchemaObject schemaObject : toBeDeleted )
+        {
+            registries.delete( errors, schemaObject );
+        }
+
+        // TODO Add some listener handling at this point
+        //notifyListenerOrRegistries( schema, registries );
+    }
+
+
     //-----------------------------------------------------------------------
     // API methods
     //-----------------------------------------------------------------------
@@ -251,20 +277,68 @@
     /**
      * {@inheritDoc}
      */
-    public boolean disable( Schema... schemas )
+    public boolean disable( Schema... schemas ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        boolean disabled = 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 )
+        {
+            unload( clonedRegistries, schema );
+        }
+
+        // Build the cross references
+        errors = clonedRegistries.buildReferences();
+
+        // Destroy the clonedRegistry
+        clonedRegistries.clear();
+
+        if ( errors.isEmpty() )
+        {
+            // Ok no errors. Check the registries now
+            errors = clonedRegistries.checkRefInteg();
+
+            if ( errors.isEmpty() )
+            {
+                // We are golden : let's apply the schemas in the real registries
+                for ( Schema schema : schemas )
+                {
+                    unload( registries, schema );
+                    schema.disable();
+                }
+
+                // Build the cross references
+                errors = registries.buildReferences();
+                registries.setStrict();
+
+                disabled = true;
+            }
+        }
+
+        // clear the cloned registries
+        clonedRegistries.clear();
+
+        return disabled;
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public boolean disable( String... schemas )
+    public boolean disable( String... schemaNames ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        Schema[] schemas = toArray( schemaNames );
+
+        return disable( schemas );
     }
 
 
@@ -368,9 +442,10 @@
     /**
      * {@inheritDoc}
      */
-    public boolean enable( String... schemas ) throws Exception
+    public boolean enable( String... schemaNames ) throws Exception
     {
-        return enable( toArray( schemas ) );
+        Schema[] schemas = toArray( schemaNames );
+        return enable( schemas );
     }
 
 
@@ -501,9 +576,11 @@
     /**
      * {@inheritDoc}
      */
-    public boolean load( String... schemas ) throws Exception
+    public boolean load( String... schemaNames ) throws Exception
     {
-        return load( toArray( schemas ) );
+        Schema[] schemas = toArray( schemaNames );
+
+        return load( schemas );
     }
 
 
@@ -559,6 +636,42 @@
 
 
     /**
+     * Unload the schema from the registries. We will unload everything accordingly to the
two flags :
+     * - isRelaxed
+     * - disabledAccepted
+     *
+     * @param registries
+     * @param schemas
+     * @return
+     * @throws Exception
+     */
+    private boolean unload( Registries registries, Schema schema ) throws Exception
+    {
+        if ( schema == null )
+        {
+            LOG.info( "The schema is null" );
+            return false;
+        }
+
+        // First avoid unloading twice the same schema
+        if ( !registries.isSchemaLoaded( schema.getSchemaName() ) )
+        {
+            return true;
+        }
+
+        if ( schema.isEnabled() )
+        {
+            LOG.info( "Unloading {} schema: \n{}", schema.getSchemaName(), schema );
+
+            deleteSchemaObjects( schema, registries );
+            registries.schemaUnloaded( schema );
+        }
+
+        return true;
+    }
+
+
+    /**
      * Add all the Schema's AttributeTypes
      */
     private void addAttributeTypes( Schema schema, Registries registries ) throws Exception
@@ -791,9 +904,11 @@
     /**
      * {@inheritDoc}
      */
-    public boolean loadDisabled( String... schemas ) throws Exception
+    public boolean loadDisabled( String... schemaNames ) throws Exception
     {
-        return loadDisabled( toArray( schemas ) );
+        Schema[] schemas = toArray( schemaNames );
+
+        return loadDisabled( schemas );
     }
 
 
@@ -810,9 +925,9 @@
     /**
      * {@inheritDoc}
      */
-    public boolean loadRelaxed( String... schemas ) throws Exception
+    public boolean loadRelaxed( String... schemaNames ) throws Exception
     {
-        // TODO Auto-generated method stub
+        Schema[] schemas = toArray( schemaNames );
         return false;
     }
 

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=888423&r1=888422&r2=888423&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
Tue Dec  8 15:01:15 2009
@@ -24,12 +24,15 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
+import javax.naming.NamingException;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
@@ -202,6 +205,47 @@
     }
 
 
+    /**
+     * Disable an enabled schema
+     */
+    @Test
+    public void testDisableEnabled() throws Exception
+    {
+        schemaManager.loadAllEnabled();
+
+        assertTrue( schemaManager.enable( "nis" ) );
+        assertTrue( schemaManager.isEnabled( "nis" ) );
+
+        assertEquals( 11, schemaManager.getRegistries().getLoadedSchemas().size() );
+
+        assertTrue( schemaManager.disable( "nis" ) );
+
+        try
+        {
+            schemaManager.lookupAttributeTypeRegistry( "gecos" );
+            fail();
+        }
+        catch ( NamingException ne )
+        {
+            // Expected
+        }
+
+        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" ) );
+
+    }
+
+
     @Test
     public void testEnableNonExisting()
     {

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=888423&r1=888422&r2=888423&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
Tue Dec  8 15:01:15 2009
@@ -264,6 +264,7 @@
      * 
      *  @param schemas The list of schemas to enable
      *  @return true if the Registries is still consistent, false otherwise.
+     *  @throws If something went wrong
      */
     boolean enable( Schema... schemas ) throws Exception;
 
@@ -277,6 +278,7 @@
      *  
      *  @param schemas The list of schema name to enable
      *  @return true if the Registries is still consistent, false otherwise.
+     *  @throws If something went wrong
      */
     boolean enable( String... schemas ) throws Exception;
 
@@ -336,8 +338,9 @@
      * 
      *  @param schemas The list of schemas to disable
      *  @return true if the Registries is still consistent, false otherwise.
+     *  @throws If something went wrong
      */
-    boolean disable( Schema... schemas );
+    boolean disable( Schema... schemas ) throws Exception;
 
 
     /**
@@ -349,8 +352,9 @@
      * 
      *  @param schemas The list of schema names to disable
      *  @return true if the Registries is still consistent, false otherwise.
+     *  @throws If something went wrong
      */
-    boolean disable( String... schemas );
+    boolean disable( String... schemas ) throws Exception;
 
 
     /**



Mime
View raw message