Author: akarasulu
Date: Fri Oct 15 11:21:19 2004
New Revision: 54860
Added:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
(contents, props changed)
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/AbstractBootstrapSchema.java
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchema.java
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/MatchingRuleFactory.java
Log:
Commit changes ...
o added loader class for schema class loading
o remove loading methods from the BootstrapSchema
o remove loading implementation form AbstractBootstrapSchema as well
o removed OidRegistry from MatchingRuleFactory method signatures since the
OidRegistry is automatically updated by all registries and they also
automatically resolve names as well as numeric OIDs
o implemented load functionality for normalizers, comparators, syntaxCheckers,
syntaxes, and matchingRules
Notes ...
o figured out how things are finally going to work out with plugin
- plugin generates factories and BootstrapSchema implementations
- if plugin finds a default implementation for a factory in the
org.apache.eve.schema.bootstrap package then it uses that
rather than creating a new factory for the schema object type
- the plugin generates all factories minus existing defaults even
if there are no objects returned; meaning an empty Map of the
schema types are returned
- plugin generated XxxxxBootstrapSchema will derive from
AbstractBootstrapSchema supplying all the needed parameters to the
protected constructor
- plugin generated XxxxxBootstrapSchema will have a default constructor
- the plugin will obtain packageName, schemaName, owner and dependency info
from plugin specific maven properties
o at bootstrap time the EveContextFactory will fire up the
BootstrapSchemaLoader and use it to populate all BootstrapSchema objects
one at a time
o by default a bunch of schemas will automatically get loaded
o additional schemas can be added or the existing schema set to use can be
overriden using two JNDI environment properties
o these environment properties are the fully qualified class names of the
BootstrapSchema implementations generated by the plugin
Conclusions ...
o this two phase scheme of generating code and storing schema object
configurations in Java classes eliminates the need to store xxxxx.schema
files
o it also makes bootstrap loading and registry population much simpler since
it is broken down into separate tasks by function within various phases
o Java configuration class file loading is very fast since all Strings are
are compiled and the code is hard coded as opposed to being dynamic
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/AbstractBootstrapSchema.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/AbstractBootstrapSchema.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/AbstractBootstrapSchema.java
Fri Oct 15 11:21:19 2004
@@ -18,8 +18,7 @@
import org.apache.ldap.common.util.ArrayUtils;
-
-import javax.naming.NamingException;
+import org.apache.ldap.common.util.ClassUtils;
/**
@@ -32,11 +31,16 @@
{
private static final String DEFAULT_OWNER = "uid=admin,ou=system";
private static final String DEFAULT_SCHEMA_NAME = "default";
+ private static final String DEFAULT_PACKAGE_NAME =
"org.apache.eve.schema.bootstrap";
private final String owner;
private final String schemaName;
+ private final String packageName;
private final String[] dependencies;
+ private transient String baseName;
+ private transient String defaultBaseName;
+
// ------------------------------------------------------------------------
// C O N S T R U C T O R S
@@ -44,8 +48,9 @@
protected AbstractBootstrapSchema( String owner,
- String schemaName,
- String[] dependencies )
+ String schemaName,
+ String packageName,
+ String[] dependencies )
{
if ( owner == null )
{
@@ -65,6 +70,15 @@
this.schemaName = schemaName;
}
+ if ( packageName == null )
+ {
+ this.packageName = DEFAULT_PACKAGE_NAME;
+ }
+ else
+ {
+ this.packageName = packageName;
+ }
+
if ( dependencies == null )
{
this.dependencies = ArrayUtils.EMPTY_STRING_ARRAY;
@@ -73,6 +87,20 @@
{
this.dependencies = dependencies;
}
+
+ StringBuffer buf = new StringBuffer();
+ buf.append( DEFAULT_PACKAGE_NAME );
+ buf.append( ClassUtils.PACKAGE_SEPARATOR_CHAR );
+ buf.append( Character.toUpperCase( schemaName.charAt( 0 ) ) );
+ buf.append( schemaName.substring( 1, schemaName.length() ) );
+ defaultBaseName = buf.toString();
+
+ buf.setLength( 0 );
+ buf.append( packageName );
+ buf.append( ClassUtils.PACKAGE_SEPARATOR_CHAR );
+ buf.append( Character.toUpperCase( schemaName.charAt( 0 ) ) );
+ buf.append( schemaName.substring( 1, schemaName.length() ) );
+ baseName = buf.toString();
}
@@ -94,15 +122,20 @@
}
- public final void populate( BootstrapRegistries registries )
- throws NamingException
+ public String getBaseClassName()
{
+ return baseName;
}
- // ------------------------------------------------------------------------
- // Utility Methods
- // ------------------------------------------------------------------------
+ public String getDefaultBaseClassName()
+ {
+ return defaultBaseName;
+ }
+ public String getPackageName()
+ {
+ return packageName;
+ }
}
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchema.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchema.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchema.java
Fri Oct 15 11:21:19 2004
@@ -17,9 +17,6 @@
package org.apache.eve.schema.bootstrap;
-import javax.naming.NamingException;
-
-
/**
* A configuration of related Schema objects bundled together and identified as
* a group.
@@ -46,6 +43,13 @@
String getSchemaName();
/**
+ * Gets the package name of the schema's object factories.
+ *
+ * @return the name of the schema's package name
+ */
+ String getPackageName();
+
+ /**
* Gets the names of other schemas that this objects within this
* BootstrapSchema depends upon. These dependent schemas are those
* whose ConfigurationSets will be processed first.
@@ -55,8 +59,21 @@
String[] getDependencies();
/**
- * Populates the set of bootstrap registries with the Schema objects from
- * this logical BootstrapSchema.
+ * Gets the base class name for bootstrap Schema class files. This name
+ * is the schema name with the first character capitalized and qualified
+ * by the package name. So for a bootstrap schema name of 'bar' within
+ * the 'foo' package would return foo.Bar as the base class name.
+ *
+ * @return the base of all bootstrap schema class names for this schema
+ */
+ String getBaseClassName();
+
+ /**
+ * If the base class name for the target class does not resolve, we attempt
+ * to load another backup class using this default base class name which
+ * tries another package for the target class factory to load.
+ *
+ * @return the default base class name
*/
- void populate( BootstrapRegistries registries ) throws NamingException;
+ String getDefaultBaseClassName();
}
Added:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
==============================================================================
--- (empty file)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
Fri Oct 15 11:21:19 2004
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.eve.schema.bootstrap;
+
+
+import org.apache.eve.schema.*;
+import org.apache.ldap.common.schema.*;
+
+import java.util.Map;
+import java.util.Iterator;
+import java.util.Comparator;
+import javax.naming.NamingException;
+
+
+/**
+ * Class which handles bootstrap schema class file loading.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BootstrapSchemaLoader
+{
+ public final void populate( BootstrapSchema schema, BootstrapRegistries
registries )
+ throws NamingException
+ {
+ populate( schema, registries.getNormalizerRegistry() );
+ populate( schema, registries.getComparatorRegistry() );
+ populate( schema, registries.getSyntaxCheckerRegistry() );
+ populate( schema, registries.getSyntaxRegistry(),
registries.getSyntaxCheckerRegistry() );
+ populate( schema, registries.getMatchingRuleRegistry(),
+ registries.getSyntaxRegistry(), registries.getNormalizerRegistry(),
+ registries.getComparatorRegistry() );
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Utility Methods
+ // ------------------------------------------------------------------------
+
+
+ private void populate( BootstrapSchema schema,
+ MatchingRuleRegistry matchingRuleRegistry,
+ SyntaxRegistry syntaxRegistry,
+ NormalizerRegistry normalizerRegistry,
+ ComparatorRegistry comparatorRegistry )
+ throws NamingException
+ {
+ MatchingRuleFactory factory;
+ factory = ( MatchingRuleFactory ) getFactory( schema,
"MatchingRuleFactory" );
+
+ Map matchingRules = factory.getMatchingRules(syntaxRegistry,
+ normalizerRegistry, comparatorRegistry );
+ Iterator list = matchingRules.values().iterator();
+ while ( list.hasNext() )
+ {
+ MatchingRule matchingRule = ( MatchingRule ) list.next();
+ matchingRuleRegistry.register( schema.getSchemaName(),
matchingRule );
+ }
+ }
+
+
+ private void populate( BootstrapSchema schema,
+ SyntaxRegistry syntaxRegistry,
+ SyntaxCheckerRegistry syntaxCheckerRegistry )
+ throws NamingException
+ {
+ SyntaxFactory factory;
+ factory = ( SyntaxFactory ) getFactory( schema, "SyntaxFactory" );
+
+ Map syntaxes = factory.getSyntaxes( syntaxCheckerRegistry );
+ Iterator list = syntaxes.values().iterator();
+ while ( list.hasNext() )
+ {
+ Syntax syntax = ( Syntax ) list.next();
+ syntaxRegistry.register( schema.getSchemaName(), syntax );
+ }
+ }
+
+
+ private void populate( BootstrapSchema schema, SyntaxCheckerRegistry
registry )
+ throws NamingException
+ {
+ SyntaxCheckerFactory factory;
+ factory = ( SyntaxCheckerFactory ) getFactory( schema,
"SyntaxCheckerFactory" );
+
+ Map syntaxCheckers = factory.getSyntaxCheckers();
+ Iterator oidList = syntaxCheckers.keySet().iterator();
+ while ( oidList.hasNext() )
+ {
+ String oid = ( String ) oidList.next();
+ SyntaxChecker syntaxChecker = ( SyntaxChecker )
syntaxCheckers.get( oid );
+ registry.register( schema.getSchemaName(), oid, syntaxChecker );
+ }
+ }
+
+
+ /**
+ * Attempts first to try to load the target class for the
NormalizerFactory,
+ * then tries for the default if the target load fails.
+ *
+ * @param schema the bootstrap schema
+ * @param registry the registry to populate
+ * @throws NamingException if there are failures loading classes
+ */
+ private void populate( BootstrapSchema schema, NormalizerRegistry registry
)
+ throws NamingException
+ {
+ NormalizerFactory factory;
+ factory = ( NormalizerFactory ) getFactory( schema,
"NormalizerFactory" );
+
+ Map normalizers = factory.getNormalizers();
+ Iterator oidList = normalizers.keySet().iterator();
+ while ( oidList.hasNext() )
+ {
+ String oid = ( String ) oidList.next();
+ Normalizer normalizer = ( Normalizer ) normalizers.get( oid );
+ registry.register( schema.getSchemaName(), oid, normalizer );
+ }
+ }
+
+
+ /**
+ * Attempts first to try to load the target class for the
ComparatorFactory,
+ * then tries for the default if the target load fails.
+ *
+ * @param schema the bootstrap schema
+ * @param registry the registry to populate
+ * @throws NamingException if there are failures loading classes
+ */
+ private void populate( BootstrapSchema schema, ComparatorRegistry registry
)
+ throws NamingException
+ {
+ ComparatorFactory factory;
+ factory = ( ComparatorFactory ) getFactory( schema,
"ComparatorFactory" );
+
+ Map comparators = factory.getComparators();
+ Iterator oidList = comparators.keySet().iterator();
+ while ( oidList.hasNext() )
+ {
+ String oid = ( String ) oidList.next();
+ Comparator comparator = ( Comparator ) comparators.get( oid );
+ registry.register( schema.getSchemaName(), oid, comparator );
+ }
+ }
+
+
+ /**
+ * Attempts first to try to load the target class for the Factory,
+ * then tries for the default if the target load fails.
+ *
+ * @param schema the bootstrap schema
+ * @param factoryBase the factory base name
+ * @throws NamingException if there are failures loading classes
+ */
+ private Object getFactory( BootstrapSchema schema, String factoryBase )
+ throws NamingException
+ {
+ Class clazz = null;
+ boolean failedTargetLoad = false;
+ String defaultClassName;
+ String targetClassName = schema.getBaseClassName() + factoryBase;
+
+ try
+ {
+ clazz = Class.forName( targetClassName );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ failedTargetLoad = true;
+ // @todo instead of trace report target class load failure to
monitor
+ e.printStackTrace();
+ }
+
+ if ( failedTargetLoad )
+ {
+ defaultClassName = schema.getDefaultBaseClassName() + factoryBase;
+
+ try
+ {
+ clazz = Class.forName( defaultClassName );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ NamingException ne = new NamingException( "Failed to load " +
+ factoryBase + " for " + schema.getSchemaName()
+ + " schema using following classes: " + targetClassName
+ + ", " + defaultClassName );
+ ne.setRootCause( e );
+ throw ne;
+ }
+ }
+
+ try
+ {
+ return clazz.newInstance();
+ }
+ catch ( IllegalAccessException e )
+ {
+ NamingException ne = new NamingException( "Failed to create " +
clazz );
+ ne.setRootCause( e );
+ throw ne;
+ }
+ catch ( InstantiationException e )
+ {
+ NamingException ne = new NamingException( "Failed to create " +
clazz );
+ ne.setRootCause( e );
+ throw ne;
+ }
+ }
+}
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/MatchingRuleFactory.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/MatchingRuleFactory.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/MatchingRuleFactory.java
Fri Oct 15 11:21:19 2004
@@ -34,8 +34,7 @@
*/
public interface MatchingRuleFactory
{
- Map getMatchingRules( OidRegistry oidRegistry,
- SyntaxRegistry syntaxRegistry,
+ Map getMatchingRules( SyntaxRegistry syntaxRegistry,
NormalizerRegistry normalizerRegistry,
ComparatorRegistry comparatorRegistry );
}