You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ba...@apache.org on 2006/11/30 20:21:29 UTC
svn commit: r481056 [3/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/
Added: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/ComponentGenerator.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/ComponentGenerator.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/ComponentGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/ComponentGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,78 @@
+/*
+ * 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.myfaces.trinidadbuild.plugin.faces.generator.ClassGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * Generates component classes
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface ComponentGenerator extends ClassGenerator
+{
+
+ void writeGenericConstants(
+ PrettyWriter out,
+ String componentFamily,
+ String componentType) throws IOException;
+
+ void writePropertyConstants(
+ PrettyWriter out,
+ String superclassName,
+ ComponentBean component) throws IOException;
+
+ void writePropertyValueConstants(
+ PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeFacetConstants(
+ PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeGetFamily(
+ PrettyWriter out) throws IOException;
+
+ void writePropertyMethods(
+ PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeFacetMethods(
+ PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeListenerMethods(
+ PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeStateManagementMethods(
+ PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeOther(
+ PrettyWriter out, ComponentBean component) throws IOException;
+
+
+ void writePropertyMethods(PrettyWriter out,
+ ComponentBean component,
+ Collection ignoreList) throws IOException;
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/ComponentGenerator.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/ComponentGenerator.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/MyFacesComponentGenerator.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/MyFacesComponentGenerator.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/MyFacesComponentGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,440 @@
+/*
+ * 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.ComponentBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Component generator for MyFaces
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class MyFacesComponentGenerator extends AbstractComponentGenerator
+{
+
+ public MyFacesComponentGenerator(Log log, boolean is12)
+ {
+ super(log, is12);
+ }
+
+
+ protected void addSpecificImports(Set imports, ComponentBean component)
+ {
+ imports.add("javax.faces.context.FacesContext");
+ imports.add("javax.el.ValueExpression");
+ for (Iterator lIterator = component.properties(); lIterator.hasNext();)
+ {
+ PropertyBean lPropertyBean = (PropertyBean) lIterator.next();
+ if (GeneratorHelper.isValidator(lPropertyBean, _is12))
+ {
+ imports.add("javax.faces.validator.Validator");
+ imports.add("java.util.ArrayList");
+ imports.add("java.util.List");
+ break;
+ }
+ }
+ }
+
+ public void writePropertyDeclaration(PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ String propName = property.getPropertyName();
+ String fieldPropName = property.getFieldPropertyName();
+ String propertyFullClass = property.getPropertyClass();
+ String propertyClass = Util.getClassFromFullClass(propertyFullClass);
+ String propertyGenerics = Util.getGenericsFromProperty(property);
+ String def = Util.getDefaultValue(property);
+
+ out.println();
+ out.println("// Property: " + propName);
+ out.println("private " + propertyClass + propertyGenerics + " " +
+ fieldPropName + (def == null ? ";" : " = " + def + ";"));
+
+ if (Util.isPrimitiveClass(propertyFullClass) && !property.isTagAttributeExcluded())
+ {
+ out.println("private boolean " + fieldPropName + "Set;");
+ }
+ }
+
+ public void writeStateManagementMethods(PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ if (!component.hasProperties())
+ {
+ return;
+ }
+
+ writeSaveState(out, component);
+ writeRestoreState(out, component);
+ }
+
+ public void writePropertyListMethods(
+ PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ // nothing
+ }
+
+ protected void writeConstructorContent(PrettyWriter out, ComponentBean component, int modifiers, String rendererType) throws IOException
+ {
+ out.println("setRendererType(" + rendererType + ");");
+ }
+
+ protected void writePropertyListMethods(PrettyWriter out, PropertyBean property, Collection ignoreList)
+ {
+ String propName = property.getPropertyName();
+ String generic;
+ String type;
+ boolean isValidator = GeneratorHelper.isValidator(property, _is12);
+ if (isValidator)
+ {
+ generic = "<Validator>";
+ type = "Validator";
+ }
+ else if (property.getAttributeClassParameters().length == 1)
+ {
+ generic = Util.getGenericsFromProperty(property);
+ type = Util.getClassFromFullClass(property.getAttributeClassParameters()[0]);
+ }
+ else
+ {
+ throw new IllegalArgumentException("only one Generic Parameter is allowed for Lists");
+ }
+
+ String singularName = getSingular(propName);
+ String propVar = Util.getVariableFromName(singularName);
+ String description = property.getDescription();
+ String addMethod = Util.getPrefixedPropertyName("add", singularName);
+ String removeMethod = Util.getPrefixedPropertyName("remove", singularName);
+ String getMethod = Util.getPrefixedPropertyName("get", singularName + "s");
+ String fieldPropName = property.getFieldPropertyName() + (isValidator ? "List" : "");
+
+ out.println();
+ out.println("// Property: " + propName);
+ out.println("private List" + generic + " " + fieldPropName + ";");
+ if (ignoreList == null || !ignoreList.contains(addMethod))
+ {
+ out.println();
+ out.println("/**");
+ if (description != null)
+ {
+ out.println(" * Adds a " + convertMultilineComment(description));
+ }
+ out.println(" */");
+ out.println("public void " + addMethod + "( " + type + " " +
+ propVar + ")");
+ out.println("{");
+ out.indent();
+ out.println("if (" + propVar + " == null) throw new NullPointerException(\"" + propVar + "\");");
+ out.println("if (" + fieldPropName + " == null)");
+ out.println(" " + fieldPropName + " = new ArrayList" + generic + "();");
+ out.println();
+ out.println(fieldPropName + ".add(" + propVar + ");");
+ out.unindent();
+ out.println("}");
+ }
+
+ if (ignoreList == null || !ignoreList.contains(removeMethod))
+ {
+ out.println();
+ out.println("/**");
+ if (description != null)
+ {
+ out.println(" * Removes a " + convertMultilineComment(description));
+ }
+ out.println(" */");
+ out.println("public void " + removeMethod + "( " + type + " " + propVar + ")");
+ out.println("{");
+ out.indent();
+ out.println("if (" + propVar + " == null || " + fieldPropName + " == null)");
+ out.println(" return;");
+ out.println();
+ out.println(fieldPropName + ".remove(" + propVar + ");");
+ out.unindent();
+ out.println("}");
+ }
+
+ if (ignoreList == null || !ignoreList.contains(getMethod))
+ {
+ if (isValidator)
+ {
+ out.println("private static final " + type + "[] EMPTY_" + type.toUpperCase() + "_ARRAY = new " + type + "[0];");
+ }
+ out.println();
+ out.println("/**");
+ if (description != null)
+ {
+ out.println(" * Gets all " + convertMultilineComment(description));
+ }
+ out.println(" */");
+ if (isValidator)
+ {
+ out.println("public " + type + "[] " + getMethod + "()");
+ }
+ else
+ {
+ out.println("public List" + generic + " " + getMethod + "()");
+ }
+ out.println("{");
+ out.indent();
+ if (isValidator)
+ {
+ out.println("return " + fieldPropName + "== null? EMPTY_" + type.toUpperCase() + "_ARRAY : " + fieldPropName + ".toArray(new " + type + "[" + fieldPropName + ".size()]);");
+ }
+ else
+ {
+ out.println("if (" + fieldPropName + " == null)");
+ out.indent();
+ out.println(fieldPropName + " = new ArrayList<" + type + ">();");
+ out.unindent();
+ out.println("return " + fieldPropName + ";");
+ }
+ out.unindent();
+ out.println("}");
+ }
+ }
+
+ protected void writePropertySetterMethodBody(PrettyWriter out,
+ PropertyBean property,
+ String propertyClass) throws IOException
+ {
+ String varName = property.getFieldPropertyName();
+ String propVar = Util.getVariableFromName(property.getPropertyName());
+
+ out.println("this." + varName + " = " + propVar + ";");
+
+ if (Util.isPrimitiveClass(propertyClass) && !property.isTagAttributeExcluded())
+ {
+ out.println("this." + _primitiveSetVarName(varName) + " = true;");
+ }
+ }
+
+ protected void writePropertyGetterMethodBody(PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ String varName = property.getFieldPropertyName();
+ String propVar = Util.getVariableFromName(property.getPropertyName());
+ String propFullClass = property.getPropertyClass();
+ String propClass = Util.getClassFromFullClass(propFullClass);
+ if (property.isTagAttributeExcluded())
+ {
+ out.println("return " + property.getFieldPropertyName() + ";");
+ }
+ else
+ {
+ if (Util.isPrimitiveClass(propFullClass))
+ {
+ out.println("if (" + _primitiveSetVarName(varName) + ")");
+ }
+ else
+ {
+ out.println("if (" + varName + " != null)");
+ }
+ out.println("{");
+ out.indent();
+ out.println("return " + property.getFieldPropertyName() + ";");
+ out.unindent();
+ out.println("}");
+ out.println("ValueExpression expression = getValueExpression(\"" + propVar + "\");");
+ out.println("if (expression != null)");
+ out.println("{");
+ out.indent();
+ out.println("return " + _castIfNecessary(propClass) + "expression.getValue(getFacesContext().getELContext());");
+ out.unindent();
+ out.println("}");
+
+ String ret = Util.getDefaultValue(property);
+ if (null != ret)
+ {
+ out.println("return " + ret + ";");
+ }
+ else if (Util.isPrimitiveClass(propFullClass))
+ {
+ out.println("return " + Util.primitiveDefaultValue(propFullClass) + ";");
+ }
+ else
+ {
+ out.println("return null;");
+ }
+ }
+ }
+
+ protected void writeSaveState(PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ String arrayName = "values";
+
+ // first we count the primitive properties, because for each primitive property
+ // we save a new property that says if the property has been set or not
+ int primitivePropertiesCount = 0;
+ for (Iterator iterator = component.properties(); iterator.hasNext();)
+ {
+ PropertyBean property = (PropertyBean) iterator.next();
+ if (Util.isPrimitiveClass(property.getPropertyClass()))
+ {
+ primitivePropertiesCount++;
+ }
+ }
+
+ // the total array size is the number of properties, plus the number of primitives,
+ // plus 1 (the super call)
+ int arraySize = component.propertiesSize() + primitivePropertiesCount + 1;
+
+ out.println();
+ out.println("@Override");
+ out.println("public Object saveState(FacesContext facesContext)");
+ out.println("{");
+ out.indent();
+ out.println("Object[] " + arrayName + " = new Object[" + arraySize + "];");
+
+ out.println(arrayName + "[" + 0 + "] = super.saveState(facesContext);");
+
+ int propIndex = 1;
+
+ for (Iterator iterator = component.properties(); iterator.hasNext();)
+ {
+ PropertyBean property = (PropertyBean) iterator.next();
+ String varName = property.getFieldPropertyName();
+
+ if (property.isStateHolder())
+ {
+ if (GeneratorHelper.isValidator(property, _is12))
+ {
+ out.println(arrayName + "[" + ++propIndex + "] = saveAttachedState(facesContext, " + varName + "List);");
+ }
+ else if (property.isList())
+ {
+ out.println(arrayName + "[" + ++propIndex + "] = saveAttachedState(facesContext, " + varName + ");");
+ }
+ else
+ {
+ out.println(arrayName + "[" + propIndex + "] = saveAttachedState(facesContext, " + varName + ");");
+ }
+ }
+ else
+ {
+ out.println(arrayName + "[" + propIndex + "] = " + varName + ";");
+ }
+
+ propIndex++;
+
+ if (Util.isPrimitiveClass(property.getPropertyClass()) && !property.isTagAttributeExcluded())
+ {
+ out.println(arrayName + "[" + propIndex + "] = " + _primitiveSetVarName(varName) + ";");
+ propIndex++;
+ }
+ }
+
+ out.println();
+ out.println("return " + arrayName + ";");
+ out.unindent();
+ out.println("}");
+ }
+
+ protected void writeRestoreState(PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ String arrayName = "values";
+
+ out.println();
+ out.println("@Override");
+ out.println("public void restoreState(FacesContext facesContext, Object state)");
+ out.println("{");
+ out.indent();
+
+ out.println("Object[] " + arrayName + " = (Object[])state;");
+ out.println("super.restoreState(facesContext," + arrayName + "[0]);");
+
+ int propIndex = 1;
+
+ for (Iterator iterator = component.properties(); iterator.hasNext();)
+ {
+ PropertyBean property = (PropertyBean) iterator.next();
+
+ String varName = property.getFieldPropertyName();
+ String propFullClass = property.getPropertyClass();
+ String propClass = Util.getClassFromFullClass(propFullClass);
+
+ if (property.isStateHolder())
+ {
+ if (GeneratorHelper.isValidator(property, _is12))
+ {
+ out.println(varName + "List = (List<Validator>) restoreAttachedState(facesContext, "
+ + arrayName + "[" + ++propIndex + "]);");
+ }
+ else if (property.isList())
+ {
+ out.println(varName + " = (List) restoreAttachedState(facesContext, "
+ + arrayName + "[" + ++propIndex + "]);");
+ }
+ else
+ {
+ out.println(varName + " = " + _castIfNecessary(propClass) + "restoreAttachedState(facesContext, "
+ + arrayName + "[" + propIndex + "]);");
+ }
+
+ }
+ else
+ {
+ out.println(varName + " = " + _castIfNecessary(propClass)
+ + arrayName + "[" + propIndex + "];");
+ }
+
+ propIndex++;
+
+ if (Util.isPrimitiveClass(property.getPropertyClass()) && !property.isTagAttributeExcluded())
+ {
+ out.println(_primitiveSetVarName(varName) + " = (Boolean)"
+ + arrayName + "[" + propIndex + "];");
+ propIndex++;
+ }
+ }
+
+ out.unindent();
+ out.println("}");
+ }
+
+ private static String _castIfNecessary(String propClass)
+ {
+ if (propClass.equals("Object") || propClass.equals("java.lang.Object"))
+ {
+ return "";
+ }
+
+ if (Util.isPrimitiveClass(propClass))
+ {
+ propClass = Util.getBoxedClass(propClass);
+ }
+
+ return "(" + propClass + ")";
+ }
+
+ private static String _primitiveSetVarName(String varName)
+ {
+ return varName + "Set";
+ }
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.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/MyFacesComponentGenerator.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/TrinidadComponentGenerator.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/TrinidadComponentGenerator.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/TrinidadComponentGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,399 @@
+/*
+ * 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.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+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.Util;
+
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.util.*;
+
+public class TrinidadComponentGenerator extends AbstractComponentGenerator
+{
+ public TrinidadComponentGenerator(Log log, boolean is12)
+ {
+ super(log, is12);
+ }
+
+ protected void addSpecificImports(Set imports, ComponentBean component)
+ {
+ // FacesBean is always needed to define the TYPE
+
+ imports.add("org.apache.myfaces.trinidad.bean.FacesBean");
+
+ Iterator properties = component.properties();
+ properties = new FilteredIterator(properties, new NonVirtualFilter());
+ // PropertyKey only needed if there are properties
+ if (properties.hasNext())
+ {
+ imports.add("org.apache.myfaces.trinidad.bean.PropertyKey");
+
+ PropertyFilter resolvable = new ResolvableTypeFilter();
+ while (properties.hasNext())
+ {
+ PropertyBean property = (PropertyBean) properties.next();
+
+ // ComponentUtils only needed for resolvable properties
+ if (resolvable.accept(property))
+ imports.add("org.apache.myfaces.trinidad.util.ComponentUtils");
+ }
+ }
+ }
+
+ protected void writeConstructorContent(PrettyWriter out,
+ ComponentBean component,
+ int modifiers,
+ String rendererType) throws IOException
+ {
+ out.println("super(" + rendererType + ");");
+ }
+
+ protected void writePropertyListMethods(PrettyWriter out, PropertyBean property, Collection gnoreList)
+ {
+ // nothing
+ }
+
+ public void writePropertyConstants(
+ PrettyWriter out,
+ String superclassName,
+ ComponentBean component) throws IOException
+ {
+ out.println("static public final FacesBean.Type TYPE = new FacesBean.Type(");
+ out.indent();
+ out.println(superclassName + ".TYPE);");
+ out.unindent();
+
+ // component property keys
+ Iterator properties = component.properties();
+ properties = new FilteredIterator(properties, new NonVirtualFilter());
+ while (properties.hasNext())
+ {
+ PropertyBean property = (PropertyBean) properties.next();
+ String propName = property.getPropertyName();
+ String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+ String propAlias = property.getAliasOf();
+
+ out.println("static public final PropertyKey " + propKey + " =");
+ out.indent();
+ if (propAlias != null)
+ {
+ String aliasKey = Util.getConstantNameFromProperty(propAlias, "_KEY");
+ out.print("TYPE.registerAlias(" + aliasKey + ", \"" + propName + "\");");
+ }
+ else
+ {
+ out.print("TYPE.registerKey(\"" + propName + "\"");
+
+ // property class
+ String propFullClass = property.getPropertyClass();
+ String propClass = Util.getClassFromFullClass(propFullClass);
+ if (propClass == null)
+ {
+ propClass = "String";
+ }
+ String propDefault = property.getDefaultValue();
+
+ if (!"Object".equals(propClass) || propDefault != null)
+ {
+ // TODO: do not use boxed class here
+ String boxedClass = Util.getBoxedClass(propClass);
+ out.print(", " + boxedClass + ".class");
+ }
+
+ if (propDefault != null)
+ {
+ out.print(", " + convertStringToBoxedLiteral(propClass, propDefault));
+ }
+
+ // property capabilities
+ String propCaps = _getPropertyCapabilities(property);
+ if (propCaps != null)
+ out.print(", " + propCaps);
+ out.println(");");
+ }
+ out.unindent();
+ }
+ }
+
+ protected void writePropertyDeclaration(PrettyWriter out, PropertyBean property) throws IOException
+ {
+ // nothing by default
+ }
+
+
+ /**
+ * Whether the getters/setters have the final modifier
+ *
+ * @return true if the getters/setters are final
+ */
+ protected boolean isAccessorMethodFinal()
+ {
+ return true;
+ }
+
+ protected void writePropertySetterMethodBody(PrettyWriter out,
+ PropertyBean property,
+ String propertyClass) throws IOException
+ {
+ String propName = property.getPropertyName();
+ String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+ String propVar = Util.getVariableFromName(propName);
+
+ if (Util.isPrimitiveClass(propertyClass))
+ {
+ // TODO: use UIXComponentBase setXXXProperty methods when possible
+ if (propertyClass.equals("boolean"))
+ {
+ // TODO: add back space before ternary operator
+ out.println("setProperty(" + propKey + ", " + propVar + "? Boolean.TRUE : Boolean.FALSE);");
+ }
+ else
+ {
+ String boxedClass = Util.getBoxedClass(propertyClass);
+ out.println("setProperty(" + propKey + ", new " + boxedClass + "(" + propVar + "));");
+ }
+ }
+ else
+ {
+ out.println("setProperty(" + propKey + ", (" + propVar + "));");
+ }
+ }
+
+ protected void writePropertyGetterMethodBody(
+ PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ String propName = property.getPropertyName();
+ String propertyFullClass = property.getPropertyClass();
+ String propertyClass = Util.getClassFromFullClass(propertyFullClass);
+ String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+
+ String resolvableType = resolveType(propertyFullClass);
+
+ if (resolvableType != null)
+ {
+ // TODO: change signature of ComponentUtils.resolveCharacter
+ // to take Object instead of Character
+ if (resolvableType.equals("Character"))
+ {
+ out.println("return ComponentUtils.resolveCharacter((Character)getProperty(" + propKey + "));");
+ }
+ else
+ {
+ // TODO: stop specifying default values in the getters
+ String resolveMethod = Util.getPrefixedPropertyName("resolve", resolvableType);
+ String propertyDefault = property.getDefaultValue();
+ out.print("return ComponentUtils." + resolveMethod + "(getProperty(" + propKey + ")");
+ if (propertyDefault != null)
+ {
+ out.print(", " + Util.convertStringToLiteral(propertyClass,
+ propertyDefault));
+ }
+ out.println(");");
+ }
+ }
+ else
+ {
+ if (propertyClass.equals("Object"))
+ {
+ // Cast is not necessary if the property class is Object
+ out.println("return getProperty(" + propKey + ");");
+ }
+ else
+ {
+ out.println("return (" + propertyClass + ")" +
+ "getProperty(" + propKey + ");");
+ }
+ }
+ }
+
+ public void writeStateManagementMethods(PrettyWriter out, ComponentBean component) throws IOException
+ {
+ // nothing to do here
+ }
+
+ public void writePropertyListMethods(
+ PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ String propName = property.getPropertyName();
+ String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+ String propertyClass = property.getPropertyClass();
+ if (!"java.util.List".equals(propertyClass))
+ {
+ getLog().error("Invalid list type: " + propertyClass);
+ return;
+ }
+
+ // Look for the generic type - if it doesn't exist, then
+ // we'll be an Object.
+ String[] params = property.getPropertyClassParameters();
+ if ((params == null) || (params.length == 0))
+ propertyClass = "java.lang.Object";
+ else
+ propertyClass = params[0];
+
+ propertyClass = Util.getClassFromFullClass(propertyClass);
+
+ String singularName = getSingular(propName);
+ String propVar = Util.getVariableFromName(singularName);
+ String description = property.getDescription();
+ String addMethod = Util.getPrefixedPropertyName("add", singularName);
+ String removeMethod = Util.getPrefixedPropertyName("remove", singularName);
+ String getMethod = Util.getPrefixedPropertyName("get", propName);
+
+ out.println();
+ out.println("/**");
+ if (description != null)
+ {
+ out.println(" * Adds a " + convertMultilineComment(description));
+ }
+ out.println(" */");
+ out.println("final public void " + addMethod + "(" + propertyClass + " " +
+ propVar + ")");
+ out.println("{");
+ out.indent();
+ out.println("if (" + propVar + " == null)");
+ out.println(" throw new NullPointerException();");
+ out.println();
+ out.println("getFacesBean().addEntry(" + propKey + ", " + propVar + ");");
+ out.unindent();
+ out.println("}");
+
+ out.println();
+ out.println("/**");
+ if (description != null)
+ {
+ out.println(" * Removes a " + convertMultilineComment(description));
+ }
+ out.println(" */");
+ out.println("final public void " + removeMethod + "(" + propertyClass + " " +
+ propVar + ")");
+ out.println("{");
+ out.indent();
+ out.println("if (" + propVar + " == null)");
+ out.println(" throw new NullPointerException();");
+ out.println();
+ out.println("getFacesBean().removeEntry(" + propKey + ", " + propVar + ");");
+ out.unindent();
+ out.println("}");
+
+ out.println();
+ out.println("/**");
+ if (description != null)
+ {
+ out.println(" * Gets all " + convertMultilineComment(description));
+ }
+ out.println(" */");
+ out.println("final public " + propertyClass + "[] " + getMethod + "()");
+ out.println("{");
+ out.indent();
+ out.println("return (" + propertyClass + "[]) getFacesBean().getEntries(");
+ out.println(" " + propKey + ", " + propertyClass + ".class);");
+ out.unindent();
+ out.println("}");
+ }
+
+ public void writeOther(PrettyWriter out, ComponentBean component) throws IOException
+ {
+ _writeGetBeanType(out);
+
+ writeConstructor(out, component, Modifier.PROTECTED);
+
+ _writeTypeLock(out, component);
+ }
+
+ protected void _writeGetBeanType(
+ PrettyWriter out) throws IOException
+ {
+ out.println();
+ out.println("@Override");
+ out.println("protected FacesBean.Type getBeanType()");
+ out.println("{");
+ out.indent();
+ out.println("return TYPE;");
+ out.unindent();
+ out.println("}");
+ }
+
+ private void _writeTypeLock(
+ PrettyWriter out, ComponentBean component) throws IOException
+ {
+ out.println();
+ out.println("static");
+ out.println("{");
+ out.indent();
+ String rendererType = component.getRendererType();
+ if (rendererType == null)
+ {
+ out.println("TYPE.lock();");
+ }
+ else
+ {
+ String componentFamily = component.findComponentFamily();
+ out.println("TYPE.lockAndRegister(\"" + componentFamily + "\"," +
+ "\"" + rendererType + "\");");
+ }
+
+ out.unindent();
+ out.println("}");
+ }
+
+ private String _getPropertyCapabilities(
+ PropertyBean property)
+ {
+ List caps = new ArrayList();
+
+ if (property.isMethodBinding() ||
+ property.isLiteralOnly())
+ {
+ caps.add("PropertyKey.CAP_NOT_BOUND");
+ }
+
+ if (property.isStateHolder())
+ {
+ caps.add("PropertyKey.CAP_STATE_HOLDER");
+ }
+
+ if (property.isTransient())
+ {
+ caps.add("PropertyKey.CAP_TRANSIENT");
+ }
+
+ if (property.isList())
+ {
+ caps.add("PropertyKey.CAP_LIST");
+ }
+
+ if (caps.isEmpty())
+ return null;
+
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < caps.size(); i++)
+ {
+ if (i > 0)
+ sb.append(" | ");
+ sb.append(caps.get(i));
+ }
+ return sb.toString();
+ }
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.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/TrinidadComponentGenerator.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/taglib/AbstractComponentTagGenerator.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/taglib/AbstractComponentTagGenerator.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/taglib/AbstractComponentTagGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/AbstractComponentTagGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,275 @@
+/*
+ * 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.taglib;
+
+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.ComponentBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator;
+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.*;
+
+/**
+ * TODO: comment this!
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractComponentTagGenerator implements ComponentTagGenerator
+{
+
+ public void writeImports(PrettyWriter out,
+ SourceTemplate template,
+ String packageName,
+ String fullSuperclassName,
+ String superclassName,
+ ComponentBean component)
+ {
+ Collection components = new HashSet();
+ components.add(component);
+ writeImports(out, template, packageName, fullSuperclassName, superclassName, components);
+ }
+
+
+ public void writeImports(PrettyWriter out, SourceTemplate template, String packageName, String fullSuperclassName,
+ String superclassName, Collection components)
+ {
+ Set imports = new TreeSet();
+
+ for (Iterator lIterator = components.iterator(); lIterator.hasNext();)
+ {
+ ComponentBean component = (ComponentBean) lIterator.next();
+ Iterator properties = component.properties();
+ properties = new FilteredIterator(properties, new TagAttributeFilter());
+
+ // 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 propertyClass = property.getPropertyClass();
+ String[] propertyClassParams = property.getPropertyClassParameters();
+
+ 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);
+ }
+
+ // 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");
+ //}
+ addSpecificImports(imports, component);
+
+ }
+
+ }
+ // do not import implicit!
+ imports.removeAll(Util.PRIMITIVE_TYPES);
+
+ GeneratorHelper.writeImports(out, packageName, imports);
+ }
+
+ public void writeClassBegin(PrettyWriter out,
+ String className,
+ String superclassName,
+ ComponentBean component,
+ SourceTemplate template)
+ {
+ int modifiers = component.getTagClassModifiers();
+ String classStart = Modifier.toString(modifiers);
+
+ 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();
+ }
+
+
+ public void writeConstructor(PrettyWriter out,
+ ComponentBean component,
+ int modifiers) 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("}");
+ }
+
+ public void writeGetComponentType(
+ PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ String componentType = component.getComponentType();
+ out.println();
+
+ // The superclass does not necessarily need to have this method
+ //out.println("@Override");
+ out.println("public String getComponentType()");
+ out.println("{");
+ out.indent();
+ out.println("return \"" + componentType + "\";");
+ out.unindent();
+ out.println("}");
+ }
+
+ public void writeGetRendererType(
+ PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ String rendererType = component.getRendererType();
+ out.println();
+
+ // The superclass does not necessarily need to have this method
+ //out.println("@Override");
+ out.println("public String getRendererType()");
+ out.println("{");
+ out.indent();
+ out.println("return " + Util.convertStringToLiteral(rendererType) + ";");
+ out.unindent();
+ out.println("}");
+ }
+
+ public void writeClassEnd(PrettyWriter out)
+ {
+ out.unindent();
+ out.println("}");
+ }
+
+ public void writePropertyMembers(PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ Iterator properties = component.properties();
+ properties = new FilteredIterator(properties, new TagAttributeFilter());
+
+ while (properties.hasNext())
+ {
+ PropertyBean property = (PropertyBean) properties.next();
+ writePropertyDeclaration(out, property);
+ writePropertySetter(out, property);
+ }
+ }
+
+
+ public void writePropertyMembers(PrettyWriter out, Collection components) throws IOException
+ {
+ for (Iterator lIterator = components.iterator(); lIterator.hasNext();)
+ {
+ writePropertyMembers(out, (ComponentBean) lIterator.next());
+ }
+ }
+
+ public void writeReleaseMethod(PrettyWriter out,
+ ComponentBean component) throws IOException
+ {
+ Collection components = new HashSet();
+ components.add(component);
+ writeReleaseMethod(out, components);
+ }
+
+
+ public void writeReleaseMethod(PrettyWriter out, Collection components) throws IOException
+ {
+ Collection all = new HashSet();
+ boolean special = false;
+ for (Iterator lIterator = components.iterator(); lIterator.hasNext();)
+ {
+ ComponentBean component = (ComponentBean) lIterator.next();
+ Iterator prop = component.properties();
+ // TODO: remove special case for UIXFormTag
+ special |= "org.apache.myfaces.trinidadinternal.taglib.UIXFormTag".equals(component.getTagClass());
+ while (prop.hasNext())
+ {
+ all.add(prop.next());
+ }
+ }
+
+ Iterator properties = all.iterator();
+ properties = new FilteredIterator(properties, new TagAttributeFilter());
+ if (properties.hasNext() || special)
+ {
+ 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 = "_" + propName;
+ out.println(propVar + " = null;");
+ }
+ out.unindent();
+ out.println("}");
+ }
+ }
+
+ protected void addSpecificImports(
+ Set imports,
+ ComponentBean component)
+ {
+ // nothing by default
+ }
+
+ protected abstract void writePropertyDeclaration(PrettyWriter out,
+ PropertyBean property) throws IOException;
+
+ protected abstract void writePropertySetter(PrettyWriter out,
+ PropertyBean property) throws IOException;
+
+ protected abstract void writeSetPropertyMethodBody(PrettyWriter out,
+ String componentClass,
+ Iterator properties) throws IOException;
+
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/AbstractComponentTagGenerator.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/taglib/AbstractComponentTagGenerator.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/taglib/ComponentTagGenerator.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/taglib/ComponentTagGenerator.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/taglib/ComponentTagGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/ComponentTagGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.taglib;
+
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.ClassGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * Generates tag classes
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface ComponentTagGenerator extends ClassGenerator
+{
+
+ void writeSetPropertiesMethod(PrettyWriter out,
+ String componentClass,
+ ComponentBean component) throws IOException;
+
+ void writeSetPropertiesMethod(PrettyWriter out,
+ String componentClass,
+ Collection components) throws IOException;
+
+ void writeReleaseMethod(PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeReleaseMethod(PrettyWriter out,
+ Collection components) throws IOException;
+
+ void writeGetComponentType(PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writeGetRendererType(PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writePropertyMembers(PrettyWriter out,
+ ComponentBean component) throws IOException;
+
+ void writePropertyMembers(PrettyWriter out,
+ Collection components) throws IOException;
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/ComponentTagGenerator.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/taglib/ComponentTagGenerator.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/taglib/MyFacesComponentTagGenerator.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/taglib/MyFacesComponentTagGenerator.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/taglib/MyFacesComponentTagGenerator.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/MyFacesComponentTagGenerator.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,539 @@
+/*
+ * 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.taglib;
+
+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.ComponentBean;
+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.util.FilteredIterator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Component tag generator for myfaces
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class MyFacesComponentTagGenerator extends AbstractComponentTagGenerator
+{
+ private boolean _is12;
+
+ public MyFacesComponentTagGenerator(boolean is12)
+ {
+ _is12 = is12;
+ }
+
+ protected void addSpecificImports(Set imports,
+ ComponentBean component)
+ {
+ imports.add("javax.faces.component.UIComponent");
+ imports.add(component.getComponentClass());
+
+ if (_is12)
+ {
+ imports.add("javax.el.ValueExpression");
+ }
+
+ Iterator properties = component.properties();
+ properties = new FilteredIterator(properties, new TagAttributeFilter());
+
+ while (properties.hasNext())
+ {
+ PropertyBean property = (PropertyBean) properties.next();
+ String propertyClass = property.getPropertyClass();
+
+ if (GeneratorHelper.isConverter(propertyClass))
+ {
+ if (!_is12)
+ {
+ imports.add("javax.faces.el.ValueBinding");
+ }
+ imports.add("javax.faces.convert.Converter");
+ }
+ else if (property.isMethodBinding())
+ {
+ if (_is12)
+ {
+ imports.add("javax.el.MethodExpression");
+ if (GeneratorHelper.isActionListener(property, _is12))
+ {
+ imports.add("javax.faces.event.MethodExpressionActionListener");
+ }
+ if (GeneratorHelper.isValueChangeListener(property, _is12))
+ {
+ imports.add("javax.faces.event.MethodExpressionValueChangeListener");
+ }
+ if (GeneratorHelper.isValidator(property, _is12))
+ {
+ imports.add("javax.faces.validator.MethodExpressionValidator");
+ }
+ }
+ else
+ {
+ imports.add("javax.faces.el.MethodBinding");
+ }
+ }
+ else if (property.isMethodExpression())
+ {
+ imports.add("javax.el.MethodExpression");
+ }
+ else if (GeneratorHelper.isActionListener(property, _is12))
+ {
+ imports.add("javax.faces.event.MethodExpressionActionListener");
+ }
+ else if (GeneratorHelper.isValueChangeListener(property, _is12))
+ {
+ imports.add("javax.faces.event.MethodExpressionValueChangeListener");
+ }
+ else if (GeneratorHelper.isValidator(property, _is12))
+ {
+ imports.add("javax.faces.validator.MethodExpressionValidator");
+ }
+ }
+ }
+
+
+ protected void writePropertyDeclaration(PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ String fieldPropName = property.getFieldPropertyName();
+ String jspPropType = GeneratorHelper.getJspPropertyType(property, _is12);
+
+ out.println();
+ out.println("private " + jspPropType + " " + fieldPropName + ";");
+ }
+
+ protected void writePropertySetter(PrettyWriter out,
+ PropertyBean property) throws IOException
+ {
+ String propName = property.getPropertyName();
+ String fieldPropName = property.getFieldPropertyName();
+ String jspPropName = property.getJspPropertyName();
+ String propVar = Util.getVariableFromName(propName);
+ String setMethod = Util.getPrefixedPropertyName("set", jspPropName);
+ String jspPropType = GeneratorHelper.getJspPropertyType(property, _is12);
+
+ out.println("public void " + setMethod + "(" + jspPropType + " " + propVar + ")");
+ out.println("{");
+ out.indent();
+ out.println(fieldPropName + " = " + propVar + ";");
+ out.unindent();
+ out.println("}");
+ }
+
+ public void writeSetPropertiesMethod(PrettyWriter out,
+ String componentClass,
+ ComponentBean component) throws IOException
+ {
+ Collection components = new HashSet();
+ components.add(component);
+ writeSetPropertiesMethod(out, componentClass, components);
+ }
+
+
+ public void writeSetPropertiesMethod(PrettyWriter out, String componentClass, Collection components)
+ throws IOException
+ {
+
+ Collection all = new HashSet();
+ for (Iterator lIterator = components.iterator(); lIterator.hasNext();)
+ {
+ ComponentBean component = (ComponentBean) lIterator.next();
+ Iterator prop = component.properties();
+ while (prop.hasNext())
+ {
+ all.add(prop.next());
+ }
+ }
+
+ Iterator properties = all.iterator();
+ properties = new FilteredIterator(properties, new TagAttributeFilter());
+
+ out.println();
+
+ if (_is12)
+ {
+ out.println("@Override");
+ }
+ out.println("protected void setProperties(UIComponent component)");
+ out.unindent();
+ out.println("{");
+ out.indent();
+
+ writeSetPropertyMethodBody(out, componentClass, properties);
+ out.unindent();
+ out.println("}");
+ }
+
+ protected void writeSetPropertyMethodBody(PrettyWriter out,
+ String componentClass,
+ Iterator properties) throws IOException
+ {
+
+ out.println("if (!(component instanceof " + componentClass + "))");
+ out.println("{");
+ out.indent();
+ out.print("throw new IllegalArgumentException(");
+ out.print("\"Component \" + component.getClass().getName() + \" is no " + componentClass + "\"");
+ out.println(");");
+ out.unindent();
+ out.println("}");
+
+ out.println(componentClass + " comp = (" + componentClass + ")component;");
+
+ out.println();
+ out.println("super.setProperties(component);");
+ out.println();
+
+ if (!_is12)
+ {
+ out.println("FacesContext context = FacesContext.getCurrentInstance();");
+ }
+
+ while (properties.hasNext())
+ {
+ PropertyBean property = (PropertyBean) properties.next();
+ _writeSetPropertiesCase(out, componentClass, property);
+ }
+ }
+
+ 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.isMethodBinding())
+ {
+ _writeSetMethodBinding(out, componentClass, property);
+ }
+ else if (property.isMethodExpression())
+ {
+ _writeSetMethodExpression(out, componentClass, property);
+ }
+ else if (GeneratorHelper.isConverter(propClass))
+ {
+ _writeSetConverter(out, componentClass, propName);
+ }
+ else
+ {
+ _writeSetProperty(out, propName, propVar);
+ }
+ }
+
+ private void _writeSetProperty(
+ PrettyWriter out,
+ String propName,
+ String propVar)
+ {
+ out.println("if (" + propVar + " != null) ");
+ out.println("{");
+ out.indent();
+
+ if (_is12)
+ {
+ out.println("comp.setValueExpression(\"" + propName + "\", " + propVar + ");");
+ }
+ else
+ {
+ _writeSetValueBinding(out, propName, propVar);
+ }
+ out.unindent();
+ out.println("}");
+ }
+
+ private void _writeSetValueBinding(
+ PrettyWriter out,
+ String propName,
+ String propVar)
+ {
+ out.println("if (isValueReference(" + propVar + ")");
+ out.println("{");
+ out.indent();
+ out.println("ValueBinding vb = context.getApplication().createValueBinding(" + propVar + ");");
+ out.println("comp.setValueBinding(\"" + propName + "\", " + propVar + ");");
+ out.unindent();
+ out.println("}");
+ out.println("else");
+ out.println("{");
+ out.indent();
+ out.println("comp.getAttributes().put(\"" + propName + "\", " + propVar + ");");
+ 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.println("{");
+ out.indent();
+ if (GeneratorHelper.isActionListener(property, _is12))
+ {
+ out.println("comp.addActionListener(new MethodExpressionActionListener(" + propVar + "));");
+ }
+ else if (GeneratorHelper.isValueChangeListener(property, _is12))
+ {
+ out.println("comp.addValueChangeListener(new MethodExpressionValueChangeListener(" + propVar + "));");
+ }
+ else if (GeneratorHelper.isValidator(property, _is12))
+ {
+ out.println("comp.addValidator(new MethodExpressionValidator(" + propVar + "));");
+ }
+ else
+ {
+ out.println("bean.setProperty(" + componentClass + "." + propKey + ", " +
+ "new MethodExpressionMethodBinding(" + propVar + "));");
+ }
+ out.unindent();
+ out.println("}");
+ }
+ 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 propVar = property.getFieldPropertyName();
+
+ out.println("if (" + propVar + " != null) ");
+ out.println("{");
+ out.indent();
+
+ if (GeneratorHelper.isAction(property))
+ {
+ out.println("comp.setActionExpression(" + propVar + ");");
+ }
+ else if (GeneratorHelper.isActionListener(property, _is12))
+ {
+ out.println("comp.addActionListener(new MethodExpressionActionListener(" + propVar + "));");
+ }
+ else
+ {
+ out.println("comp." + Util.getPrefixedPropertyName("set", propName) + "(" + propVar + ");");
+ }
+ out.unindent();
+ out.println("}");
+ }
+
+ 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 _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("comp.setValueExpression(\"" + propName + "\", " + 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("comp.setConverter(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()));
+ }
+
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/MyFacesComponentTagGenerator.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/taglib/MyFacesComponentTagGenerator.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/taglib/TagAttributeFilter.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/taglib/TagAttributeFilter.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/taglib/TagAttributeFilter.java (added)
+++ incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TagAttributeFilter.java Thu Nov 30 12:21:26 2006
@@ -0,0 +1,34 @@
+/*
+ * 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.taglib;
+
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.PropertyFilter;
+
+/**
+ * TODO: comment this!
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+final public class TagAttributeFilter extends PropertyFilter
+{
+ protected boolean accept(
+ PropertyBean property)
+ {
+ return (!property.isTagAttributeExcluded());
+ }
+}
Propchange: incubator/adffaces/branches/faces-1_2-061113/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TagAttributeFilter.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/taglib/TagAttributeFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision