dev@javaserverfaces.java.net

[REVIEW] Cleanup/Minor refactoring of Generators in jsf-tools

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Thu, 09 Dec 2004 11:07:48 -0500

Cleanup up jsf-tools generator code in preparation for JSF 1.2 work.

Generators (HtmlComponent, HtmlTaglib, and RenderKitSpecification) all
configured via a properties file. This should allow enough flexibility
to use
the taglib generator and renderkit doc generators with any faces-config.

SECTION: Modified Files
----------------------------
M jsf-ri/build.xml
  - copy the TAG-DEF files to jsf-ri before generating tags

M jsf-tools/build.xml
  - Use new ant tasks for component and renderkit doc generation
  - Update taglib generation ant task based of new modifications

M jsf-tools/src/com/sun/faces/ant/TaglibGenTask.java
    - Extend new AbstractGeneratorTask

M jsf-tools/src/com/sun/faces/generate/AbstractGenerator.java
   - general cleanup
   - moved some methods common to all generator types to new GeneratorUtils
   - Added new inner class CodeWriter with general helper methods for
     writing read-only, write-only, read/write properties, various comment
     types. This writer also simplifies formatting. User needs to call
indent
     or unindent instead of adding formatting directly into Strings as
before.

M jsf-tools/src/com/sun/faces/generate/HtmlComponentGenerator.java
  - general cleanup
  - leverage CodeWriter

M jsf-tools/src/com/sun/faces/generate/HtmlTaglibGenerator.java
 - general cleanup
 - Use the data contained in the properties file to initialize the
previously
   static structures
- leverage CodeWriter

M jsf-tools/src/com/sun/faces/generate/RenderKitSpecificationGenerator.java
  - general cleanup

A jsf-tools/conf/HtmlBasicTaglib12.properties
   - generator properties file to generate taglibs, components, and
renderkit docs
     for JSP 1.2

A jsf-tools/conf/TAG-DEF-12.txt
   - tag definition file that will be included in JSP 1.2 TLDs

A jsf-tools/conf/TAG-DEF-21.txt
   - tag definition file that will be included in JSP 2.1 TLDs

A jsf-tools/src/com/sun/faces/ant/AbstractGeneratorTask.java
A jsf-tools/src/com/sun/faces/ant/ComponentGenTask.java
A jsf-tools/src/com/sun/faces/ant/RenderkitDocGenTask.java
  - Ant tasks for the various generators

A jsf-tools/src/com/sun/faces/generate/Generator.java
  - High level interface for the various generators in jsf-tools

A jsf-tools/src/com/sun/faces/generate/GeneratorUtil.java
  - Utility methods common to one or more of the generators

A jsf-tools/src/com/sun/faces/generate/JspTLD12Generator.java
  - TLD generator for JSP 1.2

A jsf-tools/src/com/sun/faces/generate/JspTLD21Generator.java
 - TLD generator for JSP 2.0 (eventually 2.1 once is available)

A jsf-tools/src/com/sun/faces/generate/JspTLDGenerator.java
 - Base class for concrete JspTDLGenerator implmentations

A jsf-tools/src/com/sun/faces/generate/PropertyManager.java
 - Helper class for dealing with generator properties.

R jsf-tools/TAG-DEF
  - Renamed to conf/TAG-DEF-12.txt


SECTION: Diffs
----------------------------
Index: jsf-ri/build.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/build.xml,v
retrieving revision 1.173
diff -u -r1.173 build.xml
--- jsf-ri/build.xml 23 Nov 2004 19:26:55 -0000 1.173
+++ jsf-ri/build.xml 9 Dec 2004 15:45:11 -0000
@@ -236,6 +236,12 @@
       jsf-tools is ${jsf-tools.dir}
     </echo>
 
+ <copy todir="${basedir}">
+ <fileset dir="${jsf-tools.dir}/conf">
+ <include name="TAG-*"/>
+ </fileset>
+ </copy>
+
     <ant dir="${jsf-tools.dir}" inheritall="false"
target="clean.generated.taglib"/>
 
     <ant dir="${jsf-tools.dir}" inheritall="false"
target="generate.taglib"/>
@@ -257,6 +263,12 @@
       </fileset>
   
     </copy>
+
+ <delete>
+ <fileset dir="${basedir}">
+ <include name="TAG-*"/>
+ </fileset>
+ </delete>
 
     <touch file="${build.generate}/last-taglib-generation"/>
 
Index: jsf-tools/build.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-tools/build.xml,v
retrieving revision 1.37
diff -u -r1.37 build.xml
--- jsf-tools/build.xml 8 Nov 2004 19:23:13 -0000 1.37
+++ jsf-tools/build.xml 9 Dec 2004 15:45:23 -0000
@@ -179,64 +179,38 @@
                       if="standard-html-renderkit-impl"
                   unless="skip.generation">
 
- <java fork="yes"
- classname="com.sun.faces.generate.HtmlComponentGenerator">
-
-
- <classpath refid="compile.classpath"/>
- <classpath refid="run.classpath"/>
-
- <sysproperty key="java.endorsed.dirs" value="${dom.jar.dir}"/>
- <sysproperty key="org.apache.commons.logging.Log"
value="${log.impl}"/>
- <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
- value="info"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.com.sun.faces"
- value="${log.level}"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester"
- value="${log.digester}"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax"
- value="${log.sax}"/>
-
- <arg value="--config"/>
- <arg value="${build.temp}/standard-html-renderkit.xml"/>
- <arg value="--dir"/>
- <arg value="${build.generate}"/>
- <arg value="--copyright"/>
- <arg value="${basedir}/COPYRIGHT"/>
-
- </java>
+ <generateComponents
generatorConfig="${basedir}/conf/HtmlBasicTaglib12.properties"
+
facesConfig="${build.temp}/standard-html-renderkit.xml">
+ <classpath refid="run.classpath" />
+ </generateComponents>
 
   </target>
 
-
- <target name="generate.taglib"
+ <target name="generate.taglib"
           depends="tools"
- if="standard-html-renderkit-impl"
- unless="skip.taglib.generation">
-
- <generateTaglib inputfile="${build.temp}/standard-html-renderkit.xml"
- tlddir="${build.generate.tld}"
- destdir="${build.generate}" fork="yes"
- copyright="${basedir}/COPYRIGHT"
- tagdef="${basedir}/TAG-DEF">
- <sysproperty key="java.endorsed.dirs" value="${dom.jar.dir}"/>
- <sysproperty key="org.apache.commons.logging.Log"
value="${log.impl}"/>
- <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
- value="info"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.com.sun.faces"
- value="${log.level}"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester"
- value="${log.digester}"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax"
- value="${log.sax}"/>
- <!-- <jvmarg line="${debug.jvm.args}"/> -->
- <classpath refid="run.classpath" />
+ if="standard-html-renderkit-impl"
+ unless="skip.taglib.generation">
 
+ <copy todir="${basedir}">
+ <fileset dir="${basedir}/conf">
+ <include name="TAG-*"/>
+ </fileset>
+ </copy>
+
+ <generateTaglib
generatorConfig="${basedir}/conf/HtmlBasicTaglib12.properties"
+
facesConfig="${build.temp}/standard-html-renderkit.xml">
+ <classpath refid="run.classpath" />
     </generateTaglib>
 
+ <delete>
+ <fileset dir="${basedir}">
+ <include name="TAG-*"/>
+ </fileset>
+ </delete>
+
   </target>
 
- <target name="tools" depends="prepare.generate"
+ <target name="tools" depends="prepare.generate"
                        if="standard-html-renderkit-impl">
 
     <javac srcdir="${src.dir}"
@@ -252,7 +226,19 @@
 
     <taskdef name="generateTaglib"
classname="com.sun.faces.ant.TaglibGenTask">
         <classpath>
- <pathelement location="${build.classes}" />
+ <pathelement location="${build.classes}"/>
+ </classpath>
+ </taskdef>
+
+ <taskdef name="generateComponents"
classname="com.sun.faces.ant.ComponentGenTask">
+ <classpath>
+ <pathelement location="${build.classes}"/>
+ </classpath>
+ </taskdef>
+
+ <taskdef name="generateRenderkitDocs"
classname="com.sun.faces.ant.RenderkitDocGenTask">
+ <classpath>
+ <pathelement location="${build.classes}"/>
         </classpath>
     </taskdef>
 
@@ -382,33 +368,12 @@
                       if="standard-html-renderkit-impl"
                   unless="skip.generation">
 
- <java fork="yes"
- classname="com.sun.faces.generate.RenderKitSpecificationGenerator">
- <jvmarg line="${debug.jvm.args}"/>
- <classpath refid="compile.classpath"/>
- <classpath refid="run.classpath"/>
- <sysproperty key="java.endorsed.dirs" value="${dom.jar.dir}"/>
- <sysproperty key="org.apache.commons.logging.Log"
value="${log.impl}"/>
- <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
- value="info"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.com.sun.faces"
- value="${log.level}"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester"
- value="${log.digester}"/>
- <sysproperty
key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax"
- value="${log.sax}"/>
-
- <arg value="--config"/>
- <arg value="${build.temp}/standard-html-renderkit.xml"/>
- <arg value="--dir"/>
- <arg value="${build.generate.facesdoc}"/>
- <arg value="--copyright"/>
- <arg value="${basedir}/COPYRIGHT"/>
-
- </java>
+ <generateRenderkitDocs
generatorConfig="${basedir}/conf/HtmlBasicTaglib12.properties"
+
facesConfig="${build.temp}/standard-html-renderkit.xml">
+ <classpath refid="run.classpath" />
+ </generateRenderkitDocs>
 
     <touch file="${build.generate}/last-generation"/>
-
 
   </target>
 
Index: jsf-tools/src/com/sun/faces/ant/TaglibGenTask.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-tools/src/com/sun/faces/ant/TaglibGenTask.java,v
retrieving revision 1.2
diff -u -r1.2 TaglibGenTask.java
--- jsf-tools/src/com/sun/faces/ant/TaglibGenTask.java 24 Aug 2004
17:07:12 -0000 1.2
+++ jsf-tools/src/com/sun/faces/ant/TaglibGenTask.java 9 Dec 2004
15:45:26 -0000
@@ -1,72 +1,34 @@
 /*
+ * $Id$
+ */
+
+/*
  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  */
 
 package com.sun.faces.ant;
 
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.HashMap;
-
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Commandline;
-import org.apache.tools.ant.taskdefs.Java;
 
-public class TaglibGenTask extends Java {
+/**
+ * <p>Task to create a JSP tags.</p>
+ */
+public class TaglibGenTask extends AbstractGeneratorTask {
 
- private Map arguments;
+ private static final String GENERATOR_CLASS =
+ "com.sun.faces.generate.HtmlTaglibGenerator";
 
- public TaglibGenTask() {
- arguments = new HashMap();
- }
-
- public void setInputFile(String newInputFile) {
- arguments.put("--config", newInputFile);
- }
-
- public void setDestdir(String newDir) {
- arguments.put("--dir", newDir);
- }
-
- public void setTlddir(String newTlddir) {
- arguments.put("--tlddir", newTlddir);
- }
-
- public void setDtd(String newDtd) {
- arguments.put("--dtd", newDtd);
- }
-
- public void setTagdef(String newTagdef) {
- arguments.put("--tagdef", newTagdef);
- }
-
- public void setCopyright(String newCopyright) {
- arguments.put("--copyright", newCopyright);
- }
-
- public void execute() throws BuildException {
- Iterator iter = null;
- Object curObj = null;
- Commandline.Argument arg = null;
 
- iter = arguments.keySet().iterator();
- while (iter.hasNext()) {
- curObj = iter.next();
+ // ----------------------------------------------------------
Public Methods
 
- arg = super.createArg();
- arg.setValue(curObj.toString());
 
- arg = super.createArg();
- arg.setValue(arguments.get(curObj).toString());
- }
+ public void execute() throws BuildException {
 
- super.setClassname("com.sun.faces.generate.HtmlTaglibGenerator");
+ setGeneratorClass(GENERATOR_CLASS);
 
- super.execute();
- }
+ super.execute();
 
+ } // END execute
 
 }
Index: jsf-tools/src/com/sun/faces/generate/AbstractGenerator.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-tools/src/com/sun/faces/generate/AbstractGenerator.java,v
retrieving revision 1.7
diff -u -r1.7 AbstractGenerator.java
--- jsf-tools/src/com/sun/faces/generate/AbstractGenerator.java 29
Oct 2004 00:56:39 -0000 1.7
+++ jsf-tools/src/com/sun/faces/generate/AbstractGenerator.java 9 Dec
2004 15:45:29 -0000
@@ -10,23 +10,15 @@
 package com.sun.faces.generate;
 
 
-import com.sun.faces.config.DigesterFactory;
-import com.sun.faces.config.beans.FacesConfigBean;
-import com.sun.faces.config.rules.FacesConfigRuleSet;
-import org.apache.commons.digester.Digester;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.BufferedWriter;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.Writer;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
+import java.util.StringTokenizer;
 
 
 /**
@@ -38,115 +30,115 @@
  * </ul>
  */
 
-public abstract class AbstractGenerator {
+public abstract class AbstractGenerator implements Generator {
 
 
     // -------------------------------------------------------- Static
Variables
 
 
     // The set of default values for primitives, keyed by the primitive
type
- protected static Map defaults = new HashMap();
+ protected static final Map TYPE_DEFAULTS = new HashMap(8);
     static {
- defaults.put("boolean", "false");
- defaults.put("byte", "Byte.MIN_VALUE");
- defaults.put("char", "Character.MIN_VALUE");
- defaults.put("double", "Double.MIN_VALUE");
- defaults.put("float", "Float.MIN_VALUE");
- defaults.put("int", "Integer.MIN_VALUE");
- defaults.put("long", "Long.MIN_VALUE");
- defaults.put("short", "Short.MIN_VALUE");
+ TYPE_DEFAULTS.put("boolean", "false");
+ TYPE_DEFAULTS.put("byte", "Byte.MIN_VALUE");
+ TYPE_DEFAULTS.put("char", "Character.MIN_VALUE");
+ TYPE_DEFAULTS.put("double", "Double.MIN_VALUE");
+ TYPE_DEFAULTS.put("float", "Float.MIN_VALUE");
+ TYPE_DEFAULTS.put("int", "Integer.MIN_VALUE");
+ TYPE_DEFAULTS.put("long", "Long.MIN_VALUE");
+ TYPE_DEFAULTS.put("short", "Short.MIN_VALUE");
     }
 
 
     // The set of reserved keywords in the Java language
- protected static Set keywords = new HashSet();
+ protected static final Set JAVA_KEYWORDS = new HashSet(57);
     static {
- keywords.add("abstract");
- keywords.add("boolean");
- keywords.add("break");
- keywords.add("byte");
- keywords.add("case");
- keywords.add("cast");
- keywords.add("catch");
- keywords.add("char");
- keywords.add("class");
- keywords.add("const");
- keywords.add("continue");
- keywords.add("default");
- keywords.add("do");
- keywords.add("double");
- keywords.add("else");
- keywords.add("enum");
- keywords.add("extends");
- keywords.add("final");
- keywords.add("finally");
- keywords.add("float");
- keywords.add("for");
- keywords.add("future");
- keywords.add("generic");
- keywords.add("goto");
- keywords.add("if");
- keywords.add("implements");
- keywords.add("import");
- keywords.add("inner");
- keywords.add("instanceof");
- keywords.add("int");
- keywords.add("interface");
- keywords.add("long");
- keywords.add("native");
- keywords.add("new");
- keywords.add("null");
- keywords.add("operator");
- keywords.add("outer");
- keywords.add("package");
- keywords.add("private");
- keywords.add("protected");
- keywords.add("public");
- keywords.add("rest");
- keywords.add("return");
- keywords.add("short");
- keywords.add("static");
- keywords.add("strictfp");
- keywords.add("super");
- keywords.add("switch");
- keywords.add("synchronized");
- keywords.add("this");
- keywords.add("throw");
- keywords.add("throws");
- keywords.add("transient");
- keywords.add("try");
- keywords.add("var");
- keywords.add("void");
- keywords.add("volatile");
- keywords.add("while");
+ JAVA_KEYWORDS.add("abstract");
+ JAVA_KEYWORDS.add("boolean");
+ JAVA_KEYWORDS.add("break");
+ JAVA_KEYWORDS.add("byte");
+ JAVA_KEYWORDS.add("case");
+ JAVA_KEYWORDS.add("cast");
+ JAVA_KEYWORDS.add("catch");
+ JAVA_KEYWORDS.add("char");
+ JAVA_KEYWORDS.add("class");
+ JAVA_KEYWORDS.add("const");
+ JAVA_KEYWORDS.add("continue");
+ JAVA_KEYWORDS.add("default");
+ JAVA_KEYWORDS.add("do");
+ JAVA_KEYWORDS.add("double");
+ JAVA_KEYWORDS.add("else");
+ JAVA_KEYWORDS.add("enum");
+ JAVA_KEYWORDS.add("extends");
+ JAVA_KEYWORDS.add("final");
+ JAVA_KEYWORDS.add("finally");
+ JAVA_KEYWORDS.add("float");
+ JAVA_KEYWORDS.add("for");
+ JAVA_KEYWORDS.add("future");
+ JAVA_KEYWORDS.add("generic");
+ JAVA_KEYWORDS.add("goto");
+ JAVA_KEYWORDS.add("if");
+ JAVA_KEYWORDS.add("implements");
+ JAVA_KEYWORDS.add("import");
+ JAVA_KEYWORDS.add("inner");
+ JAVA_KEYWORDS.add("instanceof");
+ JAVA_KEYWORDS.add("int");
+ JAVA_KEYWORDS.add("interface");
+ JAVA_KEYWORDS.add("long");
+ JAVA_KEYWORDS.add("native");
+ JAVA_KEYWORDS.add("new");
+ JAVA_KEYWORDS.add("null");
+ JAVA_KEYWORDS.add("operator");
+ JAVA_KEYWORDS.add("outer");
+ JAVA_KEYWORDS.add("package");
+ JAVA_KEYWORDS.add("private");
+ JAVA_KEYWORDS.add("protected");
+ JAVA_KEYWORDS.add("public");
+ JAVA_KEYWORDS.add("rest");
+ JAVA_KEYWORDS.add("return");
+ JAVA_KEYWORDS.add("short");
+ JAVA_KEYWORDS.add("static");
+ JAVA_KEYWORDS.add("strictfp");
+ JAVA_KEYWORDS.add("super");
+ JAVA_KEYWORDS.add("switch");
+ JAVA_KEYWORDS.add("synchronized");
+ JAVA_KEYWORDS.add("this");
+ JAVA_KEYWORDS.add("throw");
+ JAVA_KEYWORDS.add("throws");
+ JAVA_KEYWORDS.add("transient");
+ JAVA_KEYWORDS.add("try");
+ JAVA_KEYWORDS.add("var");
+ JAVA_KEYWORDS.add("void");
+ JAVA_KEYWORDS.add("volatile");
+ JAVA_KEYWORDS.add("while");
     }
 
 
     // The set of unwrapper methods for primitives, keyed by the
primitive type
- protected static Map unwrappers = new HashMap();
+ protected static Map UNWRAPPERS = new HashMap(8);
     static {
- unwrappers.put("boolean", "booleanValue");
- unwrappers.put("byte", "byteValue");
- unwrappers.put("char", "charValue");
- unwrappers.put("double", "doubleValue");
- unwrappers.put("float", "floatValue");
- unwrappers.put("int", "intValue");
- unwrappers.put("long", "longValue");
- unwrappers.put("short", "shortValue");
+ UNWRAPPERS.put("boolean", "booleanValue");
+ UNWRAPPERS.put("byte", "byteValue");
+ UNWRAPPERS.put("char", "charValue");
+ UNWRAPPERS.put("double", "doubleValue");
+ UNWRAPPERS.put("float", "floatValue");
+ UNWRAPPERS.put("int", "intValue");
+ UNWRAPPERS.put("long", "longValue");
+ UNWRAPPERS.put("short", "shortValue");
     }
 
 
     // The set of wrapper classes for primitives, keyed by the
primitive type
- protected static Map wrappers = new HashMap();
+ protected static Map WRAPPERS = new HashMap(8);
     static {
- wrappers.put("boolean", "Boolean");
- wrappers.put("byte", "Byte");
- wrappers.put("char", "Character");
- wrappers.put("double", "Double");
- wrappers.put("float", "Float");
- wrappers.put("int", "Integer");
- wrappers.put("long", "Long");
- wrappers.put("short", "Short");
+ WRAPPERS.put("boolean", "Boolean");
+ WRAPPERS.put("byte", "Byte");
+ WRAPPERS.put("char", "Character");
+ WRAPPERS.put("double", "Double");
+ WRAPPERS.put("float", "Float");
+ WRAPPERS.put("int", "Integer");
+ WRAPPERS.put("long", "Long");
+ WRAPPERS.put("short", "Short");
     }
 
 
@@ -162,66 +154,7 @@
 
         return (Character.toUpperCase(name.charAt(0)) + name.substring(1));
 
- }
-
-
- /**
- * <p>Render the specified description text to the specified writer,
- * prefixing each line by 'indent' spaces, an asterisk ("*"), and
another
- * space. This rendering is appropriate for the creation of
- * JavaDoc comments on classes, variables, and methods.</p>
- *
- * @param desc Description text to be rendered
- * @param writer Writer to which output should be sent
- * @param indent Number of leading space for each line
- */
- protected static void description(String desc, Writer writer, int
indent)
- throws Exception {
-
- for (int i = 0; i < indent; i++) {
- writer.write(" ");
- }
- writer.write("* ");
- int n = desc.length();
- for (int i = 0; i < n; i++) {
- char ch = desc.charAt(i);
- if (ch == '\r') {
- continue;
- }
- writer.write(ch);
- if (ch == '\n') {
- for (int j = 0; j < indent; j++) {
- writer.write(" ");
- }
- writer.write("* ");
- }
- }
- writer.write("\n");
-
- }
-
-
- /**
- * <p>Configure and return a <code>Digester</code> instance
suitable for
- * use in the environment specified by our parameter flags.</p>
- *
- * @param design Include rules suitable for design time use in a tool
- * @param generate Include rules suitable for generating component,
- * renderer, and tag classes
- * @param runtime Include rules suitable for runtime execution
- */
- protected static Digester digester(boolean design,
- boolean generate, boolean runtime) {
-
- Digester digester =
DigesterFactory.newInstance(true).createDigester();
-
- // Configure parsing rules
- digester.addRuleSet(new FacesConfigRuleSet(design, generate,
runtime));
-
- // Configure preregistered entities
-
- return (digester);
- }
+ }
 
 
     /**
@@ -232,7 +165,7 @@
      */
     protected static String mangle(String name) {
 
- if (keywords.contains(name)) {
+ if (JAVA_KEYWORDS.contains(name)) {
             return ('_' + name);
         } else {
             return (name);
@@ -249,7 +182,7 @@
      * @exception IllegalArgumentException if an option flag does not start
      * with a '-' or is missing a corresponding value
      */
- protected static Map options(String args[]) {
+ protected static Map options(String[] args) {
 
         Map options = new HashMap();
         int i = 0;
@@ -270,53 +203,13 @@
 
 
     /**
- * <p>Parse the specified configuration file, and return the root
of the
- * resulting tree of configuration beans.</p>
- *
- * @param digester Digester instance to use for parsing
- * @param config Pathname of the configuration file to be parsed
- *
- * @exception IOException an input/output error occurred while parsing
- * @exception SAXException an XML processing error occurred while
parsing
- */
- protected static FacesConfigBean parse(Digester digester, String
config)
- throws IOException, SAXException {
-
- File file = null;
- FacesConfigBean fcb = null;
- InputSource source = null;
- InputStream stream = null;
- try {
- file = new File(config);
- stream = new BufferedInputStream(new FileInputStream(file));
- source = new InputSource(file.toURL().toString());
- source.setByteStream(stream);
- fcb = (FacesConfigBean) digester.parse(source);
- stream.close();
- stream = null;
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (Exception e) {
- ;
- }
- stream = null;
- }
- }
- return (fcb);
-
- }
-
-
- /**
      * <p>Return <code>true</code> if the specified type is a
primitive.</p>
      *
      * @param type Type to be tested
      */
     protected static boolean primitive(String type) {
 
- return (wrappers.containsKey(type));
+ return (WRAPPERS.containsKey(type));
 
     }
 
@@ -340,4 +233,192 @@
     }
 
 
+ // -----------------------------------------------------------
Inner Classes
+
+
+ protected static class CodeWriter extends BufferedWriter {
+
+ private final String TAB = " ";
+ private final int TAB_LENGTH = TAB.length();
+
+ private Stack depth;
+ private String formatString = "";
+
+
+ // --------------------------------------------------------
Constructors
+
+ public CodeWriter(Writer writer) {
+
+ super(writer);
+ depth = new Stack();
+
+ } // END CodeWriter
+
+
+ public void indent() {
+
+ depth.push(TAB);
+ updateFormatString(depth.size());
+
+
+ } // END indent
+
+ public void unindent() {
+
+ depth.pop();
+ updateFormatString(depth.size());
+
+ } // END unindent
+
+
+ public void fwrite(String str) throws IOException {
+
+ super.write(formatString + str);
+
+ } // END write
+
+ public void writeJavadocComment(String str) throws IOException {
+
+ fwrite("/**\n");
+ for (StringTokenizer st = new StringTokenizer(str, "\r\n\t");
+ st.hasMoreTokens(); ) {
+ fwrite(" * ");
+ write(st.nextToken().trim());
+ write('\n');
+ }
+ fwrite(" */\n");
+
+ } // END writeJavadocComment
+
+
+ public void writeLineComment(String str) throws IOException {
+
+ for (StringTokenizer st = new StringTokenizer(str, "\r\n\t");
+ st.hasMoreTokens(); ) {
+ fwrite("// ");
+ write(st.nextToken().trim());
+ write('\n');
+ }
+ write('\n');
+
+ } // END writeLineComment
+
+
+ public void writeBlockComment(String str) throws IOException {
+
+ fwrite("/*\n");
+ for (StringTokenizer st = new StringTokenizer(str, "\r\n\t");
+ st.hasMoreTokens(); ) {
+ fwrite(" * ");
+ write(st.nextToken().trim());
+ write('\n');
+ }
+ fwrite(" */\n");
+
+ } // END writeBlockComment
+
+
+ public void writeReadWriteProperty(String propertyName, String
type,
+ String defaultValue)
+ throws IOException {
+
+ String iVarName = mangle(propertyName);
+ String methodName = capitalize(propertyName);
+ writeLineComment("PROPERTY: " + propertyName);
+ fwrite("private " + type + ' ' + iVarName +
+ (defaultValue == null ? ";" : " = " + defaultValue) +
'\n');
+ fwrite("public void set" + methodName +
+ '(' + type + ' ' + iVarName + ") {\n");
+ indent();
+ fwrite("this." + iVarName + " = " + iVarName +
+ ";\n");
+ unindent();
+ fwrite("}\n\n");
+ fwrite("public " + type + "get" + methodName + "() {\n");
+ indent();
+ fwrite("return this." + iVarName + ";\n");
+ unindent();
+ fwrite("}\n\n");
+
+ } // END writeReadWriteProperty
+
+
+ public void writeReadWriteProperty(String propertyName, String
type)
+ throws IOException {
+
+ writeReadWriteProperty(propertyName, type, null);
+
+ } // END writeReadWriteProperty
+
+
+ public void writeReadOnlyProperty(String propertyName, String type,
+ String defaultValue)
+ throws IOException {
+
+ writeLineComment("PROPERTY: " + propertyName);
+ String iVarName = mangle(propertyName);
+ fwrite("private " + type + ' ' + iVarName +
+ (defaultValue == null ? ";" : " = " + defaultValue) +
'\n');
+ fwrite("public " + type + "get" + capitalize(propertyName) +
+ "() {\n");
+ indent();
+ fwrite("return this." + iVarName + ";\n");
+ unindent();
+ fwrite("}\n\n");
+
+ } // END writeReadOnlyProperty
+
+
+ public void writeReadOnlyProperty(String propertyName, String type)
+ throws IOException {
+
+ writeReadOnlyProperty(propertyName, type, null);
+
+ } // END writeReadOnlyProperty
+
+
+ public void writeWriteOnlyProperty(String propertyName, String
type,
+ String defaultValue)
+ throws IOException {
+
+ writeLineComment("PROPERTY: " + propertyName);
+ String iVarName = mangle(propertyName);
+ fwrite("private " + type + ' ' + iVarName +
+ (defaultValue == null ? ";" : " = " + defaultValue) +
'\n');
+ fwrite("public void set" + capitalize(propertyName) +
+ '(' + type + ' ' + iVarName + ") {\n");
+ indent();
+ fwrite("this." + iVarName + " = " + iVarName + ";\n");
+ unindent();
+ fwrite("}\n\n");
+
+ } // END writeWriteOnlyProperty
+
+
+ public void writeWriteOnlyProperty(String propertyName, String
type)
+ throws IOException {
+
+ writeWriteOnlyProperty(propertyName, type, null);
+
+ } // END writeWriteOnlyProperty
+
+
+ // -----------------------------------------------------
Private Methods
+
+
+ private void updateFormatString(int numTabs) {
+
+ if (numTabs == 0) {
+ formatString = "";
+ } else {
+ StringBuffer sb = new StringBuffer(numTabs * TAB_LENGTH);
+ for (int i = 0; i < numTabs; i++) {
+ sb.append(TAB);
+ }
+ formatString = sb.toString();
+ }
+
+ } // END updateFormatString
+
+ }
 }
Index: jsf-tools/src/com/sun/faces/generate/HtmlComponentGenerator.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-tools/src/com/sun/faces/generate/HtmlComponentGenerator.java,v
retrieving revision 1.11
diff -u -r1.11 HtmlComponentGenerator.java
--- jsf-tools/src/com/sun/faces/generate/HtmlComponentGenerator.java
 2 Dec 2004 21:30:58 -0000 1.11
+++ jsf-tools/src/com/sun/faces/generate/HtmlComponentGenerator.java
 9 Dec 2004 15:45:34 -0000
@@ -10,44 +10,36 @@
 package com.sun.faces.generate;
 
 
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.List;
+
 import com.sun.faces.config.beans.ComponentBean;
 import com.sun.faces.config.beans.DescriptionBean;
 import com.sun.faces.config.beans.FacesConfigBean;
 import com.sun.faces.config.beans.PropertyBean;
-import org.apache.commons.digester.Digester;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 
 /**
- * <p>Generate concrete HTML component classes. Classes will be generated
- * for each <code>&lt;component&gt;</code> element in the specified
- * configuration file whose absolute class name is in package
- * <code>javax.faces.component.html</code>.</p>
- *
- * <p>This application requires the following command line options:</p>
- * <ul>
+ * <p>Generate concrete HTML component classes. Classes will be
generated for
+ * each <code>&lt;component&gt;</code> element in the specified
configuration
+ * file whose absolute class name is in package
<code>javax.faces.component.html</code>.</p>
+ * <p/>
+ * <p>This application requires the following command line options:</p>
<ul>
  * <li><strong>--config</strong> Absolute pathname to an input
configuration
- * file that will be parsed by the <code>parse()</code> method.</li>
+ * file that will be parsed by the <code>parse()</code> method.</li>
  * <li><strong>--copyright</strong> Absolute pathname to a file
containing the
- * copyright material for the top of each Java source file.</li>
+ * copyright material for the top of each Java source file.</li>
  * <li><strong>--dir</strong> Absolute pathname to the directory into which
- * generated Java source code will be created.</li>
- * <li><strong>--dtd</strong> Pipe delimited list of public identifiers
and
- * absolute pathnames to files containing the DTDs used to validate
the
- * input configuration files. PRECONDITION: The list is the sequence:
- * <public id>|<dtd path>|<public id>|<dtd path>...</li>
- * </ul>
+ * generated Java source code will be created.</li>
<li><strong>--dtd</strong>
+ * Pipe delimited list of public identifiers and absolute pathnames to
files
+ * containing the DTDs used to validate the input configuration files.
+ * PRECONDITION: The list is the sequence: <public id>|<dtd path>|<public
+ * id>|<dtd path>...</li> </ul>
  */
 
 public class HtmlComponentGenerator extends AbstractGenerator {
@@ -61,105 +53,99 @@
 
 
     // The component configuration bean for the component class to be
generated
- private static ComponentBean cb;
-
-
- // StringBuffer containing the copyright material
- private static String copyright;
-
-
- // The directory into which the source code will be generated
- private static File directory;
+ private ComponentBean cb;
 
 
     // Base object of the configuration beans
- private static FacesConfigBean fcb;
+ private FacesConfigBean configBean;
 
     // List of relevant properties for the component class to be generated
- private static List properties;
+ private List properties;
 
     // The Writer for each component class to be generated
- private static Writer writer;
+ private CodeWriter writer;
 
+ private PropertyManager propManager;
 
- // ---------------------------------------------------------
Private Methods
 
+ // ------------------------------------------------------------
Constructors
 
- /**
- * <p>Load the copyright text for the top of each Java source file.</p>
- *
- * @param path Pathname of the copyright file
- */
- private static void copyright(String path) throws Exception {
 
- if (log.isDebugEnabled()) {
- log.debug("Loading copyright text from '" + path + "'");
- }
- StringBuffer sb = new StringBuffer();
- BufferedReader reader =
- new BufferedReader(new FileReader(path));
- int ch;
- while ((ch = reader.read()) >= 0) {
- sb.append((char) ch);
- }
- reader.close();
- if (log.isDebugEnabled()) {
- log.debug(" Copyright text contains " + sb.length() +
- " characters");
- }
- copyright = sb.toString();
+ public HtmlComponentGenerator(PropertyManager propManager) {
+
+ this.propManager = propManager;
 
     }
 
 
+ // ----------------------------------------------------------
Public Methods
+
+
     /**
- * <p>Create directories as needed to contain the output. Leave a
- * <code>directory</code> object that points at the top level directory
- * for the concrete component classes.</p>
- *
- * @param path Pathname to the base directory
+ * <p>Generate the concrete HTML component class based on the current
+ * component configuration bean.</p>
      */
- private static void directories(String path) throws Exception {
+ public void generate(FacesConfigBean configBean) {
+
+ this.configBean = configBean;
 
- directory = new File(path);
- directory = new File(path, "javax/faces/component/html");
- if (log.isDebugEnabled()) {
- log.debug("Creating output directory " +
- directory.getAbsolutePath());
+ try {
+ generateClasses();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
         }
- directory.mkdirs();
 
     }
 
 
- /**
- * <p>Generate the concrete HTML component class based on the current
- * component configuration bean.</p>
- */
- private static void generate() throws Exception {
+ // ----------------------------------------------------------
Private Method
 
- if (log.isInfoEnabled()) {
- log.info("Generating concrete HTML component class " +
- cb.getComponentClass());
- }
+ private void generateClasses() throws Exception {
+
+ final String compPackage = "javax.faces.component.html";
 
- // Initialize all per-class static variables
- properties = new ArrayList();
+ // Component generator doesn't use the TARGET_PACKAGE property
+ String packagePath = compPackage.replace('.', File.separatorChar);
+ File dir = new File(System.getProperty("user.dir") +
+ File.separatorChar +
+ propManager.getProperty(PropertyManager.BASE_OUTPUT_DIR) +
+ File.separatorChar + packagePath);
+ ComponentBean[] cbs = configBean.getComponents();
+ for (int i = 0; i < cbs.length; i++) {
+
+ String componentClass = cbs[i].getComponentClass();
+ if (componentClass.startsWith(compPackage)) {
+ cb = cbs[i];
+
+ if (log.isInfoEnabled()) {
+ log.info("Generating concrete HTML component class " +
+ cb.getComponentClass());
+ }
 
- // Create and open a Writer for generating our output
- File file = new File(directory,
- shortName(cb.getComponentClass()) + ".java");
- writer = new BufferedWriter(new FileWriter(file));
+ // Initialize all per-class static variables
+ properties = new ArrayList();
 
- // Generate the various portions of each class
- prefix();
- properties();
- suffix();
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
 
- // Flush and close the Writer for this class
- writer.flush();
- writer.close();
+ String fileName = cb.getComponentClass();
+ fileName = fileName.substring(fileName.lastIndexOf('.')
+ 1) +
+ ".java";
+ File file = new File(dir, fileName);
+ writer = new CodeWriter(new FileWriter(file));
+ // Generate the various portions of each class
+ prefix();
+ properties();
+ suffix();
+
+ // Flush and close the Writer for this class
+ writer.flush();
+ writer.close();
+ }
 
+
+ }
     }
 
 
@@ -167,88 +153,78 @@
      * <p>Generate the prefix for this component class, down to (and
including)
      * the class declaration.</p>
      */
- private static void prefix() throws Exception {
+ private void prefix() throws Exception {
 
         // Acquire the config bean for our base component
- ComponentBean base = fcb.getComponent(cb.getBaseComponentType());
+ ComponentBean base =
configBean.getComponent(cb.getBaseComponentType());
         if (base == null) {
             throw new IllegalArgumentException("No base component type
for '" +
- cb.getComponentType() +
"'");
+ cb.getComponentType() + "'");
         }
 
         // Generate the copyright information
- writer.write(copyright);
+ writer.writeJavadocComment(
+ propManager.getProperty(PropertyManager.COPYRIGHT));
 
         // Generate the package declaration
- writer.write("\npackage javax.faces.component.html;\n");
+ writer.fwrite("\npackage javax.faces.component.html;\n");
         writer.write("\n\n");
 
         // Generate the imports
- writer.write("import java.io.IOException;\n");
- writer.write("import javax.faces.context.FacesContext;\n");
- writer.write("import javax.faces.el.MethodBinding;\n");
- writer.write("import javax.faces.el.ValueBinding;\n");
+ writer.fwrite("import java.io.IOException;\n");
+ writer.fwrite("import javax.faces.context.FacesContext;\n");
+ writer.fwrite("import javax.faces.el.MethodBinding;\n");
+ writer.fwrite("import javax.faces.el.ValueBinding;\n");
         writer.write("\n\n");
 
         // Generate the class JavaDocs (if any)
         DescriptionBean db = cb.getDescription("");
- String
- rendererTypeDocs = null,
- rendererType = cb.getRendererType();
-
- if (db != null || rendererType != null) {
- writer.write("/**\n");
- }
-
- if (db != null) {
- String description = db.getDescription();
- if (description == null) {
- description = "";
- }
- description = description.trim();
- if (description.length() > 0) {
- description(description, writer, 1);
+ String rendererType = cb.getRendererType();
 
- }
+ String description = null;
+ if (db != null) {
+ description = db.getDescription().trim();
         }
 
- if (rendererType != null) {
- rendererTypeDocs = "<p>By default, the
<code>rendererType</code> property must be set to \"<code>" +
- rendererType +
- "</code>\" This value can be changed by calling the
<code>setRendererType()</code> method.</p>";
- description(rendererTypeDocs, writer, 1);
- }
+ if (rendererType != null) {
+ description +=
+ "\n<p>By default, the <code>rendererType</code> property
must be set to \"<code>" +
+ rendererType +
+ "</code>\".\nThis value can be changed by calling the
<code>setRendererType()</code> method.</p>\n";
+ }
 
- if (db != null || rendererType != null) {
- writer.write("*/\n");
- }
+ if (description != null && description.length() > 0) {
+ writer.writeJavadocComment(description);
+ }
 
         // Generate the class declaration
- writer.write("public class ");
+ writer.fwrite("public class ");
         writer.write(shortName(cb.getComponentClass()));
         writer.write(" extends ");
         writer.write(base.getComponentClass());
         writer.write(" {\n\n\n");
 
         // Generate the constructor
- writer.write(" public ");
+ writer.indent();
+ writer.fwrite("public ");
         writer.write(shortName(cb.getComponentClass()));
         writer.write("() {\n");
- writer.write(" super();\n");
+ writer.indent();
+ writer.fwrite("super();\n");
         if (rendererType != null) {
- writer.write(" setRendererType(\"");
+ writer.fwrite("setRendererType(\"");
             writer.write(rendererType);
             writer.write("\");\n");
         }
- writer.write(" }\n\n\n");
+ writer.unindent();
+ writer.fwrite("}\n\n\n");
 
- // Generate the manifest constant for the component type
- writer.write(" /*\n");
- writer.write(" * <p>The standard component type for this
component.</p>\n");
- writer.write(" */\n");
- writer.write(" public static final String COMPONENT_TYPE = \"");
- writer.write(cb.getComponentType());
- writer.write("\";\n\n\n");
+ // Generate the manifest constant for the component type
+ writer.writeJavadocComment(
+ "<p>The standard component type for this component.</p>\n");
+ writer.fwrite("public static final String COMPONENT_TYPE = \"");
+ writer.write(cb.getComponentType());
+ writer.write("\";\n\n\n");
 
     }
 
@@ -257,10 +233,10 @@
      * <p>Generate the property instance variable, and getter and setter
      * methods, for all non-duplicate properties of this component
class.</p>
      */
- private static void properties() throws Exception {
+ private void properties() throws Exception {
 
- ComponentBean base = fcb.getComponent(cb.getBaseComponentType());
- PropertyBean pbs[] = cb.getProperties();
+ ComponentBean base =
configBean.getComponent(cb.getBaseComponentType());
+ PropertyBean[] pbs = cb.getProperties();
         for (int i = 0; i < pbs.length; i++) {
 
             // Should we generate this property?
@@ -268,62 +244,53 @@
             if (base.getProperty(pb.getPropertyName()) != null) {
                 if (log.isTraceEnabled()) {
                     log.trace("Skipping base class property '" +
- pb.getPropertyName() + "'");
+ pb.getPropertyName() + "'");
                 }
                 continue;
             }
             if (log.isDebugEnabled()) {
                 log.debug("Generating property variable/getter/setter
for '" +
- pb.getPropertyName() + "'");
+ pb.getPropertyName() + "'");
             }
             properties.add(pb);
             String type = pb.getPropertyClass();
             String var = mangle(pb.getPropertyName());
 
             // Generate the instance variable
- writer.write(" private ");
+ writer.fwrite("private ");
             writer.write(type);
- writer.write(" ");
+ writer.write(' ');
             writer.write(var);
             if (pb.getDefaultValue() != null) {
                 writer.write(" = ");
                 writer.write(pb.getDefaultValue());
             } else if (primitive(type)) {
                 writer.write(" = ");
- writer.write((String) defaults.get(type));
+ writer.write((String) TYPE_DEFAULTS.get(type));
             }
             writer.write(";\n");
             if (primitive(type)) {
- writer.write(" private boolean ");
+ writer.fwrite("private boolean ");
                 writer.write(var);
                 writer.write("_set = false;\n");
             }
             writer.write("\n");
 
- // Document the getter method
- writer.write(" /**\n");
- writer.write(" * <p>Return the value of the <code>");
- writer.write(pb.getPropertyName());
- writer.write("</code> property.");
+
+ // Document getter method
+ String description = "<p>Return the value of the <code>" +
+ pb.getPropertyName() + "</code> property.</p>";
             DescriptionBean db = pb.getDescription("");
             if (db != null) {
- String description = db.getDescription();
- if (description == null) {
- description = "";
+ String temp = db.getDescription().trim();
+ if (temp != null && temp.length() > 0) {
+ description += '\n' + "<p>Contents: " + temp;
                 }
- description = description.trim();
- if (description.length() > 0) {
- writer.write(" Contents:</p><p>\n");
- description(description, writer, 3);
- }
- } else {
- writer.write("\n");
             }
- writer.write(" * </p>\n");
- writer.write(" */\n");
+ writer.writeJavadocComment(description.trim());
 
             // Generate the getter method
- writer.write(" public ");
+ writer.fwrite("public ");
             writer.write(type);
             if ("boolean".equals(type)) {
                 writer.write(" is");
@@ -332,76 +299,90 @@
             }
             writer.write(capitalize(pb.getPropertyName()));
             writer.write("() {\n");
+ writer.indent();
             if (primitive(type)) {
- writer.write(" if (this.");
+ writer.fwrite("if (this.");
                 writer.write(var);
                 writer.write("_set) {\n");
+ writer.indent();
             } else {
- writer.write(" if (null != this.");
+ writer.fwrite("if (null != this.");
                 writer.write(var);
                 writer.write(") {\n");
+ writer.indent();
             }
- writer.write(" return this.");
+ writer.fwrite("return this.");
             writer.write(var);
             writer.write(";\n");
- writer.write(" }\n");
- writer.write(" ValueBinding _vb = getValueBinding(\"");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("ValueBinding _vb = getValueBinding(\"");
             writer.write(pb.getPropertyName());
             writer.write("\");\n");
- writer.write(" if (_vb != null) {\n");
+ writer.fwrite("if (_vb != null) {\n");
+ writer.indent();
             if (primitive(type)) {
- writer.write(" Object _result =
_vb.getValue(getFacesContext());\n");
- writer.write(" if (_result == null) {\n");
- writer.write(" return ");
- writer.write((String) defaults.get(type));
+ writer.fwrite(
+ "Object _result = _vb.getValue(getFacesContext());\n");
+ writer.fwrite("if (_result == null) {\n");
+ writer.indent();
+ writer.fwrite("return ");
+ writer.write((String) TYPE_DEFAULTS.get(type));
                 writer.write(";\n");
- writer.write(" } else {\n");
- writer.write(" return ((");
- writer.write((String) wrappers.get(type));
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
+ writer.fwrite("return ((");
+ writer.write((String) WRAPPERS.get(type));
                 writer.write(") _result).");
- writer.write((String) unwrappers.get(type));
+ writer.write((String) UNWRAPPERS.get(type));
                 writer.write("();\n");
- writer.write(" }\n");
+ writer.unindent();
+ writer.fwrite("}\n");
             } else {
- writer.write(" return (");
+ writer.fwrite("return (");
                 writer.write(type);
                 writer.write(") _vb.getValue(getFacesContext());\n");
             }
- writer.write(" } else {\n");
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
             if (primitive(type)) {
- writer.write(" return this.");
+ writer.fwrite("return this.");
                 writer.write(var);
                 writer.write(";\n");
             } else {
- writer.write(" return null;\n");
+ writer.fwrite("return null;\n");
             }
- writer.write(" }\n");
- writer.write(" }\n\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
 
             // Generate the setter method
- writer.write(" /**\n");
- writer.write(" * <p>Set the value of the <code>");
- writer.write(pb.getPropertyName());
- writer.write("</code> property.</p>\n");
- writer.write(" */\n");
- writer.write(" public void set");
+ writer.writeJavadocComment("<p>Set the value of the <code>" +
+ pb.getPropertyName() + "</code> property.</p>\n");
+
+ writer.fwrite("public void set");
             writer.write(capitalize(pb.getPropertyName()));
             writer.write("(");
             writer.write(type);
- writer.write(" ");
+ writer.write(' ');
             writer.write(var);
             writer.write(") {\n");
- writer.write(" this.");
+ writer.indent();
+ writer.fwrite("this.");
             writer.write(var);
             writer.write(" = ");
             writer.write(var);
             writer.write(";\n");
             if (primitive(type)) {
- writer.write(" this.");
+ writer.fwrite("this.");
                 writer.write(var);
                 writer.write("_set = true;\n");
             }
- writer.write(" }\n\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
 
             // Generate spacing between properties
             writer.write("\n");
@@ -414,9 +395,8 @@
     /**
      * <p>Generate the suffix for this component class.</p>
      */
- private static void suffix() throws Exception {
+ private void suffix() throws Exception {
 
- int n = 0; // Index into values array
         int p = 0; // Number of primitive properties
         for (int i = 0; i < properties.size(); i++) {
             PropertyBean pb = (PropertyBean) properties.get(i);
@@ -426,17 +406,19 @@
         }
 
         // Generate the saveState() method
- writer.write(" public Object saveState(FacesContext _context)
{\n");
- writer.write(" Object _values[] = new Object[");
+ writer.fwrite("public Object saveState(FacesContext _context)
{\n");
+ writer.indent();
+ writer.fwrite("Object _values[] = new Object[");
         writer.write("" + (properties.size() + p + 1));
         writer.write("];\n");
- writer.write(" _values[0] = super.saveState(_context);\n");
- n = 1;
+ writer.fwrite("_values[0] = super.saveState(_context);\n");
+
+ int n = 1; // Index into values array
         for (int i = 0; i < properties.size(); i++) {
             PropertyBean pb = (PropertyBean) properties.get(i);
             String name = mangle(pb.getPropertyName());
             String type = pb.getPropertyClass();
- writer.write(" _values[");
+ writer.fwrite("_values[");
             writer.write("" + n++);
             writer.write("] = ");
             if ("boolean".equals(type)) {
@@ -445,7 +427,7 @@
                 writer.write(" ? Boolean.TRUE : Boolean.FALSE");
             } else if (primitive(type)) {
                 writer.write("new ");
- writer.write((String) wrappers.get(type));
+ writer.write((String) WRAPPERS.get(type));
                 writer.write("(this.");
                 writer.write(name);
                 writer.write(")");
@@ -454,35 +436,38 @@
             }
             writer.write(";\n");
             if (primitive(type)) {
- writer.write(" _values[");
+ writer.fwrite("_values[");
                 writer.write("" + n++);
                 writer.write("] = this.");
                 writer.write(name);
                 writer.write("_set ? Boolean.TRUE : Boolean.FALSE;\n");
             }
         }
- writer.write(" return _values;\n");
- writer.write(" }\n\n\n");
+ writer.fwrite("return _values;\n");
+ writer.unindent();
+ writer.write("}\n\n\n");
 
         // Generate the restoreState() method
- writer.write(" public void restoreState(FacesContext _context,
Object _state) {\n");
- writer.write(" Object _values[] = (Object[]) _state;\n");
- writer.write(" super.restoreState(_context, _values[0]);\n");
+ writer.fwrite(
+ "public void restoreState(FacesContext _context, Object
_state) {\n");
+ writer.indent();
+ writer.fwrite("Object _values[] = (Object[]) _state;\n");
+ writer.fwrite("super.restoreState(_context, _values[0]);\n");
         n = 1;
         for (int i = 0; i < properties.size(); i++) {
             PropertyBean pb = (PropertyBean) properties.get(i);
             String name = mangle(pb.getPropertyName());
             String type = pb.getPropertyClass();
- writer.write(" this.");
+ writer.fwrite("this.");
             writer.write(name);
             writer.write(" = ");
             if (primitive(type)) {
                 writer.write("((");
- writer.write((String) wrappers.get(type));
+ writer.write((String) WRAPPERS.get(type));
                 writer.write(") _values[");
                 writer.write("" + n++);
                 writer.write("]).");
- writer.write((String) unwrappers.get(type));
+ writer.write((String) UNWRAPPERS.get(type));
                 writer.write("()");
             } else {
                 writer.write("(");
@@ -493,16 +478,18 @@
             }
             writer.write(";\n");
             if (primitive(type)) {
- writer.write(" this.");
+ writer.fwrite("this.");
                 writer.write(name);
                 writer.write("_set = ((Boolean) _values[");
                 writer.write("" + n++);
                 writer.write("]).booleanValue();\n");
             }
         }
- writer.write(" }\n\n\n");
+ writer.unindent();
+ writer.fwrite("}\n\n\n");
 
         // Generate the ending of this class
+ writer.unindent();
         writer.write("}\n");
 
     }
@@ -512,46 +499,10 @@
     // -------------------------------------------------------------
Main Method
 
 
- public static void main(String args[]) throws Exception {
-
- try {
-
- // Perform setup operations
- if (log.isDebugEnabled()) {
- log.debug("Processing command line options");
- }
- Map options = options(args);
-
- copyright((String) options.get("--copyright"));
- directories((String) options.get("--dir"));
- Digester digester = digester(false, true, false);
- String config = (String) options.get("--config");
- if (log.isDebugEnabled()) {
- log.debug("Parsing configuration file '" + config + "'");
- }
- digester.push(new FacesConfigBean());
- fcb = parse(digester, config);
- if (log.isInfoEnabled()) {
- log.info("Generating HTML component classes");
- }
-
- // Generate concrete HTML component classes
- ComponentBean cbs[] = fcb.getComponents();
- for (int i = 0; i < cbs.length; i++) {
- String componentClass = cbs[i].getComponentClass();
- if
(componentClass.startsWith("javax.faces.component.html.")) {
- cb = cbs[i];
- generate();
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- System.exit(0);
-
+ public static void main(String[] args) throws Exception {
+ PropertyManager propManager = PropertyManager.newInstance(args[0]);
+ Generator generator = new HtmlComponentGenerator(propManager);
+ generator.generate(GeneratorUtil.getConfigBean(args[1]));
     }
-
 
 }
Index: jsf-tools/src/com/sun/faces/generate/HtmlTaglibGenerator.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-tools/src/com/sun/faces/generate/HtmlTaglibGenerator.java,v
retrieving revision 1.30
diff -u -r1.30 HtmlTaglibGenerator.java
--- jsf-tools/src/com/sun/faces/generate/HtmlTaglibGenerator.java 13
Nov 2004 02:17:06 -0000 1.30
+++ jsf-tools/src/com/sun/faces/generate/HtmlTaglibGenerator.java 9
Dec 2004 15:45:39 -0000
@@ -5,517 +5,217 @@
 
 package com.sun.faces.generate;
 
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
 import com.sun.faces.config.beans.AttributeBean;
 import com.sun.faces.config.beans.ComponentBean;
 import com.sun.faces.config.beans.DescriptionBean;
 import com.sun.faces.config.beans.FacesConfigBean;
 import com.sun.faces.config.beans.PropertyBean;
-import com.sun.faces.config.beans.RenderKitBean;
 import com.sun.faces.config.beans.RendererBean;
-import org.apache.commons.digester.Digester;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
 /**
- * This class generates tag handler class code that is special to the
"html_basic"
- * package.
+ * This class generates tag handler class code that is special to the
+ * "html_basic" package.
  */
 public class HtmlTaglibGenerator extends AbstractGenerator {
-
+
     // -------------------------------------------------------- Static
Variables
     
     // Log instance for this class
- protected static Log log =
LogFactory.getLog(HtmlTaglibGenerator.class);
-
- // StringBuffer containing the copyright material
- private static String copyright;
-
- // The directory into which the output will be generated
- private static File directory;
-
- // Base object of the configuration beans
- private static FacesConfigBean fcb;
+ private static Log log = LogFactory.getLog(HtmlTaglibGenerator.class);
 
     // The Writer for each component class to be generated
- private static Writer writer;
+ private CodeWriter writer;
 
- private static final String DEFAULT_RENDERKIT_ID = "DEFAULT";
 
- private static String renderKitId = DEFAULT_RENDERKIT_ID;
-
- // Defaults
- private static final String TAGCLASSPATH =
"com.sun.faces.taglib.html_basic";
- private static final String TEICLASS =
"com.sun.faces.taglib.FacesTagExtraInfo";
- private static final String BODYCONTENT = "JSP";
- private static final String REQUIRED = "false";
- private static final String RTEXPRVALUE = "false";
-
- // Maps used for generatng TLD and Tag Classes
- private static SortedMap componentsByComponentFamily;
- private static SortedMap renderersByComponentFamily;
- private static ComponentBean component = null;
- private static RendererBean renderer = null;
+ // Maps used for generatng Tag Classes
+ private ComponentBean component = null;
+ private RendererBean renderer = null;
 
     // Tag Handler Class Name
     private static String tagClassName = null;
 
- // String containing optional tag definitions loaded from external
file.
- // Currently "column" is the only tag existing in this file, because it
- // is a tag wth no renderer.
- private static String tagDef;
 
     // SPECIAL - Body Tags
- private static List bodyTags = new ArrayList();
- static {
- bodyTags.add("CommandLinkTag");
- bodyTags.add("OutputLinkTag");
- }
+ private List bodyTags;
 
     // SPECIAL - Components in this List are either a ValueHolder or
     // ConvertibleValueHolder; This is used to determine if we
generate ValueHolder
     // ConvertibleValueHolder code in "setProperties" method;
- private static List convertibleValueHolderComponents = new ArrayList();
- static {
- convertibleValueHolderComponents.add("UIOutput");
- convertibleValueHolderComponents.add("UIInput");
- convertibleValueHolderComponents.add("UISelectMany");
- convertibleValueHolderComponents.add("UISelectOne");
- }
+ private List convertibleValueHolderComponents;
 
     // SPECIAL - Value Binding Enabled Component Property Names
- private static List valueBindingEnabledProperties = new ArrayList();
- static {
- valueBindingEnabledProperties.add("immediate");
- valueBindingEnabledProperties.add("value");
- valueBindingEnabledProperties.add("first");
- valueBindingEnabledProperties.add("rows");
- valueBindingEnabledProperties.add("rowIndex");
- valueBindingEnabledProperties.add("required");
- valueBindingEnabledProperties.add("for");
- valueBindingEnabledProperties.add("showDetail");
- valueBindingEnabledProperties.add("showSummary");
- valueBindingEnabledProperties.add("globalOnly");
- valueBindingEnabledProperties.add("converter");
- valueBindingEnabledProperties.add("url");
- }
-
+ private List valueBindingEnabledProperties;
+
+
     // SPECIAL - Method Binding Enabled Component Property Names
- private static List methodBindingEnabledProperties = new ArrayList();
- static {
- methodBindingEnabledProperties = new ArrayList();
- methodBindingEnabledProperties.add("action");
- methodBindingEnabledProperties.add("actionListener");
- methodBindingEnabledProperties.add("validator");
- methodBindingEnabledProperties.add("valueChangeListener");
- }
+ private List methodBindingEnabledProperties;
 
- /**
- * The XML header for the TLD file.
- */
- private static void xmlHeader() throws Exception {
- writer.write("<?xml version="+'"'+"1.0"+'"'+"
encoding="+'"'+"ISO-8859-1"+'"'+" ?>\n\n");
- }
+ private PropertyManager propManager;
+ private FacesConfigBean configBean;
 
- /**
- * <p>Load the copyright text for the top of each Java source file
and TLD file.</p>
- *
- * @param path Pathname of the copyright file
- */
- private static void copyright(String path) throws Exception {
+ private Generator tldGenerator;
+
+ private File outputDir;
+
+
+ // ------------------------------------------------------------
Constructors
+
+ public HtmlTaglibGenerator(PropertyManager propManager) {
+
+ this.propManager = propManager;
+ tldGenerator = new JspTLD12Generator(propManager);
+
+ // initialize structures from the data in propManager
+
+ // body tags
+ StringTokenizer st =
+ new StringTokenizer(propManager.getProperty(
+ PropertyManager.TAGLIB_BODY_TAGS), ",");
 
- if (log.isDebugEnabled()) {
- log.debug("Loading copyright text from '" + path + "'");
+ bodyTags = new ArrayList(st.countTokens());
+ while(st.hasMoreTokens()) {
+ bodyTags.add(st.nextToken());
         }
- StringBuffer sb = new StringBuffer();
- BufferedReader reader =
- new BufferedReader(new FileReader(path));
- int ch;
- while ((ch = reader.read()) >= 0) {
- sb.append((char) ch);
+
+ // ValueHolder and ConvertibleValueHolder components
+ st = new StringTokenizer(propManager.getProperty(
+ PropertyManager.VALUE_HOLDER_COMPONENTS), ",");
+ convertibleValueHolderComponents = new ArrayList(st.countTokens());
+ while (st.hasMoreTokens()) {
+ convertibleValueHolderComponents.add(st.nextToken());
         }
- reader.close();
- if (log.isDebugEnabled()) {
- log.debug(" Copyright text contains " + sb.length() +
- " characters");
+
+ // ValueBinding enabled properties
+ st = new StringTokenizer(propManager.getProperty(
+ PropertyManager.VALUE_BINDING_PROPERTIES), ",");
+ valueBindingEnabledProperties = new ArrayList(st.countTokens());
+ while (st.hasMoreTokens()) {
+ valueBindingEnabledProperties.add(st.nextToken());
         }
- copyright = sb.toString();
- }
 
- /**
- * Copyright
- */
- private static void copyright() throws Exception {
- writer.write(copyright+"\n\n");
- }
+ // MethodBinding enabled properties
+ st = new StringTokenizer(propManager.getProperty(
+ PropertyManager.METHOD_BINDING_PROPERTIES), ",");
+ methodBindingEnabledProperties = new ArrayList(st.countTokens());
+ while (st.hasMoreTokens()) {
+ methodBindingEnabledProperties.add(st.nextToken());
+ }
 
- /**
- * TLD DOCTYPE
- */
- private static void tldDocType() throws Exception {
- writer.write("<!DOCTYPE taglib\n");
- writer.write("PUBLIC "+'"'+"-//Sun Microsystems, Inc.//DTD JSP Tag
Library 1.2//EN"+'"'+'\n');
-
 writer.write('"'+"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"+'"'+">\n\n");
- }
+ String packagePath =
+ propManager.getProperty(PropertyManager.TARGET_PACKAGE).
+ replace('.', File.separatorChar);
+ outputDir = new File(System.getProperty("user.dir") +
+ File.separatorChar +
+ propManager.getProperty(PropertyManager.BASE_OUTPUT_DIR) +
+ File.separatorChar + packagePath);
 
- /**
- * The description element for this TLD.
- */
- private static void tldDescription() throws Exception {
- writer.write("<taglib>\n\n");
- writer.write("<!-- ============== Tag Library Description Elements
============= -->\n\n");
-
writer.write("<tlib-version>1.0</tlib-version>\n<jsp-version>1.2</jsp-version>\n");
- writer.write("<short-name>h</short-name>\n");
- writer.write("<uri>http://java.sun.com/jsf/html</uri>\n");
- writer.write("<description>\n");
- writer.write(" This tag library contains JavaServer Faces
component tags for all\n");
- writer.write(" UIComponent + HTML RenderKit Renderer combinations
defined in the\n");
- writer.write(" JavaServer Faces Specification.\n");
- writer.write("</description>\n\n");
- }
+ if (!outputDir.exists()) {
+ outputDir.mkdirs();
+ }
 
- /**
- * The validator for this TLD.
- */
- private static void tldValidator() throws Exception {
- writer.write("<!-- ============== Tag Library Validator
============= -->\n\n");
- writer.write("<validator>\n <validator-class>\n");
- writer.write("
com.sun.faces.taglib.html_basic.HtmlBasicValidator\n");
- writer.write(" </validator-class>\n</validator>\n\n");
- }
+ setTldGenerator(GeneratorUtil.getTldGenerator(propManager));
 
- /**
- * The tags for this TLD.
- */
- private static void tldTags() throws Exception {
- writer.write("<!-- ===================== HTML 4.0 basic tags
====================== -->\n\n");
- componentsByComponentFamily = getComponentFamilyComponentMap();
- renderersByComponentFamily =
getComponentFamilyRendererMap(renderKitId);
-
- Iterator
- rendererIter = null,
- keyIter = renderersByComponentFamily.keySet().iterator();
- String componentFamily = null;
- String rendererType = null;
- List renderers = null;
- DescriptionBean description = null;
- String descriptionText = null;
- String tagName = null;
- while (keyIter.hasNext()) {
- componentFamily = (String) keyIter.next();
- renderers = (List)renderersByComponentFamily.get(componentFamily);
- rendererIter = renderers.iterator();
- while (rendererIter.hasNext()) {
- renderer = (RendererBean) rendererIter.next();
- rendererType = renderer.getRendererType();
- writer.write(" <tag>\n");
- tagName = makeTldTagName(strip(componentFamily),
- strip(rendererType));
- if (tagName == null) {
- throw new IllegalStateException("Could not determine tag
name");
- }
- writer.write(" <name>"+tagName+"</name>\n");
- if (makeTagClassName(strip(componentFamily),
strip(rendererType)) == null) {
- throw new IllegalStateException("Could not determine tag
class name");
- }
- writer.write(" <tag-class>"+getTagClassPath(tagName)+"."+
- makeTagClassName(strip(componentFamily),
strip(rendererType))+"</tag-class>\n");
- writer.write("
<tei-class>"+getTeiClass(tagName)+"</tei-class>\n");
- writer.write("
<body-content>"+getBodyContent(tagName)+"</body-content>\n");
- description = renderer.getDescription("");
- if (description != null) {
- descriptionText = description.getDescription();
- writer.write(" <description>\n");
- if (descriptionText != null) {
- if (descriptionText.indexOf("<") < 0) {
- writer.write(" "+descriptionText+"\n");
- } else {
- writer.write("
<![CDATA["+descriptionText+"]]>\n");
- }
- }
- writer.write(" </description>\n");
- }
-
- // Generate tag attributes
- //
-
- // Component Properties first...
- //
- component =
(ComponentBean)componentsByComponentFamily.get(componentFamily);
-
- PropertyBean[] properties = component.getProperties();
- PropertyBean property = null;
- for (int i = 0, len = properties.length; i < len; i++) {
- if (null == (property = properties[i])) {
- continue;
- }
- if (!property.isTagAttribute()) {
- continue;
- }
- writer.write(" <attribute>\n");
- writer.write("
<name>"+property.getPropertyName()+"</name>\n");
- if (property.isRequired()) {
- writer.write(" <required>true</required>\n");
- } else {
- writer.write(" <required>false</required>\n");
- }
- writer.write(" <rtexprvalue>"+
- getRtexprvalue(tagName,
property.getPropertyName())+
- "</rtexprvalue>\n");
- description = property.getDescription("");
- if (description != null) {
- descriptionText = description.getDescription();
- writer.write(" <description>\n");
- if (descriptionText != null) {
- if (descriptionText.indexOf("<") < 0) {
- writer.write(" "+descriptionText+"\n");
- } else {
- writer.write("
<!CDATA["+descriptionText+"]]>\n");
- }
- }
- writer.write(" </description>\n");
- }
- writer.write(" </attribute>\n");
- }
-
- // Renderer Attributes Next...
- //
- AttributeBean[] attributes = renderer.getAttributes();
- AttributeBean attribute = null;
- for (int i = 0, len = attributes.length; i < len; i++) {
- if (null == (attribute = attributes[i])) {
- continue;
- }
- if (!attribute.isTagAttribute()) {
- continue;
- }
- if (skipThisAttribute(renderer,
- attribute.getAttributeName())) {
- continue;
- }
- writer.write(" <attribute>\n");
- writer.write("
<name>"+attribute.getAttributeName()+"</name>\n");
- if (attribute.isRequired()) {
- writer.write(" <required>true</required>\n");
- } else {
- writer.write(" <required>false</required>\n");
- }
- writer.write(" <rtexprvalue>"+
- getRtexprvalue(tagName,
attribute.getAttributeName())+
- "</rtexprvalue>\n");
- description = attribute.getDescription("");
- if (description != null) {
- descriptionText = description.getDescription();
- writer.write(" <description>\n");
- if (descriptionText != null) {
- if (descriptionText.indexOf("<") < 0) {
- writer.write(" "+descriptionText+"\n");
- } else {
- writer.write("
<!CDATA["+descriptionText+"]]>\n");
- }
- }
- writer.write(" </description>\n");
- }
- writer.write(" </attribute>\n");
- }
-
- // SPECIAL: "Binding" needs to exist on every tag..
- writer.write(" <attribute>\n");
- writer.write(" <name>binding</name>\n");
- writer.write(" <required>false</required>\n");
- writer.write(" <rtexprvalue>false</rtexprvalue>\n");
- writer.write(" <description>\n");
- writer.write(" The value binding expression linking
this component to a property in a backing bean\n");
- writer.write(" </description>\n");
- writer.write(" </attribute>\n");
-
- writer.write(" </tag>\n");
- }
- }
-
- //Include any other tags defined in the optional tag definition file.
- //These might be tags that were not picked up because they have no
renderer
- //- for example "column".
- if (tagDef != null) {
- writer.write(tagDef);
- }
+ } // END HtmlTaglibGenerator
 
- writer.write("</taglib>");
- }
 
- /**
- * <p>Load any additional tag definitions from the specified
- * file. This file might include tags such as "column" which
- * have no renderer, but need to be generated into the
- * TLD file.</p>
- *
- * @param path Pathname of the tag definition file
- */
- private static void loadOptionalTags(String path) throws Exception {
+ // ----------------------------------------------------------
Public Methods
 
- if (log.isDebugEnabled()) {
- log.debug("Loading optional tag text from '" + path + "'");
- }
- StringBuffer sb = new StringBuffer();
- BufferedReader reader =
- new BufferedReader(new FileReader(path));
- int ch;
- while ((ch = reader.read()) >= 0) {
- sb.append((char) ch);
- }
- reader.close();
- if (log.isDebugEnabled()) {
- log.debug(" Optional tag text contains " + sb.length() +
- " characters");
+
+ public void generate(FacesConfigBean configBean) {
+
+ this.configBean = configBean;
+ try {
+ generateTagClasses();
+ tldGenerator.generate(configBean);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
         }
- tagDef = sb.toString();
- }
 
- /**
- * Build the tag name from componentFamily and rendererType. The
name will
- * be "camel case".
- *
- * @param componentFamily the component family
- * @param rendererType the renderer type
- */
- private static String makeTldTagName(String componentFamily, String
rendererType) {
- if (componentFamily == null) {
- return null;
- }
- String tagName =
- Character.toLowerCase(componentFamily.charAt(0)) +
- componentFamily.substring(1);
- if (rendererType == null) {
- return tagName;
- }
- if (componentFamily.equals(rendererType)) {
- return tagName;
- }
- if (rendererType != null) {
- tagName = tagName + rendererType;
- }
- return tagName;
- }
+ } // END generate
 
- /**
- * Build the tag handler class name from componentFamily and
rendererType.
- *
- * @param componentFamily the component family
- * @param rendererType the renderer type
- */
- private static String makeTagClassName(String componentFamily,
String rendererType) {
- if (componentFamily == null) {
- return null;
- }
- String tagClassName = componentFamily;
- if (rendererType != null) {
- if (!componentFamily.equals(rendererType)) {
- tagClassName = tagClassName + rendererType;
- }
- }
- return tagClassName+"Tag";
- }
 
- /**
- * <p>Create directories as needed to contain the output.
- *
- * @param path Pathname to the base directory
- */
- private static void directories(String path, boolean classesDir)
throws Exception {
+ public static void main(String[] args) {
 
- directory = new File(path);
- if (classesDir) {
- directory = new File(path, "com/sun/faces/taglib/html_basic");
- }
- if (log.isDebugEnabled()) {
- log.debug("Creating output directory " +
- directory.getAbsolutePath());
+ PropertyManager manager = PropertyManager.newInstance(args[0]);
+ try {
+ Generator generator = new HtmlTaglibGenerator(manager);
+ generator.generate(GeneratorUtil.getConfigBean(args[1]));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
         }
- directory.mkdirs();
- }
 
- // Note that the following methods simply return a global default
value now. When we
- // set up the class path, tag extra info, required, rtexprValue,
bodycontext to be
- // configurable, then we can retrieve that info using the args.
- //
+ } // END main
 
- /**
- * Return the class path for the given tag.
- */
- private static String getTagClassPath(String tagName) {
- return TAGCLASSPATH;
- }
 
- /**
- * Return the tag extra info information (if any) for a given tag.
- */
- private static String getTeiClass(String tagName) {
- return TEICLASS;
- }
+ // -------------------------------------------------------
Protected Methods
 
- /**
- * Return the tag body content information (if any) for a given tag.
- */
- private static String getBodyContent(String tagName) {
- return BODYCONTENT;
- }
 
     /**
- * Return the "rtexprvalue" element value for the tag attribute.
+ * <p>Set the <code>JspTLDGenerator</code> to be used by the taglib
+ * generator.</p>
+ * @param tldGenerator <code>JspTLDGenerator</code> instance
      */
- private static String getRtexprvalue(String tagName, String
attributeName) {
- return RTEXPRVALUE;
- }
+ protected void setTldGenerator(JspTLDGenerator tldGenerator) {
+
+ this.tldGenerator = tldGenerator;
+
+ } // END setTldGenerator
+
+
+ // ---------------------------------------------------------
Private Methods
 
- //
- // Following methods uses in tag class generation;
- //
 
     /**
- * Generate copyright, package declaration, import statements,
- * class declaration.
+ * Generate copyright, package declaration, import statements, class
+ * declaration.
      */
- private static void tagHandlerPrefix() throws Exception {
+ private void tagHandlerPrefix() throws Exception {
 
         // Generate the copyright information
- writer.write(copyright);
+ writer.writeBlockComment(
+ propManager.getProperty(PropertyManager.COPYRIGHT));
 
         // Generate the package declaration
- writer.write("\npackage com.sun.faces.taglib.html_basic;\n");
- writer.write("\n\n");
+ writer.fwrite("\npackage com.sun.faces.taglib.html_basic;\n\n\n");
 
         // Generate the imports
- writer.write("import com.sun.faces.util.Util;\n");
- writer.write("import java.io.IOException;\n");
- writer.write("import javax.faces.component.UIComponent;\n");
- writer.write("import javax.faces.component.UI" +
- strip(component.getComponentType())+";\n");
- writer.write("import javax.faces.context.FacesContext;\n");
- writer.write("import javax.faces.event.ActionEvent;\n");
- writer.write("import javax.faces.event.ValueChangeEvent;\n");
- writer.write("import javax.faces.convert.Converter;\n");
- writer.write("import javax.faces.el.ValueBinding;\n");
- writer.write("import javax.faces.el.MethodBinding;\n");
- writer.write("import javax.faces.webapp.UIComponentTag;\n");
- writer.write("import javax.faces.webapp.UIComponentBodyTag;\n");
- writer.write("import javax.servlet.jsp.JspException;\n");
- writer.write("import org.apache.commons.logging.Log;\n");
- writer.write("import org.apache.commons.logging.LogFactory;\n");
+ writer.fwrite("import com.sun.faces.util.Util;\n");
+ writer.fwrite("import java.io.IOException;\n");
+ writer.fwrite("import javax.faces.component.UIComponent;\n");
+ writer.fwrite(
+ "import javax.faces.component.UI" +
+
GeneratorUtil.stripJavaxFacesPrefix(component.getComponentType()) +
+ ";\n");
+ writer.fwrite("import javax.faces.context.FacesContext;\n");
+ writer.fwrite("import javax.faces.event.ActionEvent;\n");
+ writer.fwrite("import javax.faces.event.ValueChangeEvent;\n");
+ writer.fwrite("import javax.faces.convert.Converter;\n");
+ writer.fwrite("import javax.faces.el.ValueBinding;\n");
+ writer.fwrite("import javax.faces.el.MethodBinding;\n");
+ writer.fwrite("import javax.faces.webapp.UIComponentTag;\n");
+ writer.fwrite("import javax.faces.webapp.UIComponentBodyTag;\n");
+ writer.fwrite("import javax.servlet.jsp.JspException;\n");
+ writer.write('\n');
+ writer.fwrite("import org.apache.commons.logging.Log;\n");
+ writer.fwrite("import org.apache.commons.logging.LogFactory;\n");
         writer.write("\n\n");
 
+ writer.writeBlockComment("******* GENERATED CODE - DO NOT EDIT
*******");
+ writer.write("\n\n");
+
+
         // Generate the class JavaDocs (if any)
         DescriptionBean db = component.getDescription("");
         if (db != null) {
@@ -525,62 +225,64 @@
             }
             description = description.trim();
             if (description.length() > 0) {
- writer.write("/**\n");
- description(description, writer, 1);
- writer.write(" */\n");
+ writer.writeJavadocComment(description);
             }
         }
-
+
         // Generate the class declaration
- writer.write("public class ");
+ writer.fwrite("public class ");
         writer.write(tagClassName);
         writer.write(" extends ");
- if (isBodyTag()) {
- writer.write("UIComponentBodyTag");
- } else {
- writer.write("UIComponentTag");
- }
- writer.write(" {\n\n\n");
-
- // Generate Log declaration
- writer.write(" public static Log log =
LogFactory.getLog("+tagClassName+".class);\n\n");
+ if (isBodyTag()) {
+ writer.write("UIComponentBodyTag");
+ } else {
+ writer.write("UIComponentTag");
+ }
+ writer.write("{\n\n");
+ writer.indent();
+ // Generate Log declaration
+ writer.fwrite("private static Log log = LogFactory.getLog(" +
+ tagClassName + ".class);\n\n");
     }
-
- private static void tagHandlerReleaseMethod() throws Exception {
- writer.write(" //\n // Release Method\n //\n\n");
-
- writer.write(" public void release() {\n");
- writer.write(" super.release();\n\n");
- writer.write(" // component properties\n");
+
+
+ private void tagHandlerReleaseMethod() throws Exception {
+
+ writer.writeLineComment(" RELEASE ");
+
+ writer.fwrite("public void release() {\n");
+ writer.indent();
+ writer.fwrite("super.release();\n\n");
+ writer.writeLineComment("component properties");
 
         // Generate from component properties
         //
         PropertyBean[] properties = component.getProperties();
- PropertyBean property = null;
- String propertyName = null;
- String propertyType = null;
- String ivar = null;
         for (int i = 0, len = properties.length; i < len; i++) {
- if (null == (property = properties[i])) {
+ PropertyBean property = properties[i];
+ if (property == null) {
                 continue;
             }
+
             if (!property.isTagAttribute()) {
                 continue;
             }
- propertyName = property.getPropertyName();
- propertyType = property.getPropertyClass();
+
+ String propertyName = property.getPropertyName();
+ String propertyType = property.getPropertyClass();
 
             // SPECIAL - Don't generate these properties
- if (propertyName.equals("binding") || propertyName.equals("id")
- || propertyName.equals("rendered")) {
+ if ("binding".equals(propertyName) || "id".equals(propertyName)
+ || "rendered".equals(propertyName)) {
                 continue;
             }
 
- ivar = mangle(propertyName);
- writer.write(" this." + ivar + " = ");
- if (primitive(propertyType) &&
!(valueBindingEnabledProperties.contains(propertyName)
- ||
methodBindingEnabledProperties.contains(propertyName))) {
- writer.write((String) defaults.get(propertyType));
+ String ivar = mangle(propertyName);
+ writer.fwrite("this." + ivar + " = ");
+ if (primitive(propertyType) &&
!(valueBindingEnabledProperties.contains(
+ propertyName)
+ ||
methodBindingEnabledProperties.contains(propertyName))) {
+ writer.write((String) TYPE_DEFAULTS.get(propertyType));
             } else {
                 writer.write("null");
             }
@@ -588,467 +290,507 @@
         }
 
         writer.write("\n");
- writer.write(" // rendered attributes\n");
+ writer.writeLineComment("rendered attributes");
 
         // Generate from renderer attributes..
         //
         AttributeBean[] attributes = renderer.getAttributes();
- AttributeBean attribute = null;
- String attributeName = null;
- String attributeType = null;
+
         for (int i = 0, len = attributes.length; i < len; i++) {
- if (null == (attribute = attributes[i])) {
+ AttributeBean attribute = attributes[i];
+
+ if (attribute == null) {
                 continue;
             }
             if (!attribute.isTagAttribute()) {
                 continue;
             }
- attributeName = attribute.getAttributeName();
- attributeType = attribute.getAttributeClass();
 
- ivar = mangle(attributeName);
- writer.write(" this." + ivar + " = null;\n");
+ String attributeName = attribute.getAttributeName();
+
+ writer.fwrite("this." + mangle(attributeName) + " = null;\n");
         }
- writer.write(" }\n\n");
+
+ writer.unindent();
+ writer.fwrite("}\n\n");
     }
 
     /**
- * Generate Tag Handler instance variables from component properties
- * and renderer attributes.
+ * Generate Tag Handler setter methods from component properties and
+ * renderer attributes.
      */
- private static void tagHandlerIvars() throws Exception {
+ private void tagHandlerSetterMethods() throws Exception {
 
- writer.write(" //\n // Instance Variables\n //\n\n");
+ writer.writeLineComment("Setter Methods");
 
- // Generate from component properties
- //
+ // Generate from component properties
+ //
         PropertyBean[] properties = component.getProperties();
- PropertyBean property = null;
- String propertyName = null;
- String propertyType = null;
- String ivar = null;
- for (int i = 0, len = properties.length; i < len; i++) {
- if (null == (property = properties[i])) {
- continue;
- }
- if (!property.isTagAttribute()) {
- continue;
- }
- propertyName = property.getPropertyName();
- propertyType = property.getPropertyClass();
-
- // SPECIAL - Don't generate these properties
- if (propertyName.equals("binding") ||
- propertyName.equals("id") ||
- propertyName.equals("rendered")) {
- continue;
- }
-
- ivar = mangle(propertyName);
- if (valueBindingEnabledProperties.contains(propertyName) ||
- methodBindingEnabledProperties.contains(propertyName)) {
- writer.write(" private java.lang.String " + ivar +
";\n");
- } else {
- writer.write(" private " + propertyType + " " + ivar +
";\n");
- if (primitive(propertyType)) {
- writer.write(" = "+(String)defaults.get(propertyType)+";\n");
- }
- }
- }
 
- writer.write("\n");
+ for (int i = 0, len = properties.length; i < len; i++) {
+ PropertyBean property = properties[i];
 
- // Generate from renderer attributes..
- //
- AttributeBean[] attributes = renderer.getAttributes();
- AttributeBean attribute = null;
- String attributeName = null;
- String attributeType = null;
- for (int i = 0, len = attributes.length; i < len; i++) {
- if (null == (attribute = attributes[i])) {
+ if (property == null) {
                 continue;
             }
- if (!attribute.isTagAttribute()) {
+ if (!property.isTagAttribute()) {
                 continue;
             }
- attributeName = attribute.getAttributeName();
- attributeType = attribute.getAttributeClass();
-
- ivar = mangle(attributeName);
- writer.write(" private java.lang.String " + ivar + ";\n");
- }
- writer.write("\n");
- }
-
- /**
- * Generate Tag Handler setter methods from component properties
- * and renderer attributes.
- */
- private static void tagHandlerSetterMethods() throws Exception {
 
- writer.write(" //\n // Setter Methods\n //\n\n");
+ String propertyName = property.getPropertyName();
+ String propertyType = property.getPropertyClass();
 
- // Generate from component properties
- //
- PropertyBean[] properties = component.getProperties();
- PropertyBean property = null;
- String propertyName = null;
- String propertyType = null;
- String setVar = null;
- String ivar = null;
- for (int i = 0, len = properties.length; i < len; i++) {
- if (null == (property = properties[i])) {
- continue;
- }
- if (!property.isTagAttribute()) {
+ // SPECIAL - Don't generate these properties
+ if ("binding".equals(propertyName) ||
+ "id".equals(propertyName) ||
+ "rendered".equals(propertyName)) {
                 continue;
             }
- propertyName = property.getPropertyName();
- propertyType = property.getPropertyClass();
 
- // SPECIAL - Don't generate these properties
- if (propertyName.equals("binding") ||
- propertyName.equals("id") ||
- propertyName.equals("rendered")) {
- continue;
- }
- ivar = mangle(propertyName);
- setVar = capitalize(propertyName);
- writer.write(" public void set" + setVar + "(");
- if (valueBindingEnabledProperties.contains(propertyName) ||
- methodBindingEnabledProperties.contains(propertyName)) {
- writer.write("java.lang.String " + ivar + ") {\n");
- } else {
- writer.write(propertyType + " " + ivar + ") {\n");
- }
- writer.write(" this." + ivar + " = " + ivar + ";\n");
- writer.write(" }\n\n");
- }
+ if (valueBindingEnabledProperties.contains(propertyName) ||
+ methodBindingEnabledProperties.contains(propertyName)) {
+ writer.writeWriteOnlyProperty(propertyName,
"java.lang.String");
+ } else {
+ writer.writeWriteOnlyProperty(propertyName, propertyType);
+ }
+ }
 
- // Generate from renderer attributes..
- //
+ // Generate from renderer attributes..
+ //
         AttributeBean[] attributes = renderer.getAttributes();
- AttributeBean attribute = null;
- String attributeName = null;
- String attributeType = null;
         for (int i = 0, len = attributes.length; i < len; i++) {
- if (null == (attribute = attributes[i])) {
+ AttributeBean attribute = attributes[i];
+
+ if (attribute == null) {
                 continue;
             }
- if (!attribute.isTagAttribute()) {
+ if (!attribute.isTagAttribute()) {
                 continue;
             }
- attributeName = attribute.getAttributeName();
- attributeType = attribute.getAttributeClass();
+ String attributeName = attribute.getAttributeName();
 
- ivar = mangle(attributeName);
- setVar = capitalize(attributeName);
- writer.write(" public void set" + setVar + "(");
- writer.write("java.lang.String " + ivar + ") {\n");
- writer.write(" this." + ivar + " = " + ivar + ";\n");
- writer.write(" }\n\n");
- }
- writer.write("\n");
+ writer.writeWriteOnlyProperty(attributeName,
+ "java.lang.String");
+
+ }
+ writer.write("\n");
     }
-
+
+
     /**
- * Generate Tag Handler general methods from component properties
- * and renderer attributes.
+ * Generate Tag Handler general methods from component properties and
+ * renderer attributes.
      */
- private static void tagHandlerGeneralMethods() throws Exception {
+ private void tagHandlerGeneralMethods() throws Exception {
 
- writer.write(" //\n // General Methods\n //\n\n");
+ writer.writeLineComment("General Methods");
 
- String componentType = component.getComponentType();
- String rendererType = renderer.getRendererType();
- writer.write(" public String getRendererType() { return ");
- writer.write("\""+rendererType+"\"; }\n");
- writer.write(" public String getComponentType() { return ");
- if (componentType.equals(rendererType)) {
- writer.write("\"javax.faces.Html" + strip(componentType) + "\";
}\n");
- } else {
- writer.write("\"javax.faces.Html" + strip(componentType) +
strip(rendererType) + "\"; }\n");
- }
- writer.write("\n");
- writer.write(" protected void setProperties(UIComponent
component) {\n");
- writer.write(" super.setProperties(component);\n");
- String uicomponent = "UI"+strip(componentType);
- writer.write(" "+uicomponent+"
"+strip(componentType).toLowerCase()+
- " = null;\n");
-
- writer.write(" try {\n");
- writer.write(" "+strip(componentType).toLowerCase()+
- " = (UI"+strip(componentType)+ ")component;\n");
- writer.write(" }\n");
- writer.write(" catch (ClassCastException cce) {\n");
- writer.write(" throw new IllegalStateException(\"Component
\" + component.toString() + \" not expected type. Expected: " +
uicomponent + ". Perhaps you're missing a tag?\");\n");
- writer.write(" }\n\n");
- if (convertibleValueHolderComponents.contains(uicomponent)) {
- writer.write(" if (converter != null) {\n");
- writer.write(" if (isValueReference(converter))
{\n");
- writer.write(" ValueBinding vb = \n");
- writer.write("
Util.getValueBinding(converter);\n");
- writer.write("
"+strip(componentType).toLowerCase()+".setValueBinding(");
- writer.write("\""+"converter\", vb);\n");
- writer.write(" } else {\n");
- writer.write(" Converter _converter =
FacesContext.getCurrentInstance().\n");
- writer.write("
getApplication().createConverter(converter);\n");
- writer.write(" " +
strip(componentType).toLowerCase() + ".setConverter(_converter);\n");
+ String componentType = component.getComponentType();
+ String rendererType = renderer.getRendererType();
+ writer.fwrite("public String getRendererType() {\n");
+ writer.indent();
+ writer.fwrite("return ");
+ writer.write('\"' + rendererType + "\";\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
+
+ writer.fwrite("public String getComponentType() {\n");
+ writer.indent();
+ writer.fwrite("return ");
+ if (componentType.equals(rendererType)) {
+ writer.write(
+ "\"javax.faces.Html" +
+ GeneratorUtil.stripJavaxFacesPrefix(componentType) +
+ "\";\n");
+ } else {
+ writer.write(
+ "\"javax.faces.Html" +
+ GeneratorUtil.stripJavaxFacesPrefix(componentType) +
+ GeneratorUtil.stripJavaxFacesPrefix(rendererType) +
+ "\";\n");
+ }
+ writer.unindent();
+ writer.fwrite("}\n\n");
+
+ writer.fwrite("protected void setProperties(UIComponent
component) {\n");
+ writer.indent();
+ writer.fwrite("super.setProperties(component);\n");
+
+ String uicomponent = "UI" +
+ GeneratorUtil.stripJavaxFacesPrefix(componentType);
+ String iVar =
+
GeneratorUtil.stripJavaxFacesPrefix(componentType).toLowerCase();
+
+ writer.fwrite(uicomponent + ' ' + iVar + " = null;\n");
+
+ writer.fwrite("try {\n");
+ writer.indent();
+ writer.fwrite(iVar + " = (" + uicomponent + ") component;\n");
+ writer.unindent();
+ writer.fwrite("} catch (ClassCastException cce) {\n");
+ writer.indent();
+ writer.fwrite("throw new IllegalStateException(\"Component \" + " +
+ "component.toString() + \" not expected type. Expected: " +
+ uicomponent +
+ ". Perhaps you're missing a tag?\");\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
 
- writer.write(" }\n");
- writer.write(" }\n\n");
+ if (convertibleValueHolderComponents.contains(uicomponent)) {
+ writer.fwrite("if (converter != null) {\n");
+ writer.indent();
+ writer.fwrite("if (isValueReference(converter)) {\n");
+ writer.indent();
+ writer.fwrite("ValueBinding vb =
Util.getValueBinding(converter);\n");
+ writer.fwrite(iVar + ".setValueBinding(\"converter\", vb);\n");
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
+ writer.fwrite("Converter _converter =
FacesContext.getCurrent" +
+
"Instance().getApplication().createConverter(converter);\n");
+ writer.fwrite(iVar + ".setConverter(_converter);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
         }
 
- // Generate "setProperties" method contents from component properties
- //
+ // Generate "setProperties" method contents from component
properties
+ //
         PropertyBean[] properties = component.getProperties();
- PropertyBean property = null;
- String propertyName = null;
- String propertyType = null;
- String ivar = null;
- String vbKey = null;
         for (int i = 0, len = properties.length; i < len; i++) {
- if (null == (property = properties[i])) {
+ PropertyBean property = properties[i];
+
+ if (property == null) {
                 continue;
             }
- if (!property.isTagAttribute()) {
+ if (!property.isTagAttribute()) {
                 continue;
             }
- propertyName = property.getPropertyName();
- propertyType = property.getPropertyClass();
 
- // SPECIAL - Don't generate these properties
- if (propertyName.equals("binding") ||
- propertyName.equals("id") ||
- propertyName.equals("rendered") ||
- propertyName.equals("converter")) {
- continue;
- }
- ivar = mangle(propertyName);
- vbKey = ivar;
-
- if (valueBindingEnabledProperties.contains(propertyName)) {
- writer.write(" if ("+ivar+" != null) {\n");
- writer.write(" if
(isValueReference("+ivar+")) {\n");
- writer.write(" ValueBinding vb = ");
- writer.write("Util.getValueBinding("+ivar+");\n");
-
- writer.write("
"+strip(componentType).toLowerCase());
- writer.write(".setValueBinding(\""+vbKey+"\", vb);\n");
- writer.write(" } else {\n");
- if (primitive(propertyType)) {
- writer.write(" "+propertyType+"
_"+ivar+" ");
- writer.write("= new "+wrappers.get(propertyType));
- writer.write("("+ivar+")."+propertyType+"Value();\n");
- writer.write("
"+strip(componentType).toLowerCase()+
- ".set" + capitalize(propertyName) + "(_" + ivar
+ ");\n");
+ String propertyName = property.getPropertyName();
+ String propertyType = property.getPropertyClass();
+
+ // SPECIAL - Don't generate these properties
+ if ("binding".equals(propertyName) ||
+ "id".equals(propertyName) ||
+ "rendered".equals(propertyName) ||
+ "converter".equals(propertyName)) {
+ continue;
+ }
+ String ivar = mangle(propertyName);
+ String vbKey = ivar;
+ String comp =
+
GeneratorUtil.stripJavaxFacesPrefix(componentType).toLowerCase();
+ String capPropName = capitalize(propertyName);
+
+ if (valueBindingEnabledProperties.contains(propertyName)) {
+ writer.fwrite("if (" + ivar + " != null) {\n");
+ writer.indent();
+ writer.fwrite("if (isValueReference(" + ivar + ")) {\n");
+ writer.indent();
+ writer.fwrite("ValueBinding vb = Util.getValueBinding(" +
+ ivar + ");\n");
+
+ writer.fwrite(comp + ".setValueBinding(\"" + vbKey +
"\", vb);\n");
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
+ if (primitive(propertyType)) {
+ writer.fwrite(propertyType + " _" + ivar);
+ writer.write(" = new " + WRAPPERS.get(propertyType));
+ writer.write("(" + ivar + ")." + propertyType +
"Value();\n");
+ writer.fwrite(comp + ".set" + capPropName +
+ "(_" + ivar + ");\n");
                 } else {
- writer.write("
"+strip(componentType).toLowerCase()+
- ".set" + capitalize(propertyName) + "(" + ivar + ");\n");
+ writer.fwrite(comp + ".set" + capPropName + '(' +
ivar +
+ ");\n");
                 }
- writer.write(" }\n");
- writer.write(" }\n");
- } else if (methodBindingEnabledProperties.contains(propertyName)) {
- if (ivar.equals("action")) {
- writer.write(" if ("+ivar+" != null) {\n");
- writer.write(" if
(isValueReference("+ivar+")) {\n");
- writer.write(" MethodBinding vb =
FacesContext.getCurrentInstance().");
-
writer.write("getApplication().createMethodBinding("+ivar+", null);\n");
- writer.write("
"+strip(componentType).toLowerCase());
- writer.write(".setAction(vb);\n");
- writer.write(" } else {\n");
- writer.write(" final String outcome
= " + ivar + ";\n");
- writer.write(" MethodBinding vb =
Util.createConstantMethodBinding("+ivar+");\n");
- writer.write("
"+strip(componentType).toLowerCase()+".setAction(vb);\n");
- writer.write(" }\n");
- writer.write(" }\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
+ } else if
(methodBindingEnabledProperties.contains(propertyName)) {
+ if ("action".equals(ivar)) {
+ writer.fwrite("if (" + ivar + " != null) {\n");
+ writer.indent();
+ writer.fwrite("if (isValueReference(" + ivar + "))
{\n");
+ writer.indent();
+ writer.fwrite("MethodBinding vb =
FacesContext.getCurrentInstance().");
+ writer.write("getApplication().createMethodBinding(" +
+ ivar + ", null);\n");
+ writer.fwrite(comp + ".setAction(vb);\n");
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
+ writer.fwrite("final String outcome = " + ivar +
";\n");
+ writer.fwrite("MethodBinding vb =
Util.createConstantMethodBinding(" +
+ ivar + ");\n");
+ writer.fwrite(comp + ".setAction(vb);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("}\n");
                 } else {
                     HashMap signatureMap = new HashMap(3);
- signatureMap.put("actionListener",
- "Class args[] = { ActionEvent.class };");
+ signatureMap.put("actionListener",
+ "Class args[] = { ActionEvent.class };");
                     signatureMap.put("validator",
                         "Class args[] = { FacesContext.class,
UIComponent.class, Object.class };");
                     signatureMap.put("valueChangeListener",
                         "Class args[] = { ValueChangeEvent.class };");
- writer.write(" if ("+ivar+" != null) {\n");
- writer.write(" if
(isValueReference("+ivar+")) {\n");
- writer.write(" " +
signatureMap.get(ivar) + "\n");
- writer.write(" MethodBinding vb =
FacesContext.getCurrentInstance().");
-
writer.write("getApplication().createMethodBinding("+ivar+", args);\n");
- writer.write("
"+strip(componentType).toLowerCase());
- writer.write(".set" + capitalize(ivar) + "(vb);\n");
- writer.write(" } else {\n");
- writer.write(" Object params [] = {" +
ivar + "};\n");
- writer.write(" throw new
javax.faces.FacesException(Util.getExceptionMessageString(Util.INVALID_EXPRESSION_ID,
params));\n");
- writer.write(" }\n");
- writer.write(" }\n");
- }
- } else {
- writer.write("
"+strip(componentType).toLowerCase()+".set" +
- capitalize(propertyName) + "(" + ivar + ");\n");
- }
- }
 
- // Generate "setProperties" method contents from renderer attributes
- //
+ writer.fwrite("if (" + ivar + " != null) {\n");
+ writer.indent();
+ writer.fwrite("if (isValueReference(" + ivar + "))
{\n");
+ writer.indent();
+ writer.fwrite(signatureMap.get(ivar) + "\n");
+ writer.fwrite("MethodBinding vb =
FacesContext.getCurrentInstance().");
+ writer.write("getApplication().createMethodBinding(" +
+ ivar + ", args);\n");
+ writer.fwrite(comp + ".set" + capitalize(ivar) +
"(vb);\n");
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
+ writer.fwrite("Object params [] = {" + ivar + "};\n");
+ writer.fwrite("throw new
javax.faces.FacesException(Util." +
+
"getExceptionMessageString(Util.INVALID_EXPRESSION_ID, " +
+ "params));\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ }
+ } else {
+ writer.fwrite(comp + ".set" + capPropName + "(" + ivar
+ ");\n");
+ }
+ }
+
+ // Generate "setProperties" method contents from renderer
attributes
+ //
         AttributeBean[] attributes = renderer.getAttributes();
- AttributeBean attribute = null;
- String attributeName = null;
- String attributeType = null;
- ivar = null;
- vbKey = null;
         for (int i = 0, len = attributes.length; i < len; i++) {
- if (null == (attribute = attributes[i])) {
+ AttributeBean attribute = attributes[i];
+ if (attribute == null) {
                 continue;
             }
- if (!attribute.isTagAttribute()) {
+ if (!attribute.isTagAttribute()) {
                 continue;
             }
- attributeName = attribute.getAttributeName();
- attributeType = attribute.getAttributeClass();
-
- ivar = mangle(attributeName);
- vbKey = ivar;
+ String attributeName = attribute.getAttributeName();
+ String attributeType = attribute.getAttributeClass();
 
- writer.write(" if ("+ivar+" != null) {\n");
- writer.write(" if (isValueReference("+ivar+"))
{\n");
- writer.write(" ValueBinding vb = ");
- writer.write("Util.getValueBinding("+ivar+");\n");
- writer.write("
"+strip(componentType).toLowerCase());
- if (ivar.equals("_for")) {
- writer.write(".setValueBinding(\""+"_"+vbKey+"\", vb);\n");
- } else {
- writer.write(".setValueBinding(\""+vbKey+"\", vb);\n");
- }
- writer.write(" } else {\n");
- if (primitive(attributeType)) {
- writer.write(" "+attributeType+" _"+ivar+" ");
- writer.write("= new "+wrappers.get(attributeType));
- writer.write("("+ivar+")."+attributeType+"Value();\n");
- if (attributeType.equals("boolean")) {
- writer.write("
"+strip(componentType).toLowerCase()+
- ".getAttributes().put(\""+ivar+"\", ");
- writer.write("_"+ivar+" ? Boolean.TRUE : Boolean.FALSE);\n");
- } else {
- writer.write(" if (_"+ivar+" != ");
- writer.write(defaults.get(attributeType)+") {\n");
- writer.write("
"+strip(componentType).toLowerCase()+
- ".getAttributes().put(\""+ivar+"\", new ");
- writer.write(wrappers.get(attributeType)+"(_"+ivar+"));\n");
- writer.write(" }\n");
- }
- } else {
- if (ivar.equals("bundle")) {
- writer.write("
"+strip(componentType).toLowerCase()+
-
 ".getAttributes().put(com.sun.faces.RIConstants.BUNDLE_ATTR, ");
- } else if (ivar.equals("_for")) {
- writer.write("
"+strip(componentType).toLowerCase()+
- ".getAttributes().put(\"for\", ");
- } else {
- writer.write("
"+strip(componentType).toLowerCase()+
- ".getAttributes().put(\""+ivar+"\", ");
- }
- writer.write(ivar+");\n");
- }
- writer.write(" }\n");
- writer.write(" }\n");
- }
- writer.write(" }\n\n");
+ String ivar = mangle(attributeName);
+ String vbKey = ivar;
+ String comp =
+
GeneratorUtil.stripJavaxFacesPrefix(componentType).toLowerCase();
+
+ writer.fwrite("if (" + ivar + " != null) {\n");
+ writer.indent();
+ writer.fwrite("if (isValueReference(" + ivar + ")) {\n");
+ writer.indent();
+ writer.fwrite("ValueBinding vb = Util.getValueBinding(" +
ivar +
+ ");\n");
+ writer.fwrite(comp);
+ if ("_for".equals(ivar)) {
+ writer.write(".setValueBinding(\"" + '_' + vbKey + "\",
vb);\n");
+ } else {
+ writer.write(".setValueBinding(\"" + vbKey + "\", vb);\n");
+ }
+ writer.unindent();
+ writer.fwrite("} else {\n");
+ writer.indent();
+ if (primitive(attributeType)) {
+ writer.fwrite(attributeType + " _" + ivar + ' ');
+ writer.write("= new " + WRAPPERS.get(attributeType));
+ writer.write("(" + ivar + ")." + attributeType +
"Value();\n");
+ if ("boolean".equals(attributeType)) {
+ writer.fwrite(comp +
+ ".getAttributes().put(\"" + ivar + "\", ");
+ writer.write(
+ "_" + ivar + " ? Boolean.TRUE :
Boolean.FALSE);\n");
+ } else {
+ writer.fwrite("if (_" + ivar + " != ");
+ writer.write(TYPE_DEFAULTS.get(attributeType) + ")
{\n");
+ writer.indent();
+ writer.fwrite(comp + ".getAttributes().put(\"" + ivar +
+ "\", new ");
+ writer.write(WRAPPERS.get(attributeType) + "(_" +
ivar +
+ "));\n");
+ writer.unindent();
+ writer.write("}\n");
+ }
+ } else {
+ if ("bundle".equals(ivar)) {
+ writer.fwrite(comp +
+
".getAttributes().put(com.sun.faces.RIConstants.BUNDLE_ATTR, ");
+ } else if ("_for".equals(ivar)) {
+ writer.fwrite(comp +
+ ".getAttributes().put(\"for\", ");
+ } else {
+ writer.fwrite(comp +
+ ".getAttributes().put(\"" + ivar + "\", ");
+ }
+ writer.write(ivar + ");\n");
+ }
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ }
+ writer.unindent();
+ writer.fwrite("}\n\n");
     }
 
+
     /**
      * Generate Tag Handler support methods
      */
- private static void tagHandlerSupportMethods() throws Exception {
- writer.write(" //\n // Methods From TagSupport\n //\n\n");
- writer.write(" public int doStartTag() throws JspException {\n");
- writer.write(" int rc = 0;\n");
- writer.write(" try {\n");
- writer.write(" rc = super.doStartTag();\n");
- writer.write(" } catch (JspException e) {\n");
- writer.write(" if (log.isDebugEnabled()) {\n");
- writer.write(" log.debug(getDebugString(), e);\n");
- writer.write(" }\n");
- writer.write(" throw e;\n");
- writer.write(" } catch (Throwable t) {\n");
- writer.write(" if (log.isDebugEnabled()) {\n");
- writer.write(" log.debug(getDebugString(), t);\n");
- writer.write(" }\n");
- writer.write(" throw new JspException(t);\n");
- writer.write(" }\n");
- writer.write(" return rc;\n");
- writer.write(" }\n\n");
- writer.write(" public int doEndTag() throws JspException {\n");
- writer.write(" int rc = 0;\n");
- writer.write(" try {\n");
- writer.write(" rc = super.doEndTag();\n");
- writer.write(" } catch (JspException e) {\n");
- writer.write(" if (log.isDebugEnabled()) {\n");
- writer.write(" log.debug(getDebugString(), e);\n");
- writer.write(" }\n");
- writer.write(" throw e;\n");
- writer.write(" } catch (Throwable t) {\n");
- writer.write(" if (log.isDebugEnabled()) {\n");
- writer.write(" log.debug(getDebugString(), t);\n");
- writer.write(" }\n");
- writer.write(" throw new JspException(t);\n");
- writer.write(" }\n");
- writer.write(" return rc;\n");
- writer.write(" }\n\n");
+ private void tagHandlerSupportMethods() throws Exception {
+
+ writer.writeLineComment("Methods From TagSupport");
+
+ writer.fwrite("public int doStartTag() throws JspException {\n");
+ writer.indent();
+ writer.fwrite("int rc = 0;\n");
+ writer.fwrite("try {\n");
+ writer.indent();
+ writer.fwrite("rc = super.doStartTag();\n");
+ writer.unindent();
+ writer.fwrite("} catch (JspException e) {\n");
+ writer.indent();
+ writer.fwrite("if (log.isDebugEnabled()) {\n");
+ writer.indent();
+ writer.fwrite("log.debug(getDebugString(), e);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("throw e;\n");
+ writer.unindent();
+ writer.fwrite("} catch (Throwable t) {\n");
+ writer.indent();
+ writer.fwrite("if (log.isDebugEnabled()) {\n");
+ writer.indent();
+ writer.fwrite("log.debug(getDebugString(), t);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("throw new JspException(t);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("return rc;\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
+
+ writer.fwrite("public int doEndTag() throws JspException {\n");
+ writer.indent();
+ writer.fwrite("int rc = 0;\n");
+ writer.fwrite("try {\n");
+ writer.indent();
+ writer.fwrite("rc = super.doEndTag();\n");
+ writer.unindent();
+ writer.fwrite("} catch (JspException e) {\n");
+ writer.indent();
+ writer.fwrite("if (log.isDebugEnabled()) {\n");
+ writer.indent();
+ writer.fwrite("log.debug(getDebugString(), e);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("throw e;\n");
+ writer.unindent();
+ writer.fwrite("} catch (Throwable t) {\n");
+ writer.indent();
+ writer.fwrite("if (log.isDebugEnabled()) {\n");
+ writer.indent();
+ writer.fwrite("log.debug(getDebugString(), t);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("throw new JspException(t);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("return rc;\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
+
     }
 
+
     /**
      * Generate Body Tag Handler support methods
      */
- private static void tagHandlerBodySupportMethods() throws Exception {
- writer.write(" //\n // Methods From TagSupport\n //\n\n");
- writer.write(" public int doStartTag() throws JspException
{\n");
- writer.write(" int rc = 0;\n");
- writer.write(" try {\n");
- writer.write(" rc = super.doStartTag();\n");
- writer.write(" } catch (JspException e) {\n");
- writer.write(" if (log.isDebugEnabled()) {\n");
- writer.write(" log.debug(getDebugString(), e);\n");
- writer.write(" }\n");
- writer.write(" throw e;\n");
- writer.write(" } catch (Throwable t) {\n");
- writer.write(" if (log.isDebugEnabled()) {\n");
- writer.write(" log.debug(getDebugString(), t);\n");
- writer.write(" }\n");
- writer.write(" throw new JspException(t);\n");
- writer.write(" }\n");
- writer.write(" return rc;\n");
- writer.write(" }\n\n");
- writer.write(" public int doEndTag() throws JspException {\n");
- writer.write(" String content = null;\n");
- writer.write(" try {\n");
- writer.write(" if (null != (bodyContent =
getBodyContent())) {\n");
- writer.write(" content =
bodyContent.getString();\n");
- writer.write(" getPreviousOut().write(content);\n");
- writer.write(" }\n");
- writer.write(" } catch (IOException iox) {\n");
- writer.write(" throw new JspException(iox);\n");
- writer.write(" }\n");
- writer.write(" int rc = super.doEndTag();\n");
- writer.write(" return rc;\n");
- writer.write(" }\n\n");
+ private void tagHandlerBodySupportMethods() throws Exception {
+
+ writer.writeLineComment("Methods from TagSupport");
+
+ writer.fwrite("public int doStartTag() throws JspException {\n");
+ writer.indent();
+ writer.fwrite("int rc = 0;\n");
+ writer.fwrite("try {\n");
+ writer.indent();
+ writer.fwrite("rc = super.doStartTag();\n");
+ writer.unindent();
+ writer.fwrite("} catch (JspException e) {\n");
+ writer.indent();
+ writer.fwrite("if (log.isDebugEnabled()) {\n");
+ writer.indent();
+ writer.fwrite("log.debug(getDebugString(), e);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("throw e;\n");
+ writer.unindent();
+ writer.fwrite("} catch (Throwable t) {\n");
+ writer.indent();
+ writer.fwrite("if (log.isDebugEnabled()) {\n");
+ writer.indent();
+ writer.fwrite("log.debug(getDebugString(), t);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("throw new JspException(t);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("return rc;\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
+ writer.fwrite("public int doEndTag() throws JspException {\n");
+ writer.indent();
+ writer.fwrite("String content = null;\n");
+ writer.fwrite("try {\n");
+ writer.indent();
+ writer.fwrite("if (null != (bodyContent = getBodyContent())) {\n");
+ writer.indent();
+ writer.fwrite("content = bodyContent.getString();\n");
+ writer.fwrite("getPreviousOut().write(content);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.unindent();
+ writer.fwrite("} catch (IOException iox) {\n");
+ writer.indent();
+ writer.fwrite("throw new JspException(iox);\n");
+ writer.unindent();
+ writer.fwrite("}\n");
+ writer.fwrite("int rc = super.doEndTag();\n");
+ writer.fwrite("return rc;\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
     }
-
+
 
     /**
- * Generate remaining Tag Handler methods
+ * Generate remaining Tag Handler methods
      */
- private static void tagHandlerSuffix() throws Exception {
+ private void tagHandlerSuffix() throws Exception {
 
         // generate general purpose method used in logging.
         //
- writer.write(" public String getDebugString() {\n");
- String res = "\"id: \"+this.getId()+\" class:
\"+this.getClass().getName()";
- writer.write(" String result = "+res+";\n");
- writer.write(" return result;\n");
- writer.write(" }\n\n");
+ writer.fwrite("public String getDebugString() {\n");
+ writer.indent();
+ String res = "\"id: \" + this.getId() + \" class: \" +
this.getClass().getName()";
+ writer.fwrite("String result = " + res + ";\n");
+ writer.fwrite("return result;\n");
+ writer.unindent();
+ writer.fwrite("}\n\n");
+
+ writer.unindent();
+ writer.fwrite("}\n");
 
- writer.write("}\n");
     }
 
     //
@@ -1059,12 +801,12 @@
     /**
      * Is the tag handler we're building a body tag variety?
      */
- private static boolean isBodyTag() {
+ private boolean isBodyTag() {
         if (bodyTags.contains(tagClassName)) {
- return true;
- } else {
- return false;
- }
+ return true;
+ } else {
+ return false;
+ }
     }
 
     /**
@@ -1072,215 +814,70 @@
      * @return a SortedMap, where the keys are component-family String
      * entries, and the values are {_at_link RendererBean} instances
      */
- private static SortedMap getComponentFamilyRendererMap(String rkId)
- throws IllegalStateException {
- RenderKitBean renderKit = null;
- RendererBean [] renderers = null;
- RendererBean renderer = null;
- TreeMap result = null;
- ArrayList list = null;
- String componentFamily = null;
-
- if (null == (renderKit = fcb.getRenderKit(rkId))) {
- RenderKitBean [] kits = null;
- if (null == (kits = fcb.getRenderKits())) {
- throw new IllegalStateException("no RenderKits");
- }
- if (null == (renderKit = kits[0])) {
- throw new IllegalStateException("no RenderKits");
- }
- }
-
- if (null == (renderers = renderKit.getRenderers())) {
- throw new IllegalStateException("no Renderers");
- }
-
- result = new TreeMap();
-
- for (int i = 0, len = renderers.length; i < len; i++) {
- if (null == (renderer = renderers[i])) {
- throw new IllegalStateException("no Renderer");
- }
- // if this is the first time we've encountered this
- // componentFamily
- if (null == (list = (ArrayList)
- result.get(componentFamily =
- renderer.getComponentFamily()))) {
- // create a list for it
- list = new ArrayList();
- list.add(renderer);
- result.put(componentFamily, list);
- }
- else {
- list.add(renderer);
- }
- }
- return result;
- }
+
 
     /**
- * @return a SortedMap, where the keys are component-family String
- * entries, and the values are {_at_link ComponentBean} instances
- * Only include components that do not have a base component type.
+ * Generate the tag handler class files.
      */
- private static SortedMap getComponentFamilyComponentMap()
- throws IllegalStateException {
- TreeMap result = new TreeMap();
- ComponentBean[] components = fcb.getComponents();
- for (int i = 0, len = components.length; i < len; i++) {
- if (null == (component = components[i])) {
- throw new IllegalStateException("No Components Found");
- }
- if (component.getBaseComponentType() != null) {
- continue;
- }
- String componentFamily = component.getComponentFamily();
- String componentType = component.getComponentType();
- result.put(componentFamily, component);
- }
- return result;
- }
+ private void generateTagClasses() throws Exception {
 
+ Map renderersByComponentFamily =
+ GeneratorUtil.getComponentFamilyRendererMap(configBean,
+ propManager.getProperty(PropertyManager.RENDERKIT_ID));
+ Map componentsByComponentFamily =
+ GeneratorUtil.getComponentFamilyComponentMap(configBean);
 
- /**
- * Generate the TLD file.
- */
- private static void generateTld() throws Exception {
- // Create and open a Writer for generating our output
- File file = new File(directory, "html_basic.tld");
- writer = new BufferedWriter(new FileWriter(file));
-
- // Generate each section of the TLD consecutively
- xmlHeader();
- // copyright();
- tldDocType();
- tldDescription();
- tldValidator();
- tldTags();
-
- // Flush and close the Writer
- writer.flush();
- writer.close();
- }
+ for (Iterator keyIter =
renderersByComponentFamily.keySet().iterator();
+ keyIter.hasNext(); ) {
+
+ String componentFamily = (String) keyIter.next();
+ List renderers = (List)
renderersByComponentFamily.get(componentFamily);
+
+ component = (ComponentBean)
+ componentsByComponentFamily.get(componentFamily);
+
+ for (Iterator rendererIter = renderers.iterator();
+ rendererIter.hasNext(); ) {
 
- /**
- * Generate the tag handler class files.
- */
- private static void generateTagClasses() throws Exception {
- Iterator
- rendererIter = null,
- keyIter = renderersByComponentFamily.keySet().iterator();
- String componentFamily = null;
- String rendererType = null;
- List renderers = null;
- while (keyIter.hasNext()) {
- componentFamily = (String) keyIter.next();
- renderers = (List)renderersByComponentFamily.get(componentFamily);
- component =
(ComponentBean)componentsByComponentFamily.get(componentFamily);
- rendererIter = renderers.iterator();
- while (rendererIter.hasNext()) {
                 renderer = (RendererBean) rendererIter.next();
- rendererType = renderer.getRendererType();
- if ((tagClassName =
makeTagClassName(strip(componentFamily), strip(rendererType))) == null) {
- throw new IllegalStateException("Could not determine tag
class name");
- }
+ String rendererType = renderer.getRendererType();
+
+ tagClassName = GeneratorUtil.makeTagClassName(
+
GeneratorUtil.stripJavaxFacesPrefix(componentFamily),
+
GeneratorUtil.stripJavaxFacesPrefix(rendererType));
+
+ if (tagClassName == null) {
+ throw new IllegalStateException(
+ "Could not determine tag class name");
+ }
+
                 if (log.isInfoEnabled()) {
                     log.info("Generating " + tagClassName + "...");
                 }
- File file = new File(directory, tagClassName + ".java");
- writer = new BufferedWriter(new FileWriter(file));
 
- tagHandlerPrefix();
- tagHandlerIvars();
- tagHandlerSetterMethods();
- tagHandlerGeneralMethods();
+
+ File file = new File(outputDir, tagClassName + ".java");
+ writer = new CodeWriter(new FileWriter(file));
+
+ tagHandlerPrefix();
+ tagHandlerSetterMethods();
+ tagHandlerGeneralMethods();
                 if (isBodyTag()) {
                     tagHandlerBodySupportMethods();
                 } else {
- tagHandlerSupportMethods();
+ tagHandlerSupportMethods();
                 }
- tagHandlerReleaseMethod();
- tagHandlerSuffix();
-
- // Flush and close the Writer
+ tagHandlerReleaseMethod();
+ tagHandlerSuffix();
+
+ // Flush and close the Writer
                 writer.flush();
                 writer.close();
- }
- }
- }
-
-
-
- private static final String PREFIX = "javax.faces.";
-
- /**
- * <p>Strip any "javax.faces." prefix from the beginning of the
specified
- * identifier, and return it.</p>
- *
- * @param identifier Identifier to be stripped
- */
- private static String strip(String identifier) {
- if (identifier.startsWith(PREFIX)) {
- return (identifier.substring(PREFIX.length()));
- } else {
- return (identifier);
- }
- }
-
- /**
- * @return true if this attribute is in the set of attributes to be
- * excluded by this renderer.
- *
- */
- private static boolean skipThisAttribute(RendererBean renderer,
String attribute) {
- String excludeAttributes = null;
- boolean skip = false;
-
- if (null != (excludeAttributes = renderer.getExcludeAttributes())) {
- skip = (null != attribute &&
- -1 != excludeAttributes.indexOf(attribute));
- }
- return skip;
+ }
+ }
     }
 
+ // -----------------------------------------------------------
Inner Classes
 
- /**
- * Main routine.
- */
- public static void main(String args[]) throws Exception {
 
- try {
- // Perform setup operations
- if (log.isDebugEnabled()) {
- log.debug("Processing command line options");
- }
- Map options = options(args);
-
- copyright((String) options.get("--copyright"));
- directories((String) options.get("--tlddir"), false);
- Digester digester = digester(false, true, false);
- String config = (String) options.get("--config");
- loadOptionalTags((String) options.get("--tagdef"));
- if (log.isDebugEnabled()) {
- log.debug("Parsing configuration file '" + config + "'");
- }
- digester.push(new FacesConfigBean());
- fcb = parse(digester, config);
- if (log.isInfoEnabled()) {
- log.info("Generating Tag Library Descriptor file");
- }
-
- // Generate TLD File
- generateTld();
-
- // Generate Tag Handler Classes
- directories((String) options.get("--dir"), true);
- generateTagClasses();
-
- } catch(Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- System.exit(0);
- }
 }
Index:
jsf-tools/src/com/sun/faces/generate/RenderKitSpecificationGenerator.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-tools/src/com/sun/faces/generate/RenderKitSpecificationGenerator.java,v
retrieving revision 1.5
diff -u -r1.5 RenderKitSpecificationGenerator.java
---
jsf-tools/src/com/sun/faces/generate/RenderKitSpecificationGenerator.java
 29 Oct 2004 00:56:40 -0000 1.5
+++
jsf-tools/src/com/sun/faces/generate/RenderKitSpecificationGenerator.java
 9 Dec 2004 15:45:50 -0000
@@ -10,886 +10,459 @@
 package com.sun.faces.generate;
 
 
-import com.sun.faces.config.beans.AttributeBean;
-import com.sun.faces.config.beans.ComponentBean;
-import com.sun.faces.config.beans.DescriptionBean;
-import com.sun.faces.config.beans.FacesConfigBean;
-import com.sun.faces.config.beans.PropertyBean;
-import com.sun.faces.config.beans.RenderKitBean;
-import com.sun.faces.config.beans.RendererBean;
-import org.apache.commons.digester.Digester;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import java.io.BufferedInputStream;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.io.InputStreamReader;
-import java.io.Writer;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
 
+import com.sun.faces.config.beans.AttributeBean;
+import com.sun.faces.config.beans.DescriptionBean;
+import com.sun.faces.config.beans.FacesConfigBean;
+import com.sun.faces.config.beans.RenderKitBean;
+import com.sun.faces.config.beans.RendererBean;
 
 
 /**
- * <p>Generate javadoc style documenation about the render-kits defined
- * in a faces-config.xml file.</p>
- *
- * <p>This application requires the following command line options:</p>
- * <ul>
- * <li><strong>--config</strong> Absolute pathname to an input
configuration
- * file that will be parsed by the <code>parse()</code> method.</li>
- * <li><strong>--dir</strong> Absolute pathname to the directory into which
- * generated HTML files will be created.</li>
- * <li><strong>--dtd</strong> Pipe delimited list of public identifiers
and
- * absolute pathnames to files containing the DTDs used to validate
the
- * input configuration files. PRECONDITION: The list is the sequence:
- * <public id>|<dtd path>|<public id>|<dtd path>...</li>
- * </ul>
+ * <p>Generate javadoc style documenation about the render-kits defined
in a
+ * faces-config.xml file.</p>
+ * <p/>
  */
 
-public class RenderKitSpecificationGenerator extends AbstractGenerator {
-
- public static String DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD
HTML 4.0 Transitional//EN\"\"http://www.w3.org/TR/REC-html40/loose.dtd\">";
+public class RenderKitSpecificationGenerator implements Generator {
 
+ public static String DOCTYPE =
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\"\"http://www.w3.org/TR/REC-html40/loose.dtd\">";
 
+
     // -------------------------------------------------------- Static
Variables
 
 
- private static final Log log =
- LogFactory.getLog(RenderKitSpecificationGenerator.class);
+ // The directory into which the HTML will be generated
+ private File baseDirectory;
 
+ // The directory into which the individual Renderer HTML will be
generated
+ private File renderKitDirectory;
 
- // The component configuration bean for the component class to be
generated
- private static ComponentBean cb;
+ private String renderKitId;
 
+ private FacesConfigBean configBean;
+
 
- // The directory into which the HTML will be generated
- private static File directory;
 
- // The directory into which the individual Renderer HTML will be
generated
- private static File renderKitDirectory;
+ // ------------------------------------------------------------
Constructors
 
 
- // Base object of the configuration beans
- private static FacesConfigBean fcb;
+ public RenderKitSpecificationGenerator(PropertyManager propManager) {
 
- // List of relevant properties for the component class to be generated
- private static List properties;
+ this.renderKitId =
+ propManager.getProperty(PropertyManager.RENDERKIT_ID);
 
- // The Writer for each component class to be generated
- private static Writer writer;
+ baseDirectory =
+ new File(System.getProperty("user.dir") +
+ File.separatorChar +
+ propManager.getProperty(PropertyManager.BASE_OUTPUT_DIR) +
+ File.separatorChar + "facesdoc");
 
- private static final String DEFAULT_RENDERKIT_ID = "HTML_BASIC";
+ if (!baseDirectory.exists()) {
+ baseDirectory.mkdirs();
+ }
 
- private static String renderKitId = DEFAULT_RENDERKIT_ID;
+ renderKitDirectory = new File(baseDirectory, renderKitId);
 
+ if (!renderKitDirectory.exists()) {
+ renderKitDirectory.mkdirs();
+ }
 
- // ---------------------------------------------------------
Private Methods
 
 
- /**
- * <p>Create directories as needed to contain the output. Leave a
- * <code>directory</code> object that points at the top level directory
- * for the concrete component classes.</p>
- *
- * @param path Pathname to the base directory
- */
- private static void directories(String path) throws Exception {
-
- directory = new File(path);
- if (log.isDebugEnabled()) {
- log.debug("Creating output directory " +
- directory.getAbsolutePath());
- }
- directory.mkdirs();
-
- // make the directory for our renderKit
- renderKitDirectory = new File(directory, renderKitId);
- if (log.isDebugEnabled()) {
- log.debug("Creating output renderKitDirectory " +
- renderKitDirectory.getAbsolutePath());
- }
- renderKitDirectory.mkdirs();
- }
+ } // END RenderKitSpecificationGenerator
 
 
- /**
- * <p>Generate the concrete HTML component class based on the current
- * component configuration bean.</p>
- */
- private static void generate() throws Exception {
-
- if (log.isInfoEnabled()) {
- log.info("Generating RenderKit Documentation " +
- cb.getComponentClass());
- }
-
- // Initialize all per-class static variables
- properties = new ArrayList();
-
- // Create and open a Writer for generating our output
- File file = new File(directory,
- shortName(cb.getComponentClass()) + ".java");
- writer = new BufferedWriter(new FileWriter(file));
-
- // Generate the various portions of each class
- prefix();
- properties();
- suffix();
-
- // Flush and close the Writer for this class
- writer.flush();
- writer.close();
+ // ----------------------------------------------------------
Public Methods
 
- }
 
+ public void generate(FacesConfigBean configBean) {
 
- /**
- * <p>Generate the prefix for this component class, down to (and
including)
- * the class declaration.</p>
- */
- private static void prefix() throws Exception {
-
- // Acquire the config bean for our base component
- ComponentBean base = fcb.getComponent(cb.getBaseComponentType());
- if (base == null) {
- throw new IllegalArgumentException("No base component type
for '" +
- cb.getComponentType() +
"'");
- }
-
- // Generate the package declaration
- writer.write("\npackage javax.faces.component.html;\n");
- writer.write("\n\n");
-
- // Generate the imports
- writer.write("import java.io.IOException;\n");
- writer.write("import javax.faces.context.FacesContext;\n");
- writer.write("import javax.faces.el.MethodBinding;\n");
- writer.write("import javax.faces.el.ValueBinding;\n");
- writer.write("\n\n");
-
- // Generate the class JavaDocs (if any)
- DescriptionBean db = cb.getDescription("");
- if (db != null) {
- String description = db.getDescription();
- if (description == null) {
- description = "";
- }
- description = description.trim();
- if (description.length() > 0) {
- writer.write("/**\n");
- description(description, writer, 1);
- writer.write(" */\n");
- }
- }
+ this.configBean = configBean;
 
- // Generate the class declaration
- writer.write("public class ");
- writer.write(shortName(cb.getComponentClass()));
- writer.write(" extends ");
- writer.write(base.getComponentClass());
- writer.write(" {\n\n\n");
-
- // Generate the constructor
- writer.write(" public ");
- writer.write(shortName(cb.getComponentClass()));
- writer.write("() {\n");
- writer.write(" super();\n");
- String rendererType = cb.getRendererType();
- if (rendererType != null) {
- writer.write(" setRendererType(\"");
- writer.write(rendererType);
- writer.write("\");\n");
+ try {
+ // copy the static files to the output area
+
copyResourceToFile("com/sun/faces/generate/facesdoc/index.html",
+ new File(baseDirectory, "index.html"));
+
copyResourceToFile("com/sun/faces/generate/facesdoc/stylesheet.css",
+ new File(baseDirectory, "stylesheet.css"));
+
+ generateAllRenderersFrame();
+ generateRenderKitSummary();
+ generateRenderersDocs();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
         }
- writer.write(" }\n\n\n");
 
- }
+ } // END generate
 
 
- /**
- * <p>Generate the property instance variable, and getter and setter
- * methods, for all non-duplicate properties of this component
class.</p>
- */
- private static void properties() throws Exception {
-
- ComponentBean base = fcb.getComponent(cb.getBaseComponentType());
- PropertyBean pbs[] = cb.getProperties();
- for (int i = 0; i < pbs.length; i++) {
-
- // Should we generate this property?
- PropertyBean pb = pbs[i];
- if (base.getProperty(pb.getPropertyName()) != null) {
- if (log.isTraceEnabled()) {
- log.trace("Skipping base class property '" +
- pb.getPropertyName() + "'");
- }
- continue;
- }
- if (log.isDebugEnabled()) {
- log.debug("Generating property variable/getter/setter
for '" +
- pb.getPropertyName() + "'");
- }
- properties.add(pb);
- String type = pb.getPropertyClass();
- String var = mangle(pb.getPropertyName());
-
- // Generate the instance variable
- writer.write(" private ");
- writer.write(type);
- writer.write(" ");
- writer.write(var);
- if (pb.getDefaultValue() != null) {
- writer.write(" = ");
- writer.write(pb.getDefaultValue());
- } else if (primitive(type)) {
- writer.write(" = ");
- writer.write((String) defaults.get(type));
- }
- writer.write(";\n");
- if (primitive(type)) {
- writer.write(" private boolean ");
- writer.write(var);
- writer.write("_set = false;\n");
- }
- writer.write("\n");
+ // ---------------------------------------------------------
Private Methods
 
- // Document the getter method
- writer.write(" /**\n");
- writer.write(" * <p>Return the value of the <code>");
- writer.write(pb.getPropertyName());
- writer.write("</code> property.");
- DescriptionBean db = pb.getDescription("");
- if (db != null) {
- String description = db.getDescription();
- if (description == null) {
- description = "";
- }
- description = description.trim();
- if (description.length() > 0) {
- writer.write(" Contents:</p><p>\n");
- description(description, writer, 3);
- }
- } else {
- writer.write("\n");
- }
- writer.write(" * </p>\n");
- writer.write(" */\n");
 
- // Generate the getter method
- writer.write(" public ");
- writer.write(type);
- if ("boolean".equals(type)) {
- writer.write(" is");
- } else {
- writer.write(" get");
- }
- writer.write(capitalize(pb.getPropertyName()));
- writer.write("() {\n");
- if (primitive(type)) {
- writer.write(" if (this.");
- writer.write(var);
- writer.write("_set) {\n");
- } else {
- writer.write(" if (null != this.");
- writer.write(var);
- writer.write(") {\n");
- }
- writer.write(" return this.");
- writer.write(var);
- writer.write(";\n");
- writer.write(" }\n");
- writer.write(" ValueBinding _vb = getValueBinding(\"");
- writer.write(pb.getPropertyName());
- writer.write("\");\n");
- writer.write(" if (_vb != null) {\n");
- if (primitive(type)) {
- writer.write(" Object _result =
_vb.getValue(getFacesContext());\n");
- writer.write(" if (_result == null) {\n");
- writer.write(" return ");
- writer.write((String) defaults.get(type));
- writer.write(";\n");
- writer.write(" } else {\n");
- writer.write(" return ((");
- writer.write((String) wrappers.get(type));
- writer.write(") _result).");
- writer.write((String) unwrappers.get(type));
- writer.write("();\n");
- writer.write(" }\n");
- } else {
- writer.write(" return (");
- writer.write(type);
- writer.write(") _vb.getValue(getFacesContext());\n");
- }
- writer.write(" } else {\n");
- if (primitive(type)) {
- writer.write(" return ");
- writer.write((String) defaults.get(type));
- writer.write(";\n");
- } else {
- writer.write(" return null;\n");
- }
- writer.write(" }\n");
- writer.write(" }\n\n");
+ private static String getFirstSentance(String para) throws Exception {
+ int dot = para.indexOf('.');
+ return para.substring(0, dot + 1);
+ }
 
- // Generate the setter method
- writer.write(" /**\n");
- writer.write(" * <p>Set the value of the <code>");
- writer.write(pb.getPropertyName());
- writer.write("</code> property.</p>\n");
- writer.write(" */\n");
- writer.write(" public void set");
- writer.write(capitalize(pb.getPropertyName()));
- writer.write("(");
- writer.write(type);
- writer.write(" ");
- writer.write(var);
- writer.write(") {\n");
- writer.write(" this.");
- writer.write(var);
- writer.write(" = ");
- writer.write(var);
- writer.write(";\n");
- if (primitive(type)) {
- writer.write(" this.");
- writer.write(var);
- writer.write("_set = true;\n");
- }
- writer.write(" }\n\n");
 
- // Generate spacing between properties
- writer.write("\n");
+ private static void copyResourceToFile(String resourceName, File file)
+ throws Exception {
+
+ byte[] bytes = new byte[1024];
 
+ FileOutputStream fos = new FileOutputStream(file);
+ URL url = getCurrentLoader(fos).getResource(resourceName);
+ URLConnection conn = url.openConnection();
+ conn.setUseCaches(false);
+ BufferedInputStream bis =
+ new BufferedInputStream(conn.getInputStream());
+ for (int len = bis.read(bytes, 0, 1024); len != -1;
+ len = bis.read(bytes, 0, 1024)) {
+ fos.write(bytes, 0, len);
         }
+ fos.close();
+ bis.close();
+ }
 
+
+ private static void writeStringToFile(String toWrite,
+ File file) throws Exception {
+
+ FileOutputStream fos = new FileOutputStream(file);
+ byte[] bytes = toWrite.getBytes();
+ fos.write(bytes);
+ fos.close();
     }
 
 
- /**
- * <p>Generate the suffix for this component class.</p>
- */
- private static void suffix() throws Exception {
-
- int n = 0; // Index into values array
- int p = 0; // Number of primitive properties
- for (int i = 0; i < properties.size(); i++) {
- PropertyBean pb = (PropertyBean) properties.get(i);
- if (primitive(pb.getPropertyClass())) {
- p++;
- }
- }
+ private static void appendResourceToStringBuffer(String resourceName,
+ StringBuffer sb)
+ throws Exception {
 
- // Generate the saveState() method
- writer.write(" public Object saveState(FacesContext _context)
{\n");
- writer.write(" Object _values[] = new Object[");
- writer.write("" + (properties.size() + p + 1));
- writer.write("];\n");
- writer.write(" _values[0] = super.saveState(_context);\n");
- n = 1;
- for (int i = 0; i < properties.size(); i++) {
- PropertyBean pb = (PropertyBean) properties.get(i);
- String name = mangle(pb.getPropertyName());
- String type = pb.getPropertyClass();
- writer.write(" _values[");
- writer.write("" + n++);
- writer.write("] = ");
- if ("boolean".equals(type)) {
- writer.write("this.");
- writer.write(name);
- writer.write(" ? Boolean.TRUE : Boolean.FALSE");
- } else if (primitive(type)) {
- writer.write("new ");
- writer.write((String) wrappers.get(type));
- writer.write("(this.");
- writer.write(name);
- writer.write(")");
- } else {
- writer.write(name);
- }
- writer.write(";\n");
- if (primitive(type)) {
- writer.write(" _values[");
- writer.write("" + n++);
- writer.write("] = this.");
- writer.write(name);
- writer.write("_set ? Boolean.TRUE : Boolean.FALSE;\n");
- }
- }
- writer.write(" return _values;\n");
- writer.write(" }\n\n\n");
+ char[] chars = new char[1024];
 
- // Generate the restoreState() method
- writer.write(" public void restoreState(FacesContext _context,
Object _state) {\n");
- writer.write(" Object _values[] = (Object[]) _state;\n");
- writer.write(" super.restoreState(_context, _values[0]);\n");
- n = 1;
- for (int i = 0; i < properties.size(); i++) {
- PropertyBean pb = (PropertyBean) properties.get(i);
- String name = mangle(pb.getPropertyName());
- String type = pb.getPropertyClass();
- writer.write(" this.");
- writer.write(name);
- writer.write(" = ");
- if (primitive(type)) {
- writer.write("((");
- writer.write((String) wrappers.get(type));
- writer.write(") _values[");
- writer.write("" + n++);
- writer.write("]).");
- writer.write((String) unwrappers.get(type));
- writer.write("()");
- } else {
- writer.write("(");
- writer.write(type);
- writer.write(") _values[");
- writer.write("" + n++);
- writer.write("]");
- }
- writer.write(";\n");
- if (primitive(type)) {
- writer.write(" this.");
- writer.write(name);
- writer.write("_set = ((Boolean) _values[");
- writer.write("" + n++);
- writer.write("]).booleanValue();\n");
- }
+ URL url = getCurrentLoader(sb).getResource(resourceName);
+ URLConnection conn = url.openConnection();
+ conn.setUseCaches(false);
+ InputStreamReader isr = new
InputStreamReader(conn.getInputStream());
+ for (int len = isr.read(chars, 0, 1024); len != -1;
+ len = isr.read(chars, 0, 1024)) {
+ sb.append(chars, 0, len);
         }
- writer.write(" }\n\n\n");
+ isr.close();
+ }
 
- // Generate the ending of this class
- writer.write("}\n");
 
- }
+ private void generateAllRenderersFrame() throws Exception {
 
- /**
- *
- * @return a SortedMap, where the keys are component-family String
- * entries, and the values are {_at_link RendererBean} instances
- */
-
- public static SortedMap getComponentFamilyRendererMap(String rkId)
throws IllegalStateException {
- RenderKitBean renderKit = null;
- RendererBean [] renderers = null;
- RendererBean renderer = null;
- TreeMap result = null;
- ArrayList list = null;
- String componentFamily = null;
-
- if (null == (renderKit = fcb.getRenderKit(rkId))) {
- RenderKitBean [] kits = null;
- if (null == (kits = fcb.getRenderKits())) {
- throw new IllegalStateException("no RenderKits");
- }
- if (null == (renderKit = kits[0])) {
- throw new IllegalStateException("no RenderKits");
- }
- }
-
- if (null == (renderers = renderKit.getRenderers())) {
- throw new IllegalStateException("no Renderers");
- }
-
- result = new TreeMap();
-
- for (int i = 0, len = renderers.length; i < len; i++) {
- if (null == (renderer = renderers[i])) {
- throw new IllegalStateException("no Renderer");
- }
- // if this is the first time we've encountered this
- // componentFamily
- if (null == (list = (ArrayList)
- result.get(componentFamily =
- renderer.getComponentFamily()))) {
- // create a list for it
- list = new ArrayList();
- list.add(renderer);
- result.put(componentFamily, list);
- }
- else {
- list.add(renderer);
- }
- }
- return result;
- }
+ // generate the allrenderers-frame.html
+ StringBuffer sb = new StringBuffer(2048);
+ appendResourceToStringBuffer(
+ "com/sun/faces/generate/facesdoc/allrenderers-frame.top",
+ sb);
+ sb.append("<FONT size=\"+1\" CLASS=\"FrameHeadingFont\">\n");
+ sb.append("<B>" + renderKitId + " RenderKit</B></FONT>\n");
+ sb.append("<BR>\n\n");
+ sb.append("<DL CLASS=\"FrameItemFont\">\n\n");
 
- public static String getFirstSentance(String para) throws Exception {
- int dot = para.indexOf(".");
- return para.substring(0, dot + 1);
- }
+ Map renderersByComponentFamily =
+ GeneratorUtil.getComponentFamilyRendererMap(configBean,
renderKitId);
 
- public static void copyResourceToFile(String resourceName, File
file) throws Exception {
- FileOutputStream fos = null;
- BufferedInputStream bis = null;
- URL url = null;
- URLConnection conn = null;
- byte[] bytes = new byte[1024];
- int len = 0;
-
- fos = new FileOutputStream(file);
- url = getCurrentLoader(fos).getResource(resourceName);
- conn = url.openConnection();
- conn.setUseCaches(false);
- bis = new BufferedInputStream(conn.getInputStream());
- while (-1 != (len = bis.read(bytes, 0, 1024))) {
- fos.write(bytes, 0, len);
- }
- fos.close();
- bis.close();
+ for (Iterator keyIter =
renderersByComponentFamily.keySet().iterator();
+ keyIter.hasNext(); ) {
 
+ String curFamily = (String) keyIter.next();
+ sb.append(" <DT>" + curFamily + "</DT>\n");
+ List renderers = (List)
renderersByComponentFamily.get(curFamily);
 
- }
+ for (Iterator rendererIter = renderers.iterator();
+ rendererIter.hasNext(); ) {
 
- public static void writeStringToFile(String toWrite,
- File file) throws Exception {
- FileOutputStream fos = null;
-
- fos = new FileOutputStream(file);
- byte [] bytes = toWrite.getBytes();
- fos.write(bytes);
- fos.close();
- }
+ RendererBean renderer = (RendererBean) rendererIter.next();
+ String curType = renderer.getRendererType();
+ sb.append(" <DD><A HREF=\"" + renderKitId + "/" +
+ curFamily + curType +
+ ".html\" TARGET=\"rendererFrame\">" + curType +
+ "</A><DD>\n");
+ }
+ }
 
+ sb.append("</dl>\n");
 
- public static void appendResourceToStringBuffer(String resourceName,
- StringBuffer sb) throws Exception {
- InputStreamReader isr = null;
- URL url = null;
- URLConnection conn = null;
- char[] chars = new char[1024];
- int len = 0;
-
- url = getCurrentLoader(sb).getResource(resourceName);
- conn = url.openConnection();
- conn.setUseCaches(false);
- isr = new InputStreamReader(conn.getInputStream());
- while (-1 != (len = isr.read(chars, 0, 1024))) {
- sb.append(chars, 0, len);
- }
- isr.close();
+ appendResourceToStringBuffer(
+ "com/sun/faces/generate/facesdoc/allrenderers-frame.bottom",
+ sb);
+ writeStringToFile(sb.toString(),
+ new File(baseDirectory,
+ "allrenderers-frame.html"));
     }
 
- public static void generateAllRenderersFrame() throws Exception {
- StringBuffer sb = null;
-
- // generate the allrenderers-frame.html
- sb = new StringBuffer(2048);
-
 appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/allrenderers-frame.top",
- sb);
- sb.append("<FONT size=\"+1\" CLASS=\"FrameHeadingFont\">\n");
- sb.append("<B>" + renderKitId + " RenderKit</B></FONT>\n");
- sb.append("<BR>\n\n");
- sb.append("<DL CLASS=\"FrameItemFont\">\n\n");
-
- SortedMap renderersByComponentFamily =
- getComponentFamilyRendererMap(renderKitId);
- Iterator
- rendererIter = null,
- keyIter = renderersByComponentFamily.keySet().iterator();
- String
- curType = null,
- curFamily = null;
- List renderers = null;
- RendererBean renderer = null;
-
- while (keyIter.hasNext()) {
- curFamily = (String) keyIter.next();
- sb.append(" <DT>" + curFamily + "</DT>\n");
- renderers = (List) renderersByComponentFamily.get(curFamily);
- rendererIter = renderers.iterator();
- while (rendererIter.hasNext()) {
- renderer = (RendererBean) rendererIter.next();
- curType = renderer.getRendererType();
- sb.append(" <DD><A HREF=\"" + renderKitId + "/" +
- curFamily + curType +
- ".html\" TARGET=\"rendererFrame\">" + curType +
- "</A><DD>\n");
- }
- }
-
- sb.append("</dl>\n");
-
-
 appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/allrenderers-frame.bottom",
- sb);
- writeStringToFile(sb.toString(),
- new File(directory,
- "allrenderers-frame.html"));
- }
 
- public static void generateRenderKitSummary() throws Exception {
- StringBuffer sb = null;
-
- // generate the renderkit-summary.html
- sb = new StringBuffer(2048);
-
 appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/renderkit-summary.top",
- sb);
- sb.append("<H2>" + renderKitId + " RenderKit</H2>\n");
- sb.append("<BR>\n\n");
-
- RenderKitBean renderKit = null;
- if (null == (renderKit = fcb.getRenderKit(renderKitId))) {
- RenderKitBean [] kits = null;
- if (null == (kits = fcb.getRenderKits())) {
- throw new IllegalStateException("no RenderKits");
- }
- if (null == (renderKit = kits[0])) {
- throw new IllegalStateException("no RenderKits");
- }
- }
-
- DescriptionBean descBean = renderKit.getDescription("");
- String description = (null == descBean) ? "" :
descBean.getDescription();
- sb.append("<P>" + description + "</P>\n");
- sb.append("<P />");
- sb.append("<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\"
WIDTH=\"100%\">");
- sb.append("<TR BGCOLOR=\"#CCCCFF\" CLASS=\"TableHeadingColor\">\n");
- sb.append("<TD COLSPAN=\"3\"><FONT SIZE=\"+2\">\n");
- sb.append("<B>Renderer Summary</B></FONT></TD>\n");
- sb.append("\n");
- sb.append("<TR>\n");
- sb.append("<TH>component-family</TH>\n");
- sb.append("<TH>renderer-type</TH>\n");
- sb.append("<TH>description</TH>\n");
- sb.append("</TR>\n");
-
- SortedMap renderersByComponentFamily =
- getComponentFamilyRendererMap(renderKitId);
- Iterator
- rendererIter = null,
- keyIter = renderersByComponentFamily.keySet().iterator();
- String
- curType = null,
- curFamily = null;
- List renderers = null;
- RendererBean renderer = null;
-
- while (keyIter.hasNext()) {
- curFamily = (String) keyIter.next();
- renderers = (List) renderersByComponentFamily.get(curFamily);
- rendererIter = renderers.iterator();
- sb.append(" <TR>\n");
- sb.append(" <TD rowspan=\"" + renderers.size() + "\">" +
- curFamily + "</TD>\n");
- while (rendererIter.hasNext()) {
- renderer = (RendererBean) rendererIter.next();
- curType = renderer.getRendererType();
- sb.append(" <TD><A HREF=\"" + curFamily + curType +
- ".html\" TARGET=\"rendererFrame\">" + curType +
- "</A></TD>\n");
- descBean = renderer.getDescription("");
- description = (null == descBean) ? "" : descBean.getDescription();
- sb.append(" <TD>" + getFirstSentance(description) +
- "</TD>");
- if (rendererIter.hasNext()) {
- sb.append(" </TR>\n");
- sb.append(" <TR>\n");
- }
- }
- sb.append(" </TR>\n");
- }
-
- sb.append("</TABLE>\n\n");
-
-
 appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/renderkit-summary.bottom",
- sb);
- writeStringToFile(sb.toString(),
- new File(renderKitDirectory,
- "renderkit-summary.html"));
- }
+ private void generateRenderKitSummary() throws Exception {
 
- public static void generateRenderersDocs() throws Exception {
- StringBuffer sb = null;
- RenderKitBean renderKit = null;
- DescriptionBean descBean = null;
- AttributeBean attribute = null;
- String
- description,
- rendererType,
- componentFamily,
- defaultValue,
- title,
- curAttr;
-
-
- // generate the docus for each renderer
-
- if (null == (renderKit = fcb.getRenderKit(renderKitId))) {
- RenderKitBean [] kits = null;
- if (null == (kits = fcb.getRenderKits())) {
- throw new IllegalStateException("no RenderKits");
- }
- if (null == (renderKit = kits[0])) {
- throw new IllegalStateException("no RenderKits");
- }
- }
- RendererBean [] renderers = renderKit.getRenderers();
- AttributeBean [] attributes = null;
- sb = new StringBuffer(2048);
-
- for (int i = 0, len = renderers.length; i < len; i++) {
- if (null == renderers[i]) {
- throw new IllegalStateException("null Renderer at index: "+i);
- }
- attributes = renderers[i].getAttributes();
-
- sb.append(DOCTYPE + "\n");
- sb.append("<html>\n");
- sb.append("<head>\n");
- // PENDING timestamp
- sb.append("<title>\n");
- title = "<font size=\"-1\">component-family:</font> " +
- (componentFamily = renderers[i].getComponentFamily()) +
- " <font size=\"-1\">renderer-type:</font> " +
- (rendererType = renderers[i].getRendererType());
- sb.append(title + "\n");
- sb.append("</title>\n");
- // PENDING META tag
- sb.append("<link REL =\"stylesheet\" TYPE=\"text/css\"
HREF=\"../stylesheet.css\" TITLE=\"Style\">\n");
- sb.append("</head>\n");
- sb.append("<script>\n");
- sb.append("function asd()\n");
- sb.append("{\n");
- sb.append(" parent.document.title=" + title + "\n");
- sb.append("}\n");
- sb.append("</SCRIPT>\n");
- sb.append("<body BGCOLOR=\"white\" onload=\"asd();\">\n");
- sb.append("\n");
- sb.append("<H2><font size=\"-1\">" + renderKitId +
- " render-kit</font>\n");
- sb.append("<br />\n");
- sb.append(title + "\n");
- sb.append("</H2>\n");
- sb.append("<HR />\n");
- descBean = renderers[i].getDescription("");
- description = (null == descBean) ? "" : descBean.getDescription();
- sb.append("<P>" + description + "</P>\n");
- // render our renders children status
-
- if (renderers[i].isRendersChildren()) {
- sb.append("<P>This renderer is responsible for rendering its
children.</P>");
- }
- else {
- sb.append("<P>This renderer is not responsible for rendering
its children.</P>");
- }
-
- // if we have attributes
- if ((null == attributes) || (0 < attributes.length)) {
- sb.append("<HR />\n");
- sb.append("<a NAME=\"attributes\"><!-- --></a>\n");
- sb.append("\n");
- sb.append("<h3>Note:</h3>\n");
- sb.append("\n");
- sb.append("<p>Attributes with a <code>pass-through</code> value
of\n");
- sb.append("<code>true</code> are not interpreted by the
renderer and are passed\n");
- sb.append("straight through to the rendered markup, without
checking for validity. Attributes with a\n");
- sb.append("<code>pass-through</code> value of
<code>false</code> are interpreted\n");
- sb.append("by the renderer, and may or may not be checked for
validity by the renderer.</p>\n");
- sb.append("\n");
- sb.append("<table BORDER=\"1\" CELLPADDING=\"3\"
CELLSPACING=\"0\" WIDTH=\"100%\">\n");
- sb.append("<tr BGCOLOR=\"#CCCCFF\"
CLASS=\"TableHeadingColor\">\n");
- sb.append("<td COLSPAN=\"5\"><font SIZE=\"+2\">\n");
- sb.append("<b>Attributes</b></font></td>\n");
- sb.append("</tr>\n");
- sb.append("<tr BGCOLOR=\"#CCCCFF\"
CLASS=\"TableHeadingColor\">\n");
- sb.append("<th><b>attribute-name</b></th>\n");
- sb.append("<th><b>pass-through</b></th>\n");
- sb.append("<th><b>attribute-class</b></th>\n");
- sb.append("<th><b>description</b></th>\n");
- sb.append("<th><b>default-value</b></th>\n");
- sb.append("</tr>\n");
- sb.append(" \n");
- // output each attribute
- for (int j = 0, attrLen = attributes.length; j < attrLen; j++) {
- sb.append("<tr BGCOLOR=\"white\" CLASS=\"TableRowColor\">\n");
- sb.append("<td ALIGN=\"right\" VALIGN=\"top\"
WIDTH=\"1%\"><code>\n");
- sb.append("&nbsp;" + attributes[j].getAttributeName() + "\n");
- sb.append("</td>\n");
- sb.append("<td ALIGN=\"right\" VALIGN=\"top\">" +
- attributes[j].isPassThrough() + "</td>\n");
- sb.append("<td><code>" + attributes[j].getAttributeClass() +
- "</code></td>\n");
- descBean = attributes[j].getDescription("");
- description = (null == descBean) ? "" :
descBean.getDescription();
- sb.append("<td>" + description + "</td>\n");
- if (null == (defaultValue = attributes[j].getDefaultValue())) {
- defaultValue= "undefined";
- }
- sb.append("<td>" + defaultValue + "<td>\n");
- sb.append("</tr>\n");
- }
- sb.append("</table>\n");
- }
- else {
- sb.append("<p>This renderer-type has no attributes</p>\n");
- }
- sb.append("<hr>\n");
- sb.append("Copyright (c) 2003-2004 Sun Microsystems, Inc. All
Rights Reserved.\n");
- sb.append("</body>\n");
- sb.append("</html>\n");
- writeStringToFile(sb.toString(),
- new File(renderKitDirectory,
- componentFamily + rendererType +
- ".html"));
- sb.delete(0, sb.length());
- }
- }
-
- public static ClassLoader getCurrentLoader(Object fallbackClass) {
- ClassLoader loader =
- Thread.currentThread().getContextClassLoader();
- if (loader == null) {
- loader = fallbackClass.getClass().getClassLoader();
- }
- return loader;
- }
+ // generate the renderkit-summary.html
+ StringBuffer sb = new StringBuffer(2048);
+ appendResourceToStringBuffer(
+ "com/sun/faces/generate/facesdoc/renderkit-summary.top",
+ sb);
+ sb.append("<H2>" + renderKitId + " RenderKit</H2>\n");
+ sb.append("<BR>\n\n");
 
- // -------------------------------------------------------------
Main Method
+ RenderKitBean renderKit = configBean.getRenderKit(renderKitId);
+ if (renderKit == null) {
+ RenderKitBean[] kits = configBean.getRenderKits();
+ if (kits == null) {
+ throw new IllegalStateException("no RenderKits");
+ }
 
+ renderKit = kits[0];
+ if (renderKit == null) {
+ throw new IllegalStateException("no RenderKits");
+ }
+ }
 
- public static void main(String args[]) throws Exception {
+ DescriptionBean descBean = renderKit.getDescription("");
+ String description = (null == descBean) ?
+ "" : descBean.getDescription();
+ sb.append("<P>" + description + "</P>\n");
+ sb.append("<P />");
+ sb.append(
+ "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\"
WIDTH=\"100%\">");
+ sb.append("<TR BGCOLOR=\"#CCCCFF\"
CLASS=\"TableHeadingColor\">\n");
+ sb.append("<TD COLSPAN=\"3\"><FONT SIZE=\"+2\">\n");
+ sb.append("<B>Renderer Summary</B></FONT></TD>\n");
+ sb.append("\n");
+ sb.append("<TR>\n");
+ sb.append("<TH>component-family</TH>\n");
+ sb.append("<TH>renderer-type</TH>\n");
+ sb.append("<TH>description</TH>\n");
+ sb.append("</TR>\n");
 
- try {
+ Map renderersByComponentFamily =
+ GeneratorUtil.getComponentFamilyRendererMap(configBean,
renderKitId);
 
- // Perform setup operations
- if (log.isDebugEnabled()) {
- log.debug("Processing command line options");
+ for (Iterator keyIter =
renderersByComponentFamily.keySet().iterator();
+ keyIter.hasNext(); ) {
+ String curFamily = (String) keyIter.next();
+ List renderers = (List)
renderersByComponentFamily.get(curFamily);
+
+ sb.append(" <TR>\n");
+ sb.append(" <TD rowspan=\"" + renderers.size() + "\">" +
+ curFamily + "</TD>\n");
+ for (Iterator rendererIter = renderers.iterator();
+ rendererIter.hasNext(); ) {
+
+ RendererBean renderer = (RendererBean) rendererIter.next();
+ String curType = renderer.getRendererType();
+ sb.append(" <TD><A HREF=\"" + curFamily + curType +
+ ".html\" TARGET=\"rendererFrame\">" + curType +
+ "</A></TD>\n");
+ descBean = renderer.getDescription("");
+ description = (null == descBean) ?
+ "" : descBean.getDescription();
+ sb.append(" <TD>" + getFirstSentance(description) +
+ "</TD>");
+ if (rendererIter.hasNext()) {
+ sb.append(" </TR>\n");
+ sb.append(" <TR>\n");
+ }
             }
- Map options = options(args);
-
- directories((String) options.get("--dir"));
- Digester digester = digester(false, true, false);
- String config = (String) options.get("--config");
- if (log.isDebugEnabled()) {
- log.debug("Parsing configuration file '" + config + "'");
+ sb.append(" </TR>\n");
+ }
+
+ sb.append("</TABLE>\n\n");
+
+ appendResourceToStringBuffer(
+ "com/sun/faces/generate/facesdoc/renderkit-summary.bottom",
+ sb);
+ writeStringToFile(sb.toString(),
+ new File(renderKitDirectory,
+ "renderkit-summary.html"));
+ }
+
+
+ private void generateRenderersDocs() throws Exception {
+ StringBuffer sb;
+ RenderKitBean renderKit;
+ DescriptionBean descBean;
+
+ String description;
+ String rendererType;
+ String componentFamily;
+ String defaultValue;
+ String title;
+
+ // generate the docus for each renderer
+
+ if (null == (renderKit = configBean.getRenderKit(renderKitId))) {
+ RenderKitBean[] kits = configBean.getRenderKits();
+ if (kits == null) {
+ throw new IllegalStateException("no RenderKits");
+ }
+
+ renderKit = kits[0];
+ if (renderKit == null) {
+ throw new IllegalStateException("no RenderKits");
+ }
+ }
+ RendererBean[] renderers = renderKit.getRenderers();
+ AttributeBean[] attributes;
+ sb = new StringBuffer(2048);
+
+ for (int i = 0, len = renderers.length; i < len; i++) {
+ if (null == renderers[i]) {
+ throw new IllegalStateException("null Renderer at
index: " + i);
+ }
+ attributes = renderers[i].getAttributes();
+
+ sb.append(DOCTYPE + "\n");
+ sb.append("<html>\n");
+ sb.append("<head>\n");
+ // PENDING timestamp
+ sb.append("<title>\n");
+ title = "<font size=\"-1\">component-family:</font> " +
+ (componentFamily = renderers[i].getComponentFamily()) +
+ " <font size=\"-1\">renderer-type:</font> " +
+ (rendererType = renderers[i].getRendererType());
+ sb.append(title + "\n");
+ sb.append("</title>\n");
+ // PENDING META tag
+ sb.append(
+ "<link REL =\"stylesheet\" TYPE=\"text/css\"
HREF=\"../stylesheet.css\" TITLE=\"Style\">\n");
+ sb.append("</head>\n");
+ sb.append("<script>\n");
+ sb.append("function asd()\n");
+ sb.append("{\n");
+ sb.append(" parent.document.title=" + title + "\n");
+ sb.append("}\n");
+ sb.append("</SCRIPT>\n");
+ sb.append("<body BGCOLOR=\"white\" onload=\"asd();\">\n");
+ sb.append("\n");
+ sb.append("<H2><font size=\"-1\">" + renderKitId +
+ " render-kit</font>\n");
+ sb.append("<br />\n");
+ sb.append(title + "\n");
+ sb.append("</H2>\n");
+ sb.append("<HR />\n");
+ descBean = renderers[i].getDescription("");
+ description = (null == descBean) ? "" :
descBean.getDescription();
+ sb.append("<P>" + description + "</P>\n");
+ // render our renders children status
+
+ if (renderers[i].isRendersChildren()) {
+ sb.append(
+ "<P>This renderer is responsible for rendering its
children.</P>");
+ } else {
+ sb.append(
+ "<P>This renderer is not responsible for rendering
its children.</P>");
             }
- fcb = parse(digester, config);
- if (log.isInfoEnabled()) {
- log.info("Generating HTML component classes");
+
+ // if we have attributes
+ if ((null == attributes) || (0 < attributes.length)) {
+ sb.append("<HR />\n");
+ sb.append("<a NAME=\"attributes\"><!-- --></a>\n");
+ sb.append("\n");
+ sb.append("<h3>Note:</h3>\n");
+ sb.append("\n");
+ sb.append(
+ "<p>Attributes with a <code>pass-through</code>
value of\n");
+ sb.append(
+ "<code>true</code> are not interpreted by the
renderer and are passed\n");
+ sb.append(
+ "straight through to the rendered markup, without
checking for validity. Attributes with a\n");
+ sb.append(
+ "<code>pass-through</code> value of
<code>false</code> are interpreted\n");
+ sb.append(
+ "by the renderer, and may or may not be checked for
validity by the renderer.</p>\n");
+ sb.append("\n");
+ sb.append(
+ "<table BORDER=\"1\" CELLPADDING=\"3\"
CELLSPACING=\"0\" WIDTH=\"100%\">\n");
+ sb.append(
+ "<tr BGCOLOR=\"#CCCCFF\"
CLASS=\"TableHeadingColor\">\n");
+ sb.append("<td COLSPAN=\"5\"><font SIZE=\"+2\">\n");
+ sb.append("<b>Attributes</b></font></td>\n");
+ sb.append("</tr>\n");
+ sb.append(
+ "<tr BGCOLOR=\"#CCCCFF\"
CLASS=\"TableHeadingColor\">\n");
+ sb.append("<th><b>attribute-name</b></th>\n");
+ sb.append("<th><b>pass-through</b></th>\n");
+ sb.append("<th><b>attribute-class</b></th>\n");
+ sb.append("<th><b>description</b></th>\n");
+ sb.append("<th><b>default-value</b></th>\n");
+ sb.append("</tr>\n");
+ sb.append(" \n");
+ // output each attribute
+ for (int j = 0, attrLen = attributes.length; j <
attrLen; j++) {
+ sb.append(
+ "<tr BGCOLOR=\"white\"
CLASS=\"TableRowColor\">\n");
+ sb.append(
+ "<td ALIGN=\"right\" VALIGN=\"top\"
WIDTH=\"1%\"><code>\n");
+ sb.append(
+ "&nbsp;" + attributes[j].getAttributeName() +
"\n");
+ sb.append("</td>\n");
+ sb.append("<td ALIGN=\"right\" VALIGN=\"top\">" +
+ attributes[j].isPassThrough() + "</td>\n");
+ sb.append("<td><code>" +
attributes[j].getAttributeClass() +
+ "</code></td>\n");
+ descBean = attributes[j].getDescription("");
+ description = (null == descBean) ?
+ "" : descBean.getDescription();
+ sb.append("<td>" + description + "</td>\n");
+ if (null ==
+ (defaultValue = attributes[j].getDefaultValue())) {
+ defaultValue = "undefined";
+ }
+ sb.append("<td>" + defaultValue + "<td>\n");
+ sb.append("</tr>\n");
+ }
+ sb.append("</table>\n");
+ } else {
+ sb.append("<p>This renderer-type has no attributes</p>\n");
             }
+ sb.append("<hr>\n");
+ sb.append(
+ "Copyright (c) 2003-2004 Sun Microsystems, Inc. All
Rights Reserved.\n");
+ sb.append("</body>\n");
+ sb.append("</html>\n");
+ writeStringToFile(sb.toString(),
+ new File(renderKitDirectory,
+ componentFamily + rendererType +
+ ".html"));
+ sb.delete(0, sb.length());
+ }
+ }
 
- // Generate render-kit documentation
- // copy the static files to the output area
- copyResourceToFile("com/sun/faces/generate/facesdoc/index.html",
- new File(directory, "index.html"));
-
copyResourceToFile("com/sun/faces/generate/facesdoc/stylesheet.css",
- new File(directory, "stylesheet.css"));
-
- generateAllRenderersFrame();
- generateRenderKitSummary();
- generateRenderersDocs();
 
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
+ private static ClassLoader getCurrentLoader(Object fallbackClass) {
+ ClassLoader loader =
+ Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = fallbackClass.getClass().getClassLoader();
         }
- System.exit(0);
+ return loader;
+ }
+
+ // -------------------------------------------------------------
Main Method
+
+
+ public static void main(String[] args) throws Exception {
+ PropertyManager propManager = PropertyManager.newInstance(args[0]);
+
+ Generator generator =
+ new RenderKitSpecificationGenerator(propManager);
+
+ generator.generate(GeneratorUtil.getConfigBean(args[1]));
 
     }
 


SECTION: New Files
----------------------------
SEE ATTACHMENTS



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net