incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r471464 - in /incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces: generator/component/ util/
Date Sun, 05 Nov 2006 17:16:10 GMT
Author: baranda
Date: Sun Nov  5 09:16:09 2006
New Revision: 471464

URL: http://svn.apache.org/viewvc?view=rev&rev=471464
Log:
Fixed accessor methods for primitives in the Myfaces component generator.
Final methods depend on the generator implementation, so it generates final methods for trinidad
but not for myfaces, to follow the spec.
Fixed state holder methods to be able to deal correctly with MethodExpression/MethodBinding

Modified:
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.java
    incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/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/component/AbstractComponentGenerator.java?view=diff&rev=471464&r1=471463&r2=471464
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java
Sun Nov  5 09:16:09 2006
@@ -803,7 +803,11 @@
         out.println(" * @param listener  the " + eventName + " listener to add");
         out.println(" */");
 
-        out.println("final public void " + addMethod + "(");
+        if (isAccessorMethodFinal())
+        {
+            out.print("final ");
+        }
+        out.println("public void " + addMethod + "(");
         out.indent();
         out.println(listenerClass + " listener)");
         out.unindent();
@@ -831,7 +835,11 @@
         out.println(" * @param listener  the " + eventName + " listener to remove");
         out.println(" */");
 
-        out.println("final public void " + removeMethod + "(");
+        if (isAccessorMethodFinal())
+        {
+            out.print("final ");
+        }
+        out.println("public void " + removeMethod + "(");
         out.indent();
         out.println(listenerClass + " listener)");
         out.unindent();
@@ -859,7 +867,11 @@
         out.println(" * @return  an array of attached " + eventName + " listeners.");
         out.println(" */");
 
-        out.println("final public " + listenerClass + "[] " + getMethod + "()");
+        if (isAccessorMethodFinal())
+        {
+            out.print("final ");
+        }
+        out.println("public " + listenerClass + "[] " + getMethod + "()");
         out.println("{");
         out.indent();
         out.println("return (" + listenerClass + "[])" +

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.java?view=diff&rev=471464&r1=471463&r2=471464
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/MyFacesComponentGenerator.java
Sun Nov  5 09:16:09 2006
@@ -56,6 +56,11 @@
         out.println();
         out.println("// Property: " + propName);
         out.println("private " + propertyClass + " " + fieldPropName + ";");
+
+        if (Util.isPrimitiveClass(propertyFullClass))
+        {
+            out.println("private boolean " + fieldPropName + "Set;");
+        }
     }
 
     public void writeStateManagementMethods(PrettyWriter out,
@@ -86,7 +91,14 @@
                                               PropertyBean property,
                                               String propertyClass) throws IOException
     {
-        out.println("this."+property.getFieldPropertyName()+" = "+property.getPropertyName()+";");
+        String varName = property.getFieldPropertyName();
+
+        out.println("this."+varName+" = "+property.getPropertyName()+";");
+
+        if (Util.isPrimitiveClass(propertyClass))
+        {
+            out.println("this."+_primitiveSetVarName(varName)+" = true;");
+        }
     }
 
     protected void writePropertyGetterMethodBody(PrettyWriter out,
@@ -97,7 +109,14 @@
         String propFullClass = property.getPropertyClass();
         String propClass = Util.getClassFromFullClass(propFullClass);
 
-        out.println("if ("+varName+" != null)");
+        if (Util.isPrimitiveClass(propFullClass))
+        {
+            out.println("if ("+ _primitiveSetVarName(varName)+")");
+        }
+        else
+        {
+            out.println("if ("+varName+" != null)");
+        }
         out.println("{");
         out.indent();
         out.println("return "+property.getFieldPropertyName()+";");
@@ -110,14 +129,37 @@
         out.println("return "+_castIfNecessary(propClass)+"expression.getValue(getFacesContext().getELContext());");
         out.unindent();
         out.println("}");
-        out.println("return null;");
+
+        if (Util.isPrimitiveClass(propFullClass))
+        {
+            out.println("return "+Util.primitiveDefaultValue(propFullClass)+";");
+        }
+        else
+        {
+            out.println("return null;");
+        }
     }
 
     protected void writeSaveState(PrettyWriter out,
                                ComponentBean component) throws IOException
     {
         String arrayName = "values";
-        int arraySize = component.propertiesSize() + 1;
+
+        // first we count the primitive properties, because for each primitive property
+        // we save a new property that says if the property has been set or not
+        int primitivePropertiesCount = 0;
+        for (Iterator iterator = component.properties(); iterator.hasNext();)
+        {
+            PropertyBean property =  (PropertyBean) iterator.next();
+            if (Util.isPrimitiveClass(property.getPropertyClass()))
+            {
+                primitivePropertiesCount++;
+            }
+        }
+
+        // the total array size is the number of properties, plus the number of primitives,
+        // plus 1 (the super call)
+        int arraySize = component.propertiesSize() + primitivePropertiesCount + 1;
 
         out.println();
         out.println("@Override");
@@ -135,8 +177,22 @@
             PropertyBean property =  (PropertyBean) iterator.next();
             String varName = property.getFieldPropertyName();
 
-            out.println(arrayName+"["+propIndex+"] = "+varName+";");
+            if (property.isMethodExpression() || property.isMethodBinding())
+            {
+                out.println(arrayName+"["+propIndex+"] = saveAttachedState(facesContext,
"+varName+");");
+            }
+            else
+            {
+                out.println(arrayName+"["+propIndex+"] = "+varName+";");
+            }
+
             propIndex++;
+
+            if (Util.isPrimitiveClass(property.getPropertyClass()))
+            {
+                out.println(arrayName+"["+propIndex+"] = "+_primitiveSetVarName(varName)+";");
+                propIndex++;
+            }
         }
 
         out.println();
@@ -169,9 +225,25 @@
             String propFullClass = property.getPropertyClass();
             String propClass = Util.getClassFromFullClass(propFullClass);
 
-            out.println(varName + " = " + _castIfNecessary(propClass)
+            if (property.isMethodExpression() || property.isMethodBinding())
+            {
+                out.println(varName + " = "+_castIfNecessary(propClass)+"restoreAttachedState(facesContext,
"
+                    + arrayName + "[" + propIndex + "]);");
+            }
+            else
+            {
+                out.println(varName + " = " + _castIfNecessary(propClass)
                     + arrayName + "[" + propIndex + "];");
+            }
+
             propIndex++;
+
+            if (Util.isPrimitiveClass(property.getPropertyClass()))
+            {
+                out.println(_primitiveSetVarName(varName) + " = (Boolean)"
+                    + arrayName + "[" + propIndex + "];");
+                propIndex++;
+            }
         }
 
         out.unindent();
@@ -185,6 +257,16 @@
             return "";
         }
 
+        if (Util.isPrimitiveClass(propClass))
+        {
+            propClass = Util.getBoxedClass(propClass);
+        }
+
         return "("+propClass+")";
+    }
+
+    private static String _primitiveSetVarName(String varName)
+    {
+        return varName+"Set";
     }
 }

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.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/util/Util.java?view=diff&rev=471464&r1=471463&r2=471464
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
Sun Nov  5 09:16:09 2006
@@ -203,6 +203,28 @@
       return className;
   }
 
+  static public String primitiveDefaultValue(String className)
+  {
+     if ("boolean".equals(className))
+      return "false";
+    else if ("byte".equals(className))
+      return "0";
+    else if ("char".equals(className))
+      return "''";
+    else if ("double".equals(className))
+      return "0.0d";
+    else if ("float".equals(className))
+      return "0.0f";
+    else if ("int".equals(className))
+      return "0";
+    else if ("long".equals(className))
+      return "0L";
+    else if ("short".equals(className))
+      return "0";
+    else
+      return className;
+  }
+
   static public String fill(
     String base,
     int    length)



Mime
View raw message