directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r885494 - /directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Date Mon, 30 Nov 2009 16:56:29 GMT
Author: elecharny
Date: Mon Nov 30 16:56:29 2009
New Revision: 885494

URL: http://svn.apache.org/viewvc?rev=885494&view=rev
Log:
o Added a isRelaxed field and the associated accessors
o Modified the load() methods to apply the changes in the real registries if the cloned registries
modification was successfull

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=885494&r1=885493&r2=885494&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Mon Nov 30 16:56:29 2009
@@ -101,6 +101,13 @@
     /** the normalized name for the schema modification attributes */
     private LdapDN schemaModificationAttributesDN;
     
+    /** A flag indicating that the SchemaManager is relaxed or not */
+    private boolean isRelaxed = STRICT;
+    
+    /** Two flags for RELAXED and STRUCT */
+    public static final boolean STRICT = false;
+    public static final boolean RELAXED = true;
+    
     /**
      * Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
      *
@@ -114,6 +121,7 @@
         errors = null;
         registries = new Registries( this );
         factory = new SchemaEntityFactory();
+        isRelaxed = STRICT;
     }
     
 
@@ -130,6 +138,7 @@
         errors = null;
         registries = new Registries( this );
         factory = new SchemaEntityFactory();
+        isRelaxed = STRICT;
     }
 
     
@@ -371,17 +380,47 @@
      */
     public boolean load( Schema... schemas ) throws Exception
     {
+    	boolean loaded = false;
+    	
         // Work on a cloned and relaxed registries
         Registries clonedRegistries = cloneRegistries();
+        clonedRegistries.setRelaxed();
 
-        //Load the schemas
+        // Load the schemas
         for ( Schema schema : schemas )
         {
             load( clonedRegistries, schema  );
         }
 
-        // Swap the registries if it is consistent
-        return swapRegistries( clonedRegistries );
+        // Build the cross references
+        List<Throwable> errors = clonedRegistries.buildReferences();
+        
+        if ( errors.isEmpty() )
+        {
+        	// Ok no errors. Check the registries now
+        	errors = clonedRegistries.checkRefInteg();
+        	
+        	if ( errors.isEmpty() )
+        	{
+        		// We are golden : let's apply the schema in the real registries
+
+        		// Load the schemas
+                for ( Schema schema : schemas )
+                {
+                    load( registries, schema  );
+                }
+
+                // Build the cross references
+                registries.buildReferences();
+                
+                loaded = true;
+        	}
+        }
+
+        // clear the cloned registries
+        clonedRegistries.clear();
+        
+        return loaded;
     }
 
     
@@ -713,21 +752,47 @@
      */
     public boolean loadWithDeps( Schema... schemas ) throws Exception
     {
-        // Work on a cloned and relaxed registries
+    	boolean loaded = false;
+
+    	// Work on a cloned and relaxed registries
         Registries clonedRegistries = cloneRegistries();
         clonedRegistries.setRelaxed();
 
         // Load the schemas
         for ( Schema schema : schemas )
         {
-            loadDepsFirst( schema, clonedRegistries );
+            loadDepsFirst( clonedRegistries, schema );
         }
         
-        // Rebuild all the cross references now
-        clonedRegistries.buildReferences();
+        // Build the cross references
+        List<Throwable> errors = clonedRegistries.buildReferences();
         
-        // Swap the registries if it is consistent
-        return swapRegistries( clonedRegistries );
+        if ( errors.isEmpty() )
+        {
+        	// Ok no errors. Check the registries now
+        	errors = clonedRegistries.checkRefInteg();
+        	
+        	if ( errors.isEmpty() )
+        	{
+        		// We are golden : let's apply the schema in the real registries
+
+        		// Load the schemas
+                for ( Schema schema : schemas )
+                {
+                	loadDepsFirst( registries, schema  );
+                }
+
+                // Build the cross references
+                registries.buildReferences();
+                
+                loaded = true;
+        	}
+        }
+        
+        // clear the cloned registries
+        clonedRegistries.clear();
+
+        return loaded;
     }
     
     
@@ -745,12 +810,12 @@
      * and tracks what schemas it has seen so the recursion does not go out of
      * control with dependency cycle detection.
      *
-     * @param schema the current schema we are attempting to load
      * @param registries The Registries in which the schemas will be loaded
+     * @param schema the current schema we are attempting to load
      * @throws Exception if there is a cycle detected and/or another
      * failure results while loading, producing and or registering schema objects
      */
-    private final void loadDepsFirst( Schema schema, Registries registries ) throws Exception
+    private final void loadDepsFirst( Registries registries, Schema schema ) throws Exception
     {
         if ( schema.isDisabled() && !registries.isDisabledAccepted() )
         {
@@ -792,7 +857,7 @@
             {
                 // Call recursively this method
                 Schema schemaDep = schemaLoader.getSchema( depName );
-                loadDepsFirst( schemaDep, registries );
+                loadDepsFirst( registries, schemaDep );
             }
         }
 
@@ -954,7 +1019,10 @@
         return schemaLoader;
     }
 
-    
+
+    //-----------------------------------------------------------------------------------
+    // Immutable accessors
+    //-----------------------------------------------------------------------------------
     /**
      * {@inheritDoc}
      */
@@ -1072,12 +1140,24 @@
     }
 
 
+    //-----------------------------------------------------------------------------------
+    // SchemaObject operations
+    //-----------------------------------------------------------------------------------
     /**
      * {@inheritDoc}
      */
-    public void register( SchemaObject schemaObject ) throws NamingException
-    {
-        registries.register( schemaObject );
+    public void add( SchemaObject schemaObject ) throws NamingException
+    {
+    	if ( isRelaxed )
+    	{
+    		// Apply the addition right away
+    		registries.add( schemaObject );
+    	}
+    	else
+    	{
+    		// Clone, apply, check, then apply again if ok
+    		
+    	}
     }
 
 
@@ -1238,4 +1318,47 @@
     {
         return registries.getSyntaxCheckerRegistry().unregister( syntaxCheckerOid );
     }
+
+
+    /**
+     * Tells if the SchemaManager is permissive or if it must be checked 
+     * against inconsistencies.
+     *
+     * @return True if SchemaObjects can be added even if they break the consistency 
+     */
+    public boolean isRelaxed()
+    {
+        return isRelaxed;
+    }
+
+    
+    /**
+     * Tells if the SchemaManager is strict.
+     *
+     * @return True if SchemaObjects cannot be added if they break the consistency 
+     */
+    public boolean isStrict()
+    {
+        return !isRelaxed;
+    }
+
+    
+    /**
+     * Change the SchemaManager to a relaxed mode, where invalid SchemaObjects
+     * can be registered.
+     */
+    public void setRelaxed()
+    {
+        isRelaxed = RELAXED;
+    }
+
+    
+    /**
+     * Change the SchemaManager to a strict mode, where invalid SchemaObjects
+     * cannot be registered.
+     */
+    public void setStrict()
+    {
+        isRelaxed = STRICT;
+    }
 }



Mime
View raw message