Author: elecharny
Date: Wed Dec 2 18:08:07 2009
New Revision: 886230
URL: http://svn.apache.org/viewvc?rev=886230&view=rev
Log:
o Added a add( schemaObject ) method
o minor refactoring
Modified:
directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.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=886230&r1=886229&r2=886230&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 Wed Dec 2 18:08:07 2009
@@ -19,6 +19,7 @@
*/
package org.apache.directory.shared.schema;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -26,8 +27,12 @@
import javax.naming.NamingException;
import org.apache.directory.shared.ldap.NotImplementedException;
+import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.entry.Entry;
+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.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.EntityFactory;
@@ -71,6 +76,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
* The SchemaManager class : it handles all the schema operations (addition, removal,
* modification).
@@ -85,29 +91,30 @@
/** The NamingContext this SchemaManager is associated with */
private LdapDN namingContext;
-
+
/** The global registries for this namingContext */
private volatile Registries registries;
-
+
/** The list of errors produced when loading some schema elements */
private List<Throwable> errors;
-
+
/** The Schema schemaLoader used by this SchemaManager */
private SchemaLoader schemaLoader;
-
+
/** the factory that generates respective SchemaObjects from LDIF entries */
protected final EntityFactory factory;
-
+
/** 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
*
@@ -123,7 +130,7 @@
factory = new SchemaEntityFactory();
isRelaxed = STRICT;
}
-
+
/**
* Creates a new instance of DefaultSchemaManager, for a specific
@@ -141,7 +148,7 @@
isRelaxed = STRICT;
}
-
+
//-----------------------------------------------------------------------
// Helper methods
//-----------------------------------------------------------------------
@@ -156,18 +163,18 @@
// Clone the Registries
Registries clonedRegistries = registries.clone();
-
+
// And update references. We may have errors, that may be fixed
// by the new loaded schemas.
errors = clonedRegistries.checkRefInteg();
-
+
// Now, relax the cloned Registries if there is no error
clonedRegistries.setRelaxed();
-
+
return clonedRegistries;
}
-
-
+
+
/**
* Transform a String[] array of schema to a Schema[]
*/
@@ -175,16 +182,16 @@
{
Schema[] schemaArray = new Schema[schemas.length];
int n = 0;
-
- for ( String schemaName:schemas )
+
+ for ( String schemaName : schemas )
{
schemaArray[n++] = schemaLoader.getSchema( schemaName );
}
-
+
return schemaArray;
}
-
-
+
+
private void addSchemaObjects( Schema schema, Registries registries ) throws Exception
{
addComparators( schema, registries );
@@ -202,15 +209,15 @@
// TODO Add some listener handling at this point
//notifyListenerOrRegistries( schema, registries );
}
-
-
+
+
//-----------------------------------------------------------------------
// API methods
//-----------------------------------------------------------------------
/***
* {@inheritDoc}
*/
- public boolean swapRegistries( Registries targetRegistries ) throws NamingException
+ public boolean swapRegistries( Registries targetRegistries ) throws NamingException
{
// Check the resulting registries
errors = targetRegistries.checkRefInteg();
@@ -223,13 +230,13 @@
{
targetRegistries.setStrict();
}
-
+
Registries oldRegistries = registries;
registries = targetRegistries;
-
+
// Delete the old registries to avoid memory leaks
oldRegistries.clear();
-
+
return true;
}
else
@@ -238,8 +245,8 @@
return false;
}
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -259,7 +266,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -269,7 +276,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -279,7 +286,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -288,31 +295,31 @@
// Work on a cloned and relaxed registries
Registries clonedRegistries = cloneRegistries();
- for ( Schema schema:schemas )
+ for ( Schema schema : schemas )
{
schema.enable();
- load( clonedRegistries, schema );
+ load( clonedRegistries, schema );
}
-
+
List<Throwable> errors = clonedRegistries.checkRefInteg();
-
+
// Destroy the clonedRegistry
clonedRegistries.clear();
-
+
if ( errors.isEmpty() )
{
// No error, inject the schema in the current registries
- for ( Schema schema:schemas )
+ for ( Schema schema : schemas )
{
schema.enable();
- load( registries, schema );
+ load( registries, schema );
}
-
+
errors = registries.checkRefInteg();
}
-
+
return errors.isEmpty();
-
+
// Swap the registries if it is consistent
//return swapRegistries( clonedRegistries );
}
@@ -326,7 +333,7 @@
return enable( toArray( schemas ) );
}
-
+
/**
* {@inheritDoc}
*/
@@ -336,7 +343,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -346,7 +353,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -355,7 +362,7 @@
return errors;
}
-
+
/**
* {@inheritDoc}
*/
@@ -363,7 +370,7 @@
{
return registries;
}
-
+
/**
* {@inheritDoc}
@@ -374,14 +381,14 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
public boolean load( Schema... schemas ) throws Exception
{
- boolean loaded = false;
-
+ boolean loaded = false;
+
// Work on a cloned and relaxed registries
Registries clonedRegistries = cloneRegistries();
clonedRegistries.setRelaxed();
@@ -389,41 +396,41 @@
// Load the schemas
for ( Schema schema : schemas )
{
- load( clonedRegistries, schema );
+ load( clonedRegistries, schema );
}
// 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
+ // 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
+ // Load the schemas
for ( Schema schema : schemas )
{
- load( registries, schema );
+ load( registries, schema );
}
// Build the cross references
registries.buildReferences();
-
+
loaded = true;
- }
+ }
}
// clear the cloned registries
clonedRegistries.clear();
-
+
return loaded;
}
-
+
/**
* {@inheritDoc}
*/
@@ -432,7 +439,7 @@
return load( toArray( schemas ) );
}
-
+
/**
* Load the schema in the registries. We will load everything accordingly to the two flags :
* - isRelaxed
@@ -450,15 +457,15 @@
{
return true;
}
-
+
if ( schema.isDisabled() )
{
if ( registries.isDisabledAccepted() )
{
LOG.info( "Loading {} schema: \n{}", schema.getSchemaName(), schema );
-
+
registries.schemaLoaded( schema );
-
+
addSchemaObjects( schema, registries );
}
else
@@ -469,15 +476,15 @@
else
{
LOG.info( "Loading {} schema: \n{}", schema.getSchemaName(), schema );
-
+
registries.schemaLoaded( schema );
addSchemaObjects( schema, registries );
}
-
+
return true;
}
-
+
/**
* Add all the Schema's AttributeTypes
*/
@@ -491,7 +498,7 @@
}
}
-
+
/**
* Add all the Schema's comparators
*/
@@ -499,14 +506,13 @@
{
for ( Entry entry : schemaLoader.loadComparators( schema ) )
{
- LdapComparator<?> comparator =
- factory.getLdapComparator( this, entry, registries, schema.getSchemaName() );
-
+ LdapComparator<?> comparator = factory.getLdapComparator( this, entry, registries, schema.getSchemaName() );
+
addSchemaObject( registries, comparator, schema );
}
}
-
+
/**
* Add all the Schema's DitContentRules
*/
@@ -514,12 +520,11 @@
{
for ( Entry entry : schemaLoader.loadDitContentRules( schema ) )
{
- throw new NotImplementedException( "Need to implement factory " +
- "method for creating a DitContentRule" );
+ throw new NotImplementedException( "Need to implement factory " + "method for creating a DitContentRule" );
}
}
-
+
/**
* Add all the Schema's DitStructureRules
*/
@@ -527,12 +532,11 @@
{
for ( Entry entry : schemaLoader.loadDitStructureRules( schema ) )
{
- throw new NotImplementedException( "Need to implement factory " +
- "method for creating a DitStructureRule" );
+ throw new NotImplementedException( "Need to implement factory " + "method for creating a DitStructureRule" );
}
}
-
+
/**
* Add all the Schema's MatchingRules
*/
@@ -540,14 +544,13 @@
{
for ( Entry entry : schemaLoader.loadMatchingRules( schema ) )
{
- MatchingRule matchingRule = factory.getMatchingRule(
- this, entry, registries, schema.getSchemaName() );
+ MatchingRule matchingRule = factory.getMatchingRule( this, entry, registries, schema.getSchemaName() );
addSchemaObject( registries, matchingRule, schema );
}
}
-
+
/**
* Add all the Schema's MatchingRuleUses
*/
@@ -555,12 +558,11 @@
{
for ( Entry entry : schemaLoader.loadMatchingRuleUses( schema ) )
{
- throw new NotImplementedException( "Need to implement factory " +
- "method for creating a MatchingRuleUse" );
+ throw new NotImplementedException( "Need to implement factory " + "method for creating a MatchingRuleUse" );
}
}
-
+
/**
* Add all the Schema's NameForms
*/
@@ -568,12 +570,11 @@
{
for ( Entry entry : schemaLoader.loadNameForms( schema ) )
{
- throw new NotImplementedException( "Need to implement factory " +
- "method for creating a NameForm" );
+ throw new NotImplementedException( "Need to implement factory " + "method for creating a NameForm" );
}
}
-
+
/**
* Add all the Schema's Normalizers
*/
@@ -581,14 +582,13 @@
{
for ( Entry entry : schemaLoader.loadNormalizers( schema ) )
{
- Normalizer normalizer =
- factory.getNormalizer( this, entry, registries, schema.getSchemaName() );
-
+ Normalizer normalizer = factory.getNormalizer( this, entry, registries, schema.getSchemaName() );
+
addSchemaObject( registries, normalizer, schema );
}
}
-
+
/**
* Add all the Schema's ObjectClasses
*/
@@ -602,7 +602,7 @@
}
}
-
+
/**
* Add all the Schema's Syntaxes
*/
@@ -610,14 +610,13 @@
{
for ( Entry entry : schemaLoader.loadSyntaxes( schema ) )
{
- LdapSyntax syntax = factory.getSyntax( this,
- entry, registries, schema.getSchemaName() );
+ LdapSyntax syntax = factory.getSyntax( this, entry, registries, schema.getSchemaName() );
addSchemaObject( registries, syntax, schema );
}
}
-
+
/**Add
* Register all the Schema's SyntaxCheckers
*/
@@ -625,14 +624,13 @@
{
for ( Entry entry : schemaLoader.loadSyntaxCheckers( schema ) )
{
- SyntaxChecker syntaxChecker =
- factory.getSyntaxChecker( this, entry, registries, schema.getSchemaName() );
+ SyntaxChecker syntaxChecker = factory.getSyntaxChecker( this, entry, registries, schema.getSchemaName() );
addSchemaObject( registries, syntaxChecker, schema );
}
}
-
+
/**
* Add the schemaObject into the registries.
*
@@ -642,7 +640,7 @@
* @return the created schemaObject instance
* @throws Exception If the registering failed
*/
- private SchemaObject addSchemaObject( Registries registries, SchemaObject schemaObject, Schema schema)
+ private SchemaObject addSchemaObject( Registries registries, SchemaObject schemaObject, Schema schema )
throws Exception
{
if ( registries.isRelaxed() )
@@ -668,22 +666,22 @@
errors.add( new Throwable() );
}
}
-
+
return schemaObject;
}
-
-
+
+
/**
* {@inheritDoc}
*/
public boolean loadAllEnabled() throws Exception
{
Schema[] schemas = schemaLoader.getAllEnabled().toArray( new Schema[0] );
-
+
return loadWithDeps( schemas );
}
-
+
/**
* {@inheritDoc}
*/
@@ -701,7 +699,7 @@
{
// Work on a cloned and relaxed registries
Registries clonedRegistries = cloneRegistries();
-
+
// Accept the disabled schemas
clonedRegistries.setDisabledAccepted( true );
@@ -710,14 +708,14 @@
{
// Enable the Schema object before loading it
schema.enable();
- load( clonedRegistries, schema );
+ load( clonedRegistries, schema );
}
// Swap the registries if it is consistent
return swapRegistries( clonedRegistries );
}
-
+
/**
* {@inheritDoc}
*/
@@ -726,7 +724,7 @@
return loadDisabled( toArray( schemas ) );
}
-
+
/**
* {@inheritDoc}
*/
@@ -736,7 +734,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -745,16 +743,16 @@
// TODO Auto-generated method stub
return false;
}
-
-
+
+
/**
* {@inheritDoc}
*/
public boolean loadWithDeps( Schema... schemas ) throws Exception
{
- boolean loaded = false;
+ boolean loaded = false;
- // Work on a cloned and relaxed registries
+ // Work on a cloned and relaxed registries
Registries clonedRegistries = cloneRegistries();
clonedRegistries.setRelaxed();
@@ -763,39 +761,39 @@
{
loadDepsFirst( clonedRegistries, schema );
}
-
+
// 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
+ // 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
+ // Load the schemas
for ( Schema schema : schemas )
{
- loadDepsFirst( registries, schema );
+ loadDepsFirst( registries, schema );
}
// Build the cross references
registries.buildReferences();
-
+
loaded = true;
- }
+ }
}
-
+
// clear the cloned registries
clonedRegistries.clear();
return loaded;
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -804,7 +802,7 @@
return loadWithDeps( toArray( schemas ) );
}
-
+
/**
* Recursive method which loads schema's with their dependent schemas first
* and tracks what schemas it has seen so the recursion does not go out of
@@ -822,22 +820,22 @@
LOG.info( "The schema is disabled and the registries does not accepted disabled schema" );
return;
}
-
+
String schemaName = schema.getSchemaName();
-
+
if ( registries.isSchemaLoaded( schemaName ) )
{
LOG.info( "{} schema has already been loaded" + schema.getSchemaName() );
return;
}
-
+
String[] deps = schema.getDependencies();
// if no deps then load this guy and return
if ( ( deps == null ) || ( deps.length == 0 ) )
{
load( registries, schema );
-
+
return;
}
@@ -865,7 +863,7 @@
load( registries, schema );
}
-
+
/**
* {@inheritDoc}
*/
@@ -875,7 +873,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -885,17 +883,17 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
public void setRegistries( Registries registries )
{
// TODO Auto-generated method stub
-
+
}
-
+
/**
* {@inheritDoc}
*/
@@ -915,7 +913,7 @@
return false;
}
-
+
/**
* {@inheritDoc}
*/
@@ -923,7 +921,7 @@
{
// Work on a cloned registries
Registries clonedRegistries = cloneRegistries();
-
+
// Loop on all the schemas
for ( Schema schema : schemas )
{
@@ -931,17 +929,17 @@
{
// Inject the schema
boolean loaded = load( clonedRegistries, schema );
-
+
if ( !loaded )
{
// We got an error : exit
clonedRegistries.clear();
return false;
}
-
+
// Now, check the registries
List<Throwable> errors = clonedRegistries.checkRefInteg();
-
+
if ( errors.size() != 0 )
{
// We got an error : exit
@@ -956,14 +954,14 @@
return false;
}
}
-
+
// We can now delete the cloned registries before exiting
clonedRegistries.clear();
-
+
return true;
}
-
+
/**
* {@inheritDoc}
*/
@@ -972,7 +970,7 @@
return verify( toArray( schemas ) );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1001,8 +999,8 @@
try
{
schemaModificationAttributesDN = new LdapDN( SchemaConstants.SCHEMA_MODIFICATIONS_DN );
- schemaModificationAttributesDN.normalize(
- getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
+ schemaModificationAttributesDN
+ .normalize( getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
}
catch ( NamingException e )
{
@@ -1039,7 +1037,7 @@
{
return new ImmutableComparatorRegistry( registries.getComparatorRegistry() );
}
-
+
/**
* {@inheritDoc}
@@ -1049,7 +1047,7 @@
return new ImmutableDITContentRuleRegistry( registries.getDitContentRuleRegistry() );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1058,7 +1056,7 @@
return new ImmutableDITStructureRuleRegistry( registries.getDitStructureRuleRegistry() );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1067,7 +1065,7 @@
return new ImmutableMatchingRuleRegistry( registries.getMatchingRuleRegistry() );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1076,7 +1074,7 @@
return new ImmutableMatchingRuleUseRegistry( registries.getMatchingRuleUseRegistry() );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1085,7 +1083,7 @@
return new ImmutableNameFormRegistry( registries.getNameFormRegistry() );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1094,7 +1092,7 @@
return new ImmutableNormalizerRegistry( registries.getNormalizerRegistry() );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1140,24 +1138,103 @@
}
+ /**
+ * Check that the given OID does not already exist in the globalOidRegistry.
+ */
+ private void checkOidIsUnique( SchemaObject schemaObject ) throws NamingException
+ {
+ if ( registries.getGlobalOidRegistry().hasOid( schemaObject.getOid() ) )
+ {
+ throw new LdapSchemaViolationException( "Oid " + schemaObject.getOid()
+ + " for new schema entity is not unique.", ResultCodeEnum.OTHER );
+ }
+ }
+
+
+ /**
+ * Retrieve the schema name for a specific SchemaObject, or return "other" if none is found.
+ */
+ private String getSchemaName( SchemaObject schemaObject ) throws Exception
+ {
+ String schemaName = StringTools.toLowerCase( schemaObject.getSchemaName() );
+
+ if ( schemaLoader.getSchema( schemaName ) == null )
+ {
+ return MetaSchemaConstants.SCHEMA_OTHER;
+ }
+ else
+ {
+ return schemaName;
+ }
+ }
+
+
//-----------------------------------------------------------------------------------
// SchemaObject operations
//-----------------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
- public void add( SchemaObject schemaObject ) throws NamingException
+ public void add( SchemaObject schemaObject ) throws Exception
{
- if ( isRelaxed )
- {
- // Apply the addition right away
- registries.add( schemaObject );
- }
- else
- {
- // Clone, apply, check, then apply again if ok
-
- }
+ if ( registries.isRelaxed() )
+ {
+ // Apply the addition right away
+ registries.add( schemaObject );
+ }
+ else
+ {
+ // Clone, apply, check, then apply again if ok
+ // The new schemaObject's OID must not already exist
+ checkOidIsUnique( schemaObject );
+
+ // Build the new AttributeType from the given entry
+ String schemaName = getSchemaName( schemaObject );
+
+ // 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 = getLoadedSchema( schemaName );
+ List<Throwable> errors = new ArrayList<Throwable>();
+
+ if ( schema.isEnabled() && schemaObject.isEnabled() )
+ {
+ // As we may break the registries, work on a cloned registries
+ Registries clonedRegistries = registries.clone();
+
+ // Inject the new SchemaObject in the cloned registries
+ clonedRegistries.add( errors, schemaObject );
+
+ // Remove the cloned registries
+ clonedRegistries.clear();
+
+ // If we didn't get any error, apply the addition to the real retistries
+ if ( errors.isEmpty() )
+ {
+ // Apply the addition to the real registries
+ registries.add( errors, schemaObject );
+
+ LOG.debug( "Added {} into the enabled schema {}", schemaObject.getName(), schemaName );
+ }
+ else
+ {
+ // We have some error : reject the addition and get out
+ String msg = "Cannot add the SchemaObject " + schemaObject.getOid() + " into the registries, "
+ + "the resulting registries would be inconsistent :" + StringTools.listToString( errors );
+ LOG.info( msg );
+ throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
+ }
+ else
+ {
+ // At least, we register the OID in the globalOidRegistry, and associates it with the
+ // schema
+ registries.associateWithSchema( schemaObject );
+
+ LOG.debug( "Added {} into the disabled schema {}", schemaObject.getName(), schemaName );
+ }
+
+ }
}
@@ -1169,7 +1246,7 @@
return registries.unregister( schemaObject );
}
-
+
/**
* {@inheritDoc}
*/
@@ -1177,8 +1254,8 @@
{
return registries.getAttributeTypeRegistry().getNormalizerMapping();
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -1219,7 +1296,7 @@
return false;
}
}
-
+
/**
* {@inheritDoc}
@@ -1331,7 +1408,7 @@
return isRelaxed;
}
-
+
/**
* Tells if the SchemaManager is strict.
*
@@ -1342,7 +1419,7 @@
return !isRelaxed;
}
-
+
/**
* Change the SchemaManager to a relaxed mode, where invalid SchemaObjects
* can be registered.
@@ -1352,7 +1429,7 @@
isRelaxed = RELAXED;
}
-
+
/**
* Change the SchemaManager to a strict mode, where invalid SchemaObjects
* cannot be registered.
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=886230&r1=886229&r2=886230&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java Wed Dec 2 18:08:07 2009
@@ -19,6 +19,7 @@
*/
package org.apache.directory.shared.ldap.schema;
+
import java.util.List;
import java.util.Map;
@@ -42,6 +43,7 @@
import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
import org.apache.directory.shared.ldap.schema.registries.SyntaxCheckerRegistry;
+
/**
* A class used to manage access to the Schemas and Registries. It's associated
* with a SchemaLoader, in charge of loading the schemas from the disk.
@@ -69,7 +71,7 @@
*/
boolean load( Schema... schemas ) throws Exception;
-
+
/**
* Load some Schemas into the registries. The Registries is checked after the
* schemas have been loaded, and if there is an error, the method returns false
@@ -116,8 +118,8 @@
* @throws Exception @TODO
*/
boolean loadWithDeps( String... schemas ) throws Exception;
-
-
+
+
/**
* Load Schemas into the registries, even if there are some errors in the schemas.
* The Registries is checked after the schemas have been loaded. Even if we have
@@ -132,8 +134,8 @@
* @throws Exception @TODO
*/
boolean loadRelaxed( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Load Schemas into the registries, even if there are some errors in the schemas.
* The Registries is checked after the schemas have been loaded. Even if we have
@@ -180,8 +182,8 @@
* @throws Exception @TODO
*/
boolean loadWithDepsRelaxed( String... schemas ) throws Exception;
-
-
+
+
/**
* Load Schemas into the Registries, even if they are disabled. The disabled
* SchemaObject from an enabled schema will also be loaded. The Registries will
@@ -195,8 +197,8 @@
* @throws Exception @TODO
*/
boolean loadDisabled( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Load Schemas into the Registries, even if they are disabled. The disabled
* SchemaObject from an enabled schema will also be loaded. The Registries will
@@ -210,8 +212,8 @@
* @throws Exception @TODO
*/
boolean loadDisabled( String... schemas ) throws Exception;
-
-
+
+
/**
* Load all the enabled schema into the Registries. The Registries is strict,
* any inconsistent schema will be rejected.
@@ -220,8 +222,8 @@
* @throws Exception @TODO
*/
boolean loadAllEnabled() throws Exception;
-
-
+
+
/**
* Load all the enabled schema into the Registries. The Registries is relaxed,
* even inconsistent schema will be loaded.
@@ -230,8 +232,8 @@
* @throws Exception @TODO
*/
boolean loadAllEnabledRelaxed() throws Exception;
-
-
+
+
/**
* Unload the given set of Schemas
*
@@ -239,8 +241,8 @@
* @return True if all the schemas have been unloaded
*/
boolean unload( Schema... schemas );
-
-
+
+
/**
* Unload the given set of Schemas
*
@@ -248,8 +250,8 @@
* @return True if all the schemas have been unloaded
*/
boolean unload( String... schemas );
-
-
+
+
//---------------------------------------------------------------------------------
// Other Schema methods
//---------------------------------------------------------------------------------
@@ -264,7 +266,7 @@
* @return true if the Registries is still consistent, false otherwise.
*/
boolean enable( Schema... schemas ) throws Exception;
-
+
/**
* Enables a set of Schemas, and returns true if all the schema have been
@@ -278,7 +280,7 @@
*/
boolean enable( String... schemas ) throws Exception;
-
+
/**
* Enables a set of Schemas, and returns true if all the schema have been
* enabled, with all the dependent schemas. No check is done, the Registries
@@ -289,7 +291,7 @@
*/
boolean enableRelaxed( Schema... schemas );
-
+
/**
* Enables a set of Schemas, and returns true if all the schema have been
* enabled, with all the dependent schemas. No check is done, the Registries
@@ -299,8 +301,8 @@
* @return true if all the schemas have been enabled
*/
boolean enableRelaxed( String... schemas );
-
-
+
+
/**
* Disables a set of Schemas, and returns true if all the schema have been
* disabled, with all the dependent schemas, and if the registries is
@@ -312,8 +314,8 @@
* @return true if the Registries is still consistent, false otherwise.
*/
boolean disable( Schema... schemas );
-
-
+
+
/**
* Disables a set of Schemas, and returns true if all the schema have been
* disabled, with all the dependent schemas, and if the registries is
@@ -326,7 +328,7 @@
*/
boolean disable( String... schemas );
-
+
/**
* Disables a set of Schemas, and returns true if all the schema have been
* disabled, with all the dependent schemas. The Registries is not checked
@@ -339,7 +341,7 @@
*/
boolean disabledRelaxed( Schema... schemas );
-
+
/**
* Disables a set of Schemas, and returns true if all the schema have been
* disabled, with all the dependent schemas. The Registries is not checked
@@ -361,8 +363,8 @@
* @throws Exception if something went wrong
*/
boolean verify( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Check that the Schemas are consistent regarding the current Registries.
*
@@ -371,14 +373,14 @@
* @throws Exception if something went wrong
*/
boolean verify( String... schemas ) throws Exception;
-
-
+
+
/**
* @return The Registries
*/
Registries getRegistries();
-
-
+
+
/**
* Lookup for an AttributeType in the AttributeType registry
*
@@ -388,7 +390,7 @@
*/
AttributeType lookupAttributeTypeRegistry( String oid ) throws NamingException;
-
+
/**
* Lookup for a Comparator in the Comparator registry
*
@@ -397,8 +399,8 @@
* @throws NamingException if the OID is not found in the Comparator registry
*/
LdapComparator<?> lookupComparatorRegistry( String oid ) throws NamingException;
-
-
+
+
/**
* Get an immutable reference on the AttributeType registry
*
@@ -406,7 +408,7 @@
*/
AttributeTypeRegistry getAttributeTypeRegistry();
-
+
/**
* Get an immutable reference on the Comparator registry
*
@@ -414,7 +416,7 @@
*/
ComparatorRegistry getComparatorRegistry();
-
+
/**
* Get an immutable reference on the DITContentRule registry
*
@@ -422,7 +424,7 @@
*/
DITContentRuleRegistry getDITContentRuleRegistry();
-
+
/**
* Get an immutable reference on the DITStructureRule registry
*
@@ -430,7 +432,7 @@
*/
DITStructureRuleRegistry getDITStructureRuleRegistry();
-
+
/**
* Get an immutable reference on the MatchingRule registry
*
@@ -438,7 +440,7 @@
*/
MatchingRuleRegistry getMatchingRuleRegistry();
-
+
/**
* Get an immutable reference on the MatchingRuleUse registry
*
@@ -446,7 +448,7 @@
*/
MatchingRuleUseRegistry getMatchingRuleUseRegistry();
-
+
/**
* Get an immutable reference on the Normalizer registry
*
@@ -454,7 +456,7 @@
*/
NormalizerRegistry getNormalizerRegistry();
-
+
/**
* Get an immutable reference on the NameForm registry
*
@@ -462,7 +464,7 @@
*/
NameFormRegistry getNameFormRegistry();
-
+
/**
* Get an immutable reference on the ObjectClass registry
*
@@ -470,7 +472,7 @@
*/
ObjectClassRegistry getObjectClassRegistry();
-
+
/**
* Get an immutable reference on the LdapSyntax registry
*
@@ -478,7 +480,7 @@
*/
LdapSyntaxRegistry getLdapSyntaxRegistry();
-
+
/**
* Get an immutable reference on the SyntaxChecker registry
*
@@ -486,7 +488,7 @@
*/
SyntaxCheckerRegistry getSyntaxCheckerRegistry();
-
+
/**
* Get an immutable reference on the Normalizer mapping
*
@@ -494,15 +496,15 @@
*/
Map<String, OidNormalizer> getNormalizerMapping();
-
+
/**
* Associate a new Registries to the SchemaManager
*
* @param registries The new Registries
*/
void setRegistries( Registries registries );
-
-
+
+
/***
* Swap the registries, deleting all the schemaObjects and links from the old one
* to avoid memory leaks.
@@ -512,14 +514,14 @@
* @return true if the replacement has been done
*/
public boolean swapRegistries( Registries targetRegistries ) throws NamingException;
-
-
+
+
/**
* @return The errors obtained when checking the registries
*/
List<Throwable> getErrors();
-
-
+
+
/**
* Associate a Schema loader to this SchemaManager
*
@@ -540,8 +542,8 @@
* @throws Exception If the initialization fails
*/
void initialize() throws Exception;
-
-
+
+
/**
* @return The used loader
*/
@@ -553,10 +555,10 @@
* consistent after this addition, if the SchemaManager is in Strict mode.
*
* @param schemaObject the SchemaObject to register
- * @throws NamingException if the SchemaObject is already registered or
+ * @throws Exception if the SchemaObject is already registered or
* the registration operation is not supported
*/
- void add( SchemaObject schemaObject ) throws NamingException;
+ void add( SchemaObject schemaObject ) throws Exception;
/**
@@ -673,8 +675,8 @@
* @return The OidRegistry
*/
OidRegistry getOidRegistry();
-
-
+
+
/**
* Gets a schema that has been loaded into these Registries.
*
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java?rev=886230&r1=886229&r2=886230&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java Wed Dec 2 18:08:07 2009
@@ -48,31 +48,30 @@
{
/** static class logger */
private static final Logger LOG = LoggerFactory.getLogger( AbstractSchemaLoader.class );
-
protected SchemaLoaderListener listener;
-
+
/**
* A map of all available schema names to schema objects. This map is
* populated when this class is created with all the schemas present in
* the LDIF based schema repository.
*/
- protected final Map<String,Schema> schemaMap = new HashMap<String,Schema>();
-
+ protected final Map<String, Schema> schemaMap = new HashMap<String, Schema>();
+
public void setListener( SchemaLoaderListener listener )
{
this.listener = listener;
}
-
-
+
+
protected final void notifyListenerOrRegistries( Schema schema, Registries registries )
{
if ( listener != null )
{
listener.schemaLoaded( schema );
}
-
+
if ( registries instanceof SchemaLoaderListener )
{
if ( registries != listener )
@@ -82,8 +81,8 @@
}
}
}
-
-
+
+
/**
* {@inheritDoc}
*/
@@ -91,8 +90,8 @@
{
return schemaMap.values();
}
-
-
+
+
/**
* Recursive method which loads schema's with their dependent schemas first
* and tracks what schemas it has seen so the recursion does not go out of
@@ -197,57 +196,59 @@
return this.schemaMap.get( schemaName );
}
-
+
protected Schema getSchema( Entry entry ) throws Exception
{
String name;
String owner;
String[] dependencies = StringTools.EMPTY_STRINGS;
boolean isDisabled = false;
-
+
if ( entry == null )
{
throw new NullPointerException( "entry cannot be null" );
}
-
+
if ( entry.get( SchemaConstants.CN_AT ) == null )
{
throw new NullPointerException( "entry must have a valid cn attribute" );
}
-
+
name = entry.get( SchemaConstants.CN_AT ).getString();
-
+
if ( entry.get( SchemaConstants.CREATORS_NAME_AT ) == null )
{
- throw new NullPointerException( "entry must have a valid "
- + SchemaConstants.CREATORS_NAME_AT + " attribute" );
+ throw new NullPointerException( "entry must have a valid " + SchemaConstants.CREATORS_NAME_AT
+ + " attribute" );
}
-
+
owner = entry.get( SchemaConstants.CREATORS_NAME_AT ).getString();
-
+
if ( entry.get( MetaSchemaConstants.M_DISABLED_AT ) != null )
{
String value = entry.get( MetaSchemaConstants.M_DISABLED_AT ).getString();
value = value.toUpperCase();
isDisabled = value.equals( "TRUE" );
}
-
+
if ( entry.get( MetaSchemaConstants.M_DEPENDENCIES_AT ) != null )
{
Set<String> depsSet = new HashSet<String>();
EntryAttribute depsAttr = entry.get( MetaSchemaConstants.M_DEPENDENCIES_AT );
-
- for ( Value<?> value:depsAttr )
+
+ for ( Value<?> value : depsAttr )
{
depsSet.add( value.getString() );
}
dependencies = depsSet.toArray( StringTools.EMPTY_STRINGS );
}
-
- return new DefaultSchema( name, owner, dependencies, isDisabled ){};
+
+ return new DefaultSchema( name, owner, dependencies, isDisabled )
+ {
+ };
}
-
+
/**
* {@inheritDoc}
@@ -662,18 +663,18 @@
{
return null;
}
-
-
+
+
private Schema[] buildSchemaArray( String... schemaNames ) throws Exception
{
Schema[] schemas = new Schema[schemaNames.length];
int pos = 0;
-
+
for ( String schemaName : schemaNames )
{
schemas[pos++] = getSchema( schemaName );
}
-
+
return schemas;
}
@@ -687,7 +688,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadAttributeTypes( buildSchemaArray( schemaNames ) );
}
@@ -701,7 +702,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadComparators( buildSchemaArray( schemaNames ) );
}
@@ -715,7 +716,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadDitContentRules( buildSchemaArray( schemaNames ) );
}
@@ -729,7 +730,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadDitStructureRules( buildSchemaArray( schemaNames ) );
}
@@ -743,7 +744,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadMatchingRules( buildSchemaArray( schemaNames ) );
}
@@ -757,7 +758,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadMatchingRuleUses( buildSchemaArray( schemaNames ) );
}
@@ -771,7 +772,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadNameForms( buildSchemaArray( schemaNames ) );
}
@@ -785,7 +786,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadNormalizers( buildSchemaArray( schemaNames ) );
}
@@ -799,7 +800,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadObjectClasses( buildSchemaArray( schemaNames ) );
}
@@ -813,7 +814,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadSyntaxes( buildSchemaArray( schemaNames ) );
}
@@ -827,7 +828,7 @@
{
return new ArrayList<Entry>();
}
-
+
return loadSyntaxCheckers( buildSchemaArray( schemaNames ) );
}
}
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java?rev=886230&r1=886229&r2=886230&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java Wed Dec 2 18:08:07 2009
@@ -40,8 +40,8 @@
* @param listener the listener to notify (only one is enough for us)
*/
void setListener( SchemaLoaderListener listener );
-
-
+
+
/**
* Gets a schema object based on it's name.
*
@@ -50,8 +50,8 @@
* @throws Exception if any problems while trying to find the associated Schema
*/
Schema getSchema( String schemaName ) throws Exception;
-
-
+
+
/**
* Loads a set of schemas. A best effort should be made to load the dependended
* schemas that these schemas may rely on even if they are not included in the collection.
@@ -95,8 +95,8 @@
* @throws Exception if there are failures accessing AttributeType information
*/
List<Entry> loadAttributeTypes( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of AttributeTypes read from the underlying storage for
* a list of specific schema, using their name
@@ -105,8 +105,8 @@
* @throws Exception if there are failures accessing AttributeType information
*/
List<Entry> loadAttributeTypes( String... schemaNames ) throws Exception;
-
-
+
+
/**
* Build a list of Comparators read from the underlying storage for
* a list of specific schema.
@@ -115,8 +115,8 @@
* @throws Exception if there are failures accessing Comparator information
*/
List<Entry> loadComparators( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of Comparators read from the underlying storage for
* a list of specific schema, using their name
@@ -125,8 +125,8 @@
* @throws Exception if there are failures accessing Comparator information
*/
List<Entry> loadComparators( String... schemaNames ) throws Exception;
-
-
+
+
/**
* Build a list of DitContentRules read from the underlying storage for
* a list of specific schema.
@@ -135,8 +135,8 @@
* @throws Exception if there are failures accessing DitContentRule information
*/
List<Entry> loadDitContentRules( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of DitContentRules read from the underlying storage for
* a list of specified schema names
@@ -155,8 +155,8 @@
* @throws Exception if there are failures accessing DitStructureRule information
*/
List<Entry> loadDitStructureRules( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of DitStructureRules read from the underlying storage for
* a list of specified schema names
@@ -175,8 +175,8 @@
* @throws Exception if there are failures accessing MatchingRule information
*/
List<Entry> loadMatchingRules( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of MatchingRules read from the underlying storage for
* a list of specific schema, using their name
@@ -185,8 +185,8 @@
* @throws Exception if there are failures accessing MatchingRule information
*/
List<Entry> loadMatchingRules( String... schemaNames ) throws Exception;
-
-
+
+
/**
* Build a list of MatchingRuleUses read from the underlying storage for
* a list of specific schema.
@@ -195,8 +195,8 @@
* @throws Exception if there are failures accessing MatchingRuleUse information
*/
List<Entry> loadMatchingRuleUses( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of MatchingRuleUses read from the underlying storage for
* a list of specified schema names
@@ -215,8 +215,8 @@
* @throws Exception if there are failures accessing NameForm information
*/
List<Entry> loadNameForms( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of NameForms read from the underlying storage for
* a list of specified schema names
@@ -235,8 +235,8 @@
* @throws Exception if there are failures accessing Normalizer information
*/
List<Entry> loadNormalizers( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of Normalizers read from the underlying storage for
* a list of specified schema names
@@ -245,8 +245,8 @@
* @throws Exception if there are failures accessing Normalizer information
*/
List<Entry> loadNormalizers( String... schemaNames ) throws Exception;
-
-
+
+
/**
* Build a list of ObjectClasses read from the underlying storage for
* a list of specific schema.
@@ -255,8 +255,8 @@
* @throws Exception if there are failures accessing ObjectClass information
*/
List<Entry> loadObjectClasses( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of ObjectClasses read from the underlying storage for
* a list of specified schema names
@@ -265,8 +265,8 @@
* @throws Exception if there are failures accessing ObjectClasses information
*/
List<Entry> loadObjectClasses( String... schemaNames ) throws Exception;
-
-
+
+
/**
* Build a list of Syntaxes read from the underlying storage for
* a list of specified schema
@@ -275,8 +275,8 @@
* @throws Exception if there are failures accessing Syntax information
*/
List<Entry> loadSyntaxes( Schema... schemas ) throws Exception;
-
-
+
+
/**
* Build a list of Syntaxes read from the underlying storage for
* a list of specified schema names
@@ -285,8 +285,8 @@
* @throws Exception if there are failures accessing Syntax information
*/
List<Entry> loadSyntaxes( String... schemaNames ) throws Exception;
-
-
+
+
/**
* Build a list of SyntaxCheckers read from the underlying storage for
* a list of specified schema
|