directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 55108 - in incubator/directory/eve/trunk/backend/tools/src: java/org/apache/eve/tools/schema test/org/apache/eve/tools/schema
Date Tue, 19 Oct 2004 22:27:52 GMT
Author: akarasulu
Date: Tue Oct 19 15:27:51 2004
New Revision: 55108

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:
completed attributeType producer generators

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 15:27:51 2004
@@ -22,180 +22,72 @@
 
 import org.apache.ldap.common.schema.*;
 
-#if ( $package != "org.apache.eve.schema" )
-import org.apache.eve.schema.*;
+#if ( $package != "org.apache.eve.schema.bootstrap" )
+import org.apache.eve.schema.bootstrap.*;
 #end
-#if ( $package != "org.apache.eve.schema.config" )
-import org.apache.eve.schema.config.*;
-#end
-
 
 /**
- * A configuration set of schema attributeType definations for the $schema
- * schema.  This code has been automatically generated from velocity templates
- * and the OpenLDAP syntax specified $schema.schema file.  This has been done
+ * A producer of schema attributeType 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\$
+ * @version $Rev$
  */
-public class $classname implements AttributeTypeConfigSet
+public class $classname extends AbstractBootstrapProducer
 {
     /** a reused empty String array */
     private static final String[] EMPTY = new String[0];
-    /** the DN of the owner of the objects within this SyntaxConfigSet */
-    private static final String OWNER = "$owner";
-    /** the logical schema the objects within this SyntaxConfigSet belong to */
-    private static final String SCHEMA = "$schema";
-
-
-    private String[] schemaDeps;
-
-
-    // ------------------------------------------------------------------------
-    // Configuration Set Methods
-    // ------------------------------------------------------------------------
-
-
-    public String getOwner()
-    {
-        return OWNER;
-    }
-
 
-    public String getSchemaName()
+    public $classname()
     {
-        return SCHEMA;
-    }
-
-
-    public String[] getDependentSchemas()
-    {
-        if ( schemaDeps == null )
-        {
-            schemaDeps = new String[$schemaDepCount];
-            #foreach ( $dep in $schemaDeps )
-            #set ( $ii = $velocityCount - 1 )
-schemaDeps[$ii] = "$dep";
-            #end
-        }
-
-        return schemaDeps;
+        super( ProducerTypeEnum.ATTRIBUTE_TYPE_PRODUCER );
     }
 
 
     // ------------------------------------------------------------------------
-    // Syntax Configuration Set Methods
+    // BootstrapProducer Methods
     // ------------------------------------------------------------------------
 
 
-    public AttributeType[] load( SyntaxRegistry syntaxReg,
-                                 MatchingRuleRegistry mruleReg,
-                                 AttributeTypeRegistry attrTypeReg )
+    /**
+     * @see BootstrapProducer#produce(BootstrapRegistries, ProducerCallback)
+     */
+    public void produce( BootstrapRegistries registries, ProducerCallback cb )
         throws NamingException
     {
         ArrayList names = new ArrayList();
-        MutableAttributeType[] attributeTypes = new MutableAttributeType[$attrTypeCount];
+        BootstrapAttributeType attributeType;
 
         #foreach ( $attrType in $attrTypes )
-        #set ( $ii = $velocityCount - 1 )
 
         // --------------------------------------------------------------------
         // AttributeType $attrType.getOid() $!attrType.getName()
         // --------------------------------------------------------------------
 
+        attributeType = new BootstrapAttributeType( "$attrType.getOid()", registries );
+        attributeType.setSingleValue( $attrType.isSingleValue() );
+        attributeType.setCollective( $attrType.isCollective() );
+        attributeType.setObsolete( $attrType.isObsolete() );
+        attributeType.setCanUserModify( $attrType.isNoUserModification() );
+        attributeType.setLength( $attrType.getLength() );
+        attributeType.setUsage( UsageEnum.getUsage( "$attrType.getUsage().getName()" ) );
+#if ( $attrType.getSuperiorOid() )        attributeType.setSuperiorId( "$attrType.getSuperiorOid()"
); #end
+#if ( $attrType.getEqualityOid() )        attributeType.setEqualityId( "$attrType.getEqualityOid()"
);#end
+#if ( $attrType.getSubstrOid() )        attributeType.setSubstrId( "$attrType.getSubstrOid()"
);#end
+#if ( $attrType.getOrderingOid() )        attributeType.setOrderingId( "$attrType.getOrderingOid()"
);#end
+#if ( $attrType.getSyntaxOid() )        attributeType.setSyntaxId( "$attrType.getSyntaxOid()"
);#end
 
-        attributeTypes[$ii] = new MutableAttributeType( "$attrType.getOid()" );
-        attributeTypes[$ii].setSingleValue( $attrType.isSingleValue() );
-        attributeTypes[$ii].setCollective( $attrType.isCollective() );
-        attributeTypes[$ii].setObsolete( $attrType.isObsolete() );
-        attributeTypes[$ii].setCanUserModify( $attrType.isCanUserModify() );
-        attributeTypes[$ii].setLength( $attrType.getLength() );
-        attributeTypes[$ii].setUsage( UsageEnum.getUsage( "$attrType.getUsage().getName()"
) );
-#if ( $attrType.getSuperiorOid() )        attributeTypes[$ii].setSuperior( attrTypeReg.lookup(
"$attrType.getSuperiorOid()" ) ); #end
-#if ( $attrType.getEqualityOid() )        attributeTypes[$ii].setEquality( mruleReg.lookup(
"$attrType.getEqualityOid()" ) );#end
-#if ( $attrType.getSubstrOid() )        attributeTypes[$ii].setSubstr( mruleReg.lookup( "$attrType.getSubstrOid()"
) );#end
-#if ( $attrType.getOrderingOid() )        attributeTypes[$ii].setOrdering( mruleReg.lookup(
"$attrType.getOrderingOid()" ) );#end
-#if ( $attrType.getSyntaxOid() )        attributeTypes[$ii].setSyntax( syntaxReg.lookup(
"$attrType.getSyntaxOid()" ) );#end
-
-        #if ( $attrType.getAllNames() )
+        #if ( $attrType.getNames() )
 names.clear();
-       #foreach ( $name in $attrType.getAllNames() ) names.add( "$name" );
+       #foreach ( $name in $attrType.getNames() ) names.add( "$name" );
        #end
- attributeTypes[$ii].setAllNames( ( String[] ) names.toArray( EMPTY ) );
+ attributeType.setNames( ( String[] ) names.toArray( EMPTY ) );
+        #else
+ attributeType.setNames( EMPTY );
         #end
+cb.schemaObjectProduced( this, "$attrType.getOid()", attributeType );
 
-        #end
-
-        return attributeTypes;
-    }
-
-
-    private static class MutableAttributeType extends BaseAttributeType
-    {
-        public MutableAttributeType( String oid )
-        {
-            super( oid );
-        }
-
-        protected void setSuperior( AttributeType superior )
-        {
-            super.setSuperior( superior );
-        }
-
-        protected void setAllNames( String[] nameArray )
-        {
-            super.setAllNames( nameArray );
-        }
-
-        protected void setEquality( MatchingRule equality )
-        {
-            super.setEquality( equality );
-        }
-
-        protected void setSubstr( MatchingRule substr )
-        {
-            super.setSubstr( substr );
-        }
-
-        protected void setOrdering( MatchingRule ordering )
-        {
-            super.setOrdering( ordering );
-        }
-
-        protected void setSyntax( Syntax syntax )
-        {
-            super.setSyntax( syntax );
-        }
-
-        protected void setSingleValue( boolean singleValue )
-        {
-            super.setSingleValue( singleValue );
-        }
-
-        protected void setCollective( boolean collective )
-        {
-            super.setCollective( collective );
-        }
-
-        protected void setCanUserModify( boolean canUserModify )
-        {
-            super.setCanUserModify( canUserModify );
-        }
-
-        protected void setObsolete( boolean obsolete )
-        {
-            super.setObsolete( obsolete );
-        }
-
-        protected void setUsage( UsageEnum usage )
-        {
-            super.setUsage( usage );
-        }
-
-        protected void setLength( int length )
-        {
-            super.setLength( length );
-        }
-    }
+ #end   }
 }

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 15:27:51 2004
@@ -16,24 +16,88 @@
  */
 package org.apache.eve.tools.schema;
 
-import junit.framework.TestCase;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-import org.apache.ldap.common.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;
 
 
 /**
- * Document me.
+ * A test which tries to generate AttributeType producers for all schemas.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class AttributeTypesTemplateTest 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;
+    }
+
+
+    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() ;
@@ -75,154 +139,65 @@
     }
 
 
-    public void testGeneration() throws Exception
+    public void testCoreAttributeTypeGeneration() throws Exception
     {
-        Syntax syntax = new Syntax(){
-            public boolean isHumanReadable()
-            {
-                return false;
-            }
-
-            public String getName()
-            {
-                return null;
-            }
-
-            public String getOid()
-            {
-                return "2.3.3.6";
-            }
-
-            public SyntaxChecker getSyntaxChecker()
-            {
-                return null;
-            }
-
-            public String getDescription()
-            {
-                return null;
-            }
-        };
-
-        TestAttributeType[] attributeTypes = new TestAttributeType[2];
-        attributeTypes[0] = new TestAttributeType( "1.1.1.1" );
-        attributeTypes[0].setUsage( UsageEnum.USERAPPLICATIONS );
-        attributeTypes[0].setSyntax( syntax );
-        attributeTypes[0].setAllNames( new String[] { "commonName", "cn", "abc" } );
-
-        attributeTypes[1] = new TestAttributeType( "1.1.1.2" );
-        attributeTypes[1].setUsage( UsageEnum.DIRECTORYOPERATION );
-
-        VelocityContext context = new VelocityContext();
-        context.put( "package", "org.apache.eve.schema.config" );
-        context.put( "classname", "CoreAttributeTypes" );
-        context.put( "schema", "core" );
-        context.put( "owner", "uid=admin,ou=system" ) ;
-        context.put( "schemaDepCount", new Integer( 2 ) );
-        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",
-            "org.apache.eve.schema.config", "CoreAttributeTypes" );
-        Velocity.init();
-        Velocity.evaluate( context, writer, "LOG", template );
-        writer.flush();
-        writer.close();
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "core", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
     }
 
 
-    class TestAttributeType extends BaseAttributeType
+    public void testJavaAttributeTypeGeneration() throws Exception
     {
-        protected TestAttributeType( String oid )
-        {
-            super( oid );
-        }
-
-        protected void setSuperior( AttributeType superior )
-        {
-            super.setSuperior( superior );
-        }
-
-        protected void setAllNames( String[] names )
-        {
-            super.setAllNames( names );
-        }
-
-        protected void setEquality( MatchingRule equality )
-        {
-            super.setEquality( equality );
-        }
-
-        protected void setSubstr( MatchingRule substr )
-        {
-            super.setSubstr( substr );
-        }
-
-        protected void setOrdering( MatchingRule ordering )
-        {
-            super.setOrdering( ordering );
-        }
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "java", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
+    }
 
-        protected void setSyntax( Syntax syntax )
-        {
-            super.setSyntax( syntax );
-        }
 
-        protected void setSingleValue( boolean singleValue )
-        {
-            super.setSingleValue( singleValue );
-        }
-
-        protected void setCollective( boolean collective )
-        {
-            super.setCollective( collective );
-        }
-
-        protected void setCanUserModify( boolean canUserModify )
-        {
-            super.setCanUserModify( canUserModify );
-        }
+    public void testCorbaAttributeTypeGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "corba", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
+    }
 
-        protected void setObsolete( boolean obsolete )
-        {
-            super.setObsolete( obsolete );
-        }
 
-        protected void setUsage( UsageEnum usage )
-        {
-            super.setUsage( usage );
-        }
+    public void testCosineAttributeTypeGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "cosine", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
+    }
 
-        protected void setLength( int length )
-        {
-            super.setLength( length );
-        }
 
-        public String getSuperiorOid()
-        {
-            return super.getSuperior() != null ? super.getSuperior().getOid() : null;
-        }
+    public void testInetorgpersonAttributeTypeGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "inetorgperson", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
+    }
 
-        public String getSubstrOid()
-        {
-            return super.getSubstr() != null ? super.getSubstr().getOid() : null;
-        }
 
-        public String getOrderingOid()
-        {
-            return super.getOrdering() != null ? super.getOrdering().getOid() : null;
-        }
+    public void testMiscAttributeTypeGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "misc", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
+    }
 
-        public String getEqualityOid()
-        {
-            return super.getEquality() != null ? super.getEquality().getOid() : null;
-        }
 
-        public String getSyntaxOid()
-        {
-            return super.getSyntax() != null ? super.getSyntax().getOid() : null;
-        }
+    public void testNisAttributeTypeGeneration() throws Exception
+    {
+        AbstractBootstrapSchema schema = new AbstractBootstrapSchema(
+            "uid=admin,ou=system", "nis", "org.apache.eve.schema.bootstrap",
+            new String[] { "dep1", "dep2" }) {};
+        generateAttributeTypeProducer( schema );
     }
 }

Mime
View raw message