You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/04/05 02:43:31 UTC
svn commit: r645004 - in
/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main:
java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/
java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/
resources/MET...
Author: lu4242
Date: Fri Apr 4 17:43:27 2008
New Revision: 645004
URL: http://svn.apache.org/viewvc?rev=645004&view=rev
Log:
draft generate tag class
Modified:
myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/PropertyMeta.java
myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/MyfacesUtils.java
myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/PropertyMeta.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/PropertyMeta.java?rev=645004&r1=645003&r2=645004&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/PropertyMeta.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/PropertyMeta.java Fri Apr 4 17:43:27 2008
@@ -31,6 +31,8 @@
{
private String _name;
private String _className;
+ private String _jspName;
+ private String _fieldName;
private Boolean _required;
private Boolean _literalOnly;
private Boolean _transient;
@@ -45,6 +47,10 @@
{
out.beginElement("property");
out.writeElement("name", pm._name);
+ if (pm._jspName != null)
+ out.writeElement("jspName", pm._jspName);
+ if (pm._fieldName != null)
+ out.writeElement("fieldName", pm._fieldName);
out.writeElement("className", pm._className);
out.writeElement("required", pm._required);
out.writeElement("literalOnly", pm._literalOnly);
@@ -66,6 +72,8 @@
digester.addSetNext(newPrefix, "addProperty");
digester.addBeanPropertySetter(newPrefix + "/name");
+ digester.addBeanPropertySetter(newPrefix + "/jspName");
+ digester.addBeanPropertySetter(newPrefix + "/fieldName");
digester.addBeanPropertySetter(newPrefix + "/className");
digester.addBeanPropertySetter(newPrefix + "/required");
digester.addBeanPropertySetter(newPrefix + "/literalOnly");
@@ -85,11 +93,14 @@
// don't merge className
_name = ModelUtils.merge(this._name, other._name);
+ _jspName = ModelUtils.merge(this._jspName, other._jspName);
+ _fieldName = ModelUtils.merge(this._fieldName, other._fieldName);
_required = ModelUtils.merge(this._required, other._required);
_literalOnly = ModelUtils.merge(this._literalOnly, other._literalOnly);
_transient = ModelUtils.merge(this._transient, other._transient);
_description = ModelUtils.merge(this._description, other._description);
_longDescription = ModelUtils.merge(this._longDescription, other._longDescription);
+ _defaultValue = ModelUtils.merge(this._defaultValue, other._defaultValue);
}
/**
@@ -205,6 +216,54 @@
public String getDefaultValue()
{
return _defaultValue;
+ }
+
+ /**
+ * Sets the JSP name of this property.
+ *
+ * @param jspName the JSP property name
+ */
+ public void setJspName(
+ String jspName)
+ {
+ _jspName = jspName;
+ }
+
+ /**
+ * Returns the JSP name of this property.
+ *
+ * @return the JSP property name
+ */
+ public String getJspName()
+ {
+ if (_jspName == null)
+ return getName();
+
+ return _jspName;
+ }
+
+ /**
+ * Sets the field name of this property, when not generating Trinidad components
+ *
+ * @param fieldName the field property name
+ */
+ public void setFieldName(
+ String fieldName)
+ {
+ _fieldName = fieldName;
+ }
+
+ /**
+ * Returns the field name of this property, when not generating Trinidad components
+ *
+ * @return the field property name
+ */
+ public String getFieldName()
+ {
+ if (_fieldName == null)
+ return "_"+getName();
+
+ return _fieldName;
}
/**
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/MyfacesUtils.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/MyfacesUtils.java?rev=645004&r1=645003&r2=645004&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/MyfacesUtils.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/MyfacesUtils.java Fri Apr 4 17:43:27 2008
@@ -20,11 +20,14 @@
import java.io.File;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.PropertyMeta;
public class MyfacesUtils
@@ -33,6 +36,186 @@
{
}
+ public static String getPrefixedPropertyName(String prefix,
+ String propertyName)
+ {
+ return prefix + Character.toUpperCase(propertyName.charAt(0))
+ + propertyName.substring(1);
+ }
+
+ public static String getJspPropertyType11(PropertyMeta property)
+ {
+ if (property.isMethodExpression())
+ return "MethodExpression";
+
+ if (property.isMethodBinding())
+ return "MethodExpression";
+
+ return "String";
+ }
+
+ public static String getJspPropertyType12(PropertyMeta property)
+ {
+ if (property.isMethodExpression())
+ return "MethodExpression";
+
+ if (property.isMethodBinding())
+ return "MethodExpression";
+
+ if (!property.isLiteralOnly().booleanValue())
+ return "ValueExpression";
+ else
+ return property.getClassName();
+ }
+
+ public static String getVariableFromName(String name)
+ {
+ if (name == null)
+ return null;
+
+ if (RESERVED_WORDS.contains(name))
+ name = name + "Param";
+
+ return name;
+ }
+
+ public static String importTagClasses(ComponentMeta component)
+ {
+ Set imports = new HashSet();
+ for (Iterator it = component.properties(); it.hasNext();)
+ {
+ PropertyMeta property = (PropertyMeta) it.next();
+ if (!PRIMITIVE_TYPES.contains(property.getClassName()))
+ {
+ if (!property.getClassName().startsWith("java.lang"))
+ {
+ imports.add(property.getClassName());
+ }
+ }
+ }
+
+ StringBuilder value = new StringBuilder();
+
+ for (Iterator importIterator = imports.iterator(); importIterator
+ .hasNext();)
+ {
+ value.append("import ");
+ value.append((String) importIterator.next());
+ value.append(';');
+ value.append('\n');
+ }
+
+ return value.toString();
+ }
+
+ public static boolean isConverter(String propClass)
+ {
+ return ("javax.faces.convert.Converter".equals(propClass));
+ }
+
+ public static String getBoxedClass(String className)
+ {
+ if ("boolean".equals(className))
+ return "Boolean";
+ else if ("byte".equals(className))
+ return "Byte";
+ else if ("char".equals(className))
+ return "Character";
+ else if ("double".equals(className))
+ return "Double";
+ else if ("float".equals(className))
+ return "Float";
+ else if ("int".equals(className))
+ return "Integer";
+ else if ("long".equals(className))
+ return "Long";
+ else if ("short".equals(className))
+ return "Short";
+ else
+ return className;
+ }
+
+ public static String getPrimitiveType(String className)
+ {
+ if (className.startsWith("java.lang."))
+ {
+ className = className.replace("java.lang.", "");
+ }
+
+ if (className.endsWith("eger"))
+ {
+ className = className.replace("eger", "");
+ }
+
+ if (MyfacesUtils.isPrimitiveClass(className.toLowerCase()))
+ {
+ return className.toLowerCase();
+ }
+ else
+ {
+ return className;
+ }
+ }
+
+ public static boolean isPrimitiveClass(String className)
+ {
+ return "boolean".equals(className) || "byte".equals(className)
+ || "char".equals(className) || "double".equals(className)
+ || "float".equals(className) || "int".equals(className)
+ || "long".equals(className) || "short".equals(className);
+ }
+
+ private static Set _createPrimitiveTypesSet()
+ {
+ Set primitives = new TreeSet();
+ for (int i = 0; i < _PRIMITIVE_TYPES.length; i++)
+ {
+ String type = _PRIMITIVE_TYPES[i];
+ primitives.add(type);
+ primitives.add(type + "[]");
+ }
+ return Collections.unmodifiableSet(primitives);
+ }
+
+ private static Set _createReservedWordsSet()
+ {
+ Set reserved = new TreeSet();
+ for (int i = 0; i < _RESERVED_WORDS.length; i++)
+ {
+ String keyword = _RESERVED_WORDS[i];
+ reserved.add(keyword);
+ }
+ return Collections.unmodifiableSet(reserved);
+ }
+
+ static private final String[] _PRIMITIVE_TYPES = new String[] {// TODO: Shouldn't java.lang.* be specified in that list as well?
+ "boolean", "byte", "char", "float", "double", "int", "short", "long", };
+
+ static private final String[] _RESERVED_WORDS = new String[] { "abstract",
+ "assert", "boolean", "break", "byte", "case", "catch", "char",
+ "class", "const", "continue", "default", "do", "double", "else",
+ "extends", "final", "finally", "float", "for", "goto", "if",
+ "implements", "import", "instanceof", "int", "interface", "long",
+ "native", "new", "package", "private", "protected", "public",
+ "return", "short", "static", "super", "switch", "synchronized",
+ "this", "throw", "throws", "transient", "try", "void", "volatile",
+ "while", };
+
+ static public final Set RESERVED_WORDS = _createReservedWordsSet();
+ static public final Set PRIMITIVE_TYPES = _createPrimitiveTypesSet();
+
+ static private final Pattern _GENERIC_TYPE = Pattern
+ .compile("([^<]+)<(.+)>");
+
+ //UNUSED METHODS
+
+ static public String getMethodReaderFromProperty(String propertyName,
+ String propertyClass)
+ {
+ String methodPrefix = ("boolean".equals(propertyClass) ? "is" : "get");
+ return getPrefixedPropertyName(methodPrefix, propertyName);
+ }
+
static public String convertClassToSourcePath(String className,
String fileExtension)
{
@@ -109,13 +292,6 @@
return constantName.toString();
}
- static public String getPrefixedPropertyName(String prefix,
- String propertyName)
- {
- return prefix + Character.toUpperCase(propertyName.charAt(0))
- + propertyName.substring(1);
- }
-
static public String getPropertyClass(PropertyMeta property)
{
String propertyFullClass = property.getClassName();
@@ -152,13 +328,6 @@
+ eventName.substring(1) + methodSuffix;
}
- static public String getMethodReaderFromProperty(String propertyName,
- String propertyClass)
- {
- String methodPrefix = ("boolean".equals(propertyClass) ? "is" : "get");
- return getPrefixedPropertyName(methodPrefix, propertyName);
- }
-
static public String getEventNameFromEventType(String eventFullClass)
{
String eventName = getClassFromFullClass(eventFullClass);
@@ -166,14 +335,6 @@
+ eventName.substring(1, eventName.length());
}
- static public boolean isPrimitiveClass(String className)
- {
- return "boolean".equals(className) || "byte".equals(className)
- || "char".equals(className) || "double".equals(className)
- || "float".equals(className) || "int".equals(className)
- || "long".equals(className) || "short".equals(className);
- }
-
/*
static public String getAlternatePropertyClass(PropertyMeta property)
{
@@ -184,51 +345,6 @@
}
*/
- static public String getPrimitiveType(String className)
- {
- if (className.startsWith("java.lang."))
- {
- className = className.replace("java.lang.", "");
- }
-
- if (className.endsWith("eger"))
- {
- className = className.replace("eger", "");
- }
-
- if (MyfacesUtils.isPrimitiveClass(className.toLowerCase()))
- {
- return className.toLowerCase();
- }
- else
- {
- return null;
- }
-
- }
-
- static public String getBoxedClass(String className)
- {
- if ("boolean".equals(className))
- return "Boolean";
- else if ("byte".equals(className))
- return "Byte";
- else if ("char".equals(className))
- return "Character";
- else if ("double".equals(className))
- return "Double";
- else if ("float".equals(className))
- return "Float";
- else if ("int".equals(className))
- return "Integer";
- else if ("long".equals(className))
- return "Long";
- else if ("short".equals(className))
- return "Short";
- else
- return className;
- }
-
static public String primitiveDefaultValue(String className)
{
if ("boolean".equals(className))
@@ -287,17 +403,6 @@
+ "\" does not use initcaps");
}
- static public String getVariableFromName(String name)
- {
- if (name == null)
- return null;
-
- if (RESERVED_WORDS.contains(name))
- name = name + "Param";
-
- return name;
- }
-
static public String convertStringToLiteral(String value)
{
return convertStringToLiteral("String", value);
@@ -387,47 +492,5 @@
buffer.append(MyfacesUtils.getClassFromFullClass(type));
}
}
-
- static private Set _createPrimitiveTypesSet()
- {
- Set primitives = new TreeSet();
- for (int i = 0; i < _PRIMITIVE_TYPES.length; i++)
- {
- String type = _PRIMITIVE_TYPES[i];
- primitives.add(type);
- primitives.add(type + "[]");
- }
- return Collections.unmodifiableSet(primitives);
- }
-
- static private Set _createReservedWordsSet()
- {
- Set reserved = new TreeSet();
- for (int i = 0; i < _RESERVED_WORDS.length; i++)
- {
- String keyword = _RESERVED_WORDS[i];
- reserved.add(keyword);
- }
- return Collections.unmodifiableSet(reserved);
- }
-
- static private final String[] _PRIMITIVE_TYPES = new String[] {// TODO: Shouldn't java.lang.* be specified in that list as well?
- "boolean", "byte", "char", "float", "double", "int", "short", "long", };
-
- static private final String[] _RESERVED_WORDS = new String[] { "abstract",
- "assert", "boolean", "break", "byte", "case", "catch", "char",
- "class", "const", "continue", "default", "do", "double", "else",
- "extends", "final", "finally", "float", "for", "goto", "if",
- "implements", "import", "instanceof", "int", "interface", "long",
- "native", "new", "package", "private", "protected", "public",
- "return", "short", "static", "super", "switch", "synchronized",
- "this", "throw", "throws", "transient", "try", "void", "volatile",
- "while", };
-
- static public final Set RESERVED_WORDS = _createReservedWordsSet();
- static public final Set PRIMITIVE_TYPES = _createPrimitiveTypesSet();
-
- static private final Pattern _GENERIC_TYPE = Pattern
- .compile("([^<]+)<(.+)>");
}
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm?rev=645004&r1=645003&r2=645004&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm Fri Apr 4 17:43:27 2008
@@ -1,11 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 ${component.tagPackage};
+import javax.faces.component.UIComponent;
+import javax.faces.el.ValueBinding;
+import javax.faces.context.FacesContext;
+$utils.importTagClasses($component)
+
public class ${component.tagName}{
-#foreach( $property in ${component.propertyList} )
- public void set${property.name}(){
+ public ${component.tagName}()
+ {
+ }
+ public String getComponentType()
+ {
+#if ($component.type)
+ return "$component.type";
+#else
+ return null;
+#end
+ }
+
+ public String getRendererType()
+ {
+#if ($component.rendererType)
+ return "$component.rendererType";
+#else
+ return null;
+#end
+ }
+
+#set ($propertyList = ${component.propertyList})
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $utils.getJspPropertyType11($property))
+
+ private $type $field;
+
+#set ($var = $utils.getVariableFromName($property.name))
+ public void $utils.getPrefixedPropertyName("set", $property.jspName)($type $var)
+ {
+ $field = $var;
}
#end
+ protected void setProperties(UIComponent component)
+ {
+ if (!(component instanceof $component.className)
+ {
+ throw new IllegalArgumentException("Component "+
+ component.getClass().getName() +" is no $component.className");
+ }
+
+ comp = ($component.className) component;
+
+ super.setProperties(component);
+
+ FacesContext context = getFacesContext();
+
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $utils.getJspPropertyType11($property))
+#if ($utils.isConverter($type))
+ if ($field != null)
+ {
+ if (isValueReference($field))
+ {
+ ValueBinding vb = context.getApplication().createValueBinding($field);
+ comp.setValueBinding("$property.name", vb);
+ }
+ else
+ {
+ Converter converter = getFacesContext().getApplication().createConverter($field);
+ comp.setConverter(converter);
+ }
+ }
+#elseif ($property.isMethodBinding)
+
+#else
+ if ($field != null)
+ {
+#if ($property.isLiteralOnly)
+#set ($className = $utils.getPrimitiveType($property.className))
+#if ($utils.isPrimitiveClass($className))
+#if ($utils.isPrimitiveClass($property.className))
+ comp.getAttributes().put("$property.name", ${utils.getBoxedClass($className)}.valueOf($field));
+#else
+ comp.getAttributes().put("$property.name", $field);
+#end
+#else
+ comp.getAttributes().put("$property.name", $field);
+#end
+#else
+ if (isValueReference($field))
+ {
+ ValueBinding vb = context.getApplication().createValueBinding($field);
+ comp.setValueBinding("$property.name", vb);
+ }
+ else
+ {
+#set ($className = $utils.getPrimitiveType($property.className))
+#if ($utils.isPrimitiveClass($className))
+#if ($utils.isPrimitiveClass($property.className))
+ comp.getAttributes().put("$property.name", ${utils.getBoxedClass($className)}.valueOf($field));
+#else
+ comp.getAttributes().put("$property.name", $field);
+#end
+#else
+ comp.getAttributes().put("$property.name", $field);
+#end
+ }
+#end
+ }
+#end
+
+
+#end
+ }
+
+ public void release()
+ {
+ super.release();
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#if($utils.getJspPropertyType11($property) == "boolean")
+#set ($empty = "false")
+#else
+#set ($empty = "null")
+#end
+ $field = $empty;
+#end
+ }
}