incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r469034 - in /incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces: ./ generator/ parse/
Date Mon, 30 Oct 2006 00:29:39 GMT
Author: baranda
Date: Sun Oct 29 16:29:39 2006
New Revision: 469034

URL: http://svn.apache.org/viewvc?view=rev&rev=469034
Log:
Proper accessors for MyFaces component generator (following the spec)
saveState/restoreState autogeneration

Modified:
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/AbstractComponentGenerator.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ComponentGenerator.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/MyFacesComponentGenerator.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java?view=diff&rev=469034&r1=469033&r2=469034
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java
Sun Oct 29 16:29:39 2006
@@ -15,41 +15,25 @@
 */
 package org.apache.myfaces.trinidadbuild.plugin.faces;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.ComponentGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.MyFacesComponentGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.TrinidadComponentGenerator;
 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.EventBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.EventRefBean;
 import org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacesConfigBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacetBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.ComponentFilter;
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.PropertyFilter;
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.SourceTemplate;
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
-import org.apache.myfaces.trinidadbuild.plugin.faces.generator.ComponentGenerator;
-import org.apache.myfaces.trinidadbuild.plugin.faces.generator.TrinidadComponentGenerator;
-import org.apache.myfaces.trinidadbuild.plugin.faces.generator.MyFacesComponentGenerator;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
 
 /**
  * @version $Id$
@@ -232,6 +216,8 @@
 
         if (!suppressListenerMethods)
           generator.writeListenerMethods(out, component);
+
+        generator.writeStateManagementMethods(out, component);
 
         generator.writeGetFamily(out);
 

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/AbstractComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/AbstractComponentGenerator.java?view=diff&rev=469034&r1=469033&r2=469034
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/AbstractComponentGenerator.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/AbstractComponentGenerator.java
Sun Oct 29 16:29:39 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.myfaces.trinidadbuild.plugin.faces.generator;
 
+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.EventBean;
@@ -25,17 +26,14 @@
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.PropertyFilter;
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.SourceTemplate;
 import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
-import org.apache.maven.plugin.logging.Log;
 
 import java.io.IOException;
 import java.lang.reflect.Modifier;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
@@ -587,18 +585,22 @@
         {
             out.println(" * Sets " + convertMultilineComment(description));
         }
-        // TODO: restore this comment.
-//    if (property.isRequired())
-//    {
-//      out.println(" * <p>");
-//      out.println(" * This is a required property on the component.");
-//    }
-        // TODO: put this back in
-        //out.println(" * ");
-        //out.println(" * @param " + propName + "  the new " + propName + " value");
+
+        if (property.isRequired())
+        {
+            out.println(" * <p>");
+            out.println(" * This is a required property on the component.");
+        }
+        out.println(" * ");
+        out.println(" * @param " + propName + "  the new " + propName + " value");
         out.println(" */");
 
-        out.println("final public void " + setMethod + "(" + propertyClass + " " + propVar
+ ")");
+        if (isAccessorMethodFinal())
+        {
+            out.print("final ");
+        }
+
+        out.println("public void " + setMethod + "(" + propertyClass + " " + propVar + ")");
         out.println("{");
         out.indent();
         writePropertySetterContent(out, property, propertyClass);
@@ -641,9 +643,9 @@
             out.println(" * This is a required property on the component.");
             out.println(" * </p>");
         }
-        // TODO: put this back in
-        //out.println(" *");
-        //out.println(" * @return  the new " + propName + " value");
+
+        out.println(" *");
+        out.println(" * @return  the new " + propName + " value");
         out.println(" */");
 
         if (isUnchecked)
@@ -651,7 +653,12 @@
             out.println("@SuppressWarnings(\"unchecked\")");
         }
 
-        out.println("final public " + propertyClass + " " + getMethod + "()");
+        if (isAccessorMethodFinal())
+        {
+            out.print("final ");
+        }
+
+        out.println("public " + propertyClass + " " + getMethod + "()");
         out.println("{");
         out.indent();
 
@@ -661,6 +668,15 @@
         out.println("}");
     }
 
+    /**
+     * Whether the getters/setters have the final modifier
+     * @return true if the getters/setters are final
+     */
+    protected boolean isAccessorMethodFinal()
+    {
+        return false;
+    }
+
     protected abstract void writePropertyGetterContent(
             PrettyWriter out,
             PropertyBean property) throws IOException;
@@ -850,6 +866,10 @@
         out.unindent();
         out.println("}");
     }
+
+
+    public abstract void writeStateManagementMethods(PrettyWriter out,
+                                                     ComponentBean component) throws IOException;
 
     public void writeOther(
             PrettyWriter out, ComponentBean component) throws IOException

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ComponentGenerator.java?view=diff&rev=469034&r1=469033&r2=469034
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ComponentGenerator.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/ComponentGenerator.java
Sun Oct 29 16:29:39 2006
@@ -70,6 +70,10 @@
             PrettyWriter out,
             ComponentBean component) throws IOException;
 
+    void writeStateManagementMethods(
+            PrettyWriter out,
+            ComponentBean component) throws IOException;
+
     void writeOther(
             PrettyWriter out, ComponentBean component) throws IOException;
 }

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/MyFacesComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/MyFacesComponentGenerator.java?view=diff&rev=469034&r1=469033&r2=469034
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/MyFacesComponentGenerator.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/MyFacesComponentGenerator.java
Sun Oct 29 16:29:39 2006
@@ -16,12 +16,14 @@
 package org.apache.myfaces.trinidadbuild.plugin.faces.generator;
 
 import org.apache.maven.plugin.logging.Log;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
 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.Iterator;
+import java.util.Set;
 
 /**
  * Component generator for MyFaces
@@ -36,9 +38,11 @@
         super(log);
     }
 
-    protected void writeConstructorContent(PrettyWriter out, ComponentBean component, int
modifiers, String rendererType) throws IOException
+
+    protected void addSpecificImports(Set imports, ComponentBean component)
     {
-        out.println("setRendererType("+rendererType+");");
+        imports.add("javax.faces.context.FacesContext");
+        imports.add("javax.el.ValueExpression");
     }
 
     public void writePropertyDeclaration(PrettyWriter out,
@@ -54,6 +58,30 @@
         out.println("private " + propertyClass + " " + fieldPropName + ";");
     }
 
+    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 writePropertySetterContent(PrettyWriter out,
                                               PropertyBean property,
                                               String propertyClass) throws IOException
@@ -64,13 +92,99 @@
     protected void writePropertyGetterContent(PrettyWriter out,
                                               PropertyBean property) throws IOException
     {
-        out.println("return this."+property.getFieldPropertyName()+";");
+        String varName = property.getFieldPropertyName();
+        String propName = property.getPropertyName();
+        String propFullClass = property.getPropertyClass();
+        String propClass = Util.getClassFromFullClass(propFullClass);
+
+        out.println("if ("+varName+" != null)");
+        out.println("{");
+        out.indent();
+        out.println("return "+property.getFieldPropertyName()+";");
+        out.unindent();
+        out.println("}");
+        out.println("ValueExpression expression = getValueExpression(\""+propName+"\");");
+        out.println("if (expression != null)");
+        out.println("{");
+        out.indent();
+        out.println("return "+_castIfNecessary(propClass)+"expression.getValue(getFacesContext().getELContext());");
+        out.unindent();
+        out.println("}");
+        out.println("return null;");
     }
 
-    public void writePropertyListMethods(
-            PrettyWriter out,
-            PropertyBean property) throws IOException
+    protected void writeSaveState(PrettyWriter out,
+                               ComponentBean component) throws IOException
     {
-        // nothing
+        String arrayName = "values";
+        int arraySize = component.propertiesSize() + 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();
+
+            out.println(arrayName+"["+propIndex+"] = "+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);
+
+            out.println(varName + " = " + _castIfNecessary(propClass)
+                    + arrayName + "[" + propIndex + "];");
+            propIndex++;
+        }
+
+        out.unindent();
+        out.println("}");
+    }
+
+    private static String _castIfNecessary(String propClass)
+    {
+        if (propClass.equals("Object") || propClass.equals("java.lang.Object"))
+        {
+            return "";
+        }
+
+        return "("+propClass+")";
     }
 }

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java?view=diff&rev=469034&r1=469033&r2=469034
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
Sun Oct 29 16:29:39 2006
@@ -16,19 +16,19 @@
 package org.apache.myfaces.trinidadbuild.plugin.faces.generator;
 
 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 org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
 
-import java.util.Iterator;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
 import java.io.IOException;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
 
 public class TrinidadComponentGenerator extends AbstractComponentGenerator
 {
@@ -134,7 +134,18 @@
 
     protected void writePropertyDeclaration(PrettyWriter out, PropertyBean property) throws
IOException
     {
-        // nothing
+        // 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 writePropertySetterContent(PrettyWriter out,
@@ -211,6 +222,11 @@
                         "getProperty(" + propKey + ");");
             }
         }
+    }
+
+    public void writeStateManagementMethods(PrettyWriter out, ComponentBean component) throws
IOException
+    {
+        // nothing to do here
     }
 
     public void writePropertyListMethods(

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java?view=diff&rev=469034&r1=469033&r2=469034
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
Sun Oct 29 16:29:39 2006
@@ -15,17 +15,15 @@
 */
 package org.apache.myfaces.trinidadbuild.plugin.faces.parse;
 
-import java.lang.reflect.Modifier;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.CompoundIterator;
 
+import javax.xml.namespace.QName;
+import java.lang.reflect.Modifier;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.logging.Logger;
 
-import javax.xml.namespace.QName;
-
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.CompoundIterator;
-
 /**
  * ComponentBean is a Java representation of the faces-config component
  * XML element.
@@ -479,6 +477,15 @@
         properties = new CompoundIterator(parent.properties(true), properties);
     }
     return properties;
+  }
+
+ /**
+  * Number of properties for this component
+  * @return num of properties
+  */
+  public int propertiesSize()
+  {
+    return _properties.size();
   }
 
   /**



Mime
View raw message