Daniel Rall wrote:

>Fedor Karpelevitch <[EMAIL PROTECTED]> writes:
>
>>you forgot about FOO_BAR.
>>
>>I think the right way would be to have a choice of name conversion
>>algorithms and you specify the one that suits your naming conventions with a
>>property in build.properties
>>
>
>I would be okay with this.  Byron, feel free to submit a patch to this
>respect.
>
>Daniel Rall
>
Here is a patch that allows the user to specify a conversion method in 
the build.properties file.  The user may select from three methods, 
 "nochange"  - just as it implies,  "underscore" - as it works now, and 
"javaname" - just like underscore, but does not lower case the remaining 
letters.  The default behavior is "underscore" if the 'xmlNameConvert' 
property is not specified.

Byron


? xmlname.patch
Index: src/conf/build.properties
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/conf/build.properties,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 build.properties
--- src/conf/build.properties   2001/08/02 05:08:15     1.1.1.1
+++ src/conf/build.properties   2001/08/09 23:55:13
@@ -61,6 +61,19 @@
 # complexObjectModel=true generates an om with collection support
 #
 # addTimeStamp=true puts time stamps in generated files
+#
+# xmlNameConvert={nochange|underscore|javaname} Determines how a table
+# or column name, from the name attribute in the xml database file, is
+# converted to a Java class or method name.  
+#
+#        nochange   - indicates not change is performed.
+#        underscore - Underscores are removed, First letter is
+#                     capitalized, first letter after an underscore
+#                     is capitalized, the rest of the letters are
+#                     converted to lowercase.
+#        javaname   - same as underscore, but no letters are converted
+#                     to lowercase.
+#
 # -------------------------------------------------------------------
 
 targetPackage=org.apache.turbine
@@ -69,6 +82,7 @@
 addGetByNameMethod=true
 complexObjectModel=true
 addTimeStamp=true
+xmlNameConvert=underscore
 
 # -------------------------------------------------------------------
 # 
Index: src/conf/build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/conf/build.xml,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 build.xml
--- src/conf/build.xml  2001/08/02 05:08:16     1.1.1.1
+++ src/conf/build.xml  2001/08/09 23:55:14
@@ -244,6 +244,7 @@
       targetPackage="${targetPackage}.om"
       xmlFile="${torque.home}/${schemaDirectory}/${project}-schema.xml"
       targetDatabase="${database}"
+      xmlNameConvert="${xmlNameConvert}"
     />
   
   </target>
Index: src/java/org/apache/torque/engine/database/model/AppData.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/AppData.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 AppData.java
--- src/java/org/apache/torque/engine/database/model/AppData.java       2001/08/02 
05:08:29     1.1.1.1
+++ src/java/org/apache/torque/engine/database/model/AppData.java       2001/08/09 
+23:55:14
@@ -59,6 +59,9 @@
 import java.util.List;
 import org.xml.sax.Attributes;
 
+import org.apache.velocity.util.StringUtils;
+import org.apache.commons.collections.ExtendedProperties;
+
 /**
  * A class for holding application data structures.
  *
@@ -71,13 +74,34 @@
 
     private List dbList = new ArrayList(5);
 
+   /*
+    * Global Configuration properties.
+    */
+    private ExtendedProperties configProperties = null;
+  
     /**
      * Default Constructor
      */
+  
     public AppData()
     {
     }
 
+
+    /**
+     * Construct with configuration properties.
+     *
+     * @param configProperties contains the properties set in the
+     *        build configration file.
+     */
+  
+    public AppData(ExtendedProperties configProperties)
+    {
+      this();
+      this.configProperties = configProperties;
+    }
+
+  
     /**
      * Return an array of all databases
      */
@@ -156,5 +180,43 @@
         }
         result.append ("</app-data>");
         return result.toString();
-  }
+    }
+
+
+    /**
+     * Convert an xml name into a java class or method style name. The
+     * conversion is dictated by the xmlNameConvert property.
+     *
+     * @return String target database(s) */
+    
+    public String xmlToJavaName(String name)
+    {
+        String javaName = null;
+        String xmlNameConvert = "";
+        if (configProperties != null && 
+               configProperties.get("xmlNameConvert") != null)
+        {
+          xmlNameConvert =
+            (String)configProperties.get("xmlNameConvert");
+          
+        }
+
+        if (xmlNameConvert.equals("nochange"))
+        {
+            javaName = name;
+        }
+        else if (xmlNameConvert.equals("javaname"))
+        {
+            javaName = StringUtils.removeAndHump(name);
+        }
+        else // perform "underscore" convert method for everything else.
+        {
+            javaName = StringUtils.removeUnderScores(name);
+        }
+
+        return javaName;
+    }
+  
 }
+
+
Index: src/java/org/apache/torque/engine/database/model/Column.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Column.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Column.java
--- src/java/org/apache/torque/engine/database/model/Column.java        2001/08/02 
05:08:30     1.1.1.1
+++ src/java/org/apache/torque/engine/database/model/Column.java        2001/08/09 
+23:55:15
@@ -58,9 +58,8 @@
 import java.util.Date;
 import java.util.Hashtable;
 import java.util.List;
+import org.apache.torque.task.TorqueObjectModelTask;
 
-import org.apache.velocity.util.StringUtils;
-
 import org.xml.sax.Attributes;
 
 /**
@@ -191,13 +190,12 @@
     public String getJavaName()
     {
         if (javaName == null)
-        {
-            return StringUtils.removeUnderScores(name);
-        }
-        else
         {
-            return javaName;
+            javaName =
+              getTable().getDatabase().getAppData().xmlToJavaName(name);
         }
+
+        return javaName;
     }
 
     /**
Index: src/java/org/apache/torque/engine/database/model/Table.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Table.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Table.java
--- src/java/org/apache/torque/engine/database/model/Table.java 2001/08/02 05:08:31    
 1.1.1.1
+++ src/java/org/apache/torque/engine/database/model/Table.java 2001/08/09 23:55:16
@@ -58,9 +58,8 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
+import org.apache.torque.task.TorqueObjectModelTask;
 
-import org.apache.velocity.util.StringUtils;
-
 import org.xml.sax.Attributes;
 
 /**
@@ -453,13 +452,10 @@
     {
         if (javaName == null)
         {
-            //TO DO: Do some pritty printing here
-            return StringUtils.removeUnderScores(name);
+            javaName = getDatabase().getAppData().xmlToJavaName(name);
         }
-        else
-        {
-            return javaName;
-        }
+
+        return javaName;
     }
 
     /**
Index: src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 XmlToAppData.java
--- src/java/org/apache/torque/engine/database/transform/XmlToAppData.java      
2001/08/02 05:08:33     1.1.1.1
+++ src/java/org/apache/torque/engine/database/transform/XmlToAppData.java      
+2001/08/09 23:55:16
@@ -72,6 +72,7 @@
 import org.apache.torque.engine.database.model.Unique;
 import org.apache.xerces.framework.XMLParser;
 import org.apache.xerces.parsers.SAXParser;
+import org.apache.commons.collections.ExtendedProperties;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.EntityResolver;
@@ -81,6 +82,7 @@
 import org.xml.sax.SAXParseException;
 import org.xml.sax.helpers.DefaultHandler;
 
+
 /**
  * A Class that is used to parse an input
  * xml schema file and creates and AppData java structure.
@@ -104,7 +106,12 @@
     private boolean firstPass;
     private Table foreignTable;
     private String errorMessage;
-    
+
+   /*
+    * Global Configuration properties.
+    */
+    private ExtendedProperties configProperties = null;
+
     /**
      * Default custructor
      */
@@ -115,6 +122,19 @@
         errorMessage = "";
     }
 
+    /**
+     * Construct with configuration properties.
+     *
+     * @param configProperties contains the properties set in the
+     *        build configration file.
+     */
+  
+    public XmlToAppData(ExtendedProperties configProperties)
+    {
+      this();
+      this.configProperties = configProperties;
+    }
+  
 
     /**
      * Parse and xml input file and returns a newly
@@ -126,7 +146,7 @@
         {
             if ( firstPass ) 
             {
-                app = new AppData();                
+                app = new AppData(configProperties);                
             }
             
             SAXParser parser = new SAXParser();
Index: src/java/org/apache/torque/task/TorqueObjectModelTask.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueObjectModelTask.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 TorqueObjectModelTask.java
--- src/java/org/apache/torque/task/TorqueObjectModelTask.java  2001/08/02 05:08:37    
 1.1.1.1
+++ src/java/org/apache/torque/task/TorqueObjectModelTask.java  2001/08/09 23:55:17
@@ -81,6 +81,14 @@
     private String xmlFile;
 
     /**
+     * XML name convert method for indicating how xml names for tables
+     * and columns are converted to class names and methods.  We
+     * initialize it with "uderscore" which is the traditional
+     * expected behavior.  
+     */
+    private static String xmlNameConvert = "underscore";
+  
+    /**
      * Target Java package to place the generated
      * files in.
      */
@@ -155,6 +163,38 @@
         targetDatabase = v;
     }
 
+
+    /**
+     * Get the xmlNameConvert. 
+     *
+     * @return String method type of xml to java name conversions.
+     */
+    public String getXmlNameConvert ()
+    {
+        return xmlNameConvert;
+    }
+
+    /**
+     * Set the xmlNameConvert.  This property indicates the method by
+     * which xml names for tables and columns will be converted to
+     * java object and method names within the coresponding java
+     * object.  There are currently three method: "nochange" - xml
+     * names are converted directly to java names without
+     * modification.  "underscore" Will capitalize the first letter,
+     * remove underscores, and capitalize each letter before an
+     * underscore.  All other letters are lowercased. "javaname" works
+     * the same as the "underscore" method but will not lowercase any
+     * characters.
+     *
+     *
+     * @param String method string for conversion.
+     */
+    public void setXmlNameConvert (String v)
+    {
+        xmlNameConvert = v;
+    }
+
+
     public Context initControlContext()
     {
         /*
@@ -162,13 +202,13 @@
          */
         Context context = new VelocityContext();
 
+        
         /*
          * Build our application model from the
          * XML schema. Can someone document the
          * double pass here?
          */
-        XmlToAppData xmlParser = new XmlToAppData();
-
+        XmlToAppData xmlParser = new XmlToAppData(getContextProperties());
         app = xmlParser.parseFile(xmlFile);
         xmlParser.parseFile(xmlFile);
 
@@ -189,7 +229,17 @@
          * Place the target package in the context.
          */
         context.put("targetPackage", targetPackage);
-
+         
         return context;
     }
+
 }
+
+
+
+
+
+
+
+
+

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to