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/java/org/apache/tapestry/spec IPropertySpecification.java
Date Mon, 07 Feb 2005 19:41:19 GMT
hlship      2005/02/07 11:41:19

  Modified:    framework/src/test/org/apache/tapestry/junit
                        TapestryTestCase.java
               .        status.xml
               framework/src/java/org/apache/tapestry/enhance
                        EnhanceMessages.java EnhancementOperation.java
                        EnhanceUtils.java SpecifiedPropertyWorker.java
                        ParameterPropertyWorker.java
                        EnhanceStrings.properties
               framework/src/java/org/apache/tapestry/binding
                        BindingSource.java BindingFactory.java
               framework/src/test/org/apache/tapestry/enhance
                        TestSpecifiedPropertyWorker.java
                        TestEnhanceUtils.java
               framework/src/java/org/apache/tapestry/services/impl
                        BindingSourceImpl.java
               framework/src/descriptor/META-INF tapestry.enhance.xml
               framework/src/java/org/apache/tapestry/pageload
                        PageLoader.java
               framework/src/java/org/apache/tapestry/spec
                        IPropertySpecification.java
  Added:       framework/src/java/org/apache/tapestry/enhance
                        InitialValueBindingCreator.java
  Removed:     framework/src/test/org/apache/tapestry/pageload
                        TestPropertyBindingInitializer.java
                        ComponentFixture.java
                        TestPropertyReinitializer.java
               framework/src/java/org/apache/tapestry/pageload
                        PropertyReinitializer.java
                        PropertyBindingInitializer.java
  Log:
  Change handling of initial values for properties to be based on injected logic.
  
  Revision  Changes    Path
  1.8       +2 -3      jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TapestryTestCase.java
  
  Index: TapestryTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TapestryTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TapestryTestCase.java	31 Jan 2005 15:39:58 -0000	1.7
  +++ TapestryTestCase.java	7 Feb 2005 19:41:18 -0000	1.8
  @@ -33,7 +33,6 @@
   import org.apache.tapestry.binding.BindingSource;
   import org.apache.tapestry.binding.LiteralBinding;
   import org.apache.tapestry.coerce.ValueConverter;
  -import org.apache.tapestry.coerce.ValueConverterImpl;
   import org.apache.tapestry.parse.SpecificationParser;
   import org.apache.tapestry.spec.IApplicationSpecification;
   import org.apache.tapestry.spec.IComponentSpecification;
  @@ -67,10 +66,10 @@
       private class BindingSourceFixture implements BindingSource
       {
   
  -        public IBinding createBinding(IComponent component, String description, String
locator,
  +        public IBinding createBinding(IComponent component, String description, String
reference,
                   Location location)
           {
  -            return new LiteralBinding(description, _valueConverter, location, locator);
  +            return new LiteralBinding(description, _valueConverter, location, reference);
           }
       }
   
  
  
  
  1.65      +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- status.xml	6 Feb 2005 20:36:13 -0000	1.64
  +++ status.xml	7 Feb 2005 19:41:19 -0000	1.65
  @@ -140,6 +140,7 @@
         <action type="update" dev="HLS" fixes-bug="TAPESTRY-262"> Support more boolean
values. </action>
         <action type="update" dev="HLS"> Inject Messages into components; this means
that all Tapestry page and component classes are abstract. </action>
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-242"> Allow namespaces to
define localized messages, providing defaults for pages and components within the namespace.
</action>
  +      <action type="update" dev="HLS"> Change handling of initial values for properties
to be based on injected logic. </action>
       </release>
       <release version="3.0" date="Apr 18 2004">
         <action type="fix" dev="HLS" fixes-bug="28345"> Workbench/Upload exception
when no file specified </action>
  
  
  
  1.10      +5 -0      jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
  
  Index: EnhanceMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- EnhanceMessages.java	7 Feb 2005 17:31:02 -0000	1.9
  +++ EnhanceMessages.java	7 Feb 2005 19:41:19 -0000	1.10
  @@ -87,4 +87,9 @@
           return _formatter.format("incompatible-inject-type", locator, value, ClassFabUtils
                   .getJavaClassName(propertyType));
       }
  +
  +    public static String initialValueForProperty(String propertyName)
  +    {
  +        return _formatter.format("initial-value-for-property", propertyName);
  +    }
   }
  \ No newline at end of file
  
  
  
  1.11      +0 -1      jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java
  
  Index: EnhancementOperation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- EnhancementOperation.java	7 Feb 2005 17:31:02 -0000	1.10
  +++ EnhancementOperation.java	7 Feb 2005 19:41:19 -0000	1.11
  @@ -17,7 +17,6 @@
   import java.util.List;
   
   import org.apache.hivemind.service.MethodSignature;
  -import org.apache.tapestry.spec.IComponentSpecification;
   
   /**
    * A process object representing enhancements to a component class. The operation is passed
to
  
  
  
  1.9       +79 -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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EnhanceUtils.java	7 Feb 2005 17:50:27 -0000	1.8
  +++ EnhanceUtils.java	7 Feb 2005 19:41:19 -0000	1.9
  @@ -15,7 +15,10 @@
   package org.apache.tapestry.enhance;
   
   import java.lang.reflect.Modifier;
  +import java.util.HashMap;
  +import java.util.Map;
   
  +import org.apache.hivemind.service.ClassFabUtils;
   import org.apache.hivemind.service.MethodSignature;
   import org.apache.hivemind.util.Defense;
   import org.apache.tapestry.IBinding;
  @@ -185,4 +188,80 @@
   
           return wrapped.doubleValue();
       }
  +
  +    /**
  +     * Used to unwrap primitive types inside the accessor method. In each case, the binding
is in a
  +     * variable named "binding", and {0} will be the actual type of the property. The Map
is keyed
  +     * on the primtive type.
  +     */
  +
  +    private static Map _unwrappers = new HashMap();
  +
  +    static
  +    {
  +        _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");
  +    }
  +
  +    /**
  +     * Returns the name of the static method, within EnhanceUtils, used to unwrap a binding
to a
  +     * primitive type. Returns null if the type is not a primitve.
  +     */
  +
  +    public static String getUnwrapperMethodName(Class type)
  +    {
  +        return (String) _unwrappers.get(type);
  +    }
  +
  +    /**
  +     * Builds a Javassist expression for unwrapping a binding's value to a type (either
primitive or
  +     * a class type).
  +     * 
  +     * @param op
  +     *            the enhancement operation
  +     * @param bindingName
  +     *            the name of the field (or an expression) that will evaluate to the binding
from
  +     *            which a value will be extracted.
  +     * @param valueType
  +     *            the type of value to be extracted from the binding.
  +     */
  +
  +    public static String createUnwrapExpression(EnhancementOperation op, String bindingName,
  +            Class valueType)
  +    {
  +        StringBuffer buffer = new StringBuffer();
  +
  +        String unwrapper = getUnwrapperMethodName(valueType);
  +
  +        if (unwrapper == null)
  +        {
  +            String propertyTypeRef = op.getClassReference(valueType);
  +
  +            buffer.append("(");
  +            buffer.append(ClassFabUtils.getJavaClassName(valueType));
  +            buffer.append(") ");
  +            buffer.append(bindingName);
  +            buffer.append(".getObject(");
  +            buffer.append(propertyTypeRef);
  +            buffer.append(")");
  +        }
  +        else
  +        {
  +            buffer.append(EnhanceUtils.class.getName());
  +            buffer.append(".");
  +            buffer.append(unwrapper);
  +            buffer.append("(");
  +            buffer.append(bindingName);
  +            buffer.append(")");
  +        }
  +
  +        return buffer.toString();
  +    }
  +
   }
  \ No newline at end of file
  
  
  
  1.8       +79 -3     jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java
  
  Index: SpecifiedPropertyWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SpecifiedPropertyWorker.java	31 Jan 2005 05:36:21 -0000	1.7
  +++ SpecifiedPropertyWorker.java	7 Feb 2005 19:41:19 -0000	1.8
  @@ -18,10 +18,14 @@
   import java.util.Iterator;
   
   import org.apache.hivemind.ErrorLog;
  +import org.apache.hivemind.Location;
   import org.apache.hivemind.service.BodyBuilder;
   import org.apache.hivemind.service.MethodSignature;
   import org.apache.hivemind.util.Defense;
  +import org.apache.tapestry.IBinding;
   import org.apache.tapestry.IComponent;
  +import org.apache.tapestry.binding.BindingSource;
  +import org.apache.tapestry.event.PageDetachListener;
   import org.apache.tapestry.spec.IComponentSpecification;
   import org.apache.tapestry.spec.IPropertySpecification;
   
  @@ -36,6 +40,8 @@
   {
       private ErrorLog _errorLog;
   
  +    private BindingSource _bindingSource;
  +
       /**
        * Iterates over the specified properties, creating an enhanced property for each (a
field, an
        * accessor, a mutator). Persistent properties will invoke
  @@ -88,9 +94,74 @@
   
           addMutator(op, propertyName, propertyType, field, ps.isPersistent());
   
  -        // TODO: For properties with no initializer, should use the
  -        // same kind of logic as AbstractPropertyWorker (and remove some logic
  -        // from PageLoader.
  +        String initialValue = ps.getInitialValue();
  +
  +        if (initialValue == null)
  +            addReinitializer(op, propertyType, field);
  +        else
  +            addInitialValue(op, propertyName, propertyType, field, initialValue, ps.getLocation());
  +    }
  +
  +    private void addReinitializer(EnhancementOperation op, Class propertyType, String fieldName)
  +    {
  +        String defaultFieldName = fieldName + "$default";
  +
  +        op.addField(defaultFieldName, propertyType);
  +
  +        // On finishLoad(), store the current value into the default field.
  +
  +        op.extendMethodImplementation(
  +                IComponent.class,
  +                EnhanceUtils.FINISH_LOAD_SIGNATURE,
  +                defaultFieldName + " = " + fieldName + ";");
  +
  +        // On pageDetach(), restore the attribute to its default value.
  +
  +        op.extendMethodImplementation(
  +                PageDetachListener.class,
  +                EnhanceUtils.PAGE_DETACHED_SIGNATURE,
  +                fieldName + " = " + defaultFieldName + ";");
  +    }
  +
  +    private void addInitialValue(EnhancementOperation op, String propertyName, Class propertyType,
  +            String fieldName, String initialValue, Location location)
  +    {
  +        String description = EnhanceMessages.initialValueForProperty(propertyName);
  +
  +        InitialValueBindingCreator creator = new InitialValueBindingCreator(_bindingSource,
  +                description, initialValue, location);
  +
  +        String creatorField = fieldName + "$initialValueBindingCreator";
  +        op.addField(creatorField, InitialValueBindingCreator.class, creator);
  +
  +        String bindingField = fieldName + "$initialValueBinding";
  +        op.addField(bindingField, IBinding.class);
  +
  +        BodyBuilder builder = new BodyBuilder();
  +
  +        builder.addln("{0} = {1}.createBinding(this);", bindingField, creatorField);
  +
  +        op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE,
builder
  +                .toString());
  +
  +        builder.clear();
  +
  +        builder.addln("{0} = {1};", fieldName, EnhanceUtils.createUnwrapExpression(
  +                op,
  +                bindingField,
  +                propertyType));
  +
  +        String code = builder.toString();
  +
  +        // In finishLoad() and pageDetach(), de-reference the binding to get the value
  +        // for the property.
  +
  +        op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE,
code);
  +        op.extendMethodImplementation(
  +                PageDetachListener.class,
  +                EnhanceUtils.PAGE_DETACHED_SIGNATURE,
  +                code);
  +
       }
   
       private void addMutator(EnhancementOperation op, String propertyName, Class propertyType,
  @@ -123,4 +194,9 @@
       {
           _errorLog = errorLog;
       }
  +
  +    public void setBindingSource(BindingSource bindingSource)
  +    {
  +        _bindingSource = bindingSource;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.11      +5 -36     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ParameterPropertyWorker.java	7 Feb 2005 17:50:27 -0000	1.10
  +++ ParameterPropertyWorker.java	7 Feb 2005 19:41:19 -0000	1.11
  @@ -15,9 +15,7 @@
   package org.apache.tapestry.enhance;
   
   import java.lang.reflect.Modifier;
  -import java.util.HashMap;
   import java.util.Iterator;
  -import java.util.Map;
   
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.ErrorLog;
  @@ -39,25 +37,6 @@
   {
       private ErrorLog _errorLog;
   
  -    /**
  -     * Used to unwrap primitive types inside the accessor method. In each case, the binding
is in a
  -     * variable named "binding", and {0} will be the actual type of the property. The Map
is keyed
  -     * on the primtive type.
  -     */
  -
  -    private Map _unwrappers = new HashMap();
  -
  -    {
  -        _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)
       {
           Iterator i = spec.getParameterNames().iterator();
  @@ -239,21 +218,11 @@
   
           String javaTypeName = ClassFabUtils.getJavaClassName(propertyType);
   
  -        builder.add("{0} result = ", javaTypeName);
  -
  -        String unwrapper = (String) _unwrappers.get(propertyType);
  -
  -        if (unwrapper == null)
  -        {
  -            String propertyTypeRef = op.getClassReference(propertyType);
  -            builder.addln("({0}) binding.getObject({1});", javaTypeName, propertyTypeRef);
  -        }
  -        else
  -        {
  -            String expression = EnhanceUtils.class.getName() + "." + unwrapper + "(binding);";
  -
  -            builder.addln(expression);
  -        }
  +        builder.addln("{0} result = {1};", javaTypeName, 
  +                EnhanceUtils.createUnwrapExpression(
  +                op,
  +                "binding",
  +                propertyType));
   
           // Values read via the binding are cached during the render of
           // the component, or when the binding is invariant
  
  
  
  1.9       +2 -1      jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
  
  Index: EnhanceStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EnhanceStrings.properties	7 Feb 2005 17:31:02 -0000	1.8
  +++ EnhanceStrings.properties	7 Feb 2005 19:41:19 -0000	1.9
  @@ -21,4 +21,5 @@
   instantiation-failure=Unable to instantiate instance of class {0}: {1}
   
   located-value-is-null=Value obtained using locator ''{0}'' is null.
  -incompatible-inject-type=The value obtained using locator ''{0}'' ({1}) is not compatible
with the existing property (of type {2}).
  \ No newline at end of file
  +incompatible-inject-type=The value obtained using locator ''{0}'' ({1}) is not compatible
with the existing property (of type {2}).
  +initial-value-for-property=initial value for property {0}
  \ No newline at end of file
  
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InitialValueBindingCreator.java
  
  Index: InitialValueBindingCreator.java
  ===================================================================
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.enhance;
  
  import org.apache.hivemind.Location;
  import org.apache.tapestry.IBinding;
  import org.apache.tapestry.IComponent;
  import org.apache.tapestry.binding.BindingSource;
  
  /**
   * Encapsulates information needed to construct an initial value binding for a specified
property
   * (with an initial value).
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class InitialValueBindingCreator
  {
      private BindingSource _bindingSource;
  
      private String _description;
  
      private String _initialValue;
  
      private Location _location;
  
      /**
       * This method is just implemented for testing purposes.
       */
  
      public boolean equals(Object obj)
      {
          InitialValueBindingCreator c = (InitialValueBindingCreator) obj;
  
          return _bindingSource == c._bindingSource && _description.equals(c._description)
                  && _initialValue.equals(c._initialValue) && _location.equals(c._location);
      }
  
      public InitialValueBindingCreator(BindingSource bindingSource, String description,
              String initialValue, Location location)
      {
          _bindingSource = bindingSource;
          _description = description;
          _initialValue = initialValue;
          _location = location;
      }
  
      public IBinding createBinding(IComponent component)
      {
          return _bindingSource.createBinding(component, _description, _initialValue, _location);
      }
  }
  
  
  1.2       +8 -6      jakarta-tapestry/framework/src/java/org/apache/tapestry/binding/BindingSource.java
  
  Index: BindingSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/binding/BindingSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingSource.java	29 Jan 2005 01:03:16 -0000	1.1
  +++ BindingSource.java	7 Feb 2005 19:41:19 -0000	1.2
  @@ -28,10 +28,9 @@
   {
       /**
        * Creates a new binding. The locator is used to identify the <em>type</em>
of binding to
  -     * create as well as configure the binding instance. 
  -     * The locator is either a literal value (resulting in a
  -     * {@link org.apache.tapestry.binding.LiteralBinding literal binding}) or consists
of prefix and
  -     * a path, i.e., <code>ognl:myProperty</code>.
  +     * create as well as configure the binding instance. The locator is either a literal
value
  +     * (resulting in a {@link org.apache.tapestry.binding.LiteralBinding literal binding})
or
  +     * consists of prefix and a path, i.e., <code>ognl:myProperty</code>.
        * <p>
        * When a prefix exists and is identified, it is used to select the correct
        * {@link BindingFactory}, and the remainder of the path (i.e., <code>myProperty</code)
  @@ -42,8 +41,11 @@
        * as a kind of context for certain types of bindings (for example, the root object
when
        * evaluating OGNL expressions).
        * @param description {@link IBinding#getDescription() description} for the new binding
  -     * @param locator the binding to be created, possibly including a prefix to define
the type
  +     * @param reference the binding reference used to create the binding, possibly including
a prefix to define the type. A default
  +     * binding factory ({@link LiteralBindingFactory}) is used when the prefix is missing
  +     * or doesn't match a known binding factory.
        * @param location location used to report errors in the binding
        */
  -    public IBinding createBinding(IComponent component, String description, String locator,
Location location);
  +    public IBinding createBinding(IComponent component, String description, String reference,
  +            Location location);
   }
  \ No newline at end of file
  
  
  
  1.2       +2 -1      jakarta-tapestry/framework/src/java/org/apache/tapestry/binding/BindingFactory.java
  
  Index: BindingFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/binding/BindingFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingFactory.java	29 Jan 2005 01:03:16 -0000	1.1
  +++ BindingFactory.java	7 Feb 2005 19:41:19 -0000	1.2
  @@ -37,7 +37,8 @@
        * @param path
        *            The path used to get (or update) a value for the path. This may be an
OGNL
        *            expression, a message key, a literal value, or otherwise defined by the
type of
  -     *            binding.
  +     *            binding. It is the value of the binding reference with the prefix (used
to
  +     *            identify the factory) stripped off.
        * @param location
        *            The location of the binding, used to report any errors related to the
binding, or
        *            to the component parameter the binding is bound to.
  
  
  
  1.8       +103 -3    jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestSpecifiedPropertyWorker.java
  
  Index: TestSpecifiedPropertyWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestSpecifiedPropertyWorker.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestSpecifiedPropertyWorker.java	31 Jan 2005 05:36:21 -0000	1.7
  +++ TestSpecifiedPropertyWorker.java	7 Feb 2005 19:41:19 -0000	1.8
  @@ -27,6 +27,10 @@
   import org.apache.hivemind.service.MethodSignature;
   import org.apache.hivemind.test.HiveMindTestCase;
   import org.apache.tapestry.BaseComponent;
  +import org.apache.tapestry.IBinding;
  +import org.apache.tapestry.IComponent;
  +import org.apache.tapestry.binding.BindingSource;
  +import org.apache.tapestry.event.PageDetachListener;
   import org.apache.tapestry.spec.IComponentSpecification;
   import org.apache.tapestry.spec.IPropertySpecification;
   import org.apache.tapestry.spec.PropertySpecification;
  @@ -42,15 +46,17 @@
   {
       private List buildPropertySpecs(String name, String type, boolean persistent)
       {
  -        return buildPropertySpecs(name, type, persistent, null);
  +        return buildPropertySpecs(name, type, persistent, null, null);
       }
   
  -    private List buildPropertySpecs(String name, String type, boolean persistent, Location
location)
  +    private List buildPropertySpecs(String name, String type, boolean persistent,
  +            Location location, String initialValue)
       {
           PropertySpecification ps = new PropertySpecification();
           ps.setName(name);
           ps.setType(type);
           ps.setPersistence(persistent ? "session" : null);
  +        ps.setInitialValue(initialValue);
           ps.setLocation(location);
   
           return Collections.singletonList(ps);
  @@ -118,9 +124,91 @@
           op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "setFred", new Class[]
           { boolean.class }, null), "{\n  _$fred = $1;\n}\n");
   
  +        op.addField("_$fred$default", boolean.class);
  +
  +        op.extendMethodImplementation(
  +                IComponent.class,
  +                EnhanceUtils.FINISH_LOAD_SIGNATURE,
  +                "_$fred$default = _$fred;");
  +
  +        op.extendMethodImplementation(
  +                PageDetachListener.class,
  +                EnhanceUtils.PAGE_DETACHED_SIGNATURE,
  +                "_$fred = _$fred$default;");
  +
  +        replayControls();
  +
  +        SpecifiedPropertyWorker w = new SpecifiedPropertyWorker();
  +
  +        w.performEnhancement(op, spec);
  +
  +        verifyControls();
  +    }
  +
  +    public void testAddWithInitialValue() throws Exception
  +    {
  +        BindingSource bs = (BindingSource) newMock(BindingSource.class);
  +        Location l = fabricateLocation(12);
  +
  +        IComponentSpecification spec = buildComponentSpecification(buildPropertySpecs(
  +                "fred",
  +                "java.util.List",
  +                false,
  +                l,
  +                "ognl:foo()"));
  +
  +        InitialValueBindingCreator expectedCreator = new InitialValueBindingCreator(bs,
  +                EnhanceMessages.initialValueForProperty("fred"), "ognl:foo()", l);
  +
  +        // Training
  +
  +        MockControl opc = newControl(EnhancementOperation.class);
  +        EnhancementOperation op = (EnhancementOperation) opc.getMock();
  +
  +        op.convertTypeName("java.util.List");
  +        opc.setReturnValue(List.class);
  +
  +        op.validateProperty("fred", List.class);
  +        op.claimProperty("fred");
  +        op.addField("_$fred", List.class);
  +
  +        op.getAccessorMethodName("fred");
  +        opc.setReturnValue("getFred");
  +
  +        op.addMethod(
  +                Modifier.PUBLIC,
  +                new MethodSignature(List.class, "getFred", null, null),
  +                "return _$fred;");
  +
  +        op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "setFred", new Class[]
  +        { List.class }, null), "{\n  _$fred = $1;\n}\n");
  +
  +        op.addField(
  +                "_$fred$initialValueBindingCreator",
  +                InitialValueBindingCreator.class,
  +                expectedCreator);
  +        op.addField("_$fred$initialValueBinding", IBinding.class);
  +        op
  +                .extendMethodImplementation(
  +                        IComponent.class,
  +                        EnhanceUtils.FINISH_LOAD_SIGNATURE,
  +                        "_$fred$initialValueBinding = _$fred$initialValueBindingCreator.createBinding(this);\n");
  +
  +        op.getClassReference(List.class);
  +        opc.setReturnValue("_$class$java$util$List");
  +
  +        String code = "_$fred = (java.util.List) _$fred$initialValueBinding.getObject(_$class$java$util$List);\n";
  +
  +        op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE,
code);
  +        op.extendMethodImplementation(
  +                PageDetachListener.class,
  +                EnhanceUtils.PAGE_DETACHED_SIGNATURE,
  +                code);
  +
           replayControls();
   
           SpecifiedPropertyWorker w = new SpecifiedPropertyWorker();
  +        w.setBindingSource(bs);
   
           w.performEnhancement(op, spec);
   
  @@ -163,6 +251,18 @@
           op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "setBarney", new
Class[]
           { String.class }, null), b.toString());
   
  +        op.addField("_$barney$default", String.class);
  +
  +        op.extendMethodImplementation(
  +                IComponent.class,
  +                EnhanceUtils.FINISH_LOAD_SIGNATURE,
  +                "_$barney$default = _$barney;");
  +
  +        op.extendMethodImplementation(
  +                PageDetachListener.class,
  +                EnhanceUtils.PAGE_DETACHED_SIGNATURE,
  +                "_$barney = _$barney$default;");
  +
           replayControls();
   
           SpecifiedPropertyWorker w = new SpecifiedPropertyWorker();
  @@ -176,7 +276,7 @@
       {
           Location l = fabricateLocation(207);
           // Should be "java.lang.Long"
  -        List propertySpecs = buildPropertySpecs("wilma", "Long", false, l);
  +        List propertySpecs = buildPropertySpecs("wilma", "Long", false, l, null);
           IComponentSpecification spec = buildComponentSpecification(propertySpecs);
   
           MockControl opc = newControl(EnhancementOperation.class);
  
  
  
  1.3       +30 -0     jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestEnhanceUtils.java
  
  Index: TestEnhanceUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestEnhanceUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestEnhanceUtils.java	5 Jan 2005 23:17:27 -0000	1.2
  +++ TestEnhanceUtils.java	7 Feb 2005 19:41:19 -0000	1.3
  @@ -76,6 +76,36 @@
           assertEquals(int[].class, result);
   
           verifyControls();
  +    }
  +
  +    public void testCreateUnwrapForPrimitive()
  +    {
  +        EnhancementOperation op = (EnhancementOperation) newMock(EnhancementOperation.class);
  +
  +        replayControls();
  +
  +        String result = EnhanceUtils.createUnwrapExpression(op, "mybinding", int.class);
  +
  +        assertEquals("org.apache.tapestry.enhance.EnhanceUtils.toInt(mybinding)", result);
  +
  +        verifyControls();
  +    }
  +
  +    public void testCreateUnwrapForObjectType()
  +    {
  +        MockControl opc = newControl(EnhancementOperation.class);
  +        EnhancementOperation op = (EnhancementOperation) opc.getMock();
  +
  +        op.getClassReference(String.class);
  +        opc.setReturnValue("_$class$String");
  +
  +        replayControls();
  +
  +        String result = EnhanceUtils.createUnwrapExpression(op, "thebinding", String.class);
  +
  +        assertEquals("(java.lang.String) thebinding.getObject(_$class$String)", result);
  +
  +        verifyControls();
   
       }
   }
  \ No newline at end of file
  
  
  
  1.6       +5 -5      jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/BindingSourceImpl.java
  
  Index: BindingSourceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/BindingSourceImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BindingSourceImpl.java	29 Jan 2005 01:03:16 -0000	1.5
  +++ BindingSourceImpl.java	7 Feb 2005 19:41:19 -0000	1.6
  @@ -54,24 +54,24 @@
           }
       }
   
  -    public IBinding createBinding(IComponent component, String bindingDescription, String
locator,
  +    public IBinding createBinding(IComponent component, String bindingDescription, String
reference,
               Location location)
       {
           BindingFactory factory = _literalBindingFactory;
  -        String path = locator;
  +        String path = reference;
   
  -        int colonx = locator.indexOf(':');
  +        int colonx = reference.indexOf(':');
   
           if (colonx > 1)
           {
  -            String prefix = locator.substring(0, colonx);
  +            String prefix = reference.substring(0, colonx);
   
               BindingFactory prefixedFactory = (BindingFactory) _factoryMap.get(prefix);
   
               if (prefixedFactory != null)
               {
                   factory = prefixedFactory;
  -                path = locator.substring(colonx + 1);
  +                path = reference.substring(colonx + 1);
               }
           }
   
  
  
  
  1.10      +3 -1      jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.enhance.xml
  
  Index: tapestry.enhance.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.enhance.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- tapestry.enhance.xml	6 Feb 2005 15:08:51 -0000	1.9
  +++ tapestry.enhance.xml	7 Feb 2005 19:41:19 -0000	1.10
  @@ -95,7 +95,9 @@
       Finds specified properties (from the specification) and constructs the corresponding
properties in the enhanced class.
       
       <invoke-factory>
  -      <construct class="org.apache.tapestry.enhance.SpecifiedPropertyWorker"/>
  +      <construct class="org.apache.tapestry.enhance.SpecifiedPropertyWorker">
  +        <set-service property="bindingSource" service-id="tapestry.bindings.BindingSource"/>
  +      </construct>
       </invoke-factory>
     </service-point>
     
  
  
  
  1.18      +3 -58     jakarta-tapestry/framework/src/java/org/apache/tapestry/pageload/PageLoader.java
  
  Index: PageLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/pageload/PageLoader.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PageLoader.java	6 Feb 2005 15:08:52 -0000	1.17
  +++ PageLoader.java	7 Feb 2005 19:41:19 -0000	1.18
  @@ -19,8 +19,6 @@
   import java.util.List;
   import java.util.Locale;
   
  -import javax.servlet.ServletContext;
  -
   import org.apache.commons.logging.Log;
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.HiveMind;
  @@ -48,14 +46,12 @@
   import org.apache.tapestry.services.ComponentConstructor;
   import org.apache.tapestry.services.ComponentConstructorFactory;
   import org.apache.tapestry.services.ComponentTemplateLoader;
  -import org.apache.tapestry.services.TemplateSource;
   import org.apache.tapestry.spec.BindingType;
   import org.apache.tapestry.spec.IAssetSpecification;
   import org.apache.tapestry.spec.IBindingSpecification;
   import org.apache.tapestry.spec.IComponentSpecification;
   import org.apache.tapestry.spec.IContainedComponent;
   import org.apache.tapestry.spec.IListenerBindingSpecification;
  -import org.apache.tapestry.spec.IPropertySpecification;
   
   /**
    * Runs the process of building the component hierarchy for an entire page.
  @@ -382,17 +378,14 @@
   
               // Finish the load of the component; most components (which
               // subclass BaseComponent) load their templates here.
  +            // Properties with initial values will be set here (or the
  +            // initial value will be recorded for later use in pageDetach().
               // That may cause yet more components to be created, and more
               // bindings to be set, so we defer some checking until
               // later.
   
               container.finishLoad(cycle, this, containerSpec);
   
  -            // Finally, we create an initializer for each
  -            // specified property.
  -
  -            createPropertyInitializers(page, container, containerSpec);
  -
               // Have the component switch over to its active state.
   
               container.enterActiveState();
  @@ -653,54 +646,6 @@
       }
   
       /**
  -     * Invoked from
  -     * {@link #constructComponent(IRequestCycle, IPage, IComponent, IComponentSpecification,
INamespace)}
  -     * after {@link IComponent#finishLoad(IRequestCycle, IPageLoader, IComponentSpecification)}is
  -     * invoked. This iterates over any {@link org.apache.tapestry.spec.IPropertySpecification}s
for
  -     * the component, create an initializer for each.
  -     * 
  -     * <p>
  -     * TODO: This logic should be moved into {@link org.apache.tapestry.enhance.SpecifiedPropertyWorker}.
  -     * 
  -     */
  -
  -    private void createPropertyInitializers(IPage page, IComponent component,
  -            IComponentSpecification spec)
  -    {
  -        List names = spec.getPropertySpecificationNames();
  -        int count = names.size();
  -
  -        PageDetachListener initializer = null;
  -
  -        for (int i = 0; i < count; i++)
  -        {
  -            String name = (String) names.get(i);
  -            IPropertySpecification ps = spec.getPropertySpecification(name);
  -
  -            String initialValue = ps.getInitialValue();
  -
  -            if (initialValue == null)
  -                initializer = new PropertyReinitializer(component, name);
  -            else
  -            {
  -                String description = PageloadMessages.initializerName(name);
  -
  -                IBinding initialValueBinding = _bindingSource.createBinding(
  -                        component,
  -                        description,
  -                        initialValue,
  -                        ps.getLocation());
  -
  -                initializer = new PropertyBindingInitializer(component, name, initialValueBinding);
  -            }
  -
  -            _propertyInitializers.add(initializer);
  -            page.addPageDetachListener(initializer);
  -        }
  -
  -    }
  -
  -    /**
        * Builds an instance of {@link IAsset}from the specification.
        */
   
  @@ -712,7 +657,7 @@
   
           return _assetSource.findAsset(location.getResource(), path, _locale, location);
       }
  -    
  +
       /** @since 3.1 */
   
       public void setLog(Log log)
  
  
  
  1.6       +6 -0      jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/IPropertySpecification.java
  
  Index: IPropertySpecification.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/IPropertySpecification.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- IPropertySpecification.java	8 Jan 2005 19:52:21 -0000	1.5
  +++ IPropertySpecification.java	7 Feb 2005 19:41:19 -0000	1.6
  @@ -25,6 +25,12 @@
    */
   public interface IPropertySpecification extends LocationHolder
   {
  +    /**
  +     * Returns the initial value for this property, as a binding reference. May return
null if the
  +     * property has no initial value. The initial value is from finishLoad() and re-applied
in
  +     * pageDetached().
  +     */
  +
       public String getInitialValue();
   
       public String getName();
  
  
  

---------------------------------------------------------------------
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