incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r495044 - in /incubator/adffaces/branches/faces-1_2-070102: plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/ plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuil...
Date Wed, 10 Jan 2007 23:54:07 GMT
Author: awiner
Date: Wed Jan 10 15:54:06 2007
New Revision: 495044

URL: http://svn.apache.org/viewvc?view=rev&rev=495044
Log:
Fixes in both the generator and renderkit test framework to support Enum-typed properties
- Support mfp:enum metadata in property-extension to tell the generator that a property is
an enum (since it may not actually have access to the class to find out directly)
- Support for default values in the component generator
- RenderKitTest: Hack to (theoretically) support testing attribute values of enums
- RenderKitTest: Hack to support property types that are inner classes (the metadata uses
'.' syntax, but the classloader wants '$' syntax)

Modified:
    incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.java
    incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TrinidadComponentTagGenerator.java
    incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java
    incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
    incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
    incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/FacesConfigParser.java

Modified: incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.java?view=diff&rev=495044&r1=495043&r2=495044
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.java
(original)
+++ incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/TrinidadComponentGenerator.java
Wed Jan 10 15:54:06 2007
@@ -121,7 +121,12 @@
 
         if (propDefault != null)
         {
-          out.print(", " + convertStringToBoxedLiteral(propClass, propDefault));
+          if (property.isEnum())
+            out.print(", Enum.valueOf(" + propClass + ".class," +
+                      convertStringToBoxedLiteral("String", propDefault) +
+                      ")");
+          else
+            out.print(", " + convertStringToBoxedLiteral(propClass, propDefault));
         }
 
         // property capabilities

Modified: incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TrinidadComponentTagGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TrinidadComponentTagGenerator.java?view=diff&rev=495044&r1=495043&r2=495044
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TrinidadComponentTagGenerator.java
(original)
+++ incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/taglib/TrinidadComponentTagGenerator.java
Wed Jan 10 15:54:06 2007
@@ -122,6 +122,10 @@
       {
         imports.add("javax.el.MethodExpression");
       }
+      else if (property.isEnum())
+      {
+        imports.add(propertyClass);
+      }
     }
   }
 
@@ -235,6 +239,10 @@
     {
       _writeSetMethodExpression(out, componentClass, property);
     }
+    else if (property.isEnum())
+    {
+      _writeSetEnum(out, componentClass, property);
+    }
     else if (GeneratorHelper.isKeyStroke(propClass))
     {
       _writeSetKeyStroke(out, componentClass, propName);
@@ -509,6 +517,66 @@
     out.println("bean.setProperty(" + componentClass + "." + propKey + ", " +
         propVar + ");");
   }
+
+  private void _writeSetEnum(
+      PrettyWriter out,
+      String componentClass,
+      PropertyBean property) throws IOException
+  {
+    String propName = property.getPropertyName();
+    String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+    String propVar = "_" + propName;
+    String propClass = Util.getClassFromFullClass(property.getPropertyClass());
+
+    if (_is12)
+    {
+      out.println("if (" + propVar + " != null)");
+      out.println("{");
+      out.indent();
+      out.println("if (!" + propVar + ".isLiteralText())");
+      out.println("{");
+      out.indent();
+      out.println("bean.setValueExpression(" + componentClass + "." + propKey + ", " + propVar
+ ");");
+      out.unindent();
+      out.println("}");
+      out.println("else");
+      out.println("{");
+      out.indent();
+      out.println("Object val = " + propVar + ".getValue(null);");
+      out.println("if (val != null)");
+      out.indent();
+      out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
+      out.println("Enum.valueOf(" + propClass + ".class,val.toString()));");
+      out.unindent();
+      out.unindent();
+      out.println("}");
+      out.unindent();
+      out.println("}");
+    }
+    else
+    {
+      out.println("if (" + propVar + " != null)");
+      out.println("{");
+      out.indent();
+      out.println("if (isValueReference(" + propVar + "))");
+      out.println("{");
+      out.indent();
+      out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
+      out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
+      out.unindent();
+      out.println("}");
+      out.println("else");
+      out.println("{");
+      out.indent();
+      out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
+      out.println("Enum.valueOf(" + propClass + ".class," + propVar + "));");
+      out.unindent();
+      out.println("}");
+      out.unindent();
+      out.println("}");
+    }
+  }
+
 
   private void _writeSetKeyStroke(
       PrettyWriter out,

Modified: incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java?view=diff&rev=495044&r1=495043&r2=495044
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java
(original)
+++ incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java
Wed Jan 10 15:54:06 2007
@@ -187,6 +187,8 @@
     digester.addBeanPropertySetter("faces-config/component/property/property-extension/transient");
     digester.addBeanPropertySetter("faces-config/component/property/property-extension/literal-only",
                                    "literalOnly");
+    digester.addBeanPropertySetter("faces-config/component/property/property-extension/enum",
+                                   "enum");
     digester.addBeanPropertySetter("faces-config/component/property/property-extension/alternate-class",
                                    "alternateClass");
     digester.addBeanPropertySetter("faces-config/component/property/property-extension/tag-attribute-excluded",

Modified: incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java?view=diff&rev=495044&r1=495043&r2=495044
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
(original)
+++ incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
Wed Jan 10 15:54:06 2007
@@ -270,6 +270,22 @@
   }
 
   /**
+   * Returns true if the property is an enumerated Java type.
+   */
+  public boolean isEnum()
+  {
+    return _enum;
+  }
+
+  /**
+   * Returns true if the property is an enumerated Java type.
+   */
+  public void setEnum(boolean isEnum)
+  {
+    _enum = isEnum;
+  }
+
+  /**
    * Returns true if this property is a method binding.
    *
    * @return true  if this property is a method binding,
@@ -373,6 +389,7 @@
   private boolean _transient;
   private boolean _list;
   private boolean _tagAttributeExcluded;
+  private boolean _enum;
   private String[] _propertyValues;
   private String[] _unsupportedAgents = _EMPTY_ARRAY;
 

Modified: incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java?view=diff&rev=495044&r1=495043&r2=495044
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
(original)
+++ incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
Wed Jan 10 15:54:06 2007
@@ -176,6 +176,11 @@
       {
         return text;
       }
+      else if (Enum.class.isAssignableFrom(type))
+      {
+        return Enum.valueOf((Class<? extends Enum>) type, text);
+      }
+
       throw new IllegalArgumentException(text + " cannot be parsed into a " +
                                          type.getName());
     }
@@ -266,6 +271,10 @@
           Array.set(res, 0, arrayValue);
         }
         return res;
+      }
+      else if (Enum.class.isAssignableFrom(type))
+      {
+        return Enum.valueOf((Class<? extends Enum>) type, value.toString());
       }
 
       throw new IllegalArgumentException("Could not coerce value of type " +

Modified: incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/FacesConfigParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/FacesConfigParser.java?view=diff&rev=495044&r1=495043&r2=495044
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/FacesConfigParser.java
(original)
+++ incubator/adffaces/branches/faces-1_2-070102/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/FacesConfigParser.java
Wed Jan 10 15:54:06 2007
@@ -312,7 +312,7 @@
               
             try
             {
-              c = Class.forName(s);
+              c = _loadClass(s);
               if (isArray)
                 c = _getArrayType(c);
             }
@@ -351,6 +351,34 @@
     
     private FacesConfigInfo.ComponentInfo _info;
     private FacesConfigInfo.PropertyInfo  _property;
+  }
+
+  /**
+   * Load a class, "trying harder" - supports "." syntax
+   * to access inner classes
+   */
+  static private Class _loadClass(String s) throws ClassNotFoundException
+  {
+    try
+    {
+      return Class.forName(s);
+    }
+    catch (ClassNotFoundException cnfe)
+    {
+      // If the inner class works, great
+      int lastPeriod = s.lastIndexOf('.');
+      String ifInnerClass =
+        s.substring(0, lastPeriod) + "$" + s.substring(lastPeriod + 1);
+      try
+      {
+        return Class.forName(ifInnerClass);
+      }
+      catch (ClassNotFoundException cnfe2)
+      {
+        // Otherwise, throw the original exception
+        throw cnfe;
+      }
+    }
   }
 
   private class RendererParser extends BaseNodeParser



Mime
View raw message