incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r481056 [2/4] - in /incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces: ./ generator/ generator/component/ generator/taglib/ parse/ util/
Date Thu, 30 Nov 2006 20:21:29 GMT
Modified: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java?view=diff&rev=481056&r1=481055&r2=481056
==============================================================================
--- incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java (original)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java Thu Nov 30 12:21:26 2006
@@ -15,24 +15,20 @@
 */
 package org.apache.myfaces.trinidadbuild.plugin.faces;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringWriter;
-
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.ComponentTagGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.MyFacesComponentTagGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.TagAttributeFilter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.TrinidadComponentTagGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.*;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.*;
+import org.codehaus.plexus.util.FileUtils;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
@@ -40,38 +36,12 @@
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.*;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamResult;
-
-import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ConverterBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacesConfigBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.MethodSignatureBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ValidatorBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.ComponentFilter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.ConverterFilter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.ValidatorFilter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.XIncludeFilter;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-
-import org.codehaus.plexus.util.FileUtils;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
+import java.io.*;
+import java.lang.reflect.Modifier;
+import java.util.*;
 
 /**
  * @version $Id$
@@ -631,7 +601,7 @@
       }
       else
       {
-        ComponentTagGenerator componentGen = new ComponentTagGenerator();
+        ComponentTagHandlerGenerator componentGen = new ComponentTagHandlerGenerator();
         ConverterTagGenerator converterGen = new ConverterTagGenerator();
         ValidatorTagGenerator validatorGen = new ValidatorTagGenerator();
         int count = 0;
@@ -1474,1105 +1444,206 @@
     }
   }
 
-  class ComponentTagGenerator
-  {
-    public void generateTagHandler(
-      ComponentBean component)
-    {
-      String fullClassName = component.getTagClass();
-
-      try
-      {
-        getLog().debug("Generating " + fullClassName);
-
-        String sourcePath = Util.convertClassToSourcePath(fullClassName, ".java");
-        File targetFile = new File(generatedSourceDirectory, sourcePath);
-
-        targetFile.getParentFile().mkdirs();
-        StringWriter sw = new StringWriter();
-        PrettyWriter out = new PrettyWriter(sw);
-
-        String className = Util.getClassFromFullClass(fullClassName);
-        String packageName = Util.getPackageFromFullClass(fullClassName);
-        String fullSuperclassName = component.findJspTagSuperclass();
-        if (fullSuperclassName == null)
-          throw new IllegalArgumentException("Missing JSP Tag superclass");
-        String superclassName = Util.getClassFromFullClass(fullSuperclassName);
-        if (superclassName.equals(className))
-          superclassName = fullSuperclassName;
-        String componentFullClass = component.getComponentClass();
-        String componentClass = Util.getClassFromFullClass(componentFullClass);
-
-        // header/copyright
-        writePreamble(out);
-
-        // package
-        out.println("package " + packageName + ";");
-
-        // TODO: eliminate <mfp:tag-class-modifier> metadata
-        int modifiers = component.getTagClassModifiers();
-        String classStart = Modifier.toString(modifiers);
+	class ComponentTagHandlerGenerator {
 
-        out.println();
-        _writeImports(out, fullSuperclassName, superclassName,
-                      componentFullClass, component);
-
-        out.println("/**");
-        // TODO: remove this blank line.
-        out.println();
-        out.println(" * Auto-generated tag class.");
-        out.println(" */");
-
-        // TODO: use canonical ordering
-        classStart = classStart.replaceAll("public abstract", "abstract public");
-        out.println(classStart + " class " + className +
-                                 " extends " + superclassName);
-        out.println("{");
-        out.indent();
-
-        _writeConstructor(out, component);
+		private Set initComponentList(ComponentBean component, String fullSuperclassName) {
+			Set _componentList = new HashSet();
+			_componentList.add(component);
+			ComponentBean lBean = component;
+			while ((lBean = lBean.resolveSupertype()) != null && !fullSuperclassName.equals(lBean.getTagClass())) {
+				getLog().debug(component.getComponentType()+": Add additional Tags from: " + lBean.getComponentType());
+				_componentList.add(lBean);
+			}
+			return _componentList;
+		}
+
+		public void generateTagHandler(ComponentBean component) {
+			ComponentTagGenerator generator;
+			Set componentList;
+
+			String fullSuperclassName = component.findJspTagSuperclass();
+			if (fullSuperclassName == null) {
+				getLog().warn("Missing JSP Tag superclass for component: " + component.getComponentClass()
+						+ ", generation of this Tag is skipped");
+				return;
+			}
+			componentList = initComponentList(component, fullSuperclassName);
+
+			String fullClassName = component.getTagClass();
+			try {
+				getLog().debug("Generating " + fullClassName);
+
+				String sourcePath = Util.convertClassToSourcePath(fullClassName, ".java");
+				File targetFile = new File(generatedSourceDirectory, sourcePath);
+
+				targetFile.getParentFile().mkdirs();
+				StringWriter sw = new StringWriter();
+				PrettyWriter out = new PrettyWriter(sw);
+
+				if (component.isTrinidadComponent()) {
+					generator = new TrinidadComponentTagGenerator(_is12());
+				} else {
+					generator = new MyFacesComponentTagGenerator(_is12());
+				}
+
+				String className = Util.getClassFromFullClass(fullClassName);
+				String packageName = Util.getPackageFromFullClass(fullClassName);
+
+				// header/copyright
+				writePreamble(out);
+
+				// package
+				out.println("package " + packageName + ";");
+
+				out.println();
+
+				String superclassName = Util.getClassFromFullClass(fullSuperclassName);
+				if (superclassName.equals(className)) {
+					superclassName = fullSuperclassName;
+				}
+				String componentFullClass = component.getComponentClass();
+				String componentClass = Util.getClassFromFullClass(componentFullClass);
+
+				generator.writeImports(out, null, packageName, fullSuperclassName, superclassName, componentList);
+
+				generator.writeClassBegin(out, className, superclassName, component, null);
+
+				int modifiers = component.getTagClassModifiers();
+				generator.writeConstructor(out, component, modifiers);
+
+
+				if (!Modifier.isAbstract(modifiers)) {
+					generator.writeGetComponentType(out, component);
+					generator.writeGetRendererType(out, component);
+				}
+				generator.writePropertyMembers(out, componentList);
+				generator.writeSetPropertiesMethod(out, componentClass, componentList);
+				generator.writeReleaseMethod(out, componentList);
+
+				generator.writeClassEnd(out);
+				out.close();
+
+				// delay write in case of error
+				// timestamp should not be updated when an error occurs
+				// delete target file first, because it is readonly
+				targetFile.delete();
+				FileWriter fw = new FileWriter(targetFile);
+				StringBuffer buf = sw.getBuffer();
+				fw.write(buf.toString());
+				fw.close();
+				targetFile.setReadOnly();
+			}
+			catch (Throwable e)
+            {
+				getLog().error("Error generating " + fullClassName, e);
+			}
+		}
+	}
 
-        if (!Modifier.isAbstract(modifiers))
-        {
-          _writeGetComponentType(out, component);
-          _writeGetRendererType(out, component);
-        }
-        _writePropertyMethods(out, component);
-        _writeSetProperties(out, componentClass, component);
-        _writeRelease(out, component);
+  private boolean _is12()
+  {
+    return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
+  }
 
-        out.unindent();
-        out.println("}");
-        out.close();
+  private class IfComponentModifiedFilter extends ComponentFilter
+  {
+    protected boolean accept(
+      ComponentBean component)
+    {
+      String tagClass = component.getTagClass();
+      String sourcePath = Util.convertClassToSourcePath(tagClass, ".java");
+      String templatePath = Util.convertClassToSourcePath(tagClass, "Template.java");
+      File targetFile = new File(generatedSourceDirectory, sourcePath);
+      File templateFile = new File(templateSourceDirectory, templatePath);
 
-        // delay write in case of error
-        // timestamp should not be updated when an error occurs
-        // delete target file first, because it is readonly
-        targetFile.delete();
-        FileWriter fw = new FileWriter(targetFile);
-        StringBuffer buf = sw.getBuffer();
-        fw.write(buf.toString());
-        fw.close();
-        targetFile.setReadOnly();
-      }
-      catch (Throwable e)
-      {
-        getLog().error("Error generating " + fullClassName, e);
-      }
+      // accept if templateFile is newer or component has been modified
+      return (templateFile.lastModified() > targetFile.lastModified() ||
+              component.isModifiedSince(targetFile.lastModified()));
     }
+  }
 
-    private void _writeImports(
-      PrettyWriter   out,
-      String         fullSuperclassName,
-      String         superclassName,
-      String         componentFullClass,
-      ComponentBean  component)
+  private class IfConverterModifiedFilter extends ConverterFilter
+  {
+    protected boolean accept(
+      ConverterBean converter)
     {
-      Set imports = new TreeSet();
-
-      Iterator properties = component.properties();
-      properties = new FilteredIterator(properties, new TagAttributeFilter());
-      if (properties.hasNext())
-      {
-        imports.add(componentFullClass);
-      }
-
-      imports.add("org.apache.myfaces.trinidad.bean.FacesBean");
-
-      // TODO: remove these imports
-      // FIXME: Actually last 2 can be kept when not abstract
-      //imports.add("javax.faces.component.UIComponent");
-
-      // superclassName is fully qualified if it collides
-      // with the generated class name and should not be
-      // imported when such a collision would occur
-      if (!superclassName.equals(fullSuperclassName))
-        imports.add(fullSuperclassName);
-
-      while (properties.hasNext())
-      {
-        PropertyBean property = (PropertyBean)properties.next();
+      String tagClass = converter.getTagClass();
+      String sourcePath = Util.convertClassToSourcePath(tagClass, ".java");
+      String templatePath = Util.convertClassToSourcePath(tagClass, "Template.java");
+      File targetFile = new File(generatedSourceDirectory, sourcePath);
+      File templateFile = new File(templateSourceDirectory, templatePath);
 
-        String   propertyClass = property.getPropertyClass();
-        String[] propertyClassParams = property.getPropertyClassParameters();
+      // accept if templateFile is newer or component has been modified
+      return (templateFile.lastModified() > targetFile.lastModified() ||
+              converter.isModifiedSince(targetFile.lastModified()));
+    }
+  }
 
-        if (propertyClass != null && property.isLiteralOnly())
-        {
-          // Import the property class only if only litterals are supported
-          // otherwise the class will be a String inside the tag to support 
-          // ValueBinding
-          imports.add(propertyClass);
-        }
+  private class IfValidatorModifiedFilter extends ValidatorFilter
+  {
+    protected boolean accept(
+      ValidatorBean validator)
+    {
+      String tagClass = validator.getTagClass();
+      String sourcePath = Util.convertClassToSourcePath(tagClass, ".java");
+      String templatePath = Util.convertClassToSourcePath(tagClass, "Template.java");
+      File targetFile = new File(generatedSourceDirectory, sourcePath);
+      File templateFile = new File(templateSourceDirectory, templatePath);
 
-        imports.add("javax.el.ValueExpression");
+      // accept if templateFile is newer or component has been modified
+      return (templateFile.lastModified() > targetFile.lastModified() ||
+              validator.isModifiedSince(targetFile.lastModified()));
+    }
+  }
 
-        if (_isKeyStroke(propertyClass))
-        {
-          if (_is12())
-            imports.add("javax.el.ValueExpression");
-          else
-            imports.add("javax.faces.el.ValueBinding");
-          imports.add("javax.swing.KeyStroke");
-        }
-        else if (_isAWTKeyStroke(propertyClass))
-        {
-          if (_is12())
-            imports.add("javax.el.ValueExpression");
-          else
-            imports.add("javax.faces.el.ValueBinding");
-          imports.add("java.awt.AWTKeyStroke");
-        }
-        else if (_isConverter(propertyClass))
-        {
-          if (_is12())
-            imports.add("javax.el.ValueExpression");
-          else
-            imports.add("javax.faces.el.ValueBinding");
-          imports.add("javax.faces.convert.Converter");
-        }
-        else if (property.isVirtual())
-        {
-          if (_is12())
-            imports.add("javax.el.ValueExpression");
-          else
-            imports.add("javax.faces.el.ValueBinding");
-          imports.add("org.apache.myfaces.trinidadinternal.taglib.util.VirtualAttributeUtils");
-        }
-        else if (_isColorList(propertyClass, propertyClassParams))
-        {
-          if (_is12())
-            imports.add("javax.el.ValueExpression");
-          else
-            imports.add("javax.faces.el.ValueBinding");
-          imports.add("java.text.ParseException");
-          imports.add("org.apache.myfaces.trinidadinternal.taglib.util.TagUtils");
-        }
-        else if (property.isMethodBinding())
-        {
-          if (_is12())
-          {
-            imports.add("javax.el.MethodExpression");
-            imports.add("org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding");
-          }
-          else
-          {
-            imports.add("javax.faces.el.MethodBinding");
-          }
-        }
-        else if (property.isMethodExpression())
-        {
-          imports.add("javax.el.MethodExpression");
-        }
+  /**
+   * @parameter expression="${project}"
+   * @required
+   * @readonly
+   */
+  private MavenProject project;
 
-        // TODO: restore import and make reference to
-        //       ConstantMethodBinding relative rather
-        //       than absolute
-        //if (property.isMethodBinding() &&
-        //    isStringMethodBindingReturnType(property))
-        //{
-        //  imports.add("org.apache.myfaces.trinidadinternal.taglib.ConstantMethodBinding");
-        //}
-      }
+  /**
+   * @parameter
+   * @required
+   */
+  private Map taglibs;
 
-      // do not import implicit!
-      imports.removeAll(Util.PRIMITIVE_TYPES);
+  /**
+   * @parameter expression="META-INF/maven-faces-plugin/faces-config.xml"
+   * @required
+   * @readonly
+   */
+  private String resourcePath;
 
-      String tagClass = component.getTagClass();
-      String packageName = Util.getPackageFromFullClass(tagClass);
-      writeImports(out, packageName, imports);
-    }
+  /**
+   * @parameter expression="src/main/conf"
+   * @required
+   */
+  private File configSourceDirectory;
 
-    private void _writeConstructor(
-      PrettyWriter  out,
-      ComponentBean component) throws IOException
-    {
-      String fullClassName = component.getTagClass();
-      String className = Util.getClassFromFullClass(fullClassName);
-      out.println();
-      out.println("/**");
-      // TODO: restore this correctly phrased comment (tense vs. command)
-      //out.println(" * Constructs an instance of " + className + ".");
-      out.println(" * Construct an instance of the " + className + ".");
-      out.println(" */");
-      out.println("public " + className + "()");
-      out.println("{");
-      out.println("}");
-    }
+  /**
+   * @parameter expression="src/main/java-templates"
+   * @required
+   */
+  private File templateSourceDirectory;
 
-    private void _writeGetComponentType(
-      PrettyWriter  out,
-      ComponentBean component) throws IOException
-    {
-      String componentType = component.getComponentType();
-      out.println();
-      out.println("@Override");
-      out.println("public String getComponentType()");
-      out.println("{");
-      out.indent();
-      out.println("return \"" + componentType + "\";");
-      out.unindent();
-      out.println("}");
-    }
+  /**
+   * @parameter expression="${project.build.directory}/maven-faces-plugin/main/java"
+   * @required
+   */
+  private File generatedSourceDirectory;
 
-    private void _writeGetRendererType(
-      PrettyWriter  out,
-      ComponentBean component) throws IOException
-    {
-      String rendererType = component.getRendererType();
-      out.println();
-      out.println("@Override");
-      out.println("public String getRendererType()");
-      out.println("{");
-      out.indent();
-      out.println("return " + convertStringToLiteral(rendererType) + ";");
-      out.unindent();
-      out.println("}");
-    }
-
-    private void _writeRelease(
-      PrettyWriter  out,
-      ComponentBean component) throws IOException
-    {
-      Iterator properties = component.properties();
-      properties = new FilteredIterator(properties, new TagAttributeFilter());
-      // TODO: remove special case for UIXFormTag
-      if (properties.hasNext() ||
-          "org.apache.myfaces.trinidadinternal.taglib.UIXFormTag".equals(component.getTagClass()))
-      {
-        out.println();
-        out.println("@Override");
-        out.println("public void release()");
-        out.println("{");
-        out.indent();
-        out.println("super.release();");
-        while (properties.hasNext())
-        {
-          PropertyBean property = (PropertyBean)properties.next();
-          String propName = property.getPropertyName();
-          String propVar = "_" + Util.getVariableFromName(propName);
-          out.println(propVar + " = null;");
-        }
-        out.unindent();
-        out.println("}");
-      }
-    }
-
-    private void _writePropertyMethods(
-      PrettyWriter  out,
-      ComponentBean component) throws IOException
-    {
-      Iterator properties = component.properties();
-      properties = new FilteredIterator(properties, new TagAttributeFilter());
-      while (properties.hasNext())
-      {
-        PropertyBean property = (PropertyBean)properties.next();
-        out.println();
-        _writePropertyMember(out, property);
-        _writePropertySet(out, property);
-      }
-    }
-
-    private void _writePropertyMembers(
-      PrettyWriter  out,
-      ComponentBean component) throws IOException
-    {
-      Iterator properties = component.properties();
-      properties = new FilteredIterator(properties, new TagAttributeFilter());
-      if (properties.hasNext())
-      {
-        out.println();
-        while (properties.hasNext())
-        {
-          PropertyBean property = (PropertyBean)properties.next();
-          _writePropertyMember(out, property);
-        }
-      }
-    }
-
-    private void _writePropertyMember(
-     PrettyWriter  out,
-     PropertyBean  property) throws IOException
-    {
-      String propName = property.getPropertyName();
-      String propVar = "_" + Util.getVariableFromName(propName);
-      String jspPropType = _getJspPropertyType(property);
-      
-      out.println("private " + jspPropType + " " + propVar + ";");
-    }
-
-    private String _getJspPropertyType(PropertyBean property)
-    {
-      if (property.isMethodExpression())
-        return "MethodExpression";
-
-      if (_is12() && property.isMethodBinding())
-        return "MethodExpression";
-
-      if (_is12() && !property.isLiteralOnly())
-        return "ValueExpression";
-      return "String";
-    }
-
-    private void _writePropertySet(
-     PrettyWriter  out,
-     PropertyBean  property) throws IOException
-    {
-      String propName = property.getPropertyName();
-      String jspPropName = property.getJspPropertyName();
-      String propVar = Util.getVariableFromName(propName);
-      String setMethod = Util.getPrefixedPropertyName("set", jspPropName);
-      String jspPropType = _getJspPropertyType(property);
-
-      // TODO: restore coding standards, and make final
-      out.println("public void " + setMethod + "(" + jspPropType + " " + propVar + ")");
-      out.println("{");
-      out.indent();
-      out.println("_" + propVar + " = " + propVar + ";");
-      out.unindent();
-      out.println("}");
-    }
-
-    private void _writeSetProperties(
-      PrettyWriter  out,
-      String        componentClass,
-      ComponentBean component) throws IOException
-    {
-      Iterator properties = component.properties();
-      properties = new FilteredIterator(properties, new TagAttributeFilter());
-      // TODO: only write out setProperties when properties exist
-  //    if (properties.hasNext())
-  //    {
-        out.println();
-        out.println("@Override");
-        out.println("protected void setProperties(");
-        out.indent();
-        out.println("FacesBean bean)");
-        out.unindent();
-        out.println("{");
-        out.indent();
-        out.println("super.setProperties(bean);");
-
-        while (properties.hasNext())
-        {
-          PropertyBean property = (PropertyBean)properties.next();
-          _writeSetPropertiesCase(out, componentClass, property);
-        }
-        out.unindent();
-        out.println("}");
-  //    }
-    }
-
-    private void _writeSetPropertiesCase(
-      PrettyWriter  out,
-      String             componentClass,
-      PropertyBean        property) throws IOException
-    {
-      String propName = property.getPropertyName();
-      String propClass = property.getPropertyClass();
-      String propVar = "_" + Util.getVariableFromName(propName);
-
-      if (property.isVirtual())
-      {
-        _writeVirtualSetMethod(out, componentClass, propName);
-      }
-      else if (property.isMethodBinding())
-      {
-        _writeSetMethodBinding(out, componentClass, property);
-      }
-      else if (property.isMethodExpression())
-      {
-        _writeSetMethodExpression(out, componentClass, property);
-      }
-      else if (_isKeyStroke(propClass))
-      {
-        _writeSetKeyStroke(out, componentClass, propName);
-      }
-      else if (_isAWTKeyStroke(propClass))
-      {
-        _writeSetAWTKeyStroke(out, componentClass, propName);
-      }
-      else if (_isColorList(propClass, property.getPropertyClassParameters()))
-      {
-        _writeSetColorList(out, componentClass, propName);
-      }
-      else if (_isConverter(propClass))
-      {
-        _writeSetConverter(out, componentClass, propName);
-      }
-      else if (property.isLiteralOnly())
-      {
-        _writeSetLiteral(out, componentClass, propName, propClass, propVar);
-      }
-      else //if (_hasPropertySetter(property))
-      {
-        _writeSetProperty(out, componentClass, propName, propClass, propVar);
-      }
-  //    else
-  //    {
-  //      _writeSetValueBinding(out, componentClass, propName, propVar);
-  //    }
-    }
-
-    /**
-     * Returns true if this property is a complex Object.
-     *
-     * @return true  if this property is a complex Object,
-     *         otherwise false
-     */
-    private boolean _hasPropertySetter(
-      PropertyBean property)
-    {
-      String propertyClass = property.getPropertyClass();
-      return (Util.PRIMITIVE_TYPES.contains(propertyClass) ||
-              "java.lang.Object".equals(propertyClass) ||
-              "java.lang.String".equals(propertyClass) ||
-              "java.lang.String[]".equals(propertyClass));
-    }
-
-    private boolean _isConverter(
-      String propClass)
-    {
-      return ("javax.faces.convert.Converter".equals(propClass));
-    }
-
-    private String[] _getAccessKeyPropertyKeys(
-      String componentClass,
-      String propName)
-    {
-      String[] propKeys = new String[2];
-
-      int offset = propName.indexOf("AndAccessKey");
-      if (offset != -1)
-      {
-        String mainProp = propName.substring(0, offset);
-        propKeys[0] = componentClass + "." +
-                      Util.getConstantNameFromProperty(mainProp, "_KEY");
-        propKeys[1] = componentClass + "." +
-                      Util.getConstantNameFromProperty("accessKey", "_KEY");
-      }
-
-      return propKeys;
-    }
-
-    private boolean _isKeyStroke(
-      String propClass)
-    {
-      return ("javax.swing.KeyStroke".equals(propClass));
-    }
-
-    private boolean _isAWTKeyStroke(
-      String propClass)
-    {
-      return ("java.awt.AWTKeyStroke".equals(propClass));
-    }
-
-    private boolean _isColorList(
-      String   propClass,
-      String[] propClassParams)
-    {
-      return ("java.util.List".equals(propClass) &&
-              propClassParams.length == 1 &&
-              "java.awt.Color".equals(propClassParams[0]));
-    }
-
-    private void _writeSetLiteral(
-      PrettyWriter out,
-      String       componentClass,
-      String       propName,
-      String       propFullClass,
-      String       propVar)
-    {
-      String propClass = Util.getClassFromFullClass(propFullClass);
-      String boxedClass = Util.getBoxedClass(propClass);
-      if ((!_is12() && !boxedClass.equals(propClass)) ||
-           "java.util.Date".equals(propFullClass) ||
-          (boxedClass.indexOf("[]") != -1))
-      {
-        // TODO: reject value binding expressions for literal-only
-        _writeSetProperty(out, componentClass, propName, propFullClass, propVar);
-      }
-      else
-      {
-        String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-        out.println("bean.setProperty(" +
-                    componentClass + "." + propKey + ", " +
-                    propVar + ");" );
-       }
-    }
-
-    private void _writeSetProperty(
-      PrettyWriter out,
-      String       componentClass,
-      String       propName,
-      String       propFullClass,
-      String       propVar)
-    {
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propClass = Util.getClassFromFullClass(propFullClass);
-      String boxedClass = Util.getBoxedClass(propClass);
-      String setProperty = "setProperty";
-      if ((!_is12() && !boxedClass.equals(propClass)) ||
-          "java.lang.Number".equals(propFullClass) ||
-           "java.util.Date".equals(propFullClass) ||
-          (boxedClass.indexOf("[]") != -1))
-      {
-        String propType = boxedClass.replaceAll("\\[\\]", "Array");
-        setProperty = Util.getPrefixedPropertyName("set", propType + "Property");
-      }
-      
-      out.println(setProperty + "(bean, " +
-                                  componentClass + "." + propKey + ", " +
-                                  propVar + ");" );
-    }
-
-    private void _writeSetValueBinding(
-      PrettyWriter out,
-      String       componentClass,
-      String       propName,
-      String       propVar)
-    {
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", " +
-                                        "createValueBinding(" + propVar + "));" );
-    }
-
-    private void _writeVirtualSetMethod(
-      PrettyWriter  out,
-      String        componentClass,
-      String        propName) throws IOException
-    {
-      String[] propKeys = _getAccessKeyPropertyKeys(componentClass, propName);
-
-      String propVar = "_" + propName;
-      out.println("if (" + propVar + " != null)");
-      out.println("{");
-      out.indent();
-
-      if (_is12())
-      {
-        out.println("if (!" + propVar + ".isLiteralText())");
-        out.println("{");
-        out.indent();
-        out.println("VirtualAttributeUtils.setAccessKeyAttribute(");
-        out.indent();
-        out.println("bean,");
-        out.println(propVar + ",");
-        out.println(propKeys[0] + ",");
-        out.println(propKeys[1] +  ");");
-        out.unindent();
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("Object o = " + propVar + ".getValue(null);");
-        out.println("if (o != null)");
-        out.indent();
-        out.println("VirtualAttributeUtils.setAccessKeyAttribute(");
-        out.indent();
-        out.println("bean,");
-        out.println("o.toString(),");
-        out.println(propKeys[0] + ",");
-        out.println(propKeys[1] +  ");");
-        out.unindent();
-        out.unindent();
-        out.unindent();
-        out.println("}");
-      }
-      else
-      {
-        out.println("if (isValueReference(" + propVar + "))");
-        out.println("{");
-        out.indent();
-        out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
-        out.println("VirtualAttributeUtils.setAccessKeyAttribute(");
-        out.indent();
-        out.println("bean,");
-        out.println("vb,");
-        out.println(propKeys[0] + ",");
-        out.println(propKeys[1] +  ");");
-        out.unindent();
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("VirtualAttributeUtils.setAccessKeyAttribute(");
-        out.indent();
-        out.println("bean,");
-        out.println(propVar + ",");
-        out.println(propKeys[0] + ",");
-        out.println(propKeys[1] +  ");");
-        out.unindent();
-        out.unindent();
-        out.println("}");
-      }
-
-      out.unindent();
-      out.println("}");
-    }
-
-    private void _writeSetMethodBinding(
-      PrettyWriter  out,
-      String             componentClass,
-      PropertyBean        property) throws IOException
-    {
-      String propName = property.getPropertyName();
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propVar = "_" + propName;
-
-      if (_is12())
-      {
-        out.println("if (" + propVar + " != null)");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ", " +
-                    "new MethodExpressionMethodBinding(" + propVar + "));");
-        out.unindent();
-      }
-      else
-      {
-        MethodSignatureBean signature = property.getMethodBindingSignature();
-        String[] paramTypes = (signature != null) ? signature.getParameterTypes() : null;
-        
-        String classArray;
-        
-        if (paramTypes == null || paramTypes.length == 0)
-        {
-          classArray = "new Class[0]";
-        }
-        else
-        {
-          StringBuffer sb = new StringBuffer();
-          sb.append("new Class[]{");
-          for (int i=0; i < paramTypes.length; i++)
-          {
-            if (i > 0)
-              sb.append(',');
-            sb.append(paramTypes[i]);
-            sb.append(".class");
-          }
-          
-          // TODO: remove trailing comma
-          sb.append(',');
-          
-          sb.append('}');
-          classArray = sb.toString();
-        }
-        
-        out.println("if (" + propVar + " != null)");
-        out.println("{");
-        out.indent();
-        
-        if (isStringMethodBindingReturnType(signature))
-        {
-          out.println("MethodBinding mb;");
-          out.println("if (isValueReference(" + propVar + "))");
-          out.indent();
-          out.println("mb = createMethodBinding(" + propVar + ", " + classArray + ");");
-          out.unindent();
-          out.println("else");
-          out.indent();
-          out.println("mb = new org.apache.myfaces.trinidadinternal.taglib.ConstantMethodBinding(" + propVar + ");");
-          out.unindent();
-        }
-        else
-        {
-          // never a literal, no need for ConstantMethodBinding
-          out.println("MethodBinding mb = createMethodBinding(" + propVar + ", " +
-                      classArray + ");");
-        }
-        
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ", mb);");
-        out.unindent();
-        out.println("}");
-      }
-    }
-
-    private void _writeSetMethodExpression(
-      PrettyWriter  out,
-      String             componentClass,
-      PropertyBean        property) throws IOException
-    {
-      String propName = property.getPropertyName();
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propVar = "_" + propName;
-
-      out.println("bean.setProperty(" + componentClass + "." + propKey + ", " +
-                  propVar + ");");
-    }
-
-    private void _writeSetKeyStroke(
-      PrettyWriter  out,
-      String        componentClass,
-      String        propName) throws IOException
-    {
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propVar = "_" + propName;
-
-
-      if (_is12())
-      {
-        out.println("if (" + propVar + " != null)");
-        out.println("{");
-        out.indent();
-        out.println("if (!" + propVar + ".isLiteralText())");
-        out.println("{");
-        out.indent();
-        out.println("bean.setValueExpression(" + componentClass + "." + propKey + ", " + propVar + ");");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("Object val = " + propVar + ".getValue(null);");
-        out.println("if (val != null)");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
-        out.println("\tKeyStroke.getKeyStroke(val.toString()));");
-        out.unindent();
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");
-      }
-      else
-      {
-        out.println("if (" + propVar + " != null)");
-        out.println("{");
-        out.indent();
-        out.println("if (isValueReference(" + propVar + "))");
-        out.println("{");
-        out.indent();
-        out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
-        out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
-        out.println("\tKeyStroke.getKeyStroke(" + propVar + "));");
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");
-      }
-    }
-
-
-    private void _writeSetAWTKeyStroke(
-      PrettyWriter  out,
-      String        componentClass,
-      String        propName) throws IOException
-    {
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propVar = "_" + propName;
-
-      if (_is12())
-      {
-        out.println("if (" + propVar + " != null)");
-        out.println("{");
-        out.indent();
-        out.println("if (!" + propVar + ".isLiteralText())");
-        out.println("{");
-        out.indent();
-        out.println("bean.setValueExpression(" + componentClass + "." + propKey + ", " + propVar + ");");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("Object val = " + propVar + ".getValue(null);");
-        out.println("if (val != null)");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
-        out.println("\tAWTKeyStroke.getAWTKeyStroke(val.toString()));");
-        out.unindent();
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");
-      }
-      else
-      {
-        out.println("if (" + propVar + " != null)");
-        out.println("{");
-        out.indent();
-        out.println("if (isValueReference(" + propVar + "))");
-        out.println("{");
-        out.indent();
-        out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
-        out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
-        out.println("\tAWTKeyStroke.getAWTKeyStroke(" + propVar + "));");
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");
-      }
-    }
-
-
-
-    private void _writeSetColorList(
-      PrettyWriter  out,
-      String        componentClass,
-      String        propName) throws IOException
-    {
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propVar = "_" + propName;
-
-      out.println("if (" + propVar + " != null)");
-      out.println("{");
-      out.indent();
-      if (_is12())
-      {
-        out.println("if (!" + propVar + ".isLiteralText())");
-        out.println("{");
-        out.indent();
-        out.println("bean.setValueExpression(" + componentClass + "." + propKey + ", " + propVar + ");");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("Object o = " + propVar + ".getValue(null);");
-        out.println("if (o != null)");
-        out.indent();
-        out.println("{");
-        out.println("try");
-        out.println("{");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
-        out.println("                 TagUtils.getColorList(o.toString()));");
-        out.unindent();
-        out.println("}");
-        out.println("catch (ParseException pe)");
-        out.println("{");
-        out.indent();
-        out.println("setValidationError(");
-        out.println("  pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");        
-      }
-      else
-      {
-        out.println("if (isValueReference(" + propVar + "))");
-        out.println("{");
-        out.indent();
-        out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
-        out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("try");
-        out.println("{");
-        out.indent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
-        out.println("                 TagUtils.getColorList(" + propVar + "));");
-        out.unindent();
-        out.println("}");
-        out.println("catch (ParseException pe)");
-        out.println("{");
-        out.indent();
-        out.println("setValidationError(");
-        out.println("  pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
-        out.unindent();
-        out.println("}");
-        out.unindent();
-        out.println("}");
-      }
-      out.unindent();
-      out.println("}");
-    }
-
-
-    private void _writeSetConverter(
-      PrettyWriter  out,
-      String             componentClass,
-      String             propName) throws IOException
-    {
-      String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
-      String propVar = "_" + propName;
-
-      out.println("if (" + propVar + " != null)");
-      out.println("{");
-      out.indent();
-      if (_is12())
-      {
-        out.println("if (!" + propVar + ".isLiteralText())");
-        out.println("{");
-        out.indent();
-        out.println("bean.setValueExpression(" + componentClass + "." + propKey + ", " + propVar + ");");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("Object o = " + propVar + ".getValue(null);");
-        out.println("if (o != null)");
-        out.println("{");
-
-        out.indent();
-        out.println("Converter converter = getFacesContext().getApplication().");
-        out.indent();
-        out.println("createConverter(o.toString());");
-        out.unindent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ", converter);");
-        
-        out.unindent();
-        out.println("}");
-        
-        out.unindent();
-        out.println("}");
-      }
-      else
-      {
-        out.println("if (isValueReference(" + propVar + "))");
-        out.println("{");
-        out.indent();
-        out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
-        out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
-        out.unindent();
-        out.println("}");
-        out.println("else");
-        out.println("{");
-        out.indent();
-        out.println("Converter converter = getFacesContext().getApplication().");
-        out.indent();
-        out.println("createConverter(" + propVar + ");");
-        out.unindent();
-        out.println("bean.setProperty(" + componentClass + "." + propKey + ", converter);");
-        out.unindent();
-        out.println("}");
-      }
-      out.unindent();
-      out.println("}");
-    }
-  }
-
-  private boolean isStringMethodBindingReturnType(
-    MethodSignatureBean sig)
-  {
-    return (sig != null && "java.lang.String".equals(sig.getReturnType()));
-  }
-
-  private boolean _is12()
-  {
-    return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
-  }
-
-  private class IfComponentModifiedFilter extends ComponentFilter
-  {
-    protected boolean accept(
-      ComponentBean component)
-    {
-      String tagClass = component.getTagClass();
-      String sourcePath = Util.convertClassToSourcePath(tagClass, ".java");
-      String templatePath = Util.convertClassToSourcePath(tagClass, "Template.java");
-      File targetFile = new File(generatedSourceDirectory, sourcePath);
-      File templateFile = new File(templateSourceDirectory, templatePath);
-
-      // accept if templateFile is newer or component has been modified
-      return (templateFile.lastModified() > targetFile.lastModified() ||
-              component.isModifiedSince(targetFile.lastModified()));
-    }
-  }
-
-  private class IfConverterModifiedFilter extends ConverterFilter
-  {
-    protected boolean accept(
-      ConverterBean converter)
-    {
-      String tagClass = converter.getTagClass();
-      String sourcePath = Util.convertClassToSourcePath(tagClass, ".java");
-      String templatePath = Util.convertClassToSourcePath(tagClass, "Template.java");
-      File targetFile = new File(generatedSourceDirectory, sourcePath);
-      File templateFile = new File(templateSourceDirectory, templatePath);
-
-      // accept if templateFile is newer or component has been modified
-      return (templateFile.lastModified() > targetFile.lastModified() ||
-              converter.isModifiedSince(targetFile.lastModified()));
-    }
-  }
-
-  private class IfValidatorModifiedFilter extends ValidatorFilter
-  {
-    protected boolean accept(
-      ValidatorBean validator)
-    {
-      String tagClass = validator.getTagClass();
-      String sourcePath = Util.convertClassToSourcePath(tagClass, ".java");
-      String templatePath = Util.convertClassToSourcePath(tagClass, "Template.java");
-      File targetFile = new File(generatedSourceDirectory, sourcePath);
-      File templateFile = new File(templateSourceDirectory, templatePath);
-
-      // accept if templateFile is newer or component has been modified
-      return (templateFile.lastModified() > targetFile.lastModified() ||
-              validator.isModifiedSince(targetFile.lastModified()));
-    }
-  }
-
-  /**
-   * @parameter expression="${project}"
-   * @required
-   * @readonly
-   */
-  private MavenProject project;
-
-  /**
-   * @parameter
-   * @required
-   */
-  private Map taglibs;
-
-  /**
-   * @parameter expression="META-INF/maven-faces-plugin/faces-config.xml"
-   * @required
-   * @readonly
-   */
-  private String resourcePath;
-
-  /**
-   * @parameter expression="src/main/conf"
-   * @required
-   */
-  private File configSourceDirectory;
-
-  /**
-   * @parameter expression="src/main/java-templates"
-   * @required
-   */
-  private File templateSourceDirectory;
-
-  /**
-   * @parameter expression="${project.build.directory}/maven-faces-plugin/main/java"
-   * @required
-   */
-  private File generatedSourceDirectory;
-
-  /**
-   * @parameter expression="${project.build.directory}/maven-faces-plugin/main/resources"
-   * @required
-   */
-  private File generatedResourcesDirectory;
+  /**
+   * @parameter expression="${project.build.directory}/maven-faces-plugin/main/resources"
+   * @required
+   */
+  private File generatedResourcesDirectory;
 
   /**
    * @parameter
-   * @required
    */
-  private String packageContains;
+  private String packageContains = "";
 
   /**
    * @parameter

Added: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ClassGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ClassGenerator.java?view=auto&rev=481056
==============================================================================
--- incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ClassGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ClassGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.faces.generator;
+
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.SourceTemplate;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * Generator
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface ClassGenerator
+{
+  void writeImports(
+      PrettyWriter out,
+      SourceTemplate template,
+      String packageName,
+      String fullSuperclassName,
+      String superclassName,
+      ComponentBean component);
+
+  void writeImports(
+      PrettyWriter out,
+      SourceTemplate template,
+      String packageName,
+      String fullSuperclassName,
+      String superclassName,
+      Collection components);
+
+  void writeClassBegin(
+      PrettyWriter out,
+      String className,
+      String superclassName,
+      ComponentBean component,
+      SourceTemplate template);
+
+  void writeConstructor(
+      PrettyWriter out,
+      ComponentBean component,
+      int modifiers) throws IOException;
+
+  void writeClassEnd(
+      PrettyWriter out);
+
+}

Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ClassGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ClassGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/GeneratorHelper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/GeneratorHelper.java?view=auto&rev=481056
==============================================================================
--- incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/GeneratorHelper.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/GeneratorHelper.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.faces.generator;
+
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.Filter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
+
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * TODO: comment this!
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class GeneratorHelper
+{
+  private GeneratorHelper()
+  {
+  }
+
+  public static boolean isConverter(
+      String propClass)
+  {
+    return ("javax.faces.convert.Converter".equals(propClass));
+  }
+
+  public static boolean isKeyStroke(
+      String propClass)
+  {
+    return ("javax.swing.KeyStroke".equals(propClass));
+  }
+
+  public static boolean isAWTKeyStroke(
+      String propClass)
+  {
+    return ("java.awt.AWTKeyStroke".equals(propClass));
+  }
+
+  public static boolean isColorList(
+      String propClass,
+      String[] propClassParams)
+  {
+    return ("java.util.List".equals(propClass) &&
+        propClassParams.length == 1 &&
+        "java.awt.Color".equals(propClassParams[0]));
+  }
+
+  public static boolean isAction(PropertyBean property)
+  {
+    return (property.getClass().equals("javax.el.MethodExpression")
+        && property.getJspPropertyName().equals("action"));
+  }
+
+  public static boolean isActionListener(PropertyBean property, boolean is12)
+  {
+    return (property.getJspPropertyName().equals("actionListener") &&
+        ((property.isMethodExpression()) || (is12 && property.isMethodBinding())));
+  }
+
+  public static boolean isValueChangeListener(PropertyBean property, boolean is12)
+  {
+    return (property.getJspPropertyName().equals("valueChangeListener") &&
+        ((property.isMethodExpression()) || (is12 && property.isMethodBinding())));
+  }
+
+  public static boolean isValidator(PropertyBean property, boolean is12)
+  {
+    return (property.getJspPropertyName().equals("validator")) &&
+        ((property.isMethodExpression()) || (is12 && property.isMethodBinding()));
+  }
+
+  static public void writeImports(
+      PrettyWriter out,
+      String packageName,
+      Set imports)
+  {
+    Iterator iterator = imports.iterator();
+    iterator = new FilteredIterator(iterator,
+        new PackageImportsFilter(packageName));
+    while (iterator.hasNext())
+    {
+      String className = (String) iterator.next();
+      out.println("import " + className + ";");
+    }
+
+    out.println();
+  }
+
+  public static class PackageImportsFilter implements Filter
+  {
+    public PackageImportsFilter(
+        String packageName)
+    {
+      _packageName = packageName;
+    }
+
+    public boolean accept(
+        Object object)
+    {
+      String className = (String) object;
+      String packageName = Util.getPackageFromFullClass(className);
+      return (!packageName.equals(_packageName) &&
+          !packageName.equals("java.lang"));
+    }
+
+    private final String _packageName;
+  }
+
+  public static String getJspPropertyType(PropertyBean property, boolean is12)
+  {
+    if (property.isMethodExpression())
+      return "MethodExpression";
+
+    if (is12 && property.isMethodBinding())
+      return "MethodExpression";
+
+    if (is12 && !property.isLiteralOnly())
+      return "ValueExpression";
+    return "String";
+  }
+}

Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/GeneratorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/GeneratorHelper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java?view=auto&rev=481056
==============================================================================
--- incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,974 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadbuild.plugin.faces.generator.component;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.GeneratorHelper;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.*;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.PropertyFilter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.SourceTemplate;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
+
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public abstract class AbstractComponentGenerator implements ComponentGenerator
+{
+
+  private Log _log;
+  boolean _is12;
+
+  public AbstractComponentGenerator(Log log, boolean is12)
+  {
+    _log = log;
+    _is12 = is12;
+  }
+
+  protected Log getLog()
+  {
+    return _log;
+  }
+
+  public void writeClassBegin(
+      PrettyWriter out,
+      String className,
+      String superclassName,
+      ComponentBean component,
+      SourceTemplate template)
+  {
+    out.println("/**");
+
+    // TODO: restore description (needs escaping?)
+//    String description = component.getDescription();
+//    if (description != null)
+//    {
+//      out.println(" *");
+//      out.println(" * " + convertMultilineComment(description));
+//    }
+
+    String longDescription = component.getLongDescription();
+    if (longDescription != null)
+    {
+      out.println(" *");
+      out.println(" * " + convertMultilineComment(longDescription));
+    }
+
+    if (component.hasEvents(true))
+    {
+      // the events javadoc
+      out.println(" *");
+      out.println(" * <h4>Events:</h4>");
+      out.println(" * <table border=\"1\" width=\"100%\" cellpadding=\"3\" summary=\"\">");
+      out.println(" * <tr bgcolor=\"#CCCCFF\" class=\"TableHeadingColor\">");
+      out.println(" * <th align=\"left\">Type</th>");
+      out.println(" * <th align=\"left\">Phases</th>");
+      out.println(" * <th align=\"left\">Description</th>");
+      out.println(" * </tr>");
+      Iterator events = component.events(true);
+      while (events.hasNext())
+      {
+        EventRefBean eventRef = (EventRefBean) events.next();
+        EventBean event = eventRef.resolveEventType();
+        if (event != null)
+        {
+          String eventClass = event.getEventClass();
+          String[] eventPhases = eventRef.getEventDeliveryPhases();
+          String eventDescription = event.getDescription();
+          out.println(" * <tr class=\"TableRowColor\">");
+          out.println(" * <td valign=\"top\"><code>" + eventClass + "</code></td>");
+          out.print(" * <td valign=\"top\" nowrap>");
+          if (eventPhases != null)
+          {
+            for (int i = 0; i < eventPhases.length; i++)
+            {
+              if (i > 0)
+                out.print("<br>");
+              out.print(eventPhases[i]);
+            }
+          }
+          out.println("</td>");
+          out.println(" * <td valign=\"top\">" + eventDescription + "</td>");
+          out.println(" * </tr>");
+        }
+      }
+      out.println(" * </table>");
+    }
+
+    if (!component.hasChildren())
+    {
+      out.println(" * <p>");
+      out.println(" * It does not support any children.");
+    }
+
+    out.println(" */");
+
+    // TODO: eliminate <mfp:component-class-modifier> metadata
+    int modifiers = component.getComponentClassModifiers();
+    String classStart = Modifier.toString(modifiers);
+    // TODO: use canonical ordering
+    classStart = classStart.replaceAll("public abstract", "abstract public");
+    out.println(classStart + " class " + className +
+        " extends " + superclassName);
+
+    Set interfaces = new HashSet();
+    if (template != null)
+      interfaces.addAll(template.getImplements());
+
+    if (component.isNamingContainer())
+      interfaces.add("javax.faces.component.NamingContainer");
+
+    Iterator events = component.events();
+    while (events.hasNext())
+    {
+      EventRefBean eventRef = (EventRefBean) events.next();
+      EventBean event = eventRef.resolveEventType();
+      if (event != null)
+      {
+        if (!eventRef.isIgnoreSourceInterface())
+        {
+          String source = event.getEventSourceInterface();
+          if (source != null)
+            interfaces.add(Util.getClassFromFullClass(source));
+        }
+      }
+    }
+
+    if (!interfaces.isEmpty())
+    {
+      Set implementsSet = new HashSet();
+      for (Iterator iter = interfaces.iterator(); iter.hasNext();)
+      {
+        String fcqn = (String) iter.next();
+        implementsSet.add(Util.getClassFromFullClass(fcqn));
+      }
+
+      // implements clause spans multiple lines
+      char[] indent = new char[classStart.length() +
+          " class ".length() +
+          className.length() + 1];
+      Arrays.fill(indent, ' ');
+      out.print(indent);
+      out.print("implements ");
+      for (Iterator iter = implementsSet.iterator(); iter.hasNext();)
+      {
+        out.print((String) iter.next());
+        if (iter.hasNext())
+        {
+          out.println(",");
+          out.print(indent);
+          out.print("           ");  // same length as "implements "
+        }
+      }
+      out.println();
+    }
+
+    out.println("{");
+    out.indent();
+  }
+
+  public void writeClassEnd(
+      PrettyWriter out)
+  {
+    out.unindent();
+    out.println("}");
+  }
+
+
+  public void writeImports(PrettyWriter out, SourceTemplate template, String packageName, String fullSuperclassName,
+                           String superclassName, Collection components)
+  {
+    throw new UnsupportedOperationException("not implemented");
+  }
+
+  public void writeImports(
+      PrettyWriter out,
+      SourceTemplate template,
+      String packageName,
+      String fullSuperclassName,
+      String superclassName,
+      ComponentBean component)
+  {
+    Set imports = new TreeSet();
+
+    // Use the template imports
+    if (template != null)
+      imports.addAll(template.getImports());
+
+    // Detect NamingContainer
+    if (component.isNamingContainer())
+      imports.add("javax.faces.component.NamingContainer");
+
+    Iterator properties = component.properties();
+    properties = new FilteredIterator(properties, new NonVirtualFilter());
+    // PropertyKey only needed if there are properties
+    if (properties.hasNext())
+    {
+      while (properties.hasNext())
+      {
+        PropertyBean property = (PropertyBean) properties.next();
+        String propertyClass = property.getPropertyClass();
+        if (propertyClass != null)
+        {
+          imports.add(propertyClass);
+          // Check for generics
+          String[] types = property.getAttributeClassParameters();
+          if (types != null)
+          {
+            for (int i = types.length - 1; i >= 0; i--)
+            {
+              addGenericImports(imports, types[i]);
+            }
+          }
+        }
+      }
+    }
+
+    Iterator facets = component.facets();
+    // UIComponent needed if there are facets
+    if (facets.hasNext())
+      imports.add("javax.faces.component.UIComponent");
+
+    Iterator events = component.events();
+    while (events.hasNext())
+    {
+      EventRefBean eventRef = (EventRefBean) events.next();
+      EventBean event = eventRef.resolveEventType();
+
+      if (event == null)
+      {
+        getLog().warn("Unknown event type \"" + eventRef.getEventType() + "\"" +
+            " in component:" + component.getComponentType());
+      }
+      else
+      {
+        String listenerClass = event.getEventListenerClass();
+        if (listenerClass != null)
+          imports.add(listenerClass);
+
+        if (!eventRef.isIgnoreSourceInterface())
+        {
+          String sourceInterface = event.getEventSourceInterface();
+          if (sourceInterface != null)
+            imports.add(sourceInterface);
+        }
+      }
+    }
+
+    // Import causes a collision if className and superclassName are equal
+    if (!superclassName.equals(fullSuperclassName))
+    {
+      String superPackageName = Util.getPackageFromFullClass(fullSuperclassName);
+      // component superclass only needed if not in
+      // same package as component class
+      if (superPackageName != packageName)
+        imports.add(fullSuperclassName);
+    }
+
+    // add other imports (generator specific)
+    addSpecificImports(imports, component);
+
+    // do not import implicit types!
+    imports.removeAll(Util.PRIMITIVE_TYPES);
+
+    GeneratorHelper.writeImports(out, packageName, imports);
+  }
+
+  protected void addSpecificImports(
+      Set imports,
+      ComponentBean component)
+  {
+    // nothing by default
+  }
+
+  public void addGenericImports(Set imports, String type)
+  {
+    Matcher matcher = _GENERIC_TYPE.matcher(type);
+    if (matcher.matches())
+    {
+      // Generic type
+      imports.add(matcher.group(1));
+      String[] types = matcher.group(2).split(",");
+      for (int i = types.length - 1; i >= 0; i--)
+      {
+        addGenericImports(imports, types[i]);
+      }
+    }
+    else
+    {
+      // Non-generic type
+      imports.add(type);
+    }
+  }
+
+  public void writeGenericConstants(
+      PrettyWriter out,
+      String componentFamily,
+      String componentType) throws IOException
+  {
+    out.println();
+    out.println("static public final String COMPONENT_FAMILY =");
+    out.println("  \"" + componentFamily + "\";");
+    out.println("static public final String COMPONENT_TYPE =");
+    out.println("  \"" + componentType + "\";");
+  }
+
+  public void writePropertyConstants(
+      PrettyWriter out,
+      String superclassName,
+      ComponentBean component) throws IOException
+  {
+    // nothing
+  }
+
+  public void writePropertyValueConstants(
+      PrettyWriter out,
+      ComponentBean component) throws IOException
+  {
+    //  component property keys
+    Iterator properties = component.properties();
+    properties = new FilteredIterator(properties, new NonVirtualFilter());
+    while (properties.hasNext())
+    {
+      PropertyBean property = (PropertyBean) properties.next();
+      String[] propertyValues = property.getPropertyValues();
+
+      if (propertyValues != null)
+      {
+        String propName = property.getPropertyName();
+
+        for (int i = 0; i < propertyValues.length; i++)
+        {
+          String propValue = propertyValues[i];
+          String propValueName = propName +
+              Character.toUpperCase(propValue.charAt(0)) +
+              propValue.substring(1);
+          String propValueKey = Util.getConstantNameFromProperty(propValueName);
+
+          out.println("static public final String " + propValueKey + " = \"" + propValue + "\";");
+        }
+
+      }
+    }
+  }
+
+  public void writeFacetConstants(
+      PrettyWriter out,
+      ComponentBean component) throws IOException
+  {
+    Iterator facets = component.facets();
+    while (facets.hasNext())
+    {
+      FacetBean facet = (FacetBean) facets.next();
+      String facetName = facet.getFacetName();
+      String facetKey = Util.getConstantNameFromProperty(facetName, "_FACET");
+      out.println("static public final " +
+          "String " + facetKey + " = \"" + facetName + "\";");
+    }
+  }
+
+  protected String convertStringToBoxedLiteral(
+      String className,
+      String value)
+  {
+    if (value == null)
+    {
+      return null;
+    }
+    else if ("String".equals(className))
+    {
+      return "\"" + value.replaceAll("\'", "\\'") + "\"";
+    }
+    else if ("boolean".equals(className))
+    {
+      return ("true".equals(value)) ? "Boolean.TRUE" : "Boolean.FALSE";
+    }
+    else if ("char".equals(className))
+    {
+      return "new Character('" + value.replaceAll("\'", "\\'") + "')";
+    }
+    else if ("int".equals(className))
+    {
+      return "new Integer(" + value + ")";
+    }
+    else if ("float".equals(className))
+    {
+      return "new Float(" + value + ")";
+    }
+    else
+    {
+      throw new IllegalStateException();
+    }
+  }
+
+  public void writeConstructor(
+      PrettyWriter out,
+      ComponentBean component,
+      int modifiers) throws IOException
+  {
+    String fullClassName = component.getComponentClass();
+    String className = Util.getClassFromFullClass(fullClassName);
+
+    if (Modifier.isPublic(modifiers))
+    {
+      // TODO: eliminate this inconsistency
+      if (!Modifier.isAbstract(component.getComponentClassModifiers()))
+      {
+        String rendererType = component.getRendererType();
+
+        if (rendererType != null)
+          rendererType = convertStringToBoxedLiteral("String", rendererType);
+
+        out.println();
+        out.println("/**");
+        // TODO: restore this correctly phrased comment (tense vs. command)
+        //out.println(" * Constructs an instance of " + className + ".");
+        out.println(" * Construct an instance of the " + className + ".");
+        out.println(" */");
+        out.println("public " + className + "()");
+        out.println("{");
+        out.indent();
+
+        writeConstructorContent(out, component, modifiers, rendererType);
+
+        out.unindent();
+        out.println("}");
+      }
+    }
+    else if (Modifier.isProtected(modifiers))
+    {
+      out.println();
+      out.println("/**");
+      // TODO: restore this more descriptive comment with param docs
+      //out.println(" * Construct an instance of the " + className);
+      //out.println(" * with the specified renderer type.");
+      //out.println(" * ");
+      //out.println(" * @param rendererType  the renderer type");
+      out.println(" * Construct an instance of the " + className + ".");
+      out.println(" */");
+      out.println("protected " + className + "(");
+      out.indent();
+      out.println("String rendererType");
+      out.println(")");
+      out.unindent();
+      out.println("{");
+      out.indent();
+
+      writeConstructorContent(out, component, modifiers, "rendererType");
+
+      out.unindent();
+      out.println("}");
+
+      // TODO: eliminate this inconsistency
+      if (Modifier.isAbstract(component.getComponentClassModifiers()))
+      {
+        out.println();
+        out.println("/**");
+        // TODO: restore this correctly phrased comment (tense vs. command)
+        //out.println(" * Constructs an instance of " + className + ".");
+        out.println(" * Construct an instance of the " + className + ".");
+        out.println(" */");
+        out.println("protected " + className + "()");
+        out.println("{");
+        out.indent();
+        out.println("this(null);");
+        out.unindent();
+        out.println("}");
+      }
+    }
+  }
+
+  protected abstract void writeConstructorContent(
+      PrettyWriter out,
+      ComponentBean component,
+      int modifiers, String rendererType) throws IOException;
+
+  public void writeGetFamily(
+      PrettyWriter out) throws IOException
+  {
+    out.println();
+    out.println("@Override");
+    out.println("public String getFamily()");
+    out.println("{");
+    out.indent();
+    out.println("return COMPONENT_FAMILY;");
+    out.unindent();
+    out.println("}");
+  }
+
+  public void writePropertyMethods(
+      PrettyWriter out,
+      ComponentBean component) throws IOException
+  {
+    writePropertyMethods(out, component, null);
+  }
+
+
+  public void writePropertyMethods(PrettyWriter out, ComponentBean component, Collection ignoreList)
+      throws IOException
+  {
+    Iterator properties = component.properties();
+    properties = new FilteredIterator(properties, new NonVirtualFilter());
+    while (properties.hasNext())
+    {
+      PropertyBean property = (PropertyBean) properties.next();
+      if (property.isList())
+        writePropertyListMethods(out, property, ignoreList);
+      else
+      {
+        writePropertyDeclaration(out, property);
+        writePropertyGet(out, property, ignoreList);
+        writePropertySet(out, property, ignoreList);
+        if (GeneratorHelper.isValidator(property, _is12))
+        {
+          writePropertyListMethods(out, property, ignoreList);
+        }
+      }
+    }
+  }
+
+  abstract protected void writePropertyListMethods(
+      PrettyWriter out,
+      PropertyBean property,
+      Collection inoreList) throws IOException;
+
+  abstract protected void writePropertyListMethods(
+      PrettyWriter out,
+      PropertyBean property) throws IOException;
+
+  static protected String getSingular(String plural)
+  {
+    if (plural.endsWith("s"))
+      return plural.substring(0, plural.length() - 1);
+    return plural;
+  }
+
+  protected abstract void writePropertyDeclaration(
+      PrettyWriter out,
+      PropertyBean property) throws IOException;
+
+  protected void writePropertySet(
+      PrettyWriter out,
+      PropertyBean property,
+      Collection ignoreList) throws IOException
+  {
+    String propertyClass = Util.getPropertyClass(property);
+    writePropertySet(out, property, propertyClass, ignoreList);
+
+    if (property.getAlternateClass() != null)
+    {
+      String alternateClass = Util.getAlternatePropertyClass(property);
+      writePropertySet(out, property, alternateClass, ignoreList);
+    }
+  }
+
+  protected void writePropertySet(
+      PrettyWriter out,
+      PropertyBean property,
+      String propertyClass,
+      Collection ignoreList) throws IOException
+  {
+    String propName = property.getPropertyName();
+    String propVar = Util.getVariableFromName(propName);
+    String description = property.getDescription();
+    String setMethod = Util.getPrefixedPropertyName("set", propName);
+    if (ignoreList != null && ignoreList.contains(setMethod))
+    {
+      return;
+    }
+    out.println();
+    out.println("/**");
+    if (description != null)
+    {
+      out.println(" * Sets " + convertMultilineComment(description));
+    }
+
+    if (property.isRequired())
+    {
+      out.println(" * <p>");
+      out.println(" * This is a required property on the component.");
+    }
+    out.println(" * ");
+    out.println(" * @param " + Util.getVariableFromName(propName) + "  the new " + propName + " value");
+    if (property.isMethodBinding() && _is12)
+    {
+      out.println(" * @deprecated");
+    }
+    out.println(" */");
+
+    if (isAccessorMethodFinal())
+    {
+      out.print("final ");
+    }
+
+    out.println("public void " + setMethod + "(" + propertyClass + " " + propVar + ")");
+    out.println("{");
+    out.indent();
+    writePropertySetterMethodBody(out, property, propertyClass);
+    out.unindent();
+    out.println("}");
+  }
+
+  protected abstract void writePropertySetterMethodBody(
+      PrettyWriter out,
+      PropertyBean property,
+      String propertyClass) throws IOException;
+
+  protected void writePropertyGet(
+      PrettyWriter out,
+      PropertyBean property,
+      Collection ignoreList) throws IOException
+  {
+    String propName = property.getPropertyName();
+    String propertyFullClass = property.getPropertyClass();
+    String propertyClass = Util.getClassFromFullClass(propertyFullClass);
+    String description = property.getDescription();
+    String getMethod = Util.getMethodReaderFromProperty(propName, propertyClass);
+    if (ignoreList != null && ignoreList.contains(getMethod))
+    {
+      return;
+    }
+    boolean isUnchecked = false;
+    String[] genericTypes = property.getPropertyClassParameters();
+    if (genericTypes != null && genericTypes.length > 0)
+    {
+      isUnchecked = true;
+      propertyClass = Util.getPropertyClass(property);
+    }
+
+    out.println();
+    out.println("/**");
+    if (description != null)
+    {
+      out.println(" * Gets " + convertMultilineComment(description));
+    }
+    if (property.isRequired())
+    {
+      out.println(" * <p>");
+      out.println(" * This is a required property on the component.");
+      out.println(" * </p>");
+    }
+
+    out.println(" *");
+    out.println(" * @return  the new " + propName + " value");
+    if (property.isMethodBinding() && _is12)
+    {
+      out.println(" * @deprecated");
+    }
+    out.println(" */");
+
+    if (isUnchecked)
+    {
+      out.println("@SuppressWarnings(\"unchecked\")");
+    }
+
+    if (isAccessorMethodFinal())
+    {
+      out.print("final ");
+    }
+
+    out.println("public " + propertyClass + " " + getMethod + "()");
+    out.println("{");
+    out.indent();
+
+    writePropertyGetterMethodBody(out, property);
+
+    out.unindent();
+    out.println("}");
+  }
+
+  /**
+   * Whether the getters/setters have the final modifier
+   *
+   * @return true if the getters/setters are final
+   */
+  protected boolean isAccessorMethodFinal()
+  {
+    return false;
+  }
+
+  protected abstract void writePropertyGetterMethodBody(
+      PrettyWriter out,
+      PropertyBean property) throws IOException;
+
+  public void writeFacetMethods(
+      PrettyWriter out,
+      ComponentBean component) throws IOException
+  {
+    Iterator facets = component.facets();
+    while (facets.hasNext())
+    {
+      FacetBean facet = (FacetBean) facets.next();
+      writeFacetGet(out, facet);
+      writeFacetSet(out, facet);
+    }
+  }
+
+  public void writeFacetSet(
+      PrettyWriter out,
+      FacetBean facet) throws IOException
+  {
+    String facetName = facet.getFacetName();
+    // TODO: drop the unnecessary "Facet" suffix
+    String facetVar = facetName + "Facet";
+    String facetKey = Util.getConstantNameFromProperty(facetName, "_FACET");
+    String setMethod = Util.getPrefixedPropertyName("set", facetName);
+    String description = facet.getDescription();
+
+    out.println();
+    out.println("/**");
+    if (description != null)
+    {
+      out.println(" * " + convertMultilineComment(description));
+    }
+    if (facet.isRequired())
+    {
+      out.println(" * <p>");
+      out.println(" * This is a required facet on the component.");
+    }
+    // TODO: put this back in
+    //out.println(" * ");
+    //out.println(" * @param " + facetVar + "  the new " + facetName + " facet");
+    out.println(" */");
+
+    // Remove type safety warning since getFacets is not generics enabled
+    // under JSF 1.1 spec
+    // TODO: Remove this line when Trinidad switch to JSF 1.2
+    out.println("@SuppressWarnings(\"unchecked\")");
+
+    out.println("final public void " + setMethod + "(UIComponent " + facetVar + ")");
+    out.println("{");
+    out.indent();
+    out.println("getFacets().put(" + facetKey + ", " + facetVar + ");");
+    out.unindent();
+    out.println("}");
+  }
+
+  public void writeFacetGet(
+      PrettyWriter out,
+      FacetBean facet) throws IOException
+  {
+    String facetName = facet.getFacetName();
+    String facetKey = Util.getConstantNameFromProperty(facetName, "_FACET");
+    String getMethod = Util.getPrefixedPropertyName("get", facetName);
+    String description = facet.getDescription();
+
+    out.println();
+    out.println("/**");
+    if (description != null)
+    {
+      out.println(" * " + convertMultilineComment(description));
+    }
+    if (facet.isRequired())
+    {
+      out.println(" * <p>");
+      out.println(" * This is a required facet on the component.");
+    }
+    // TODO: put this back in
+    //out.println(" * ");
+    //out.println(" * @return  the " + facetName + " facet");
+    out.println(" */");
+
+    out.println("final public UIComponent " + getMethod + "()");
+    out.println("{");
+    out.indent();
+    out.println("return getFacet(" + facetKey + ");");
+    out.unindent();
+    out.println("}");
+  }
+
+  public void writeListenerMethods(
+      PrettyWriter out,
+      ComponentBean component) throws IOException
+  {
+    Iterator events = component.events();
+    while (events.hasNext())
+    {
+      EventRefBean eventRef = (EventRefBean) events.next();
+      EventBean event = eventRef.resolveEventType();
+      if (event != null)
+      {
+        writeListenerAdd(out, event);
+        writeListenerRemove(out, event);
+        writeListenersGet(out, event);
+      }
+    }
+  }
+
+  public void writeListenerAdd(
+      PrettyWriter out,
+      EventBean event) throws IOException
+  {
+    String listenerFullClass = event.getEventListenerClass();
+    String listenerClass = Util.getClassFromFullClass(listenerFullClass);
+
+    String eventName = event.getEventName();
+    String addMethod = Util.getMethodNameFromEvent("add", eventName, "Listener");
+
+    out.println();
+    out.println("/**");
+    out.println(" * Adds a " + eventName + " listener.");
+    out.println(" *");
+    out.println(" * @param listener  the " + eventName + " listener to add");
+    out.println(" */");
+
+    if (isAccessorMethodFinal())
+    {
+      out.print("final ");
+    }
+    out.println("public void " + addMethod + "(");
+    out.indent();
+    out.println(listenerClass + " listener)");
+    out.unindent();
+    out.println("{");
+    out.indent();
+    out.println("addFacesListener(listener);");
+    out.unindent();
+    out.println("}");
+  }
+
+  public void writeListenerRemove(
+      PrettyWriter out,
+      EventBean event) throws IOException
+  {
+    String listenerFullClass = event.getEventListenerClass();
+    String listenerClass = Util.getClassFromFullClass(listenerFullClass);
+
+    String eventName = event.getEventName();
+    String removeMethod = Util.getMethodNameFromEvent("remove", eventName, "Listener");
+
+    out.println();
+    out.println("/**");
+    out.println(" * Removes a " + eventName + " listener.");
+    out.println(" *");
+    out.println(" * @param listener  the " + eventName + " listener to remove");
+    out.println(" */");
+
+    if (isAccessorMethodFinal())
+    {
+      out.print("final ");
+    }
+    out.println("public void " + removeMethod + "(");
+    out.indent();
+    out.println(listenerClass + " listener)");
+    out.unindent();
+    out.println("{");
+    out.indent();
+    out.println("removeFacesListener(listener);");
+    out.unindent();
+    out.println("}");
+  }
+
+  public void writeListenersGet(
+      PrettyWriter out,
+      EventBean event) throws IOException
+  {
+    String listenerFullClass = event.getEventListenerClass();
+    String listenerClass = Util.getClassFromFullClass(listenerFullClass);
+
+    String eventName = event.getEventName();
+    String getMethod = Util.getMethodNameFromEvent("get", eventName, "Listeners");
+
+    out.println();
+    out.println("/**");
+    out.println(" * Returns an array of attached " + eventName + " listeners.");
+    out.println(" *");
+    out.println(" * @return  an array of attached " + eventName + " listeners.");
+    out.println(" */");
+
+    if (isAccessorMethodFinal())
+    {
+      out.print("final ");
+    }
+    out.println("public " + listenerClass + "[] " + getMethod + "()");
+    out.println("{");
+    out.indent();
+    out.println("return (" + listenerClass + "[])" +
+        "getFacesListeners(" + listenerClass + ".class);");
+    out.unindent();
+    out.println("}");
+  }
+
+
+  public abstract void writeStateManagementMethods(PrettyWriter out,
+                                                   ComponentBean component) throws IOException;
+
+  public void writeOther(
+      PrettyWriter out, ComponentBean component) throws IOException
+  {
+    // nothing
+  }
+
+  protected String convertMultilineComment(
+      String commentBody)
+  {
+    return commentBody.replaceAll("\n", "\n * ");
+  }
+
+  protected class ResolvableTypeFilter extends PropertyFilter
+  {
+    protected boolean accept(
+        PropertyBean property)
+    {
+      String propertyClass = property.getPropertyClass();
+      String resolvableType = resolveType(propertyClass);
+      return (resolvableType != null);
+    }
+  }
+
+  protected class NonVirtualFilter extends PropertyFilter
+  {
+    protected boolean accept(
+        PropertyBean property)
+    {
+      return (!property.isVirtual());
+    }
+  }
+
+  static protected String resolveType(
+      String className)
+  {
+    return (String) _RESOLVABLE_TYPES.get(className);
+  }
+
+
+  static private Map _createResolvableTypes()
+  {
+    Map resolvableTypes = new HashMap();
+
+    resolvableTypes.put("boolean", "Boolean");
+    resolvableTypes.put("char", "Character");
+    // TODO: put this back in
+    //resolvableTypes.put("java.util.Date", "Date");
+    resolvableTypes.put("int", "Integer");
+    resolvableTypes.put("float", "Float");
+    resolvableTypes.put("java.util.Locale", "Locale");
+    resolvableTypes.put("long", "Long");
+    resolvableTypes.put("java.lang.String", "String");
+    // TODO: put this back in
+    //resolvableTypes.put("java.lang.String[]", "StringArray");
+    resolvableTypes.put("java.util.TimeZone", "TimeZone");
+
+    return Collections.unmodifiableMap(resolvableTypes);
+  }
+
+  static private final Pattern _GENERIC_TYPE = Pattern.compile("([^<]+)<(.+)>");
+  static final private Map _RESOLVABLE_TYPES = _createResolvableTypes();
+}

Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message