directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r835116 - 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 23:00:59 GMT
Author: elecharny
Date: Wed Nov 11 23:00:59 2009
New Revision: 835116

URL: http://svn.apache.org/viewvc?rev=835116&view=rev
Log:
Fixed the MatchingRule handling

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.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/MatchingRuleSynchronizer.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/MatchingRuleSynchronizer.java?rev=835116&r1=835115&r2=835116&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java
Wed Nov 11 23:00:59 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;
@@ -32,6 +34,7 @@
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 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;
@@ -106,41 +109,65 @@
         
         // Build the new MatchingRule from the given entry
         String schemaName = getSchemaName( dn );
-        MatchingRule matchingRule = factory.getMatchingRule( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
         
-        // At this point, the constructed MatchingRule has not been checked against the 
-        // existing Registries. It may be broken (missing SYNTAX), it will be checked
-        // there, if the schema and the MatchingRule are both enabled.
-        Schema schema = schemaManager.getLoadedSchema( schemaName );
-
-        if ( schema.isEnabled() && matchingRule.isEnabled() )
-        {
-            matchingRule.applyRegistries( schemaManager.getRegistries() );
-        }
+        // At this point, as we may break the registries, work on a cloned registries
+        Registries clonedRegistries = schemaManager.getRegistries().clone();
         
-        // Associates this MatchingRule with the schema
-        addToSchema( matchingRule, schemaName );
-
-        // Don't inject the modified element if the schema is disabled
-        if ( isSchemaEnabled( schemaName ) )
+        // Relax the cloned registries
+        clonedRegistries.setRelaxed();
+        
+        MatchingRule matchingRule = factory.getMatchingRule( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
+        
+        // if the matchingRule is null, that means the schema is disabled
+        if ( matchingRule != null )
         {
-            // Update the referenced and referencing objects
-            // The Syntax
-            schemaManager.getRegistries().addReference( matchingRule, matchingRule.getSyntax()
);
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
             
-            // The Normalizer
-            schemaManager.getRegistries().addReference( matchingRule, matchingRule.getNormalizer()
);
+            if ( errors.size() == 0 )
+            {
+                clonedRegistries.setStrict();
+                schemaManager.swapRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the addition and get out
+                return;
+            }
             
-            // The Comparator
-            schemaManager.getRegistries().addReference( matchingRule, matchingRule.getLdapComparator()
);
+            // At this point, the constructed MatchingRule has not been checked against the

+            // existing Registries. It may be broken (missing SYNTAX), it will be checked
+            // there, if the schema and the MatchingRule are both enabled.
+            Schema schema = schemaManager.getLoadedSchema( schemaName );
+    
+            if ( schema.isEnabled() && matchingRule.isEnabled() )
+            {
+                matchingRule.applyRegistries( schemaManager.getRegistries() );
+            }
             
-            schemaManager.register( matchingRule );
-            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
-        }
-        else
-        {
-            registerOids( matchingRule );
-            LOG.debug( "Added {} into the disabled schema {}", dn.getUpName(), schemaName
);
+            // Associates this MatchingRule with the schema
+            addToSchema( matchingRule, schemaName );
+    
+            // Don't inject the modified element if the schema is disabled
+            if ( isSchemaEnabled( schemaName ) )
+            {
+                // Update the referenced and referencing objects
+                // The Syntax
+                schemaManager.getRegistries().addReference( matchingRule, matchingRule.getSyntax()
);
+                
+                // The Normalizer
+                schemaManager.getRegistries().addReference( matchingRule, matchingRule.getNormalizer()
);
+                
+                // The Comparator
+                schemaManager.getRegistries().addReference( matchingRule, matchingRule.getLdapComparator()
);
+                
+                schemaManager.register( matchingRule );
+                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+            }
+            else
+            {
+                registerOids( matchingRule );
+                LOG.debug( "Added {} into the disabled schema {}", dn.getUpName(), schemaName
);
+            }
         }
     }
 

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java?rev=835116&r1=835115&r2=835116&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
Wed Nov 11 23:00:59 2009
@@ -26,6 +26,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -139,6 +140,36 @@
         assertTrue( isOnDisk( dn ) );
     }
     
+    
+    @Test
+    public void testAddMatchingRuleToUnloadedSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaMatchingRule",
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0 );
+        
+        LdapDN dn = getMatchingRuleContainer( "notloaded" );
+        dn.add( "m-oid" + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Excpected result
+        }
+        
+        assertFalse( "adding new matchingRule to disabled schema should not register it into
the registries", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
+    }
+    
 
     @Test
     public void testDeleteMatchingRuleFromEnabledSchema() 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=835116&r1=835115&r2=835116&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 23:00:59 2009
@@ -739,9 +739,7 @@
         String oid = getOid( entry, SchemaConstants.MATCHING_RULE );
 
         // 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 MatchingRule
             String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() + ",
as the associated schema (" +
@@ -750,6 +748,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 MatchingRule " + entry.getDn().getUpName() + " into
the registries, "+
+                "as the associated schema (" + schemaName + ") is disabled";
+            LOG.info( msg );
+            schema = schemaManager.getLoadedSchema( schemaName );
+        }
+
         MatchingRule matchingRule = new MatchingRule( oid );
 
         // The syntax field



Mime
View raw message