directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r835099 - 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 22:21:53 GMT
Author: elecharny
Date: Wed Nov 11 22:21:49 2009
New Revision: 835099

URL: http://svn.apache.org/viewvc?rev=835099&view=rev
Log:
Fix for Syntax handler

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.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/SyntaxSynchronizer.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/SyntaxSynchronizer.java?rev=835099&r1=835098&r2=835099&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
Wed Nov 11 22:21:49 2009
@@ -39,6 +39,7 @@
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
+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;
@@ -109,27 +110,53 @@
         
         // Build the new Syntax 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();
+        
         LdapSyntax syntax = factory.getSyntax( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
 
-        // Applies the Registries to this Syntax 
-        Schema schema = schemaManager.getLoadedSchema( schemaName );
-
-        if ( schema.isEnabled() && syntax.isEnabled() )
+        if ( syntax != null )
         {
-            syntax.applyRegistries( schemaManager.getRegistries() );
-        }
-        
-        // Associates this Syntax with the schema
-        addToSchema( syntax, schemaName );
+            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;
+            }
 
-        // Don't inject the modified element if the schema is disabled
-        if ( isSchemaEnabled( schemaName ) )
-        {
-            // Update the using table, as a Syntax is associated with a SyntaxChecker
-            schemaManager.getRegistries().addReference( syntax, syntax.getSyntaxChecker()
);
+            // At this point, the constructed Syntax has not been checked against the 
+            // existing Registries. It may be broken , it will be checked
+            // there, if the schema and the Syntax are both enabled.
+            Schema schema = schemaManager.getLoadedSchema( schemaName );
+            
+            if ( schema.isEnabled() && syntax.isEnabled() )
+            {
+                syntax.applyRegistries( schemaManager.getRegistries() );
+            }
+            
+            
+            // Associates this Syntax with the schema
+            addToSchema( syntax, schemaName );
 
-            schemaManager.register( syntax );
-            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+            // Don't inject the modified element if the schema is disabled
+            if ( isSchemaEnabled( schemaName ) )
+            {
+                // Update the using table, as a Syntax is associated with a SyntaxChecker
+                schemaManager.getRegistries().addReference( syntax, syntax.getSyntaxChecker()
);
+
+                schemaManager.register( syntax );
+                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+            }
         }
         else
         {

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.java?rev=835099&r1=835098&r2=835099&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.java
Wed Nov 11 22:21:49 2009
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -153,7 +154,38 @@
         assertTrue( isOnDisk( dn ) );
     }
 
-
+    
+    @Test
+    public void testAddSyntaxToUnloadedSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntax",
+            "m-oid", OID,
+            "m-description", DESCRIPTION0 );
+        
+        // nis is by default inactive
+        LdapDN dn = getSyntaxContainer( "notloaded" );
+        dn.add( "m-oid" + "=" + OID );
+        createDummySyntaxChecker( OID, "nis" );
+        
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Expected result.
+        }
+        
+        assertFalse( "adding new syntax to disabled schema should not register it into the
registries", 
+            schemaManager.getLdapSyntaxRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
+    }
+    
+    
     @Test
     public void testDeleteSyntaxFromEnabledSchema() throws Exception
     {

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=835099&r1=835098&r2=835099&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 22:21:49 2009
@@ -688,9 +688,7 @@
         String oid = getOid( entry, SchemaConstants.SYNTAX );
 
         // 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 Syntax
             String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + ", as the
associated schema (" +
@@ -699,6 +697,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 SyntaxChecker " + entry.getDn().getUpName() + "
into the registries, "+
+                "as the associated schema (" + schemaName + ") is disabled";
+            LOG.info( msg );
+            schema = schemaManager.getLoadedSchema( schemaName );
+        }
+
         // Create the new LdapSyntax instance
         LdapSyntax syntax = new LdapSyntax( oid );
         



Mime
View raw message