Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 53133 invoked from network); 30 Nov 2009 16:56:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Nov 2009 16:56:54 -0000 Received: (qmail 5285 invoked by uid 500); 30 Nov 2009 16:56:54 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 5223 invoked by uid 500); 30 Nov 2009 16:56:53 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 5213 invoked by uid 99); 30 Nov 2009 16:56:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Nov 2009 16:56:52 +0000 X-ASF-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Nov 2009 16:56:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B55262388996; Mon, 30 Nov 2009 16:56:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091130165629.B55262388996@eris.apache.org> 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 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 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; + } }