directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r885745 - /directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/
Date Tue, 01 Dec 2009 11:42:49 GMT
Author: elecharny
Date: Tue Dec  1 11:42:48 2009
New Revision: 885745

URL: http://svn.apache.org/viewvc?rev=885745&view=rev
Log:
Fixing all the 'add' methods

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
    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/MatchingRuleSynchronizer.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-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.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/AttributeTypeSynchronizer.java?rev=885745&r1=885744&r2=885745&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
Tue Dec  1 11:42:48 2009
@@ -106,6 +106,8 @@
             {
                 // Apply the addition to the real registries
                 add( errors, schemaManager.getRegistries(), attributeType );
+                
+                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
             }
             else
             {
@@ -120,15 +122,10 @@
         {
             // At least, we register the OID in the globalOidRegistry, and associates it
with the
             // schema
-
-            // Associate the AT with its schema
             schemaManager.getRegistries().associateWithSchema( attributeType );
 
-            // And register the attributeType in the globalOidregistry
-            registerOids( attributeType );
+            LOG.debug( "Added {} into the disabled schema {}", dn.getUpName(), schemaName
);
         }
-    
-        LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName );
     }
 
 

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=885745&r1=885744&r2=885745&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
Tue Dec  1 11:42:48 2009
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.NamingException;
@@ -118,31 +119,28 @@
         // existing Registries. It will be checked there, if the schema and the 
         // LdapComparator are both enabled.
         Schema schema = schemaManager.getLoadedSchema( schemaName );
-        List<Throwable> errors = null;
+        List<Throwable> errors = new ArrayList<Throwable>();
 
         if ( schema.isEnabled() && comparator.isEnabled() )
         {
             // As we may break the registries, work on a cloned registries
             Registries clonedRegistries = schemaManager.getRegistries().clone();
             
-            errors = applyAdd( clonedRegistries, comparator );
+            // Inject the newly created Comparator in the cloned registries
+            add( errors, clonedRegistries, comparator );
             
             // Remove the cloned registries
             clonedRegistries.clear();
             
-            // If we didn't get any error, swap the registries
+            // If we didn't get any error, add the Comparator into the real registries
             if ( errors.isEmpty() )
             {
                 // Apply the addition to the real registries
-                schemaManager.getRegistries().applyAdd( comparator );
+                add( errors, schemaManager.getRegistries(), comparator );
             }
             else
             {
                 // We have some error : reject the addition and get out
-                // Destroy the cloned registries
-                clonedRegistries.clear();
-                
-                // The schema is disabled. We still have to update the backend
                 String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + "
into the registries, "+
                     "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
                 LOG.info( msg );
@@ -153,6 +151,8 @@
         }
         else
         {
+            LOG.debug( "The comparator {} cannot be added in schema {}", dn.getUpName(),
schemaName );
+
             // At least, we associates the comparator with the schema
             schemaManager.getRegistries().associateWithSchema( comparator );
         }

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=885745&r1=885744&r2=885745&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
Tue Dec  1 11:42:48 2009
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.NamingException;
@@ -113,6 +114,7 @@
         String schemaName = getSchemaName( dn );
         
         MatchingRule matchingRule = factory.getMatchingRule( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
+        List<Throwable> errors = new ArrayList<Throwable>();
 
         // At this point, the constructed MatchingRule has not been checked against the 
         // existing Registries. It may be broken (missing SUP, or such), it will be checked
@@ -123,38 +125,23 @@
         {
             // As we may break the registries, work on a cloned registries
             Registries clonedRegistries = schemaManager.getRegistries().clone();
-            
-            // Relax the cloned registries
-            clonedRegistries.setRelaxed();
-            
-            // Register the MatchingRule in the cloned registries
-            clonedRegistries.register( matchingRule );
-        
-            // Associate the MatchingRule with its schema
-            clonedRegistries.associateWithSchema( matchingRule );
 
-            // Apply the registries to the newly created MatchingRule
-            matchingRule.applyRegistries( clonedRegistries );
+            add( errors, clonedRegistries, matchingRule );
             
-            // Update the cross references for MatchingRule
-            clonedRegistries.addCrossReferences( matchingRule );
-            
-            // Check the registries now
-            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            // Remove the cloned registries
+            clonedRegistries.clear();
             
             // If we didn't get any error, swap the registries
-            if ( errors.size() == 0 )
+            if ( errors.isEmpty() )
             {
-                clonedRegistries.setStrict();
-                schemaManager.swapRegistries( clonedRegistries  );
+                // Apply the addition to the real registries
+                add( errors, schemaManager.getRegistries(), matchingRule );
+
+                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
             }
             else
             {
                 // We have some error : reject the addition and get out
-                // Destroy the cloned registries
-                clonedRegistries.clear();
-                
-                // The schema is disabled. We still have to update the backend
                 String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() +
" into the registries, "+
                     "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
                 LOG.info( msg );
@@ -165,12 +152,9 @@
         {
             // At least, we register the OID in the globalOidRegistry, and associates it
with the
             // schema
-
-            // Associate the MatchingRule with its schema
             schemaManager.getRegistries().associateWithSchema( matchingRule );
 
-            // And register the macthingRule in the globalOidregistry
-            registerOids( matchingRule );
+            LOG.debug( "Added {} into the disabled 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=885745&r1=885744&r2=885745&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
Tue Dec  1 11:42:48 2009
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.NamingException;
@@ -38,6 +39,7 @@
 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.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -108,45 +110,48 @@
         // 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 );
+
+        // At this point, the constructed Normalizer has not been checked against the 
+        // existing Registries. It will be checked there, if the schema and the 
+        // Normalizer are both enabled.
+        Schema schema = schemaManager.getLoadedSchema( schemaName );
+        List<Throwable> errors = new ArrayList<Throwable>();
         
-        if ( normalizer != null )
+        if ( schema.isEnabled() && normalizer.isEnabled() )
         {
-            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
+            
+            // Inject the newly created Normalizer in the cloned registries
+            add( errors, clonedRegistries, normalizer );
+            
+            // Remove the cloned registries
+            clonedRegistries.clear();
             
-            if ( errors.size() == 0 )
+            // If we didn't get any error, add the Normalizer into the real registries
+            if ( errors.isEmpty() )
             {
-                clonedRegistries.setStrict();
-                schemaManager.swapRegistries( clonedRegistries  );
+                // Apply the addition to the real registries
+                add( errors, schemaManager.getRegistries(), normalizer );
             }
             else
             {
                 // We have some error : reject the addition and get out
-                return;
+                String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + "
into the registries, "+
+                    "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
+                LOG.info( msg );
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
-
-            // 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.add( normalizer );
-                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
-            }
+            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
         }
         else
         {
             LOG.debug( "The normalizer {} cannot be added in schema {}", dn.getUpName(),
schemaName );
+
+            // At least, we associates the Normalizer with the schema
+            schemaManager.getRegistries().associateWithSchema( normalizer );
         }
     }
 

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.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/ObjectClassSynchronizer.java?rev=885745&r1=885744&r2=885745&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java
Tue Dec  1 11:42:48 2009
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.NamingException;
@@ -38,6 +39,7 @@
 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.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -107,70 +109,47 @@
         // Build the new ObjectClass 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();
-        
         ObjectClass objectClass = factory.getObjectClass( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
+        List<Throwable> errors = new ArrayList<Throwable>();
 
-        // if the AT is null, that means the schema is disabled
-        if ( objectClass != null )
+        // At this point, the constructed ObjectClass has not been checked against the 
+        // existing Registries. It may be broken (missing SUP, or such), it will be checked
+        // there, if the schema and the ObjectClass are both enabled.
+        Schema schema = schemaManager.getLoadedSchema( schemaName );
+        
+        if ( schema.isEnabled() && objectClass.isEnabled() )
         {
-            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
+
+            add( errors, clonedRegistries, objectClass );
+            
+            // Remove the cloned registries
+            clonedRegistries.clear();
             
-            if ( errors.size() == 0 )
+            // If we didn't get any error, swap the registries
+            if ( errors.isEmpty() )
             {
-                clonedRegistries.setStrict();
-                schemaManager.swapRegistries( clonedRegistries  );
+                // Apply the addition to the real registries
+                add( errors, schemaManager.getRegistries(), objectClass );
+
+                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
             }
             else
             {
                 // We have some error : reject the addition and get out
-                return;
-            }
-            // At this point, the constructed ObjectClass has not been checked against the

-            // existing Registries. It may be broken (missing SUPs), it will be checked
-            // there, if the schema and the ObjectClass are both enabled.
-            Schema schema = schemaManager.getLoadedSchema( schemaName );
-    
-            if ( schema.isEnabled() && objectClass.isEnabled() )
-            {
-                objectClass.applyRegistries( schemaManager.getRegistries() );
-            }
-            
-            // Associates this ObjectClass with the schema
-            addToSchema( objectClass, schemaName );
-    
-            if ( isSchemaEnabled( schemaName ) )
-            {
-                // Update the referenced and referencing objects
-                // The MAY AttributeTypes
-                for ( AttributeType may : objectClass.getMayAttributeTypes() )
-                {
-                    schemaManager.getRegistries().addReference( objectClass, may );
-                }
-                
-                // The MUST AttributeTypes
-                for ( AttributeType must : objectClass.getMayAttributeTypes() )
-                {
-                    schemaManager.getRegistries().addReference( objectClass, must );
-                }
-                
-                // The superiors
-                for ( ObjectClass superior : objectClass.getSuperiors() )
-                {
-                    schemaManager.getRegistries().addReference( objectClass, superior );
-                }
-                
-                schemaManager.add( objectClass );
-                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+                String msg = "Cannot add the ObjectClass " + entry.getDn().getUpName() +
" into the registries, "+
+                    "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
+                LOG.info( msg );
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
         }
         else
         {
-            registerOids( objectClass );
+            // At least, we register the OID in the globalOidRegistry, and associates it
with the
+            // schema
+            schemaManager.getRegistries().associateWithSchema( objectClass );
+
             LOG.debug( "Added {} into the disabled schema {}", dn.getUpName(), schemaName
);
         }
     }
@@ -197,7 +176,7 @@
 
         if ( schema.isEnabled() && objectClass.isEnabled() )
         {
-            objectClass.applyRegistries( schemaManager.getRegistries() );
+            objectClass.applyRegistries( null, schemaManager.getRegistries() );
         }
         
         String oid = objectClass.getOid();

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.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/SyntaxCheckerSynchronizer.java?rev=885745&r1=885744&r2=885745&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java
Tue Dec  1 11:42:48 2009
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.naming.NamingException;
@@ -38,6 +39,7 @@
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.schema.registries.Schema;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -109,45 +111,48 @@
         // Build the new SyntaxChecker 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();
-        
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
 
-        if ( syntaxChecker != null )
+        // At this point, the constructed SyntaxChecker has not been checked against the

+        // existing Registries. It will be checked there, if the schema and the 
+        // SyntaxChecker are both enabled.
+        Schema schema = schemaManager.getLoadedSchema( schemaName );
+        List<Throwable> errors = new ArrayList<Throwable>();
+        
+        if ( schema.isEnabled() && syntaxChecker.isEnabled() )
         {
-            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
+            
+            // Inject the newly created SyntaxChecker in the cloned registries
+            add( errors, clonedRegistries, syntaxChecker );
+            
+            // Remove the cloned registries
+            clonedRegistries.clear();
             
-            if ( errors.size() == 0 )
+            // If we didn't get any error, add the SyntaxChecker into the real registries
+            if ( errors.isEmpty() )
             {
-                clonedRegistries.setStrict();
-                schemaManager.swapRegistries( clonedRegistries  );
+                // Apply the addition to the real registries
+                add( errors, schemaManager.getRegistries(), syntaxChecker );
             }
             else
             {
                 // We have some error : reject the addition and get out
-                return;
+                String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName()
+ " into the registries, "+
+                    "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
+                LOG.info( msg );
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
-
-            // At this point, the constructed syntaxChecker 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() && syntaxChecker.isEnabled() )
-            {
-                syntaxChecker.applyRegistries( schemaManager.getRegistries() );
-                addToSchema( syntaxChecker, schemaName );
-                schemaManager.add( syntaxChecker );
-                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
-            }
+            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
         }
         else
         {
             LOG.debug( "The syntaxChecker {} cannot be added in schema {}", dn.getUpName(),
schemaName );
+
+            // At least, we associates the syntaxChecker with the schema
+            schemaManager.getRegistries().associateWithSchema( syntaxChecker );
         }
     }
 

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=885745&r1=885744&r2=885745&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
Tue Dec  1 11:42:48 2009
@@ -41,6 +41,7 @@
 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.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -111,57 +112,49 @@
         // 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 );
 
-        if ( syntax != null )
+        // At this point, the constructed Syntax has not been checked against the 
+        // existing Registries. It may be broken (missing SUP, or such), it will be checked
+        // there, if the schema and the Syntax are both enabled.
+        Schema schema = schemaManager.getLoadedSchema( schemaName );
+        List<Throwable> errors = new ArrayList<Throwable>();
+        
+        if ( schema.isEnabled() && syntax.isEnabled() )
         {
-            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
             
-            if ( errors.size() == 0 )
-            {
-                clonedRegistries.setStrict();
-                schemaManager.swapRegistries( clonedRegistries  );
-            }
-            else
-            {
-                // We have some error : reject the addition and get out
-                return;
-            }
-
-            // 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() );
-            }
+            // Inject the newly created Syntax in the cloned registries
+            add( errors, clonedRegistries, syntax );
             
+            // Remove the cloned registries
+            clonedRegistries.clear();
             
-            // Associates this Syntax with the schema
-            addToSchema( syntax, schemaName );
-
-            // Don't inject the modified element if the schema is disabled
-            if ( isSchemaEnabled( schemaName ) )
+            // If we didn't get any error, apply the addition to the real retistries
+            if ( errors.isEmpty() )
             {
-                // Update the using table, as a Syntax is associated with a SyntaxChecker
-                schemaManager.getRegistries().addReference( syntax, syntax.getSyntaxChecker()
);
+                // Apply the addition to the real registries
+                add( errors, schemaManager.getRegistries(), syntax );
 
-                schemaManager.add( syntax );
                 LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
             }
+            else
+            {
+                // We have some error : reject the addition and get out
+                String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + " into
the registries, "+
+                    "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
+                LOG.info( msg );
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+            }
         }
         else
         {
-            registerOids( syntax );
-            LOG.debug( "Added {} into the disabled schema {}", dn.getUpName(), schemaName
);
+            // At least, we register the OID in the globalOidRegistry, and associates it
with the
+            // schema
+            schemaManager.getRegistries().associateWithSchema( syntax );
+
+            LOG.debug( "The Syntax {} cannot be added in schema {}", dn.getUpName(), schemaName
);
         }
     }
 
@@ -240,7 +233,7 @@
 
         if ( schema.isEnabled() && syntax.isEnabled() )
         {
-            syntax.applyRegistries( schemaManager.getRegistries() );
+            syntax.applyRegistries( null, schemaManager.getRegistries() );
         }
 
         String oid = syntax.getOid();



Mime
View raw message