directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 55116 - in incubator/directory/eve/trunk/backend/tools/src: java/org/apache/eve/tools/schema test/org/apache/eve/tools/schema
Date Wed, 20 Oct 2004 01:40:48 GMT
Author: akarasulu
Date: Tue Oct 19 18:40:47 2004
New Revision: 55116

Added:
   incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/ObjectClasses.template
  (contents, props changed)
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AbstractTestCase.java
  (contents, props changed)
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/ObjectClassesTemplateTest.java
  (contents, props changed)
Modified:
   incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypesTemplateTest.java
Log:
Commit changes ...

 o finished the ObjectClasses.template for generating ObjectClass objects
 o cleaned up AttributeTypes template
 o created abstract test case for testing parsing and code generation
 o created separate test cases off of abstract test case
 o all tests ran and passed - generated code compiles



Modified: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
(original)
+++ incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
Tue Oct 19 18:40:47 2004
@@ -37,8 +37,6 @@
  */
 public class $classname extends AbstractBootstrapProducer
 {
-    /** a reused empty String array */
-    private static final String[] EMPTY = new String[0];
 
     public $classname()
     {

Added: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/ObjectClasses.template
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/ObjectClasses.template
Tue Oct 19 18:40:47 2004
@@ -0,0 +1,119 @@
+/*
+ *   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 $package;
+
+
+import java.util.ArrayList;
+import javax.naming.NamingException;
+
+#if ( $package != "org.apache.eve.schema.bootstrap" )
+import org.apache.eve.schema.bootstrap.*;
+#end
+
+/**
+ * A producer of schema objectClass definations for the $schema schema.  This
+ * code has been automatically generated using schema files in the OpenLDAP
+ * format along with the eve schema plugin for maven.  This has been done
+ * to facilitate Eve<->OpenLDAP schema interoperability.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class $classname extends AbstractBootstrapProducer
+{
+
+    public $classname()
+    {
+        super( ProducerTypeEnum.OBJECT_CLASS_PRODUCER );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // BootstrapProducer Methods
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * @see BootstrapProducer#produce(BootstrapRegistries, ProducerCallback)
+     */
+    public void produce( BootstrapRegistries registries, ProducerCallback cb )
+        throws NamingException
+    {
+        ArrayList array = new ArrayList();
+        BootstrapObjectClass objectClass;
+
+        #foreach ( $objectClass in $objectClasses )
+
+        // --------------------------------------------------------------------
+        // ObjectClass $objectClass.getOid() $!objectClass.getName()
+        // --------------------------------------------------------------------
+
+        objectClass = new BootstrapObjectClass( "$objectClass.getOid()", registries );
+        objectClass.setObsolete( $objectClass.isObsolete() );
+        objectClass.setDescription( "$objectClass.getDescription()" );
+
+        #if ( $objectClass.getObjectClassType().getName() == "ABSTRACT" )
+        objectClass.setType( ObjectClassTypeEnum.ABSTRACT );
+        #elseif ( $objectClass.getObjectClassType().getName() == "AUXILIARY" )
+        objectClass.setType( ObjectClassTypeEnum.AUXILIARY );
+        #elseif ( $objectClass.getObjectClassType().getName() == "STRUCTURAL" )
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        #end
+
+        // set superior objectClasses
+        #if ( $objectClass.getSuperiors() )
+array.clear();
+       #foreach ( $id in $objectClass.getSuperiors() ) array.add( "$id" );
+       #end
+ objectClass.setSuperClassIds( ( String[] ) array.toArray( EMPTY ) );
+        #else
+ objectClass.setSuperClassIds( EMPTY );
+        #end
+
+        // set must list
+        #if ( $objectClass.getMust() )
+array.clear();
+       #foreach ( $id in $objectClass.getMust() ) array.add( "$id" );
+       #end
+ objectClass.setMustListIds( ( String[] ) array.toArray( EMPTY ) );
+        #else
+ objectClass.setMustListIds( EMPTY );
+        #end
+
+        // set may list
+        #if ( $objectClass.getMay() )
+array.clear();
+       #foreach ( $id in $objectClass.getMay() ) array.add( "$id" );
+       #end
+ objectClass.setMayListIds( ( String[] ) array.toArray( EMPTY ) );
+        #else
+ objectClass.setMayListIds( EMPTY );
+        #end
+
+        // set names
+        #if ( $objectClass.getNames() )
+array.clear();
+       #foreach ( $id in $objectClass.getNames() ) array.add( "$id" );
+       #end
+ objectClass.setNames( ( String[] ) array.toArray( EMPTY ) );
+        #else
+ objectClass.setNames( EMPTY );
+        #end
+cb.schemaObjectProduced( this, "$objectClass.getOid()", objectClass );
+
+ #end   }
+}

Added: incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AbstractTestCase.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AbstractTestCase.java
Tue Oct 19 18:40:47 2004
@@ -0,0 +1,170 @@
+/*
+ *   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.tools.schema;
+
+
+import junit.framework.TestCase;
+
+import java.io.InputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.File;
+
+import org.apache.eve.schema.bootstrap.BootstrapSchema;
+import org.apache.eve.schema.bootstrap.ProducerTypeEnum;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+
+
+/**
+ * An abstract test case that incorporates both the parser and code generators.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AbstractTestCase extends TestCase
+{
+    private OpenLdapSchemaParser parser;
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        parser = new OpenLdapSchemaParser();
+        parser.setParserMonitor( new ConsoleParserMonitor() );
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        parser = null;
+    }
+
+    protected ObjectClassLiteral[] getObjectClasses( String schemaFile )
+        throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( schemaFile );
+        parser.parse( in );
+        int size = parser.getObjectClassTypes().size();
+        ObjectClassLiteral[] objectClasses = new ObjectClassLiteral[size];
+        objectClasses = ( ObjectClassLiteral[] )
+            parser.getObjectClassTypes().values().toArray( objectClasses );
+        return objectClasses;
+    }
+
+    protected AttributeTypeLiteral[] getSchemaAttributes( String schemaFile )
+        throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( schemaFile );
+        parser.parse( in );
+        int size = parser.getAttributeTypes().size();
+        AttributeTypeLiteral[] attributeTypes = new AttributeTypeLiteral[size];
+        attributeTypes = ( AttributeTypeLiteral[] )
+            parser.getAttributeTypes().values().toArray( attributeTypes );
+        return attributeTypes;
+    }
+
+    protected void generateAttributeTypeProducer( BootstrapSchema schema )
+        throws Exception
+    {
+        AttributeTypeLiteral[] attributeTypes =
+            getSchemaAttributes( schema.getSchemaName() + ".schema" );
+
+        VelocityContext context = new VelocityContext();
+        context.put( "package", schema.getPackageName() );
+        context.put( "classname",
+            schema.getUnqualifiedClassName( ProducerTypeEnum.ATTRIBUTE_TYPE_PRODUCER ) );
+        context.put( "schema", schema.getSchemaName() );
+        context.put( "owner", schema.getOwner() ) ;
+        context.put( "schemaDepCount", new Integer( schema.getDependencies().length ) );
+        context.put( "schemaDeps", new String[] { "dep1", "dep2" }  ) ;
+        context.put( "attrTypes", attributeTypes );
+
+        FileReader template = getResourceReader( "AttributeTypes.template" );
+        FileWriter writer = getResourceWriter( "target/schema",
+            schema.getPackageName(),
+            schema.getUnqualifiedClassName( ProducerTypeEnum.ATTRIBUTE_TYPE_PRODUCER ) );
+        Velocity.init();
+        Velocity.evaluate( context, writer, "LOG", template );
+        writer.flush();
+        writer.close();
+    }
+
+    protected void generateObjectClassProducer( BootstrapSchema schema )
+        throws Exception
+    {
+        ObjectClassLiteral[] objectClasses =
+            getObjectClasses( schema.getSchemaName() + ".schema" );
+
+        VelocityContext context = new VelocityContext();
+        context.put( "package", schema.getPackageName() );
+        context.put( "classname",
+            schema.getUnqualifiedClassName( ProducerTypeEnum.OBJECT_CLASS_PRODUCER ) );
+        context.put( "schema", schema.getSchemaName() );
+        context.put( "owner", schema.getOwner() ) ;
+        context.put( "schemaDepCount", new Integer( schema.getDependencies().length ) );
+        context.put( "schemaDeps", new String[] { "dep1", "dep2" }  ) ;
+        context.put( "objectClasses", objectClasses );
+
+        FileReader template = getResourceReader( "ObjectClasses.template" );
+        FileWriter writer = getResourceWriter( "target/schema",
+            schema.getPackageName(),
+            schema.getUnqualifiedClassName( ProducerTypeEnum.OBJECT_CLASS_PRODUCER ) );
+        Velocity.init();
+        Velocity.evaluate( context, writer, "LOG", template );
+        writer.flush();
+        writer.close();
+    }
+
+    protected FileReader getResourceReader( String res ) throws Exception
+    {
+        String path = getClass().getResource( res ).getFile() ;
+        return new FileReader( path );
+    }
+
+    protected boolean mkdirs( String base, String path )
+    {
+        String[] comps = path.split( "/" );
+        File file = new File( base );
+
+        if ( ! file.exists() )
+        {
+            file.mkdirs();
+        }
+
+        for ( int ii = 0; ii < comps.length; ii++ )
+        {
+            file = new File( file, comps[ii] );
+            if ( ! file.exists() )
+            {
+                file.mkdirs();
+            }
+        }
+
+        return file.exists();
+    }
+
+    protected FileWriter getResourceWriter( String srcBase, String pkg,
+                                            String classname ) throws Exception
+    {
+        mkdirs( srcBase, pkg.replace( '.', File.separatorChar ) );
+        File base = new File( srcBase );
+        String relativePath = pkg.replace( '.', File.separatorChar );
+        File dir = new File( base, relativePath );
+        return new FileWriter( new File( dir, classname + ".java" ) );
+    }
+}

Modified: incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypesTemplateTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypesTemplateTest.java
(original)
+++ incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypesTemplateTest.java
Tue Oct 19 18:40:47 2004
@@ -17,16 +17,6 @@
 package org.apache.eve.tools.schema;
 
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.InputStream;
-
-import junit.framework.TestCase;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-import org.apache.eve.schema.bootstrap.BootstrapSchema;
-import org.apache.eve.schema.bootstrap.ProducerTypeEnum;
 import org.apache.eve.schema.bootstrap.AbstractBootstrapSchema;
 
 
@@ -36,107 +26,8 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class AttributeTypesTemplateTest extends TestCase
+public class AttributeTypesTemplateTest extends AbstractTestCase
 {
-    private OpenLdapSchemaParser parser;
-
-
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-
-        parser = new OpenLdapSchemaParser();
-        parser.setParserMonitor( new ConsoleParserMonitor() );
-    }
-
-
-    protected void tearDown() throws Exception
-    {
-        super.tearDown();
-        parser = null;
-    }
-
-
-    public AttributeTypeLiteral[] getSchemaAttributes( String schemaFile )
-        throws Exception
-    {
-        InputStream in = getClass().getResourceAsStream( schemaFile );
-        parser.parse( in );
-        int size = parser.getAttributeTypes().size();
-        AttributeTypeLiteral[] attributeTypes = new AttributeTypeLiteral[size];
-        attributeTypes = ( AttributeTypeLiteral[] )
-            parser.getAttributeTypes().values().toArray( attributeTypes );
-        return attributeTypes;
-    }
-
-
-    public void generateAttributeTypeProducer( BootstrapSchema schema )
-        throws Exception
-    {
-        AttributeTypeLiteral[] attributeTypes =
-            getSchemaAttributes( schema.getSchemaName() + ".schema" );
-
-        VelocityContext context = new VelocityContext();
-        context.put( "package", schema.getPackageName() );
-        context.put( "classname",
-            schema.getUnqualifiedClassName( ProducerTypeEnum.ATTRIBUTE_TYPE_PRODUCER ) );
-        context.put( "schema", schema.getSchemaName() );
-        context.put( "owner", schema.getOwner() ) ;
-        context.put( "schemaDepCount", new Integer( schema.getDependencies().length ) );
-        context.put( "schemaDeps", new String[] { "dep1", "dep2" }  ) ;
-        context.put( "attrTypeCount", new Integer( attributeTypes.length ) );
-        context.put( "attrTypes", attributeTypes );
-
-        FileReader template = getResourceReader( "AttributeTypes.template" );
-        FileWriter writer = getResourceWriter( "target/schema",
-            schema.getPackageName(),
-            schema.getUnqualifiedClassName( ProducerTypeEnum.ATTRIBUTE_TYPE_PRODUCER ) );
-        Velocity.init();
-        Velocity.evaluate( context, writer, "LOG", template );
-        writer.flush();
-        writer.close();
-    }
-
-
-    private FileReader getResourceReader( String res ) throws Exception
-    {
-        String path = getClass().getResource( res ).getFile() ;
-        return new FileReader( path );
-    }
-
-
-    private boolean mkdirs( String base, String path )
-    {
-        String[] comps = path.split( "/" );
-        File file = new File( base );
-
-        if ( ! file.exists() )
-        {
-            file.mkdirs();
-        }
-
-        for ( int ii = 0; ii < comps.length; ii++ )
-        {
-            file = new File( file, comps[ii] );
-            if ( ! file.exists() )
-            {
-                file.mkdirs();
-            }
-        }
-
-        return file.exists();
-    }
-
-
-    private FileWriter getResourceWriter( String srcBase, String pkg,
-                                          String classname ) throws Exception
-    {
-        mkdirs( srcBase, pkg.replace( '.', File.separatorChar ) );
-        File base = new File( srcBase );
-        String relativePath = pkg.replace( '.', File.separatorChar );
-        File dir = new File( base, relativePath );
-        return new FileWriter( new File( dir, classname + ".java" ) );
-    }
 
 
     public void testCoreAttributeTypeGeneration() throws Exception

Added: incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/ObjectClassesTemplateTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/ObjectClassesTemplateTest.java
Tue Oct 19 18:40:47 2004
@@ -0,0 +1,94 @@
+/*
+ *   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.tools.schema;
+
+
+import org.apache.eve.schema.bootstrap.AbstractBootstrapSchema;
+
+
+/**
+ * A test which tries to generate ObjectClass producers for all schemas.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ObjectClassesTemplateTest extends AbstractTestCase
+{
+
+
+    public void testCoreObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "core", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+
+
+    public void testJavaObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "java", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+
+
+    public void testCorbaObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "corba", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+
+
+    public void testCosineObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "cosine", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+
+
+    public void testInetorgpersonObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "inetorgperson", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+
+
+    public void testMiscObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "misc", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+
+
+    public void testNisObjectClassGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "nis", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateObjectClassProducer( schema );
+    }
+}

Mime
View raw message