directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r835395 - /directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
Date Thu, 12 Nov 2009 14:40:01 GMT
Author: elecharny
Date: Thu Nov 12 14:40:01 2009
New Revision: 835395

URL: http://svn.apache.org/viewvc?rev=835395&view=rev
Log:
Refactored the Add operation to avoid useless code and tests.

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.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=835395&r1=835394&r2=835395&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
Thu Nov 12 14:40:01 2009
@@ -83,59 +83,49 @@
         
         AttributeType at = factory.getAttributeType( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
         
-        // if the AT is null, that means the schema is disabled
-        if ( at != null )
+        // 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() )
         {
-            // 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 );
+            // As we may break the registries, work on a cloned registries
+            Registries clonedRegistries = schemaManager.getRegistries().clone();
+            
+            // Relax the cloned registries
+            clonedRegistries.setRelaxed();
             
-            if ( schema.isEnabled() && at.isEnabled() )
+            // Apply the registries to the newly created AT
+            at.applyRegistries( schemaManager.getRegistries() );
+            
+            // Check the registries now
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            
+            // If we didn't get any error, swap the registries
+            if ( errors.size() == 0 )
             {
-                // As we may break the registries, work on a cloned registries
-                Registries clonedRegistries = schemaManager.getRegistries().clone();
-                
-                // Relax the cloned registries
-                clonedRegistries.setRelaxed();
-                
-                // Apply the registries to the newly created AT
-                at.applyRegistries( schemaManager.getRegistries() );
-                
-                // Check the registries now
-                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 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 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 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
);
-                }
+                // The schema is disabled. We still have to update the backend
+                String msg = "Cannot add 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
);
             }
-        
-            // Associates this AttributeType with the schema
-            addToSchema( at, schemaName );
-            
-            schemaManager.register( at );
-    
-            LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
-        }
-        else
-        {
-            registerOids( at );
-            LOG.debug( "Added {} into the disabled schema {}", dn.getUpName(), schemaName
);
         }
+    
+        // Associates this AttributeType with the schema
+        schemaManager.register( at );
+
+        LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName );
     }
 
 
@@ -202,7 +192,7 @@
         // 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 ( isSchemaEnabled( schemaName ) )
+        if ( schema.isEnabled() )
         {
             if ( schemaManager.getRegistries().isReferenced( attributeType ) )
             {



Mime
View raw message