myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r645313 [4/4] - in /myfaces/tobago/trunk: ./ core/ core/src/main/faces-config/ core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/taglib/component/ core/src/main/java/org/apache/myfaces/toba...
Date Sun, 06 Apr 2008 21:53:37 GMT
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java?rev=645313&r1=645312&r2=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java
Sun Apr  6 14:53:32 2008
@@ -44,6 +44,8 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Map;
+import java.util.Collections;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
@@ -65,16 +67,27 @@
   private StringTemplateGroup componentStringTemplateGroup;
   private Set<String> renderer = new HashSet<String>();
   private Set<String> ignoredProperties;
+  private String jsfVersion = "1.1";
 
   public CreateComponentAnnotationVisitor(AnnotationProcessorEnvironment env) {
     super(env);
+
+    for (Map.Entry<String, String> entry : getEnv().getOptions().entrySet()) {
+      if (entry.getKey().startsWith("-Ajsf-version=")) {
+        String version = entry.getKey().substring("-Ajsf-version=".length());
+        if ("1.2".equals(version)) {
+          jsfVersion = "1.2";
+        }
+      }
+    }
     InputStream stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/renderer.stg");
     Reader reader = new InputStreamReader(stream);
     rendererStringTemplateGroup = new StringTemplateGroup(reader);
-    stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/tag.stg");
+    stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/tag"
+ jsfVersion + ".stg");
     reader = new InputStreamReader(stream);
     tagStringTemplateGroup = new StringTemplateGroup(reader);
-    stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/component.stg");
+    stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/component"
+        + jsfVersion + ".stg");
     reader = new InputStreamReader(stream);
     componentStringTemplateGroup = new StringTemplateGroup(reader);
     ignoredProperties = new HashSet<String>();
@@ -102,8 +115,8 @@
       String className = "org.apache.myfaces.tobago.internal.taglib."
           + tag.name().substring(0, 1).toUpperCase(Locale.ENGLISH) + tag.name().substring(1)
+ "Tag";
       TagInfo tagInfo = new TagInfo(className, componentTag.rendererType());
-      if (tag.isBodyTag()) {
-        tagInfo.setSuperClass("org.apache.myfaces.tobago.internal.taglib.TobagoBodyTag");
+      if (is12()) {
+        tagInfo.setSuperClass("org.apache.myfaces.tobago.internal.taglib12.TobagoELTag");
       } else {
         tagInfo.setSuperClass("org.apache.myfaces.tobago.internal.taglib.TobagoTag");
       }
@@ -125,6 +138,10 @@
       ComponentInfo componentInfo = new ComponentInfo(componentTag.uiComponent(), componentTag.rendererType());
       componentInfo.setSuperClass(componentTag.uiComponentBaseClass());
       componentInfo.setComponentFamily(componentTag.componentFamily());
+      List<String> elMethods = Collections.emptyList();
+      if (is12()) {
+        elMethods = checkForElMethods(componentInfo, componentTag.interfaces());
+      }
       for (String interfaces:componentTag.interfaces()) {
         componentInfo.addInterface(interfaces);
       }
@@ -134,24 +151,37 @@
         componentInfo.setComponentType(componentTag.uiComponent().replace(".component.UI",
"."));
       }
       try {
-        Class componentClass = Class.forName(componentTag.uiComponentBaseClass());
+        Class componentBaseClass = Class.forName(componentTag.uiComponentBaseClass());
         int index = 0;
         for (PropertyInfo info:properties) {
+          String methodName = (info.getType().equals("java.lang.Boolean")?"is":"get") + info.getUpperCamelCaseName();
+          String possibleUnifiedElAlternative = "set" + info.getUpperCamelCaseName() + "Expression";
           try {
-            String methodName = (info.getType().equals("java.lang.Boolean")?"is":"get") +
info.getUpperCamelCaseName();
-            Method method = componentClass.getMethod(methodName);
+            Method method = componentBaseClass.getMethod(methodName);
             if (Modifier.isAbstract(method.getModifiers())) {
-              addPropertyToComponent(componentInfo, info, index);
+              ComponentPropertyInfo property = addPropertyToComponent(componentInfo, info,
index, false);
+              if (elMethods.contains(possibleUnifiedElAlternative)) {
+                addPropertyToComponent(componentInfo, info, index, true);
+                property.setElAlternativeAvailable(true);
+              }
               index++;
             }   
           } catch (NoSuchMethodException e) {
-            addPropertyToComponent(componentInfo, info, index);
+            ComponentPropertyInfo property = addPropertyToComponent(componentInfo, info,
index, false);
+            if (elMethods.contains(possibleUnifiedElAlternative)) {
+              addPropertyToComponent(componentInfo, info, index, true);
+              property.setElAlternativeAvailable(true);
+            }
             index++;
           }
         }
-        try {
-          componentClass.getMethod("invokeOnComponent");
-        } catch (NoSuchMethodException e) {
+        boolean found = false;
+        for (Method method:componentBaseClass.getMethods()) {
+          if ("invokeOnComponent".equals(method.getName())) {
+            found = true;
+          }
+        }
+        if (!found) {
           componentInfo.setInvokeOnComponent(true);
           componentInfo.addImport("javax.faces.context.FacesContext");
           componentInfo.addImport("javax.faces.FacesException");
@@ -165,7 +195,7 @@
         int index = 0;
         for (PropertyInfo info:properties) {
           if (!baseClassProperties.contains(info)) {
-            addPropertyToComponent(componentInfo, info, index);
+            addPropertyToComponent(componentInfo, info, index, false);
             index++;
           }
         }
@@ -177,6 +207,27 @@
 
   }
 
+  private List<String> checkForElMethods(ComponentInfo info, String[] interfaces) {
+    List<String> elMethods = new ArrayList<String>();
+    for (String interfaceName:interfaces) {
+      try {
+        Class.forName(interfaceName);
+        Class interfaceClass2 = Class.forName(interfaceName + "2");
+        info.addInterface(interfaceClass2.getName());
+        for (Method method:interfaceClass2.getMethods()) {
+          Class[] parameter = method.getParameterTypes();
+          if (parameter.length == 1 && "javax.el.MethodExpression".equals(parameter[0].getName()))
{
+            elMethods.add(method.getName());
+          }
+        }
+      } catch (ClassNotFoundException e) {
+        // ignore
+      }
+    }
+    return elMethods;
+
+  }
+
   private List<PropertyInfo> getBaseClassProperties(String baseClass) {
     for (InterfaceDeclaration decl: getCollectedInterfaceDeclarations()) {
       if (decl.getAnnotation(UIComponentTag.class)!= null) {
@@ -191,19 +242,21 @@
     throw new IllegalStateException("No UIComponentTag found for componentClass " + baseClass);
   }
 
-  private void addPropertyToComponent(ComponentInfo componentInfo, PropertyInfo info, int
index) {
+  private ComponentPropertyInfo addPropertyToComponent(ComponentInfo componentInfo, PropertyInfo
info, int index, boolean methodExpression) {
     ComponentPropertyInfo componentPropertyInfo =
         (ComponentPropertyInfo) info.fill(new ComponentPropertyInfo());
     componentPropertyInfo.setIndex(index);
-    componentInfo.addImport(info.getUnmodifiedType());
+    if (methodExpression) {
+      componentPropertyInfo.setType("javax.el.MethodExpression");
+      componentPropertyInfo.setName(info.getName() + "Expression");
+    }
+    componentInfo.addImport(componentPropertyInfo.getUnmodifiedType());
     componentInfo.addImport("javax.faces.context.FacesContext");
     componentInfo.getProperties().add(componentPropertyInfo);
-    if ("suggestMethod".equals(info.getName())) {
-      componentInfo.addInterface("org.apache.myfaces.tobago.component.InputSuggest");
-    }
     if ("markup".equals(info.getName())) {
       componentInfo.addInterface("org.apache.myfaces.tobago.component.SupportsMarkup");
     }
+    return componentPropertyInfo;
   }
 
   private void createRenderer(TypeDeclaration decl) {
@@ -266,6 +319,7 @@
         propertyInfo.setAllowdValues(uiComponentTagAttribute.allowedValues());
         String type;
         if (uiComponentTagAttribute.expression().isMethodExpression()) {
+          propertyInfo.setMethodExpressionRequired(true);
           type = "javax.faces.el.MethodBinding";
         } else if (uiComponentTagAttribute.expression() == DynamicExpression.VALUE_BINDING_REQUIRED)
{
           propertyInfo.setValueExpressionRequired(true);
@@ -276,6 +330,9 @@
           }
 
         } else if (uiComponentTagAttribute.type().length == 1) {
+          if (uiComponentTagAttribute.expression() == DynamicExpression.PROHIBITED) {
+            propertyInfo.setLiteralOnly(true);
+          }
           type = uiComponentTagAttribute.type()[0];
         } else {
           throw new IllegalArgumentException("Type should be single argument "
@@ -304,5 +361,9 @@
     } finally {
       IOUtils.closeQuietly(writer);
     }
+  }
+
+  private boolean is12() {
+    return "1.2".equals(jsfVersion);
   }
 }

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java?rev=645313&r1=645312&r2=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
Sun Apr  6 14:53:32 2008
@@ -38,6 +38,7 @@
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.Namespace;
+import org.jdom.Attribute;
 import org.jdom.filter.ContentFilter;
 import org.jdom.input.SAXBuilder;
 import org.jdom.output.Format;
@@ -69,6 +70,8 @@
   public static final String SOURCE_FACES_CONFIG_KEY = "sourceFacesConfig";
   public static final String TARGET_FACES_CONFIG_KEY = "targetFacesConfig";
 
+  private String jsfVersion = "1.1";
+
   private static final String SEPARATOR = System.getProperty("line.separator");
   private static final String COMPONENT = "component";
   private static final String COMPONENT_TYPE = "component-type";
@@ -128,6 +131,12 @@
       if (entry.getKey().startsWith("-A" + TARGET_FACES_CONFIG_KEY + "=")) {
         targetFacesConfigFile = entry.getKey().substring(TARGET_FACES_CONFIG_KEY.length()
+ 3);
       }
+      if (entry.getKey().startsWith("-Ajsf-version=")) {
+        String version = entry.getKey().substring("-Ajsf-version=".length());
+        if ("1.2".equals(version)) {
+          jsfVersion = "1.2";
+        }
+      }
     }
     Document document;
     Writer writer = null;
@@ -152,7 +161,18 @@
       // rewrite DOM as a string to find differences, since text outside the root element
is not tracked
 
       Element rootElement = document.getRootElement();
+      if (is12()) {
+        rootElement.setNamespace(Namespace.getNamespace("http://java.sun.com/xml/ns/javaee"));
+        Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+        rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));
+        rootElement.setAttribute(new Attribute("schemaLocation",
+            "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd",
xsi));
+        rootElement.setAttribute("version", "1.2");
+      }
       Namespace namespace = rootElement.getNamespace();
+      if (is12()) {
+        applyNamespace(rootElement, namespace);
+      }
       List<Element> components = rootElement.getChildren(COMPONENT, namespace);
 
       List<Element> newComponents = new ArrayList<Element>();
@@ -207,10 +227,11 @@
       if (!newValidators.isEmpty()) {
         rootElement.addContent(newValidators);
       }
-      document.setDocType(new DocType("faces-config",
-          "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
-          "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"));
-
+      if (!is12()) {
+        document.setDocType(new DocType("faces-config",
+            "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
+           "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"));
+      }
       writer =
           getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE, "", new File(targetFacesConfigFile),
null);
 
@@ -218,25 +239,28 @@
       Format format = Format.getPrettyFormat();
       format.setLineSeparator(SEPARATOR);
       XMLOutputter out = new XMLOutputter(format);
-
       out.output(document, facesConfig);
-      // TODO: is this replace really necessary?
-      String facesConfigStr =
-          facesConfig.toString().replaceFirst(" xmlns=\"http://java.sun.com/JSF/Configuration\"",
"");
-      // TODO: Find a better way
-      facesConfigStr = facesConfigStr.replaceFirst("\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"",
-          "\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"[\n"
-              + "<!ELEMENT allowed-child-components (#PCDATA)>\n"
-              + "<!ELEMENT category (#PCDATA)>\n"
-              + "<!ELEMENT deprecated (#PCDATA)>\n"
-              + "<!ELEMENT hidden (#PCDATA)>\n"
-              + "<!ELEMENT preferred (#PCDATA)>\n"
-              + "<!ELEMENT read-only (#PCDATA)>\n"
-              + "<!ELEMENT value-expression (#PCDATA)>\n"
-              + "<!ELEMENT property-values (#PCDATA)>\n"
-              + "<!ELEMENT required (#PCDATA)>\n"
-              + "]");
-      writer.append(facesConfigStr);
+      if (!is12()) {
+        // TODO: is this replace really necessary?
+        String facesConfigStr =
+            facesConfig.toString().replaceFirst(" xmlns=\"http://java.sun.com/JSF/Configuration\"",
"");
+        // TODO: Find a better way
+        facesConfigStr = facesConfigStr.replaceFirst("\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"",
+            "\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"[\n"
+                + "<!ELEMENT allowed-child-components (#PCDATA)>\n"
+                + "<!ELEMENT category (#PCDATA)>\n"
+                + "<!ELEMENT deprecated (#PCDATA)>\n"
+                + "<!ELEMENT hidden (#PCDATA)>\n"
+                + "<!ELEMENT preferred (#PCDATA)>\n"
+                + "<!ELEMENT read-only (#PCDATA)>\n"
+                + "<!ELEMENT value-expression (#PCDATA)>\n"
+                + "<!ELEMENT property-values (#PCDATA)>\n"
+                + "<!ELEMENT required (#PCDATA)>\n"
+                + "]");
+        writer.append(facesConfigStr);
+      } else {
+        writer.append(facesConfig.toString());
+      }
 
     } catch (JDOMException e) {
       e.printStackTrace();
@@ -247,6 +271,13 @@
     }
   }
 
+  private void applyNamespace(Element parent, Namespace namespace) {
+    for (Element element:(List<Element>)parent.getChildren()) {
+      element.setNamespace(namespace);
+      applyNamespace(element, namespace);
+    }
+  }
+
   private void addConverter(ClassDeclaration decl, List<Element> newConverters, Namespace
namespace) {
     Converter converterAnn = decl.getAnnotation(Converter.class);
     Element converter = new Element(CONVERTER, namespace);
@@ -427,17 +458,19 @@
           Element property = new Element(PROPERTY, namespace);
           Element propertyName = new Element(PROPERTY_NAME, namespace);
           Element propertyClass = new Element(PROPERTY_CLASS, namespace);
-          Element defaultValue = new Element(DEFAULT_VALUE, namespace);
 
           propertyName.setText(attributeStr);
           addClass(componentAttribute, propertyClass);
-          defaultValue.setText(componentAttribute.defaultValue());
 
           addDescription(d, property, namespace);
 
           property.addContent(propertyName);
           property.addContent(propertyClass);
-          property.addContent(defaultValue);
+          if (componentAttribute.defaultValue().length() > 0) {
+            Element defaultValue = new Element(DEFAULT_VALUE, namespace);
+            defaultValue.setText(componentAttribute.defaultValue());
+            property.addContent(defaultValue);
+          }
 
           property.addContent(createPropertyOrAttributeExtension(PROPERTY_EXTENSION, d, componentAttribute,
namespace));
           properties.add(property);
@@ -446,17 +479,19 @@
           Element attribute = new Element(ATTRIBUTE, namespace);
           Element attributeName = new Element(ATTRIBUTE_NAME, namespace);
           Element attributeClass = new Element(ATTRIBUTE_CLASS, namespace);
-          Element defaultValue = new Element(DEFAULT_VALUE, namespace);
 
           attributeName.setText(attributeStr);
           addClass(componentAttribute, attributeClass);
-          defaultValue.setText(componentAttribute.defaultValue());
 
           addDescription(d, attribute, namespace);
 
           attribute.addContent(attributeName);
           attribute.addContent(attributeClass);
-          attribute.addContent(defaultValue);
+          if (componentAttribute.defaultValue().length() > 0) {
+            Element defaultValue = new Element(DEFAULT_VALUE, namespace);
+            defaultValue.setText(componentAttribute.defaultValue());
+            attribute.addContent(defaultValue);
+          }
 
           attribute.addContent(createPropertyOrAttributeExtension(ATTRIBUTE_EXTENSION, d,
               componentAttribute, namespace));
@@ -474,7 +509,20 @@
       attributeClass.setText(Object.class.getName());
     } else if (componentAttribute.type().length == 1) {
       String className = componentAttribute.type()[0];
-      attributeClass.setText(className.equals(Boolean.class.getName()) ? "boolean" : className);
+      if (componentAttribute.expression().isMethodExpression() && is12()) {
+        className = "javax.el.MethodExpression";
+      }
+      attributeClass.setText((className.equals(Boolean.class.getName()) && !is12())
? "boolean" : className);
+    } else {
+      if (componentAttribute.expression().isMethodExpression()) {
+        String className = "";
+        if (is12()) {
+          className = "javax.el.MethodExpression";
+        } else {
+          className = "javax.faces.el.MethodBinding";
+        }
+        attributeClass.setText(className);
+      }
     }
   }
 
@@ -664,5 +712,9 @@
       Comment c = (Comment) i.next();
       c.setText(c.getText().replaceAll("\n", SEPARATOR));
     }
+  }
+
+  private boolean is12() {
+    return "1.2".equals(jsfVersion);
   }
 }

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java?rev=645313&r1=645312&r2=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java
Sun Apr  6 14:53:32 2008
@@ -26,6 +26,7 @@
 import com.sun.mirror.declaration.PackageDeclaration;
 import com.sun.mirror.type.InterfaceType;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.tobago.apt.annotation.BodyContent;
 import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
 import org.apache.myfaces.tobago.apt.annotation.Preliminary;
@@ -35,6 +36,7 @@
 import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
 import org.apache.myfaces.tobago.apt.annotation.Facet;
 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -53,6 +55,7 @@
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Locale;
+import java.util.Map;
 
 /*
  * Created: Mar 22, 2005 8:18:35 PM
@@ -62,9 +65,18 @@
   private Set<String> tagSet = new HashSet<String>();
   private Set<String> attributeSet = new HashSet<String>();
   private String currentTag;
+  private String jsfVersion = "1.1";
 
   public TaglibAnnotationVisitor(AnnotationProcessorEnvironment env) {
     super(env);
+    for (Map.Entry<String, String> entry : getEnv().getOptions().entrySet()) {
+      if (entry.getKey().startsWith("-Ajsf-version=")) {
+        String version = entry.getKey().substring("-Ajsf-version=".length());
+        if ("1.2".equals(version)) {
+          jsfVersion = "1.2";
+        }
+      }
+    }
   }
 
   public void process() throws Exception {
@@ -85,8 +97,21 @@
     Document document = parser.newDocument();
 
     Element taglib = document.createElement("taglib");
-    addLeafTextElement(taglibAnnotation.tlibVersion(), "tlib-version", taglib, document);
-    addLeafTextElement(taglibAnnotation.jspVersion(), "jsp-version", taglib, document);
+    if (is12()) {
+      taglib.setAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
+      taglib.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+      taglib.setAttribute("xsi:schemaLocation",
+        "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd");
+      taglib.setAttribute("version", "2.1");
+    }
+    if (is12()) {
+      addLeafTextElement("1.2", "tlib-version", taglib, document);
+    } else {
+      addLeafTextElement(taglibAnnotation.tlibVersion(), "tlib-version", taglib, document);
+    }
+    if (!is12()) {
+      addLeafTextElement(taglibAnnotation.jspVersion(), "jsp-version", taglib, document);
+    }
     addLeafTextElement(taglibAnnotation.shortName(), "short-name", taglib, document);
     addLeafTextElement(taglibAnnotation.uri(), "uri", taglib, document);
     String displayName = taglibAnnotation.displayName();
@@ -130,10 +155,12 @@
       TransformerFactory transFactory = TransformerFactory.newInstance();
       transFactory.setAttribute("indent-number", 2);
       Transformer transformer = transFactory.newTransformer();
-      transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
-          "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN");
-      transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
-          "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd");
+      if (!is12()) {
+        transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
+            "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN");
+        transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
+            "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd");
+      }
       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformer.transform(new DOMSource(document),
           new StreamResult(writer));
@@ -387,6 +414,33 @@
         addLeafTextElement(attributeStr, "name", attribute, document);
 
         addLeafTextElement(Boolean.toString(tagAttribute.required()), "required", attribute,
document);
+        UIComponentTagAttribute componentTagAttribute = d.getAnnotation(UIComponentTagAttribute.class);
+        if (is12() && componentTagAttribute != null && !tagAttribute.rtexprvalue())
{
+          if (componentTagAttribute.expression().isMethodExpression()) {
+            Element deferredMethod = document.createElement("deferred-method");
+            StringBuilder signature = new StringBuilder();
+            signature.append(componentTagAttribute.methodReturnType());
+            signature.append(" ");
+            signature.append(attributeStr);
+            signature.append("(");
+            signature.append(StringUtils.join(componentTagAttribute.methodSignature(), ",
"));
+            signature.append(")");   
+            addLeafTextElement(signature.toString(), "method-signature", deferredMethod,
document);
+            attribute.appendChild(deferredMethod);
+          } else if (componentTagAttribute.expression().isValueExpression()) {
+            Element deferredValue = document.createElement("deferred-value");
+            String type = "java.lang.Object";
+            if (componentTagAttribute.expression().isValueExpression()) {
+              if (componentTagAttribute.type().length == 1) {
+                type = componentTagAttribute.type()[0];
+              }
+            } else {
+              type = componentTagAttribute.type()[0];
+            }
+            addLeafTextElement(type, "type", deferredValue, document);
+            attribute.appendChild(deferredValue);
+          }
+        }
         addLeafTextElement(Boolean.toString(tagAttribute.rtexprvalue()), "rtexprvalue", attribute,
document);
         addDescription(d, attribute, document, false);
         tagElement.appendChild(attribute);
@@ -396,4 +450,7 @@
     }
   }
 
+  private boolean is12() {
+    return "1.2".equals(jsfVersion);
+  }
 }

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java?rev=645313&r1=645312&r2=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java
Sun Apr  6 14:53:32 2008
@@ -19,6 +19,7 @@
 
 public class ComponentPropertyInfo extends PropertyInfo {
   private int index;
+  private boolean elAlternativeAvailable;
 
   public String getPropertyTemplate() {
     return getShortTypeProperty() + "Property";
@@ -42,5 +43,13 @@
 
   public int getIndexPlusOne() {
     return index + 1;
+  }
+
+  public boolean isElAlternativeAvailable() {
+    return elAlternativeAvailable;
+  }
+
+  public void setElAlternativeAvailable(boolean elAlternativeAvailable) {
+    this.elAlternativeAvailable = elAlternativeAvailable;
   }
 }

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java?rev=645313&r1=645312&r2=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java
Sun Apr  6 14:53:32 2008
@@ -27,7 +27,8 @@
   private String defaultValue;
   private String defaultCode;
   private boolean valueExpressionRequired;
-  private boolean literal;
+  private boolean methodExpressionRequired;
+  private boolean literalOnly;
   private boolean deprecated;
 
   public PropertyInfo() {
@@ -37,12 +38,12 @@
     this.name = name;
   }
 
-  public boolean isLiteral() {
-    return literal;
+  public boolean isLiteralOnly() {
+    return literalOnly;
   }
 
-  public void setLiteral(boolean literal) {
-    this.literal = literal;
+  public void setLiteralOnly(boolean literalOnly) {
+    this.literalOnly = literalOnly;
   }
 
   public String getTemplate() {
@@ -165,6 +166,14 @@
     this.valueExpressionRequired = valueExpressionRequired;
   }
 
+  public boolean isMethodExpressionRequired() {
+    return methodExpressionRequired;
+  }
+
+  public void setMethodExpressionRequired(boolean methodExpressionRequired) {
+    this.methodExpressionRequired = methodExpressionRequired;
+  }
+
   public PropertyInfo fill(PropertyInfo info) {
     info.setName(name);
     info.setType(type);
@@ -174,7 +183,8 @@
     info.setMethodSignature(methodSignature);
     info.setDefaultCode(defaultCode);
     info.setValueExpressionRequired(valueExpressionRequired);
-    info.setLiteral(literal);
+    info.setLiteralOnly(literalOnly);
+    info.setMethodExpressionRequired(methodExpressionRequired);
     return info;
   }
 

Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.1.stg
(from r644224, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.1.stg?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.1.stg&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg&r1=644224&r2=645313&rev=645313&view=diff
==============================================================================
    (empty)

Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.1.stg
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.2.stg
(from r644224, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component12.stg)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.2.stg?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.2.stg&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component12.stg&r1=644224&r2=645313&rev=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component12.stg
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component1.2.stg
Sun Apr  6 14:53:32 2008
@@ -235,6 +235,38 @@
 MethodBindingProperty(property) ::= <<
 
 public <property.type> get<property.upperCamelCaseName>() {
+<if(property.elAlternativeAvailable)>
+  javax.el.MethodExpression expression = get<property.upperCamelCaseName>Expression();
+  if (expression instanceof org.apache.myfaces.tobago.component.MethodBindingToMethodExpression)
{
+    return ((org.apache.myfaces.tobago.component.MethodBindingToMethodExpression)expression).getMethodBinding();
+  }
+  if (expression != null) {
+     return new org.apache.myfaces.tobago.component.MethodExpressionToMethodBinding(expression);
+  }
+  return null;
+<else>
+  return <property.propertyName>;
+<endif>
+
+}
+
+public void set<property.upperCamelCaseName>(<property.type> <property.propertyName>)
{
+<if(property.elAlternativeAvailable)>
+  if (<property.propertyName> != null) {
+    set<property.upperCamelCaseName>Expression(new org.apache.myfaces.tobago.component.MethodBindingToMethodExpression(<property.propertyName>));
+  } else {
+    set<property.upperCamelCaseName>Expression(null);
+  }
+<else>
+  this.<property.propertyName> = <property.propertyName>;
+<endif>
+
+}
+>>
+
+MethodExpressionProperty(property) ::= <<
+
+public <property.type> get<property.upperCamelCaseName>() {
   return <property.propertyName>;
 }
 
@@ -278,7 +310,10 @@
 
 
 field() ::= <<
+<if(it.elAlternativeAvailable)>
+<else>
 private <it.type> <it.propertyName>;
+<endif>
 >>
 
 restoreStateField() ::= <<
@@ -326,6 +361,13 @@
 >>
 
 MethodBindingSaveStateProperty() ::= <<
+<if(it.elAlternativeAvailable)>
+<else>
+values[<it.indexPlusOne>] = saveAttachedState(context, <it.propertyName>);
+<endif>
+>>
+
+MethodExpressionSaveStateProperty() ::= <<
 values[<it.indexPlusOne>] = saveAttachedState(context, <it.propertyName>);
 >>
 
@@ -367,10 +409,15 @@
 >>
 
 MethodBindingRestoreStateProperty() ::= <<
+<if(it.elAlternativeAvailable)>
+<else>
 <it.propertyName> = (<it.type>) restoreAttachedState(context, values[<it.indexPlusOne>]);
+<endif>
 >>
 
-
+MethodExpressionRestoreStateProperty() ::= <<
+<it.propertyName> = (<it.type>) restoreAttachedState(context, values[<it.indexPlusOne>]);
+>>
 
 getValueExpression(property) ::= <<
 javax.el.ValueExpression ve = getValueExpression("<property.name>");

Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg
(from r644224, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag12.stg)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag12.stg&r1=644224&r2=645313&rev=645313&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag12.stg
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg
Sun Apr  6 14:53:32 2008
@@ -89,6 +89,7 @@
 >>
 
 property() ::= <<
+<if(it.literalOnly)>
 public String get<it.upperCamelCaseName>() {
   return <it.propertyName>;
 }
@@ -96,16 +97,48 @@
 public void set<it.upperCamelCaseName>(String <it.propertyName>) {
   this.<it.propertyName> = <it.propertyName>;
 }
+<else>
+<if(it.methodExpressionRequired)>
+public javax.el.MethodExpression get<it.upperCamelCaseName>() {
+  return <it.propertyName>;
+}
+
+public void set<it.upperCamelCaseName>(javax.el.MethodExpression <it.propertyName>)
{
+  this.<it.propertyName> = <it.propertyName>;
+}
+<else>
+public javax.el.ValueExpression get<it.upperCamelCaseName>() {
+  return <it.propertyName>;
+}
+
+public void set<it.upperCamelCaseName>(javax.el.ValueExpression <it.propertyName>)
{
+  this.<it.propertyName> = <it.propertyName>;
+}
+<endif>
+<endif>
+
 
 >>
 
 field() ::= <<
+<if(it.literalOnly)>
 private String <it.propertyName>;
+<else>
+  <if(it.methodExpressionRequired)>
+private javax.el.MethodExpression  <it.propertyName>;
+  <else>
+private javax.el.ValueExpression  <it.propertyName>;
+  <endif>
+<endif>
 >>
 
 ValueExpression() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createValueBinding(it)>
+if (<it.propertyName> != null) {
+  if (!<it.propertyName>.isLiteralText()) {
+    <createValueBinding(it)>
+  /*} else {
+    component.set<it.upperCamelCaseName>(<it.propertyName>.getExpressionString());*/
+  }
 }
 >>
 
@@ -115,10 +148,10 @@
 
 Severity() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
-    component.getAttributes().put("<it.name>", <it.propertyName>);
+    component.getAttributes().put("<it.name>", <it.propertyName>.getExpressionString());
   }
 }
 >>
@@ -129,146 +162,138 @@
 
 Character() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
-    component.set<it.upperCamelCaseName>(<it.propertyName>.charAt(0));
+    component.set<it.upperCamelCaseName>(<it.propertyName>.getExpressionString().charAt(0));
   }
 }
 >>
 
 Boolean() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
-    component.set<it.upperCamelCaseName>(Boolean.valueOf(<it.propertyName>));
+    component.set<it.upperCamelCaseName>(Boolean.valueOf(<it.propertyName>.getExpressionString()));
   }
 }
 >>
 
 Integer() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
     <if(it.widthOrHeight)>
-    if (<it.propertyName>.endsWith("px")) {
-      <it.propertyName> = <it.propertyName>.substring(0, <it.propertyName>.length()
- 2);
+    String <it.propertyName>Str = <it.propertyName>.getExpressionString();
+    if (<it.propertyName>Str.endsWith("px")) {
+      <it.propertyName>Str = <it.propertyName>Str.substring(0, <it.propertyName>Str.length()
- 2);
     }
+    component.set<it.upperCamelCaseName>(Integer.parseInt(<it.propertyName>Str));
+    <else>
+    component.set<it.upperCamelCaseName>(Integer.parseInt(<it.propertyName>.getExpressionString()));
     <endif>
-    component.set<it.upperCamelCaseName>(Integer.parseInt(<it.propertyName>));
   }
 }
 >>
 
 OrderBy() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
-    component.set<it.upperCamelCaseName>(org.apache.myfaces.tobago.component.AbstractUIMessages.OrderBy.parse(<it.propertyName>));
+    component.set<it.upperCamelCaseName>(org.apache.myfaces.tobago.component.AbstractUIMessages.OrderBy.parse(<it.propertyName>.getExpressionString()));
   }
 }
 >>
 
 StringArray() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
-    component.set<it.upperCamelCaseName>(splitList(<it.propertyName>));
+    component.set<it.upperCamelCaseName>(splitList(<it.propertyName>.getExpressionString()));
   }
 }
 >>
 
 TabChangeListener() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createMethodBinding(it)>
-  component.set<it.template>(methodBinding);
+if (<it.propertyName> != null) {
+  component.add<it.template>(new org.apache.myfaces.tobago.event.MethodExpressionTabChangeListener(<it.propertyName>));
 }
 >>
 
 ActionListener() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
- <createMethodBinding(it)>
- component.set<it.template>(methodBinding);
+if (<it.propertyName> != null) {
+  component.add<it.template>(new javax.faces.event.MethodExpressionActionListener(<it.propertyName>));
 }
 >>
 
 ValueChangeListener() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createMethodBinding(it)>
-  component.set<it.template>(methodBinding);
+if (<it.propertyName> != null) {
+  component.add<it.template>(new javax.faces.event.MethodExpressionValueChangeListener(<it.propertyName>));
 }
 >>
 
 StateChangeListener() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createMethodBinding(it)>
-  component.set<it.template>(methodBinding);
+if (<it.propertyName> != null) {
+  component.add<it.template>(new org.apache.myfaces.tobago.event.MethodExpressionStateChangeListener(<it.propertyName>));
 }
 >>
 
 SortActionListener() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createMethodBinding(it)>
-  component.set<it.template>(methodBinding);
+if (<it.propertyName> != null) {
+  component.set<it.template>Expression(<it.propertyName>);
 }
 >>
 
 SuggestMethod() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createMethodBinding(it)>
-  component.set<it.template>(methodBinding);
+if (<it.propertyName> != null) {
+  component.set<it.template>Expression(<it.propertyName>);
 }
 >>
 
 Validator() ::= <<
-if (<it.propertyName> != null && isValueReference(<it.propertyName>))
{
-  <createMethodBinding(it)>
-  component.setValidator(methodBinding);
+if (<it.propertyName> != null) {
+  component.addValidator(new javax.faces.validator.MethodExpressionValidator(<it.propertyName>));
 }
 >>
 
 Action() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
-    <createMethodBinding(it)>
-    component.setAction(methodBinding);
-  } else {
-    component.setAction(new org.apache.myfaces.tobago.el.ConstantMethodBinding(<it.propertyName>));
-  }
+  component.setActionExpression(<it.propertyName>);
 }
 >>
 
 Converter() ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
+  if (!<it.propertyName>.isLiteralText()) {
     <createValueBinding(it)>
   } else {
-    component.setConverter(context.getApplication().createConverter(<it.propertyName>));
+    component.setConverter(application.createConverter(<it.propertyName>.getExpressionString()));
   }
 }
 >>
 
 createMethodBinding(it) ::= <<
-javax.faces.el.MethodBinding methodBinding = application.createMethodBinding(<it.propertyName>,
+javax.faces.el.MethodBinding methodBinding = application.createMethodBinding(<it.propertyName>.getExpressionString(),
     new Class[] { <first(it.methodSignature):{ n | <n>.class }><rest(it.methodSignature):{
n | , <n>.class}>} );
 >>
 
 createStringProperty(it) ::= <<
 if (<it.propertyName> != null) {
-  if (isValueReference(<it.propertyName>)) {
-    <createValueBinding(it)>
-  } else {
-    component.set<it.upperCamelCaseName>(<it.propertyName>);
-  }
+  <if(it.literalOnly)>
+  component.set<it.upperCamelCaseName>(<it.propertyName>);
+  <else>
+  <createValueBinding(it)>
+  <endif>
 }
+
 >>
 
 createValueBinding(it) ::= <<
-component.setValueBinding("<it.name>", application.createValueBinding(<it.propertyName>));
+component.setValueExpression("<it.name>", <it.propertyName>);
 >>
 
 



Mime
View raw message