tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance TestParameterPropertyWorker.java
Date Mon, 07 Feb 2005 17:50:27 GMT
hlship      2005/02/07 09:50:27

  Modified:    framework/src/java/org/apache/tapestry/enhance
                        ParameterPropertyWorker.java EnhanceUtils.java
               framework/src/test/org/apache/tapestry/enhance
                        TestParameterPropertyWorker.java
  Log:
  Move some logic for extracting primitives from bindings into EnhanceUtils.
  
  Revision  Changes    Path
  1.10      +16 -11    jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java
  
  Index: ParameterPropertyWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ParameterPropertyWorker.java	31 Jan 2005 05:36:20 -0000	1.9
  +++ ParameterPropertyWorker.java	7 Feb 2005 17:50:27 -0000	1.10
  @@ -48,14 +48,14 @@
       private Map _unwrappers = new HashMap();
   
       {
  -        _unwrappers.put(boolean.class, "((Boolean) binding.getObject({0})).booleanValue();");
  -        _unwrappers.put(byte.class, "((Byte) binding.getObject({0})).byteValue();");
  -        _unwrappers.put(char.class, "((Character) binding.getObject({0})).charValue();");
  -        _unwrappers.put(short.class, "((Short) binding.getObject({0})).shortValue();");
  -        _unwrappers.put(int.class, "((Integer) binding.getObject({0})).intValue();");
  -        _unwrappers.put(long.class, "((Long) binding.getObject({0})).longValue();");
  -        _unwrappers.put(float.class, "((Float) binding.getObject({0})).floatValue();");
  -        _unwrappers.put(double.class, "((Double) binding.getObject({0})).doubleValue();");
  +        _unwrappers.put(boolean.class, "toBoolean");
  +        _unwrappers.put(byte.class, "toByte");
  +        _unwrappers.put(char.class, "toChar");
  +        _unwrappers.put(short.class, "toShort");
  +        _unwrappers.put(int.class, "toInt");
  +        _unwrappers.put(long.class, "toLong");
  +        _unwrappers.put(float.class, "toFloat");
  +        _unwrappers.put(double.class, "toDouble");
       }
   
       public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
  @@ -237,8 +237,6 @@
   
           builder.addln("if (binding == null) return {0};", defaultFieldName);
   
  -        String propertyTypeRef = op.getClassReference(propertyType);
  -
           String javaTypeName = ClassFabUtils.getJavaClassName(propertyType);
   
           builder.add("{0} result = ", javaTypeName);
  @@ -246,9 +244,16 @@
           String unwrapper = (String) _unwrappers.get(propertyType);
   
           if (unwrapper == null)
  +        {
  +            String propertyTypeRef = op.getClassReference(propertyType);
               builder.addln("({0}) binding.getObject({1});", javaTypeName, propertyTypeRef);
  +        }
           else
  -            builder.addln(unwrapper, propertyTypeRef);
  +        {
  +            String expression = EnhanceUtils.class.getName() + "." + unwrapper + "(binding);";
  +
  +            builder.addln(expression);
  +        }
   
           // Values read via the binding are cached during the render of
           // the component, or when the binding is invariant
  
  
  
  1.8       +59 -0     jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java
  
  Index: EnhanceUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EnhanceUtils.java	31 Jan 2005 05:36:21 -0000	1.7
  +++ EnhanceUtils.java	7 Feb 2005 17:50:27 -0000	1.8
  @@ -18,6 +18,7 @@
   
   import org.apache.hivemind.service.MethodSignature;
   import org.apache.hivemind.util.Defense;
  +import org.apache.tapestry.IBinding;
   import org.apache.tapestry.IRequestCycle;
   import org.apache.tapestry.engine.IPageLoader;
   import org.apache.tapestry.event.PageEvent;
  @@ -126,4 +127,62 @@
           return propertyType == null ? Object.class : propertyType;
       }
   
  +    // The following methods are actually invoked from fabricated methods in
  +    // enhanced classes.
  +
  +    public static boolean toBoolean(IBinding binding)
  +    {
  +        Boolean wrapped = (Boolean) binding.getObject(Boolean.class);
  +
  +        return wrapped.booleanValue();
  +    }
  +
  +    public static byte toByte(IBinding binding)
  +    {
  +        Byte wrapped = (Byte) binding.getObject(Byte.class);
  +
  +        return wrapped.byteValue();
  +    }
  +
  +    public static char toChar(IBinding binding)
  +    {
  +        Character wrapped = (Character) binding.getObject(Character.class);
  +
  +        return wrapped.charValue();
  +    }
  +
  +    public static short toShort(IBinding binding)
  +    {
  +        Short wrapped = (Short) binding.getObject(Short.class);
  +
  +        return wrapped.shortValue();
  +    }
  +
  +    public static int toInt(IBinding binding)
  +    {
  +        Integer wrapped = (Integer) binding.getObject(Integer.class);
  +
  +        return wrapped.intValue();
  +    }
  +
  +    public static long toLong(IBinding binding)
  +    {
  +        Long wrapped = (Long) binding.getObject(Long.class);
  +
  +        return wrapped.longValue();
  +    }
  +
  +    public static float toFloat(IBinding binding)
  +    {
  +        Float wrapped = (Float) binding.getObject(Float.class);
  +
  +        return wrapped.floatValue();
  +    }
  +
  +    public static double toDouble(IBinding binding)
  +    {
  +        Double wrapped = (Double) binding.getObject(Double.class);
  +
  +        return wrapped.doubleValue();
  +    }
   }
  \ No newline at end of file
  
  
  
  1.9       +1 -4      jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestParameterPropertyWorker.java
  
  Index: TestParameterPropertyWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestParameterPropertyWorker.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestParameterPropertyWorker.java	31 Jan 2005 05:36:21 -0000	1.8
  +++ TestParameterPropertyWorker.java	7 Feb 2005 17:50:27 -0000	1.9
  @@ -308,16 +308,13 @@
           MockControl opc = newControl(EnhancementOperation.class);
           EnhancementOperation op = (EnhancementOperation) opc.getMock();
   
  -        op.getClassReference(boolean.class);
  -        opc.setReturnValue("_class$boolean");
  -
           BodyBuilder builder = new BodyBuilder();
           builder.begin();
           builder.addln("if (_$fred$Cached) return _$fred;");
           builder.addln("org.apache.tapestry.IBinding binding = getBinding(\"barney\");");
           builder.addln("if (binding == null) return _$fred$Default;");
           builder.add("boolean result = ");
  -        builder.addln("((Boolean) binding.getObject(_class$boolean)).booleanValue();");
  +        builder.addln(EnhanceUtils.class.getName() + ".toBoolean(binding);");
           builder.addln("if (isRendering() || binding.isInvariant())");
           builder.begin();
           builder.addln("_$fred = result;");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


Mime
View raw message