directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r881403 - /directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/
Date Tue, 17 Nov 2009 17:40:56 GMT
Author: elecharny
Date: Tue Nov 17 17:40:56 2009
New Revision: 881403

URL: http://svn.apache.org/viewvc?rev=881403&view=rev
Log:
Many cleanups and bug fixes in the synchronizers, for Add and Delete opersions, on AT and
C

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java
    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/SchemaSynchronizer.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.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/AbstractRegistrySynchronizer.java?rev=881403&r1=881402&r2=881403&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java
Tue Nov 17 17:40:56 2009
@@ -35,13 +35,14 @@
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
-import org.apache.directory.shared.ldap.schema.SchemaWrapper;
+import org.apache.directory.shared.ldap.schema.SchemaObjectWrapper;
 import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.apache.directory.shared.schema.loader.ldif.SchemaEntityFactory;
 import org.slf4j.Logger;
@@ -172,6 +173,26 @@
 
     
     /**
+     * Check that a SchemaObject exists in the global OidRegsitry, and if so,
+     * return it.
+     */
+    protected SchemaObject checkOidExists( ServerEntry entry ) throws Exception
+    {
+        String oid = getOid( entry );
+
+        if ( schemaManager.getOidRegistry().hasOid( oid ) )
+        {
+            return schemaManager.getOidRegistry().getSchemaObject( oid );
+        }
+        else
+        {
+            throw new LdapSchemaViolationException( "Oid " + oid + " for new schema entity
does not exist.",
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+    
+    /**
      * Checks that the parent DN is a valid DN
      */
     protected void checkParent( LdapDN newParent, SchemaManager schemaManager, String objectType
) throws NamingException
@@ -206,7 +227,7 @@
 
         if ( schemaManager.getOidRegistry().hasOid( oid ) )
         {
-            throw new LdapNamingException( "Oid " + oid + " for new schema entity is not
unique.",
+            throw new LdapSchemaViolationException( "Oid " + oid + " for new schema entity
is not unique.",
                 ResultCodeEnum.OTHER );
         }
     }
@@ -216,7 +237,7 @@
     {
         if ( schemaManager.getOidRegistry().hasOid( oid ) )
         {
-            throw new LdapNamingException( "Oid " + oid + " for new schema entity is not
unique.",
+            throw new LdapSchemaViolationException( "Oid " + oid + " for new schema entity
is not unique.",
                 ResultCodeEnum.OTHER );
         }
     }
@@ -231,7 +252,7 @@
         if ( isSchemaLoaded( schemaName ) )
         {
             // Get the set of all the SchemaObjects associated with this schema
-            Set<SchemaWrapper> schemaObjects = schemaManager.getRegistries().getObjectBySchemaName().get(
schemaName );
+            Set<SchemaObjectWrapper> schemaObjects = schemaManager.getRegistries().getObjectBySchemaName().get(
schemaName );
             
             if ( schemaObjects == null )
             {
@@ -239,9 +260,9 @@
                 schemaObjects = schemaManager.getRegistries().addSchema( schemaName );
             }
             
-            SchemaWrapper schemaWrapper = new SchemaWrapper( schemaObject );
+            SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper( schemaObject
);
             
-            if ( schemaObjects.contains( schemaWrapper ) )
+            if ( schemaObjects.contains( schemaObjectWrapper ) )
             {
                 String msg = "Cannot inject " + schemaObject.getName() + " into " + schemaName
+ 
                 " as this schema already contains this element";
@@ -250,7 +271,7 @@
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
             
-            schemaObjects.add( schemaWrapper );
+            schemaObjects.add( schemaObjectWrapper );
             LOG.debug( "The SchemaObject {} has been added to the schema {}", schemaObject,
schemaName   );
         }
         else
@@ -274,11 +295,11 @@
     {
         if ( isSchemaLoaded( schemaName ) )
         {
-            Set<SchemaWrapper> schemaObjects = schemaManager.getRegistries().getObjectBySchemaName().get(
schemaName );
+            Set<SchemaObjectWrapper> schemaObjects = schemaManager.getRegistries().getObjectBySchemaName().get(
schemaName );
 
-            SchemaWrapper schemaWrapper = new SchemaWrapper( schemaObject );
+            SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper( schemaObject
);
             
-            if ( !schemaObjects.contains( schemaWrapper ) )
+            if ( !schemaObjects.contains( schemaObjectWrapper ) )
             {
                 String msg = "Cannot remove " + schemaObject.getName() + " from " + schemaName
+ 
                 " as this schema does not contain this element";
@@ -287,7 +308,7 @@
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
             
-            schemaObjects.remove( schemaWrapper );
+            schemaObjects.remove( schemaObjectWrapper );
             LOG.debug(  "The SchemaObject {} has been removed from the schema {}", schemaObject,
schemaName );
         }
         else
@@ -386,9 +407,9 @@
     {
         StringBuilder sb = new StringBuilder();
         
-        Set<SchemaWrapper> useds = schemaManager.getRegistries().getUsedBy( schemaObject
);
+        Set<SchemaObjectWrapper> useds = schemaManager.getRegistries().getUsedBy( schemaObject
);
         
-        for ( SchemaWrapper used:useds )
+        for ( SchemaObjectWrapper used:useds )
         {
             sb.append( used );
             sb.append( '\n' );

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=881403&r1=881402&r2=881403&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 Nov 17 17:40:56 2009
@@ -81,14 +81,14 @@
         // Build the new AttributeType from the given entry
         String schemaName = getSchemaName( dn );
         
-        AttributeType at = factory.getAttributeType( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
+        AttributeType attributeType = factory.getAttributeType( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
         
         // At this point, the constructed AttributeType 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 AttributeType are both enabled.
         Schema schema = schemaManager.getLoadedSchema( schemaName );
         
-        if ( schema.isEnabled() && at.isEnabled() )
+        if ( schema.isEnabled() && attributeType.isEnabled() )
         {
             // As we may break the registries, work on a cloned registries
             Registries clonedRegistries = schemaManager.getRegistries().clone();
@@ -96,8 +96,17 @@
             // Relax the cloned registries
             clonedRegistries.setRelaxed();
             
+            // Associates this AttributeType with the schema
+            clonedRegistries.register( attributeType );
+            
+            // Associate the AT with its schema
+            clonedRegistries.associateWithSchema( attributeType );
+
             // Apply the registries to the newly created AT
-            at.applyRegistries( schemaManager.getRegistries() );
+            attributeType.applyRegistries( clonedRegistries );
+            
+            // Update the cross references for AT
+            clonedRegistries.addCrossReferences( attributeType );
             
             // Check the registries now
             List<Throwable> errors = clonedRegistries.checkRefInteg();
@@ -121,10 +130,18 @@
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
         }
-    
-        // Associates this AttributeType with the schema
-        schemaManager.register( at );
+        else
+        {
+            // 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 enabled schema {}", dn.getUpName(), schemaName );
     }
 
@@ -169,66 +186,61 @@
         // The parent DN must be ou=attributetypes,cn=<schemaName>,ou=schema
         checkParent( parentDn, schemaManager, SchemaConstants.ATTRIBUTE_TYPE );
         
-        // Get the AttributeType from the given entry ( it has been grabbed from the server
earlier)
-        String schemaName = getSchemaName( entry.getDn() );
+        // Test that the Oid exists
+        AttributeType attributeType = (AttributeType)checkOidExists( entry );
         
-        AttributeType attributeType = factory.getAttributeType( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
+        // Get the SchemaName
+        String schemaName = getSchemaName( entry.getDn() );
         
-        // Applies the Registries to this AttributeType 
+        // Get the schema 
         Schema schema = schemaManager.getLoadedSchema( schemaName );
         
         if ( schema.isEnabled() && attributeType.isEnabled() )
         {
-            attributeType.applyRegistries( schemaManager.getRegistries() );
-        }
-        
-        String oid = attributeType.getOid();
-        
-        // Depending on the fact that the schema is enabled or disabled, we will have
-        // to unregister the AttributeType from the registries or not. In any case,
-        // we have to remove it from the schemaPartition.
-        // We also have to check that the removal will let the server Registries in a 
-        // stable state, which means in this case that we don't have any AttributeType
-        // directly inherit from the removed AttributeType, and that no ObjectClass
-        // has this AttributeType in its MAY or MUST...
-        // We will also have to remove an index that has been set on this AttributeType.
-        if ( schema.isEnabled() )
-        {
-            if ( schemaManager.getRegistries().isReferenced( attributeType ) )
-            {
-                String msg = "Cannot delete " + entry.getDn().getUpName() + ", as there are
some " +
-                    " dependant SchemaObjects :\n" + getReferenced( attributeType );
-                LOG.warn( msg );
-                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
-            }
-        }
-
-        // Remove the AttributeType from the schema content
-        deleteFromSchema( attributeType, schemaName );
-
-        // Update the Registries now
-        if ( schemaManager.getAttributeTypeRegistry().contains( oid ) )
-        {
-            // Update the references.
-            // The Syntax
-            schemaManager.getRegistries().delReference( attributeType, attributeType.getSyntax()
);
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
             
-            // The Superior
-            schemaManager.getRegistries().delReference( attributeType, attributeType.getSuperior()
);
+            // Relax the cloned registries
+            clonedRegistries.setRelaxed();
             
-            // The MatchingRules
-            schemaManager.getRegistries().delReference( attributeType, attributeType.getEquality()
);
-            schemaManager.getRegistries().delReference( attributeType, attributeType.getOrdering()
);
-            schemaManager.getRegistries().delReference( attributeType, attributeType.getSubstring()
);
+            // Remove this AttributeType from the Registries
+            clonedRegistries.unregister( attributeType );
             
-            // Update the Registry
-            schemaManager.unregister( attributeType );
+            // Remove the AttributeType from the schema/SchemaObject Map
+            clonedRegistries.dissociateFromSchema( attributeType );
+
+            // Update the cross references for AT
+            clonedRegistries.delCrossReferences( attributeType );
+            
+            // Check the registries now
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
             
-            LOG.debug( "Removed {} from the enabled schema {}", attributeType, schemaName
);
+            // If we didn't get any error, swap the registries
+            if ( errors.size() == 0 )
+            {
+                clonedRegistries.setStrict();
+                schemaManager.swapRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the deletion and get out
+                // Destroy the cloned registries
+                schemaManager.destroy( clonedRegistries );
+                
+                // The schema is disabled. We still have to update the backend
+                String msg = "Cannot delete the AttributeType " + 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
         {
             unregisterOids( attributeType );
+            
+            // Remove the AttributeType from the schema/SchemaObject Map
+            schemaManager.getRegistries().dissociateFromSchema( attributeType );
+            
             LOG.debug( "Removed {} from the disabled schema {}", attributeType, 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=881403&r1=881402&r2=881403&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 Nov 17 17:40:56 2009
@@ -31,6 +31,7 @@
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
@@ -113,50 +114,56 @@
         
         LdapComparator<?> comparator = factory.getLdapComparator( schemaManager, entry,
schemaManager.getRegistries(), schemaName );
         
-        if ( comparator != null )
+        // At this point, the constructed LdapComparator 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() && comparator.isEnabled() )
         {
-            // At this point, the constructed LdapComparator 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 );
+            // 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();
+            
+            // Associates this Comparator with the schema
+            clonedRegistries.register( comparator );
+            
+            // Associate the Comparator with its schema
+            clonedRegistries.associateWithSchema( comparator );
+
+            // Apply the registries to the newly created Comparator
+            comparator.applyRegistries( clonedRegistries );
+            
+            // Check the registries now
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
             
-            if ( schema.isEnabled() && comparator.isEnabled() )
+            // If we didn't get any error, swap the registries
+            if ( errors.size() == 0 )
             {
-                // 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();
-                
-                comparator.applyRegistries( schemaManager.getRegistries() );
-                
-                List<Throwable> errors = clonedRegistries.checkRefInteg();
+                clonedRegistries.setStrict();
+                schemaManager.swapRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the addition and get out
+                // Destroy the cloned registries
+                schemaManager.destroy( clonedRegistries );
                 
-                if ( errors.size() == 0 )
-                {
-                    clonedRegistries.setStrict();
-                    schemaManager.swapRegistries( clonedRegistries  );
-                }
-                else
-                {
-                    // We have some error : reject the addition and get out
-                    // TODO : we have to destroy the cloned registries
-                    //schemaManager.destroy( clonedRegistries );
-                    // 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 );
-                    throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
-                }
-
-                schemaManager.register( comparator );
-
-                LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
+                // 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 );
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
+            
+            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
         }
         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 );
         }
     }
 
@@ -173,35 +180,98 @@
         // The parent DN must be ou=comparators,cn=<schemaName>,ou=schema
         checkParent( parentDn, schemaManager, SchemaConstants.COMPARATOR );
         
-        // Get the Comparator from the given entry ( it has been grabbed from the server
earlier)
+        // Test that the Oid exists
+        LdapComparator<?> comparator = null;
+        
+        try
+        {
+            comparator = (LdapComparator<?>)checkComparatorOidExists( entry );
+        }
+        catch ( LdapSchemaViolationException lsve )
+        {
+            // The comparator does not exist : may be normal, if the schema is disabled
+            // We will check that by looking on the disk
+            String schemaName = getSchemaName( dn );
+            comparator = factory.getLdapComparator( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
+            
+            if ( schemaManager.getRegistries().contains( comparator ) )
+            {
+                // Remove the Comparator from the schema/SchemaObject Map
+                schemaManager.getRegistries().dissociateFromSchema( comparator);
+
+                // Ok, we can exit. 
+                return;
+            }
+            else
+            {
+                // Ok, definitively an error
+                String msg = "Cannot delete the Comparator " + entry.getDn().getUpName()
+ " as it "+
+                    "does not exist in any schema";
+                LOG.info( msg );
+                throw new LdapSchemaViolationException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+            }
+        }
+        
+        // Get the SchemaName
         String schemaName = getSchemaName( entry.getDn() ); 
-        LdapComparator<?> comparator = factory.getLdapComparator( schemaManager, entry,
schemaManager.getRegistries(), schemaName );
         
-        String oid = comparator.getOid();
+        // Get the Schema
+        Schema schema = schemaManager.getLoadedSchema( schemaName );
         
-        if ( isSchemaEnabled( schemaName ) )
+        if ( schema.isEnabled() && comparator.isEnabled() )
         {
-            if ( schemaManager.getRegistries().isReferenced( comparator ) )
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
+            
+            // Relax the cloned registries
+            clonedRegistries.setRelaxed();
+            
+            // Before removing a comparator, we have to check that there are no MR pointing
+            // on it, as it won't be done during the integrity check : in this case, the
+            // check will create a default comparator instead of raising an error...
+            if ( clonedRegistries.getMatchingRuleRegistry().contains( comparator.getOid()
) )
             {
-                String msg = "Cannot delete " + entry.getDn().getUpName() + ", as there are
some " +
-                " dependant SchemaObjects :\n" + getReferenced( comparator );
-                LOG.warn( msg );
+                // We have some error : reject the deletion and get out
+                // Destroy the cloned registries
+                schemaManager.destroy( clonedRegistries );
+
+                String msg = "There is at least one MatchingRule using the Comparator with
OID " + comparator.getOid();
+                LOG.debug( msg );
+                
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
 
-            // As the comparator has the same OID than its attached MR, it won't
-            // be loaded into the schemaManager if it's disabled
-            deleteFromSchema( comparator, schemaName );
-        }
+            // Remove this Comparator from the Registries
+            clonedRegistries.unregister( comparator );
 
-        if ( schemaManager.getComparatorRegistry().contains( oid ) )
-        {
-            schemaManager.unregisterComparator( oid );
-            LOG.debug( "Removed {} from the enabled schema {}", comparator, schemaName );
+            // Remove the Comparator from the schema/SchemaObject Map
+            clonedRegistries.dissociateFromSchema( comparator );
+
+            // Check the registries now
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            
+            // If we didn't get any error, swap the registries
+            if ( errors.size() == 0 )
+            {
+                clonedRegistries.setStrict();
+                schemaManager.swapRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the deletion and get out
+                // Destroy the cloned registries
+                schemaManager.destroy( clonedRegistries );
+                
+                // The schema is disabled. We still have to update the backend
+                String msg = "Cannot delete the Comparator " + 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
         {
-            LOG.debug( "Removed {} from the disabled schema {}", comparator, schemaName );
+            // Should not be there...
         }
     }
 
@@ -337,6 +407,26 @@
     }
 
 
+    /**
+     * Check that a Comparator exists in the ComparatorRegistry, and if so,
+     * return it.
+     */
+    protected LdapComparator<?> checkComparatorOidExists( ServerEntry entry ) throws
Exception
+    {
+        String oid = getOid( entry );
+
+        if ( schemaManager.getComparatorRegistry().contains( oid ) )
+        {
+            return (LdapComparator<?>)schemaManager.getComparatorRegistry().get( oid
);
+        }
+        else
+        {
+            throw new LdapSchemaViolationException( "Oid " + oid + " for new schema entity
does not exist.",
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+    
     private void checkNewParent( LdapDN newParent ) throws NamingException
     {
         if ( newParent.size() != 3 )

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=881403&r1=881402&r2=881403&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 Nov 17 17:40:56 2009
@@ -118,56 +118,55 @@
         
         MatchingRule matchingRule = factory.getMatchingRule( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
         
-        // if the matchingRule is null, that means the schema is disabled
-        if ( matchingRule != null )
+        List<Throwable> errors = clonedRegistries.checkRefInteg();
+        
+        if ( errors.size() == 0 )
         {
-            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            // Update the references
+            clonedRegistries.buildReferences();
             
-            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 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() );
-            }
+            clonedRegistries.setStrict();
+            schemaManager.swapRegistries( clonedRegistries  );
+        }
+        else
+        {
+            // We have some error : reject the addition and get out
+            return;
+        }
+        
+        // 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() );
+        }
+        
+        // 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()
);
             
-            // 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
);
-            }
+            // 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-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.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/SchemaSynchronizer.java?rev=881403&r1=881402&r2=881403&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
Tue Nov 17 17:40:56 2009
@@ -49,7 +49,7 @@
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.SchemaObjectType;
-import org.apache.directory.shared.ldap.schema.SchemaWrapper;
+import org.apache.directory.shared.ldap.schema.SchemaObjectWrapper;
 import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.schema.registries.DefaultSchemaObjectRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
@@ -549,7 +549,7 @@
         operationManager.modify( modifyContext );
         
         // Now iterate on all the schemaObject under this schema
-        for ( SchemaWrapper schemaWrapper : schema.getContent() )
+        for ( SchemaObjectWrapper schemaObjectWrapper : schema.getContent() )
         {
             
         }
@@ -596,9 +596,9 @@
         // searching for those associated with the disabled schema
         disableAT( session, schemaName );
         
-        Set<SchemaWrapper> content = registries.getLoadedSchema( schemaName ).getContent();

+        Set<SchemaObjectWrapper> content = registries.getLoadedSchema( schemaName ).getContent();

 
-        for ( SchemaWrapper schemaWrapper : content )
+        for ( SchemaObjectWrapper schemaWrapper : content )
         {
             SchemaObject schemaObject = schemaWrapper.get();
             



Mime
View raw message