Author: akarasulu
Date: Fri Oct 22 00:42:55 2004
New Revision: 55314
Added:
incubator/directory/eve/trunk/backend/core/src/test/
incubator/directory/eve/trunk/backend/core/src/test/org/
incubator/directory/eve/trunk/backend/core/src/test/org/apache/
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/schema/
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/schema/bootstrap/
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/schema/bootstrap/BootstrapSchemaLoaderTest.java
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
incubator/directory/eve/trunk/backend/core/src/schema/core.schema
Log:
Commit changes ...
o corrected reproduced attributeType in core which was already in system schema
o added test case to test correct loading
o added code to load schemas in order of depenencies
Notes ...
We still need to make sure resolution occurs by testing all objects in all
repositories.
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapSchemaLoader.java
Fri Oct 22 00:42:55 2004
@@ -17,8 +17,7 @@
package org.apache.eve.schema.bootstrap;
-import java.util.List;
-import java.util.Comparator;
+import java.util.*;
import javax.naming.NamingException;
@@ -34,8 +33,11 @@
*/
public class BootstrapSchemaLoader
{
+ /** stores schemas of producers for callback access */
private ThreadLocal schemas;
+ /** stores registries associated with producers for callback access */
private ThreadLocal registries;
+ /** the callback that just calls register() */
private final ProducerCallback cb = new ProducerCallback()
{
public void schemaObjectProduced( BootstrapProducer producer,
@@ -48,6 +50,9 @@
};
+ /**
+ * Creates a BootstrapSchema loader.
+ */
public BootstrapSchemaLoader()
{
schemas = new ThreadLocal();
@@ -55,7 +60,125 @@
}
- public final void loadProducers( BootstrapSchema schema,
BootstrapRegistries registries )
+
+ /**
+ * Loads a set of schemas by loading and running all producers for each
+ * dependent schema first.
+ *
+ * @param schemaClasses the full qualified class names of the schema
classes
+ * @param registries the registries to fill with producer created objects
+ * @throws NamingException if there are any failures during this process
+ */
+ public final void load( String[] schemaClasses, BootstrapRegistries
registries )
+ throws NamingException
+ {
+ BootstrapSchema[] schemas = new BootstrapSchema[schemaClasses.length];
+ HashMap loaded = new HashMap();
+ HashMap notLoaded = new HashMap();
+
+
+ for ( int ii = 0; ii < schemas.length; ii++ )
+ {
+ try
+ {
+ Class schemaClass = Class.forName( schemaClasses[ii] );
+ schemas[ii] = ( BootstrapSchema ) schemaClass.newInstance();
+ notLoaded.put( schemas[ii].getSchemaName(), schemas[ii] );
+ }
+ catch ( Exception e )
+ {
+ String msg = "problem loading/creating " + schemaClasses[ii];
+ NamingException ne = new NamingException( msg );
+ ne.setRootCause( e );
+ throw ne;
+ }
+ }
+
+ // kick it off by loading system which will never depend on anything
+ BootstrapSchema schema = ( BootstrapSchema ) notLoaded.get( "system" );
+ load( schema, registries );
+ notLoaded.remove( "system" );
+ loaded.put( schema.getSchemaName(), schema );
+
+ Iterator list = notLoaded.values().iterator();
+ while ( list.hasNext() )
+ {
+ schema = ( BootstrapSchema ) list.next();
+ loadDepsFirst( new Stack(), notLoaded, schema, registries );
+ list = notLoaded.values().iterator();
+ }
+ }
+
+
+ /**
+ * 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
+ * control with depenency cycle detection.
+ *
+ * @param beenthere stack of schema names we have visited and have yet to
load
+ * @param notLoaded hash of schemas keyed by name which have yet to be
loaded
+ * @param schema the current schema we are attempting to load
+ * @param registries the set of registries to use while loading
+ * @throws NamingException if there is a cycle detected and/or another
+ * failure results while loading, producing and or registering schema
objects
+ */
+ public final void loadDepsFirst( Stack beenthere, HashMap notLoaded,
+ BootstrapSchema schema,
+ BootstrapRegistries registries )
+ throws NamingException
+ {
+ beenthere.push( schema.getSchemaName() );
+ String[] deps = schema.getDependencies();
+
+ // if no deps then load this guy and return
+ if ( deps == null || deps.length == 0 )
+ {
+ load( schema, registries );
+ notLoaded.remove( schema.getSchemaName() );
+ beenthere.pop();
+ return;
+ }
+
+ /*
+ * We got deps and need to load them before this schema. We go through
+ * all deps loading them with their deps first if they have not been
+ * loaded.
+ */
+ for ( int ii = 0; ii < deps.length; ii++ )
+ {
+ if ( ! notLoaded.containsKey( deps[ii] ) )
+ {
+ continue;
+ }
+
+ BootstrapSchema dep = ( BootstrapSchema ) notLoaded.get( deps[ii]
);
+
+ if ( beenthere.contains( dep.getSchemaName() ) )
+ {
+ // push again so we show the cycle in output
+ beenthere.push( dep.getSchemaName() );
+ throw new NamingException( "schema dependency cycle detected: "
+ + beenthere );
+ }
+
+ loadDepsFirst( beenthere, notLoaded, dep, registries );
+ }
+
+ // We have loaded all our deps so we can load this schema
+ load( schema, registries );
+ notLoaded.remove( schema.getSchemaName() );
+ beenthere.pop();
+ }
+
+
+ /**
+ * Loads a schema by loading and running all producers for te schema.
+ *
+ * @param schema the schema to load
+ * @param registries the registries to fill with producer created objects
+ * @throws NamingException if there are any failures during this process
+ */
+ public final void load( BootstrapSchema schema, BootstrapRegistries
registries )
throws NamingException
{
this.registries.set( registries );
Modified: incubator/directory/eve/trunk/backend/core/src/schema/core.schema
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/schema/core.schema
(original)
+++ incubator/directory/eve/trunk/backend/core/src/schema/core.schema Fri Oct
22 00:42:55 2004
@@ -468,10 +468,12 @@
#
# Standard Track URI label schema from RFC 2079
#
-attributetype ( 1.3.6.1.4.1.250.1.57 NAME 'labeledURI'
- DESC 'RFC2079: Uniform Resource Identifier with optional label'
- EQUALITY caseExactMatch
- SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
+
+# this is already in system.schema
+#attributetype ( 1.3.6.1.4.1.250.1.57 NAME 'labeledURI'
+# DESC 'RFC2079: Uniform Resource Identifier with optional label'
+# EQUALITY caseExactMatch
+# SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
# This was malformed with MAY list before the SUP and AUXILIARY fields
objectclass ( 1.3.6.1.4.1.250.3.15 NAME 'labeledURIObject'
Added:
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/schema/bootstrap/BootstrapSchemaLoaderTest.java
==============================================================================
--- (empty file)
+++
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/schema/bootstrap/BootstrapSchemaLoaderTest.java
Fri Oct 22 00:42:55 2004
@@ -0,0 +1,272 @@
+/*
+ * 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 javax.naming.NamingException;
+
+import junit.framework.TestCase;
+import org.apache.ldap.common.schema.AttributeType;
+
+
+/**
+ * A unit test case for the BootstrapSchemaLoader class.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BootstrapSchemaLoaderTest extends TestCase
+{
+ BootstrapRegistries registries;
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ registries = new BootstrapRegistries();
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ registries = null;
+ }
+
+
+ public void testLoad() throws NamingException
+ {
+ BootstrapRegistries registries = new BootstrapRegistries();
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ String[] schemaClasses = {
+ "org.apache.eve.schema.bootstrap.AutofsSchema",
+ "org.apache.eve.schema.bootstrap.CoreSchema",
+ "org.apache.eve.schema.bootstrap.CosineSchema",
+ "org.apache.eve.schema.bootstrap.CorbaSchema",
+ "org.apache.eve.schema.bootstrap.EveSchema",
+ "org.apache.eve.schema.bootstrap.InetorgpersonSchema",
+ "org.apache.eve.schema.bootstrap.JavaSchema",
+ "org.apache.eve.schema.bootstrap.Krb5kdcSchema",
+ "org.apache.eve.schema.bootstrap.NisSchema",
+ "org.apache.eve.schema.bootstrap.SystemSchema"
+ };
+ loader.load( schemaClasses, registries );
+ AttributeType type;
+
+ // from autofs.schema
+ type = registries.getAttributeTypeRegistry().lookup(
"automountInformation" );
+ assertNotNull( type );
+
+ // from core.schema
+ type = registries.getAttributeTypeRegistry().lookup(
"knowledgeInformation" );
+ assertNotNull( type );
+
+ // from cosine.schema
+ type = registries.getAttributeTypeRegistry().lookup(
"textEncodedORAddress" );
+ assertNotNull( type );
+
+ // from corba.schema
+ type = registries.getAttributeTypeRegistry().lookup(
"corbaRepositoryId" );
+ assertNotNull( type );
+
+ // from eve.schema
+ type = registries.getAttributeTypeRegistry().lookup( "eveAlias" );
+ assertNotNull( type );
+
+ // from inetorgperson.schema
+ type = registries.getAttributeTypeRegistry().lookup( "carLicense" );
+ assertNotNull( type );
+
+ // from java.schema
+ type = registries.getAttributeTypeRegistry().lookup( "javaClassName" );
+ assertNotNull( type );
+
+ // from krb5kdc.schema
+ type = registries.getAttributeTypeRegistry().lookup(
"krb5PrincipalName" );
+ assertNotNull( type );
+
+ // from nis.schema
+ type = registries.getAttributeTypeRegistry().lookup( "homeDirectory" );
+ assertNotNull( type );
+
+ // from system.schema
+ type = registries.getAttributeTypeRegistry().lookup(
"distinguishedName" );
+ assertNotNull( type );
+
+ }
+
+
+ public void testSystemSchemaLoad() throws NamingException
+ {
+ SystemSchema systemSchema = new SystemSchema();
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ loader.load( systemSchema, registries );
+
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup(
"distinguishedName" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "objectClass" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "modifyTimestamp"
);
+ assertNotNull( type );
+ }
+
+
+ public void testEveSchemaLoad() throws NamingException
+ {
+ testSystemSchemaLoad();
+
+ EveSchema eveSchema = new EveSchema();
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ loader.load( eveSchema, registries );
+
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup( "eveNdn" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "eveAlias" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "eveUpdn" );
+ assertNotNull( type );
+ }
+
+
+ public void testEveDepsSchemaLoad() throws NamingException
+ {
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ String[] schemaClasses = {
+ "org.apache.eve.schema.bootstrap.EveSchema",
+ "org.apache.eve.schema.bootstrap.SystemSchema"
+ };
+ loader.load( schemaClasses, registries );
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup( "eveNdn" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "eveAlias" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "eveUpdn" );
+ assertNotNull( type );
+ }
+
+
+ public void testCoreSchemaLoad() throws NamingException
+ {
+ testSystemSchemaLoad();
+
+ CoreSchema coreSchema = new CoreSchema();
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ loader.load( coreSchema, registries );
+
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup(
"knowledgeInformation" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "countryName" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "serialNumber" );
+ assertNotNull( type );
+ }
+
+
+ public void testCoreDepsSchemaLoad() throws NamingException
+ {
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ String[] schemaClasses = {
+ "org.apache.eve.schema.bootstrap.CoreSchema",
+ "org.apache.eve.schema.bootstrap.SystemSchema"
+ };
+ loader.load( schemaClasses, registries );
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup(
"knowledgeInformation" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "countryName" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "serialNumber" );
+ assertNotNull( type );
+ }
+
+
+ public void testJavaSchemaLoad() throws NamingException
+ {
+ testCoreSchemaLoad();
+
+ JavaSchema javaSchema = new JavaSchema();
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ loader.load( javaSchema, registries );
+
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup( "javaFactory" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup(
"javaSerializedData" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "javaClassNames"
);
+ assertNotNull( type );
+ }
+
+
+ public void testJavaDepsSchemaLoad() throws NamingException
+ {
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ String[] schemaClasses = {
+ "org.apache.eve.schema.bootstrap.CoreSchema",
+ "org.apache.eve.schema.bootstrap.JavaSchema",
+ "org.apache.eve.schema.bootstrap.SystemSchema"
+ };
+ loader.load( schemaClasses, registries );
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup( "javaFactory" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup(
"javaSerializedData" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "javaClassNames"
);
+ assertNotNull( type );
+ }
+
+
+ public void testEveAndJavaDepsSchemaLoad() throws NamingException
+ {
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+ String[] schemaClasses = {
+ "org.apache.eve.schema.bootstrap.EveSchema",
+ "org.apache.eve.schema.bootstrap.CoreSchema",
+ "org.apache.eve.schema.bootstrap.JavaSchema",
+ "org.apache.eve.schema.bootstrap.SystemSchema"
+ };
+ loader.load( schemaClasses, registries );
+ AttributeType type;
+ type = registries.getAttributeTypeRegistry().lookup( "eveAlias" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "eveNdn" );
+ assertNotNull( type );
+
+ type = registries.getAttributeTypeRegistry().lookup( "eveUpdn" );
+ assertNotNull( type );
+ }
+}