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 04:52:02 UTC
svn commit: r645021 - in
/myfaces/myfaces-build-tools/branches/builder_plugin:
myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/
myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plu...
Author: lu4242
Date: Fri Apr 4 19:51:43 2008
New Revision: 645021
URL: http://svn.apache.org/viewvc?rev=645021&view=rev
Log:
added MethodBinding for template
Added:
myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/MethodSignatureMeta.java (with props)
Modified:
myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ModelUtils.java
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
myfaces/myfaces-build-tools/branches/builder_plugin/test/api/src/main/java/javax/faces/component/html/HtmlCommandButton.java
Added: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/MethodSignatureMeta.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/MethodSignatureMeta.java?rev=645021&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/MethodSignatureMeta.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/MethodSignatureMeta.java Fri Apr 4 19:51:43 2008
@@ -0,0 +1,108 @@
+/*
+ * 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 org.apache.myfaces.buildtools.maven2.plugin.builder.model;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.digester.Digester;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.io.XmlWriter;
+
+/**
+ * MethodSignatureMeta is a Java representation of the faces-config component
+ * property-extension method-signature XML element.
+ */
+public class MethodSignatureMeta extends Object
+{
+ /**
+ * Creates a new MethodSignatureBean.
+ */
+ public MethodSignatureMeta()
+ {
+ _parameterTypes = new LinkedList();
+ }
+
+ public static void addXmlRules(Digester digester, String prefix)
+ {
+ String newPrefix = prefix + "/methodBindingSignature";
+ digester.addObjectCreate(newPrefix , MethodSignatureMeta.class);
+ digester.addBeanPropertySetter(newPrefix +"/returnType", "returnType");
+ digester.addCallMethod(newPrefix +"/parameterType","addParameterType", 1);
+ digester.addCallParam(newPrefix +"/parameterType", 0);
+ digester.addSetNext(newPrefix ,"setMethodBindingSignature", MethodSignatureMeta.class.getName());
+
+ }
+
+ public static void writeXml(XmlWriter out, MethodSignatureMeta pm){
+ out.beginElement("methodBindingSignature");
+ out.writeElement("returnType", pm._returnType);
+
+ for (Iterator i = pm._parameterTypes.iterator(); i.hasNext();)
+ {
+ String param = (String) i.next();
+ out.writeElement("parameterType", param);
+ }
+
+ out.endElement("methodBindingSignature");
+ }
+
+ /**
+ * Adds a new parameter type to this method signature.
+ *
+ * @param parameterType the parameter type
+ */
+ public void addParameterType(String parameterType)
+ {
+ _parameterTypes.add(parameterType);
+ }
+
+ /**
+ * Returns the list of parameter types as an array.
+ *
+ * @return the parameter type list
+ */
+ public String[] getParameterTypes()
+ {
+ return (String[]) _parameterTypes.toArray(new String[0]);
+ }
+
+ /**
+ * Sets the return type of this method signature.
+ *
+ * @param returnType the method signature return type
+ */
+ public void setReturnType(String returnType)
+ {
+ _returnType = returnType;
+ }
+
+ /**
+ * Returns the return type of this method signature.
+ *
+ * @return the method signature return type
+ */
+ public String getReturnType()
+ {
+ return _returnType;
+ }
+
+ private String _returnType;
+ private List _parameterTypes;
+}
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/MethodSignatureMeta.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/MethodSignatureMeta.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ModelUtils.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/ModelUtils.java?rev=645021&r1=645020&r2=645021&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ModelUtils.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ModelUtils.java Fri Apr 4 19:51:43 2008
@@ -42,6 +42,18 @@
/**
* Inherit setting only if current one is empty.
*/
+ public static Object merge(Object curr, Object inherited)
+ {
+ if (curr != null)
+ {
+ return curr;
+ }
+ return inherited;
+ }
+
+ /**
+ * Inherit setting only if current one is empty.
+ */
public static Boolean merge(Boolean curr, Boolean inherited)
{
if (curr != null)
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=645021&r1=645020&r2=645021&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 19:51:43 2008
@@ -39,6 +39,7 @@
private String _description;
private String _longDescription;
private String _defaultValue;
+ private MethodSignatureMeta _signature;
/**
* Write this model out as xml.
@@ -82,6 +83,9 @@
digester.addBeanPropertySetter(newPrefix + "/longDesc",
"longDescription");
digester.addBeanPropertySetter(newPrefix + "/defaultValue", "defaultValue");
+
+ MethodSignatureMeta.addXmlRules(digester, newPrefix);
+
}
/**
@@ -101,6 +105,7 @@
_description = ModelUtils.merge(this._description, other._description);
_longDescription = ModelUtils.merge(this._longDescription, other._longDescription);
_defaultValue = ModelUtils.merge(this._defaultValue, other._defaultValue);
+ _signature = (MethodSignatureMeta) ModelUtils.merge(this._signature, other._signature);
}
/**
@@ -265,6 +270,28 @@
return _fieldName;
}
+
+ /**
+ * Sets the method binding signature of this property.
+ *
+ * @param signature the method binding signature of this property
+ */
+ public void setMethodBindingSignature(
+ MethodSignatureMeta signature)
+ {
+ _signature = signature;
+ }
+
+ /**
+ * Returns the method binding signature of this property.
+ *
+ * @return the method binding signature of this property
+ */
+ public MethodSignatureMeta getMethodBindingSignature()
+ {
+ return _signature;
+ }
+
/**
* Returns true if this property is a method binding.
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=645021&r1=645020&r2=645021&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 19:51:43 2008
@@ -28,6 +28,7 @@
import java.util.regex.Pattern;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.MethodSignatureMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.PropertyMeta;
public class MyfacesUtils
@@ -134,7 +135,49 @@
else
return className;
}
+
+ public static String getSignatureParams(MethodSignatureMeta signature){
+ 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();
+ }
+ return classArray;
+ }
+
+ public static boolean isStringMethodBindingReturnType(MethodSignatureMeta sig)
+ {
+ return (sig != null && "java.lang.String".equals(sig.getReturnType()));
+ }
+
+ static public String getMethodReaderFromProperty(String propertyName,
+ String propertyClass)
+ {
+ String methodPrefix = ("boolean".equals(propertyClass) ? "is" : "get");
+ return getPrefixedPropertyName(methodPrefix, propertyName);
+ }
+
public static String getPrimitiveType(String className)
{
if (className.startsWith("java.lang."))
@@ -209,12 +252,6 @@
//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)
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=645021&r1=645020&r2=645021&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 19:51:43 2008
@@ -1,3 +1,5 @@
+// WARNING: This file was automatically generated. Do not edit it directly,
+// or you will lose your changes.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -74,11 +76,11 @@
super.setProperties(component);
FacesContext context = getFacesContext();
-
-#foreach( $property in $propertyList )
+
+#foreach( $property in $propertyList )## 1
#set ($field = $property.fieldName)
#set ($type = $utils.getJspPropertyType11($property))
-#if ($utils.isConverter($type))
+#if ($utils.isConverter($type))## 2
if ($field != null)
{
if (isValueReference($field))
@@ -92,23 +94,45 @@
comp.setConverter(converter);
}
}
-#elseif ($property.isMethodBinding)
-
-#else
+#elseif ($property.isMethodBinding)## 2
+ if ($field != null)
+ {
+#if ($utils.isStringMethodBindingReturnType($property.methodBindingSignature)))##3
+ MethodBinding mb;
+ if (isValueReference($field))
+ {
+ mb = context.getApplication().createMethodBinding(
+ $field, $utils.getSignatureParams($property.methodBindingSignature));
+ }
+ else
+ {
+#if ($property.jspName == "value")## 4
+ mb = new org.apache.myfaces.shared_impl.el.SimpleActionMethodBinding($field);
+#else## 4
+ throw new IllegalStateException("Invalid expression " + $field);
+#end## 4
+ }
+#else## 3
+ MethodBinding mb = context.getApplication().createMethodBinding(
+ $field, $utils.getSignatureParams($property.methodBindingSignature));
+ comp.setActionListener(mb);
+#end## 3
+ }
+#else## 2
if ($field != null)
{
-#if ($property.isLiteralOnly)
+#if ($property.isLiteralOnly)## 3
#set ($className = $utils.getPrimitiveType($property.className))
-#if ($utils.isPrimitiveClass($className))
-#if ($utils.isPrimitiveClass($property.className))
+#if ($utils.isPrimitiveClass($className))## 4
+#if ($utils.isPrimitiveClass($property.className))## 5
comp.getAttributes().put("$property.name", ${utils.getBoxedClass($className)}.valueOf($field));
-#else
+#else## 5
comp.getAttributes().put("$property.name", $field);
-#end
-#else
+#end## 5
+#else## 4
comp.getAttributes().put("$property.name", $field);
-#end
-#else
+#end# 4
+#else## 3
if (isValueReference($field))
{
ValueBinding vb = context.getApplication().createValueBinding($field);
@@ -117,22 +141,20 @@
else
{
#set ($className = $utils.getPrimitiveType($property.className))
-#if ($utils.isPrimitiveClass($className))
-#if ($utils.isPrimitiveClass($property.className))
+#if ($utils.isPrimitiveClass($className))## 4
+#if ($utils.isPrimitiveClass($property.className))## 5
comp.getAttributes().put("$property.name", ${utils.getBoxedClass($className)}.valueOf($field));
-#else
+#else## 5
comp.getAttributes().put("$property.name", $field);
-#end
-#else
+#end## 5
+#else## 4
comp.getAttributes().put("$property.name", $field);
-#end
+#end## 4
}
-#end
+#end## 3
}
-#end
-
-
-#end
+#end## 2
+#end## 1
}
public void release()
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/test/api/src/main/java/javax/faces/component/html/HtmlCommandButton.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/test/api/src/main/java/javax/faces/component/html/HtmlCommandButton.java?rev=645021&r1=645020&r2=645021&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/test/api/src/main/java/javax/faces/component/html/HtmlCommandButton.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/test/api/src/main/java/javax/faces/component/html/HtmlCommandButton.java Fri Apr 4 19:51:43 2008
@@ -20,4 +20,11 @@
public Object getValue(){
return null;
}
+
+ /**
+ * @JSFProperty
+ */
+ public boolean isRendered(){
+ return false;
+ }
}