directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 54042 - in incubator/directory/eve/trunk/backend/tools: . src/java/org/apache/eve/tools/schema src/template src/test/org/apache/eve/tools/schema
Date Fri, 08 Oct 2004 04:22:04 GMT
Author: akarasulu
Date: Thu Oct  7 21:22:03 2004
New Revision: 54042

Added:
   incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
      - copied, changed from rev 54037, incubator/directory/eve/trunk/backend/tools/src/template/AttributeTypes.template
Removed:
   incubator/directory/eve/trunk/backend/tools/src/template/AttributeTypes.template
Modified:
   incubator/directory/eve/trunk/backend/tools/project.xml
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypesTemplateTest.java
Log:
still refining the template

Modified: incubator/directory/eve/trunk/backend/tools/project.xml
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/project.xml	(original)
+++ incubator/directory/eve/trunk/backend/tools/project.xml	Thu Oct  7 21:22:03 2004
@@ -64,7 +64,17 @@
   <build>
     <sourceDirectory>src/java</sourceDirectory>
     <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
+
     <unitTest>
+      <resources>
+        <resource>
+          <directory>src/java</directory>
+          <includes>
+            <include>**/*.template</include>
+          </includes>
+        </resource>
+      </resources>
+
       <includes>
         <include>**/*Test.java</include>
       </includes>
@@ -72,13 +82,15 @@
         <exclude>**/NaughtyTest.java</exclude>
       </excludes>
     </unitTest>
+
     <resources>
       <resource>
-        <directory>src/conf</directory>
+        <directory>src/java</directory>
         <includes>
-          <include>*.properties</include>
+          <include>**/*.template</include>
         </includes>
       </resource>
     </resources>
+
   </build>
 </project>

Copied: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
(from rev 54037, incubator/directory/eve/trunk/backend/tools/src/template/AttributeTypes.template)
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/template/AttributeTypes.template	(original)
+++ incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypes.template
Thu Oct  7 21:22:03 2004
@@ -80,13 +80,59 @@
     // ------------------------------------------------------------------------
 
 
-    public AttributeType[] load()
+    public AttributeType[] load( AttributeTypeRegistry attrTypeReg,
+                                 MatchingRuleRegistry mruleReg )
+        throws NamingException
     {
+        String usage;
+        String mruleOid;
+        String superiorOid;
+        MatchingRule mrule;
+        AttributeType superior;
         AttributeType[] attributeTypes = new AttributeType[$attrTypeCount];
 
         #foreach ( $attrType in $attrTypes )
         #set ( $ii = $velocityCount - 1 )
 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() );
+
+        // set the superior attribute type
+        superiorOid = "$!attrType.getSuperiorOid()";
+        if ( ! superiorOid.equals("") )
+        {
+            attributeTypes[$ii].setSuperior( attrTypeReg.lookup( superiorOid ) );
+        }
+
+        // set usage enumeration value
+        usage = "$attrType.getUsage().getName()";
+        attributeTypes[$ii].setUsageEnum( UsageEnum.getUsageEnum( usage ) );
+
+        // set the equality matching rule
+        mruleOid = "$!attrType.getEqualityOid()";
+        if ( ! mruleOid.equals("") )
+        {
+            attributeTypes[$ii].setEquality( mruleReg.lookup( mruleOid ) );
+        }
+
+        // set the substr matching rule
+        mruleOid = "$!attrType.getSubstrOid()";
+        if ( ! mruleOid.equals("") )
+        {
+            attributeTypes[$ii].setSubstr( mruleReg.lookup( mruleOid ) );
+        }
+
+        // set the ordering matching rule
+        mruleOid = "$!attrType.getOrderingOid()";
+        if ( ! mruleOid.equals("") )
+        {
+            attributeTypes[$ii].setOrdering( mruleReg.lookup( mruleOid ) );
+        }
+
+
         #end
 
         return attributeTypes;

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
Thu Oct  7 21:22:03 2004
@@ -19,11 +19,12 @@
 import junit.framework.TestCase;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
-import org.apache.ldap.common.schema.BaseAttributeType;
+import org.apache.ldap.common.schema.*;
 
-import java.io.StringWriter;
+import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.util.ArrayList;
 
 
 /**
@@ -34,11 +35,55 @@
  */
 public class AttributeTypesTemplateTest extends TestCase
 {
+    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 testGeneration() throws Exception
     {
         TestAttributeType[] attributeTypes = new TestAttributeType[2];
         attributeTypes[0] = new TestAttributeType( "1.1.1.1" );
+        attributeTypes[0].setUsage( UsageEnum.DIRECTORYOPERATION );
+
         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" );
@@ -50,10 +95,9 @@
         context.put( "attrTypeCount", new Integer( attributeTypes.length ) );
         context.put( "attrTypes", attributeTypes );
 
-        FileReader template = new FileReader(
-            "c:\\projects\\home\\akarasulu\\projects\\directory\\eve\\trunk\\backend\\tools\\src\\template\\AttributeTypes.template"
);
-        FileWriter writer = new FileWriter(
-            "c:\\projects\\home\\akarasulu\\projects\\directory\\eve\\trunk\\backend\\tools\\src\\java\\org\\apache\\eve\\schema\\config\\CoreAttributeTypes.java"
);
+        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();
@@ -66,6 +110,86 @@
         protected TestAttributeType( String oid )
         {
             super( oid );
+        }
+
+        protected void setSuperior( AttributeType superior )
+        {
+            super.setSuperior( superior );
+        }
+
+        protected void setNameList( ArrayList nameList )
+        {
+            super.setNameList( nameList );
+        }
+
+        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 );
+        }
+
+        public String getSuperiorOid()
+        {
+            return super.getSuperior() != null ? super.getSuperior().getOid() : null;
+        }
+
+        public String getSubstrOid()
+        {
+            return super.getSubstr() != null ? super.getSubstr().getOid() : null;
+        }
+
+        public String getOrderingOid()
+        {
+            return super.getOrdering() != null ? super.getOrdering().getOid() : null;
+        }
+
+        public String getEqualityOid()
+        {
+            return super.getEquality() != null ? super.getEquality().getOid() : null;
         }
     }
 }

Mime
View raw message