directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r834897 - in /directory: apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/...
Date Wed, 11 Nov 2009 15:07:53 GMT
Author: elecharny
Date: Wed Nov 11 15:07:52 2009
New Revision: 834897

URL: http://svn.apache.org/viewvc?rev=834897&view=rev
Log:
Fixed errors in NormalizerHandler

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java?rev=834897&r1=834896&r2=834897&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
Wed Nov 11 15:07:52 2009
@@ -149,7 +149,6 @@
         else
         {
             LOG.debug( "The comparator {} cannot be added in schema {}", dn.getUpName(),
schemaName );
-
         }
     }
 

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java?rev=834897&r1=834896&r2=834897&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java
Wed Nov 11 15:07:52 2009
@@ -20,6 +20,8 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.List;
+
 import javax.naming.NamingException;
 
 import org.apache.directory.server.core.entry.ServerEntry;
@@ -34,6 +36,8 @@
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+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;
 
@@ -104,14 +108,45 @@
         // Build the new Normalizer from the given entry
         String schemaName = getSchemaName( dn );
         
+        // At this point, as we may break the registries, work on a cloned registries
+        Registries clonedRegistries = schemaManager.getRegistries().clone();
+        
+        // Relax the cloned registries
+        clonedRegistries.setRelaxed();
+        
         Normalizer normalizer = factory.getNormalizer( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
         
-        addToSchema( normalizer, schemaName );
+        if ( normalizer != null )
+        {
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            
+            if ( errors.size() == 0 )
+            {
+                clonedRegistries.setStrict();
+                schemaManager.swapRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the addition and get out
+                return;
+            }
 
-        if ( isSchemaEnabled( schemaName ) )
+            // At this point, the constructed Normalizer has not been checked against the

+            // existing Registries. It will be checked there, if the schema and the 
+            // LdapComparator are both enabled.
+            Schema schema = schemaManager.getLoadedSchema( schemaName );
+            
+            if ( schema.isEnabled() && normalizer.isEnabled() )
+            {
+                normalizer.applyRegistries( schemaManager.getRegistries() );
+                addToSchema( normalizer, schemaName );
+                schemaManager.register( normalizer );
+                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+            }
+        }
+        else
         {
-            schemaManager.register( normalizer );
-            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+            LOG.debug( "The normalizer {} cannot be added in schema {}", dn.getUpName(),
schemaName );
         }
     }
 
@@ -139,13 +174,16 @@
             if ( schemaManager.getRegistries().isReferenced( normalizer ) )
             {
                 String msg = "Cannot delete " + entry.getDn().getUpName() + ", as there are
some " +
-                " dependant SchemaObjects :\n" + getReferenced( normalizer );
-            LOG.warn( msg );
-            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+                    " dependant SchemaObjects :\n" + getReferenced( normalizer );
+                LOG.warn( msg );
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
+
+            // As the normalizer has the same OID than its attached MR, it won't
+            // be loaded into the schemaManager if it's disabled
+            deleteFromSchema( normalizer, schemaName );
         }
         
-        deleteFromSchema( normalizer, schemaName );
 
         if ( schemaManager.getNormalizerRegistry().contains( oid ) )
         {

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java?rev=834897&r1=834896&r2=834897&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java
Wed Nov 11 15:07:52 2009
@@ -29,6 +29,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -98,8 +99,6 @@
     // ----------------------------------------------------------------------
     // Test all core methods with normal operational pathways
     // ----------------------------------------------------------------------
-
-
     @Test
     public void testAddNormalizerToEnabledSchema() throws Exception
     {
@@ -146,6 +145,37 @@
     
     
     @Test
+    public void testAddNormalizerToUnloadedSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaNormalizer",
+            "m-fqcn", NoOpNormalizer.class.getName(),
+            "m-oid", OID,
+            "m-description: A test normalizer" );
+        
+        // nis is by default inactive
+        LdapDN dn = getNormalizerContainer( "notloaded" );
+        dn.add( "m-oid" + "=" + OID );
+
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Expected result.
+        }
+        
+        assertFalse( "adding new normalizer to disabled schema should not register it into
the registries", 
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
+    }
+    
+    
+    @Test
     public void testAddNormalizerWithByteCodeToEnabledSchema() throws Exception
     {
         InputStream in = getClass().getResourceAsStream( "DummyNormalizer.bytecode" );

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java?rev=834897&r1=834896&r2=834897&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
Wed Nov 11 15:07:52 2009
@@ -588,8 +588,7 @@
      * {@inheritDoc}
      */
     public Normalizer getNormalizer( SchemaManager schemaManager, Entry entry, 
-        Registries targetRegistries, String schemaName ) 
-        throws Exception
+        Registries targetRegistries, String schemaName ) throws Exception
     {
         checkEntry( entry, SchemaConstants.NORMALIZER );
         
@@ -597,9 +596,7 @@
         String oid = getOid( entry, SchemaConstants.NORMALIZER );
 
         // Get the schema
-        Schema schema = getSchema( schemaName, targetRegistries );
-
-        if ( schema == null )
+        if ( !schemaManager.isSchemaLoaded( schemaName ) )
         {
             // The schema is not loaded. We can't create the requested Normalizer
             String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + ", as
the associated schema (" +
@@ -608,6 +605,17 @@
             throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
         }
         
+        Schema schema = getSchema( schemaName, targetRegistries );
+
+        if ( schema == null )
+        {
+            // The schema is disabled. We still have to update the backend
+            String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + " into
the registries, "+
+                "as the associated schema (" + schemaName + ") is disabled";
+            LOG.info( msg );
+            schema = schemaManager.getLoadedSchema( schemaName );
+        }
+        
         // The FQCN
         String className = getFqcn( entry, SchemaConstants.NORMALIZER );
         



Mime
View raw message