cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/junit TestComponentMessages.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/junit TestComponentMessages.java

hlship
hlship      2005/05/12 11:18:19

  Modified:    framework/src/java/org/apache/tapestry/enhance
                        InjectSpecificationWorker.java EnhanceMessages.java
                        EnhancementOperation.java InjectStateWorker.java
                        EnhancementOperationImpl.java
                        SpecifiedPropertyWorker.java
                        EnhanceStrings.properties InjectMessagesWorker.java
               .        status.xml
               src/documentation/content/xdocs/UsersGuide spec.xml
                        common.ent index.xml state.xml
               framework/src/java/org/apache/tapestry/spec
                        InjectSpecificationImpl.java
                        IComponentSpecification.java SpecFactory.java
                        InjectSpecification.java
                        ComponentSpecification.java
               framework/src/test/org/apache/tapestry/enhance
                        TestSpecifiedPropertyWorker.java
                        TestInjectMessagesWorker.java
                        TestInjectSpecificationWorker.java
                        TestInjectStateWorker.java
               framework/src/java/org/apache/tapestry/parse
                        SpecificationParser.java Tapestry_4_0.dtd
               framework/src/descriptor/META-INF tapestry.enhance.xml
               framework/src/test/org/apache/tapestry/junit/parse
                        Inject.jwc TestSpecificationParser.java
               framework/src/test/org/apache/tapestry/junit
                        TestComponentMessages.java
  Added:       framework/src/java/org/apache/tapestry/enhance
                        DispatchToInjectWorker.java InjectObjectWorker.java
                        InjectEnhancementWorker.java
               framework/src/test/org/apache/tapestry/enhance
                        TestDispatchToInjectWorker.java
                        TestInjectObjectWorker.java
  Removed:     framework/src/java/org/apache/tapestry/enhance
                        InjectWorker.java
               framework/src/java/org/apache/tapestry/spec
                        InjectStateSpecification.java
                        InjectStateSpecificationImpl.java
               framework/src/test/org/apache/tapestry/enhance
                        TestInjectWorker.java
               framework/src/test/org/apache/tapestry/junit/parse
                        InjectState.page
  Log:
  Remove <inject-state>, add type attribute to <inject>.
 
  Revision  Changes    Path
  1.3       +1 -3      jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectSpecificationWorker.java
 
  Index: InjectSpecificationWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectSpecificationWorker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InjectSpecificationWorker.java 18 Apr 2005 17:06:34 -0000 1.2
  +++ InjectSpecificationWorker.java 12 May 2005 18:18:18 -0000 1.3
  @@ -47,9 +47,7 @@
       {
           op.claimProperty(SPECIFICATION_PROPERTY_NAME);
   
  -        String fieldName = "_$" + SPECIFICATION_PROPERTY_NAME;
  -
  -        op.addField(fieldName, IComponentSpecification.class, spec);
  +        String fieldName = op.addFinalField("_$" + SPECIFICATION_PROPERTY_NAME, spec);
   
           EnhanceUtils.createSimpleAccessor(
                   op,
 
 
 
  1.13      +15 -12    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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- EnhanceMessages.java 18 Apr 2005 17:06:34 -0000 1.12
  +++ EnhanceMessages.java 12 May 2005 18:18:18 -0000 1.13
  @@ -31,19 +31,19 @@
       private static final MessageFormatter _formatter = new MessageFormatter(EnhanceMessages.class,
               "EnhanceStrings");
   
  -    public static String noImplForAbstractMethod(Method method, Class declareClass,
  -            String className, Class enhancedClass)
  +    static String noImplForAbstractMethod(Method method, Class declareClass, String className,
  +            Class enhancedClass)
       {
           return _formatter.format("no-impl-for-abstract-method", new Object[]
           { method, declareClass.getName(), className, enhancedClass.getName() });
       }
   
  -    public static String unabelToIntrospectClass(Class targetClass, Throwable cause)
  +    static String unabelToIntrospectClass(Class targetClass, Throwable cause)
       {
           return _formatter.format("unable-to-introspect-class", targetClass.getName(), cause);
       }
   
  -    public static String propertyTypeMismatch(Class componentClass, String propertyName,
  +    static String propertyTypeMismatch(Class componentClass, String propertyName,
               Class actualPropertyType, Class expectedPropertyType)
       {
           return _formatter.format("property-type-mismatch", new Object[]
  @@ -52,9 +52,7 @@
                   ClassFabUtils.getJavaClassName(expectedPropertyType) });
       }
   
  -
  -    public static String errorAddingProperty(String propertyName, Class componentClass,
  -            Throwable cause)
  +    static String errorAddingProperty(String propertyName, Class componentClass, Throwable cause)
       {
           return _formatter.format(
                   "error-adding-property",
  @@ -63,29 +61,34 @@
                   cause);
       }
   
  -    public static String claimedProperty(String propertyName)
  +    static String claimedProperty(String propertyName)
       {
           return _formatter.format("claimed-property", propertyName);
       }
   
  -    public static String instantiationFailure(Constructor c, Throwable cause)
  +    static String instantiationFailure(Constructor c, Throwable cause)
       {
           return _formatter.format("instantiation-failure", c.getDeclaringClass().getName(), cause);
       }
   
  -    public static String locatedValueIsNull(String objectReference)
  +    static String locatedValueIsNull(String objectReference)
       {
           return _formatter.format("located-value-is-null", objectReference);
       }
   
  -    public static String incompatibleInjectType(String locator, Object value, Class propertyType)
  +    static String incompatibleInjectType(String locator, Object value, Class propertyType)
       {
           return _formatter.format("incompatible-inject-type", locator, value, ClassFabUtils
                   .getJavaClassName(propertyType));
       }
   
  -    public static String initialValueForProperty(String propertyName)
  +    static String initialValueForProperty(String propertyName)
       {
           return _formatter.format("initial-value-for-property", propertyName);
       }
  +
  +    static String unknownInjectType(String propertyName, String injectType)
  +    {
  +        return _formatter.format("unknown-inject-type", propertyName, injectType);
  +    }
   }
  \ No newline at end of file
 
 
 
  1.14      +17 -8     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- EnhancementOperation.java 18 Apr 2005 17:06:34 -0000 1.13
  +++ EnhancementOperation.java 12 May 2005 18:18:18 -0000 1.14
  @@ -54,10 +54,20 @@
   
       /**
        * Adds a field containing an initial value. The EnhancementOperation will ensure that the value
  -     * is passed into the enhanced class' constructor and assigned.
  +     * is passed into the enhanced class' constructor and assigned. This method may be called
  +     * multiple times with the same value and will return the name variable name (an identity map is
  +     * kept internally).
  +     *
  +     * @param fieldName
  +     *            The name of the field, used if a new field (and contructor argument) is being
  +     *            created. Only used if a field for the value doesn't exist.
  +     * @param value
  +     *            the value to be referenced, which may not be null
  +     * @return the name of the field (which may be fieldName, or maybe not, if some other
  +     *         enhancement worker created the field first).
        */
   
  -    public void addField(String name, Class type, Object value);
  +    public String addFinalField(String fieldName, Object value);
   
       /**
        * Converts a type name (an object class name, a primtive name, or an array) into the
  @@ -133,13 +143,12 @@
        */
       public void extendMethodImplementation(Class interfaceClass, MethodSignature methodSignature,
               String code);
  -    
  +
       /**
  -     * Returns true if the class implements the specified interface.  Checks the base class
  -     * (as identified in the specification), but <em>also</em> accounts for any additional
  -     * interfaces that may be added by {@link #extendMethodImplementation(Class, MethodSignature, String)}.
  -     *
  +     * Returns true if the class implements the specified interface. Checks the base class (as
  +     * identified in the specification), but <em>also</em> accounts for any additional interfaces
  +     * that may be added by {@link #extendMethodImplementation(Class, MethodSignature, String)}.
        */
  -    
  +
       public boolean implementsInterface(Class interfaceClass);
   }
  \ No newline at end of file
 
 
 
  1.4       +12 -51    jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java
 
  Index: InjectStateWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InjectStateWorker.java 18 Apr 2005 17:06:34 -0000 1.3
  +++ InjectStateWorker.java 12 May 2005 18:18:18 -0000 1.4
  @@ -15,17 +15,13 @@
   package org.apache.tapestry.enhance;
   
   import java.lang.reflect.Modifier;
  -import java.util.Iterator;
  -import java.util.List;
   
  -import org.apache.hivemind.ErrorLog;
   import org.apache.hivemind.service.BodyBuilder;
   import org.apache.hivemind.service.ClassFabUtils;
   import org.apache.hivemind.service.MethodSignature;
   import org.apache.tapestry.engine.state.ApplicationStateManager;
   import org.apache.tapestry.event.PageDetachListener;
  -import org.apache.tapestry.spec.IComponentSpecification;
  -import org.apache.tapestry.spec.InjectStateSpecification;
  +import org.apache.tapestry.spec.InjectSpecification;
   
   /**
    * Worker for injecting application state objects as properties of the component. These properties
  @@ -36,66 +32,36 @@
    * @author Howard M. Lewis Ship
    * @since 4.0
    */
  -public class InjectStateWorker implements EnhancementWorker
  +public class InjectStateWorker implements InjectEnhancementWorker
   {
  -    private ErrorLog _errorLog;
  -
       private ApplicationStateManager _applicationStateManager;
   
  -    public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
  +    public void performEnhancement(EnhancementOperation op, InjectSpecification spec)
       {
  -        List injects = spec.getInjectStateSpecifications();
  -
  -        if (injects.isEmpty())
  -            return;
  -
  -        // TODO: The EnhancementOperation should have a way of assigning non-conflicting
  -        // attribute names. What if someone injects a property named "applicationStateManager"
  -        // as well?
  -
  -        op.addField(
  -                "_$applicationStateManager",
  -                ApplicationStateManager.class,
  -                _applicationStateManager);
  -
  -        Iterator i = injects.iterator();
  -        while (i.hasNext())
  -        {
  -            InjectStateSpecification iss = (InjectStateSpecification) i.next();
  -
  -            try
  -            {
  -                injectState(op, iss.getProperty(), iss.getObjectName());
  -            }
  -            catch (Exception ex)
  -            {
  -                _errorLog.error(EnhanceMessages.errorAddingProperty(iss.getProperty(), op
  -                        .getBaseClass(), ex), iss.getLocation(), ex);
  -            }
  -        }
  +        injectState(op, spec.getProperty(), spec.getObject());
       }
   
       private void injectState(EnhancementOperation op, String propertyName, String objectName)
       {
  -        Class propertyType =
  -            EnhanceUtils.extractPropertyType(op, propertyName, null);
  +        Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
           String fieldName = "_$" + propertyName;
   
           op.claimProperty(propertyName);
   
           op.addField(fieldName, propertyType);
   
  +        String managerField = op.addFinalField(
  +                "_$applicationStateManager",
  +                _applicationStateManager);
  +
           BodyBuilder builder = new BodyBuilder();
   
           // Accessor
   
           builder.begin();
           builder.addln("if ({0} == null)", fieldName);
  -        builder.addln(
  -                "  {0} = ({1}) _$applicationStateManager.get(\"{2}\");",
  -                fieldName,
  -                ClassFabUtils.getJavaClassName(propertyType),
  -                objectName);
  +        builder.addln("  {0} = ({1}) {2}.get(\"{3}\");", new Object[]
  +        { fieldName, ClassFabUtils.getJavaClassName(propertyType), managerField, objectName });
           builder.addln("return {0};", fieldName);
           builder.end();
   
  @@ -109,7 +75,7 @@
   
           builder.clear();
           builder.begin();
  -        builder.addln("_$applicationStateManager.store(\"{0}\", $1);", objectName);
  +        builder.addln("{0}.store(\"{1}\", $1);", managerField, objectName);
           builder.addln("{0} = $1;", fieldName);
           builder.end();
   
  @@ -131,9 +97,4 @@
       {
           _applicationStateManager = applicationStateManager;
       }
  -
  -    public void setErrorLog(ErrorLog errorLog)
  -    {
  -        _errorLog = errorLog;
  -    }
   }
  \ No newline at end of file
 
 
 
  1.17      +38 -20    jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java
 
  Index: EnhancementOperationImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- EnhancementOperationImpl.java 18 Apr 2005 17:06:34 -0000 1.16
  +++ EnhancementOperationImpl.java 12 May 2005 18:18:18 -0000 1.17
  @@ -24,6 +24,7 @@
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.HashSet;
  +import java.util.IdentityHashMap;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  @@ -58,13 +59,15 @@
   
       private ClassFab _classFab;
   
  -    private Set _claimedProperties = new HashSet();
  +    private final Set _claimedProperties = new HashSet();
   
  -    private JavaClassMapping _javaClassMapping = new JavaClassMapping();
  +    private final JavaClassMapping _javaClassMapping = new JavaClassMapping();
   
  -    private List _constructorTypes = new ArrayList();
  +    private final List _constructorTypes = new ArrayList();
   
  -    private List _constructorArguments = new ArrayList();
  +    private final List _constructorArguments = new ArrayList();
  +
  +    private final Map _finalFields = new IdentityHashMap();
   
       /**
        * Set of interfaces added to the enhanced class.
  @@ -79,12 +82,6 @@
       private Map _incompleteMethods = new HashMap();
   
       /**
  -     * Keyed on class to instance variable name.
  -     */
  -
  -    private Map _classReferences = new HashMap();
  -
  -    /**
        * Map of property names to {@link PropertyDescriptor}.
        */
   
  @@ -227,13 +224,38 @@
           _classFab.addField(name, type);
       }
   
  -    public void addField(String name, Class type, Object value)
  +    public String addFinalField(String fieldName, Object value)
       {
  -        _classFab.addField(name, type);
  +        Defense.notNull(fieldName, "fieldName");
  +        Defense.notNull(value, "value");
  +
  +        String existing = (String) _finalFields.get(value);
  +
  +        // See if this object has been previously added.
  +
  +        if (existing != null)
  +            return existing;
  +
  +        // TODO: Should be ensure that the name is unique?
  +
  +        // Add a new field using the object's actual type.
   
  -        int x = addConstructorParameter(type, value);
  +        Class type = value.getClass();
   
  -        constructorBuilder().addln("{0} = ${1};", name, Integer.toString(x));
  +        // ClassFab doesn't have an option for saying the field should be final, just private.
  +        // Doesn't make a huge difference.
  +
  +        _classFab.addField(fieldName, type);
  +
  +        int parameterIndex = addConstructorParameter(type, value);
  +
  +        constructorBuilder().addln("{0} = ${1};", fieldName, Integer.toString(parameterIndex));
  +
  +        // Remember the mapping from the value to the field name.
  +
  +        _finalFields.put(value, fieldName);
  +
  +        return fieldName;
       }
   
       public Class convertTypeName(String type)
  @@ -314,7 +336,7 @@
       {
           Defense.notNull(clazz, "clazz");
   
  -        String result = (String) _classReferences.get(clazz);
  +        String result = (String) _finalFields.get(clazz);
   
           if (result == null)
               result = addClassReference(clazz);
  @@ -338,11 +360,7 @@
   
           String fieldName = buffer.toString();
   
  -        addField(fieldName, Class.class, clazz);
  -
  -        _classReferences.put(clazz, fieldName);
  -
  -        return fieldName;
  +        return addFinalField(fieldName, clazz);
       }
   
       /**
 
 
 
  1.10      +1 -2      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SpecifiedPropertyWorker.java 18 Apr 2005 17:06:34 -0000 1.9
  +++ SpecifiedPropertyWorker.java 12 May 2005 18:18:18 -0000 1.10
  @@ -131,8 +131,7 @@
           InitialValueBindingCreator creator = new InitialValueBindingCreator(_bindingSource,
                   description, initialValue, location);
   
  -        String creatorField = fieldName + "$initialValueBindingCreator";
  -        op.addField(creatorField, InitialValueBindingCreator.class, creator);
  +        String creatorField = op.addFinalField(fieldName + "$initialValueBindingCreator", creator);
   
           String bindingField = fieldName + "$initialValueBinding";
           op.addField(bindingField, IBinding.class);
 
 
 
  1.11      +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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- EnhanceStrings.properties 10 Feb 2005 16:22:58 -0000 1.10
  +++ EnhanceStrings.properties 12 May 2005 18:18:18 -0000 1.11
  @@ -21,4 +21,5 @@
   
   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}).
  -initial-value-for-property=initial value for property {0}
  \ No newline at end of file
  +initial-value-for-property=initial value for property {0}
  +unknown-inject-type=Unable to create injected property {0}: injection type ''{1}'' is not defined.
  \ No newline at end of file
 
 
 
  1.3       +11 -9     jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectMessagesWorker.java
 
  Index: InjectMessagesWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectMessagesWorker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InjectMessagesWorker.java 18 Apr 2005 17:06:34 -0000 1.2
  +++ InjectMessagesWorker.java 12 May 2005 18:18:18 -0000 1.3
  @@ -18,6 +18,7 @@
   
   import org.apache.hivemind.ErrorLog;
   import org.apache.hivemind.Messages;
  +import org.apache.hivemind.service.BodyBuilder;
   import org.apache.hivemind.service.MethodSignature;
   import org.apache.tapestry.services.ComponentMessagesSource;
   import org.apache.tapestry.spec.IComponentSpecification;
  @@ -37,10 +38,6 @@
   
       private ComponentMessagesSource _componentMessagesSource;
   
  -    final String METHOD_CODE = "{\nif (_$messages == null)\n"
  -            + "  _$messages = _$componentMessagesSource.getMessages(this);\n"
  -            + "return _$messages;\n}\n";
  -
       final MethodSignature METHOD_SIGNATURE = new MethodSignature(Messages.class, "getMessages",
               null, null);
   
  @@ -50,13 +47,18 @@
           {
               op.claimProperty(MESSAGES_PROPERTY);
   
  -            op.addField(
  -                    "_$componentMessagesSource",
  -                    ComponentMessagesSource.class,
  -                    _componentMessagesSource);
  +            String sourceField = op.addFinalField("_$componentMessagesSource", _componentMessagesSource);
  +
               op.addField("_$messages", Messages.class);
   
  -            op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, METHOD_CODE);
  +            BodyBuilder builder = new BodyBuilder();
  +            builder.begin();
  +            builder.addln("if (_$messages == null)");
  +            builder.addln("  _$messages = {0}.getMessages(this);", sourceField);
  +            builder.addln("return _$messages;");
  +            builder.end();
  +
  +            op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, builder.toString());
           }
           catch (Exception ex)
           {
 
 
 
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/DispatchToInjectWorker.java
 
  Index: DispatchToInjectWorker.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 java.util.Iterator;
  import java.util.Map;
 
  import org.apache.hivemind.ErrorLog;
  import org.apache.tapestry.spec.IComponentSpecification;
  import org.apache.tapestry.spec.InjectSpecification;
 
  /**
   * Iterates over the {@link org.apache.tapestry.spec.InjectSpecification}s and locates and
   * delegates to a {@link org.apache.tapestry.enhance.InjectEnhancementWorker} for each one.
   *
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class DispatchToInjectWorker implements EnhancementWorker
  {
      private ErrorLog _errorLog;
 
      private Map _injectWorkers;
 
      public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
      {
          Iterator i = spec.getInjectSpecifications().iterator();
 
          while (i.hasNext())
          {
              InjectSpecification is = (InjectSpecification) i.next();
 
              invokeWorker(op, is);
          }
      }
 
      private void invokeWorker(EnhancementOperation op, InjectSpecification spec)
      {
          try
          {
              InjectEnhancementWorker worker = (InjectEnhancementWorker) _injectWorkers.get(spec
                      .getType());
 
              if (worker == null)
              {
                  _errorLog.error(EnhanceMessages.unknownInjectType(spec.getProperty(), spec
                          .getType()), spec.getLocation(), null);
                  return;
              }
 
              worker.performEnhancement(op, spec);
 
          }
          catch (Exception ex)
          {
              _errorLog.error(EnhanceMessages.errorAddingProperty(spec.getProperty(), op
                      .getBaseClass(), ex), spec.getLocation(), ex);
          }
      }
 
      public void setErrorLog(ErrorLog errorLog)
      {
          _errorLog = errorLog;
      }
 
      public void setInjectWorkers(Map injectWorkers)
      {
          _injectWorkers = injectWorkers;
      }
  }
 
 
 
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectObjectWorker.java
 
  Index: InjectObjectWorker.java
  ===================================================================
  // Copyright 2004, 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 java.lang.reflect.Modifier;
 
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.service.MethodSignature;
  import org.apache.tapestry.services.InjectedValueProvider;
  import org.apache.tapestry.spec.InjectSpecification;
 
  /**
   * Implementation for injection type "object" (the default). Adds read-only properties to the
   * enhanced class that contain objects injected from HiveMind.
   *
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class InjectObjectWorker implements InjectEnhancementWorker
  {
      private InjectedValueProvider _provider;
 
      public void performEnhancement(EnhancementOperation op, InjectSpecification is)
      {
          String name = is.getProperty();
          String objectReference = is.getObject();
 
          Class propertyType = op.getPropertyType(name);
          if (propertyType == null)
              propertyType = Object.class;
 
          String fieldName = "_$" + name;
 
          op.claimProperty(name);
 
          Object injectedValue = _provider.obtainValue(objectReference, is.getLocation());
 
          if (injectedValue == null)
              throw new ApplicationRuntimeException(EnhanceMessages
                      .locatedValueIsNull(objectReference), is.getLocation(), null);
 
          if (!propertyType.isAssignableFrom(injectedValue.getClass()))
              throw new ApplicationRuntimeException(EnhanceMessages.incompatibleInjectType(
                      objectReference,
                      injectedValue,
                      propertyType), is.getLocation(), null);
 
          op.addFinalField(fieldName, injectedValue);
 
          String methodName = EnhanceUtils.createAccessorMethodName(name);
 
          op.addMethod(
                  Modifier.PUBLIC,
                  new MethodSignature(propertyType, methodName, null, null),
                  "return " + fieldName + ";");
      }
 
      public void setProvider(InjectedValueProvider provider)
      {
          _provider = provider;
      }
  }
 
 
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectEnhancementWorker.java
 
  Index: InjectEnhancementWorker.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.tapestry.spec.InjectSpecification;
 
  /**
   * A kind of enhancement worker dedicated to injection, based on the &lt;inject&gt; element of the
   * specification. There are different types of injection which match up to different implementations
   * of this interface (i.e., the Strategy pattern).
   *
   * @author Howard M. Lewis Ship
   * @since 4.0
   * @see org.apache.tapestry.spec.InjectSpecification
   * @see org.apache.tapestry.enhance.DispatchToInjectWorker
   */
  public interface InjectEnhancementWorker
  {
      /**
       * Perform the enhancement defined by the {@link org.apache.tapestry.spec.InjectSpecification}.
       * Thrown runtime exceptions are caught and reported by the invoker.
       */
 
      public void performEnhancement(EnhancementOperation op, InjectSpecification spec);
 
  }
 
 
 
  1.104     +1 -0      jakarta-tapestry/status.xml
 
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.103
  retrieving revision 1.104
  diff -u -r1.103 -r1.104
  --- status.xml 11 May 2005 17:07:20 -0000 1.103
  +++ status.xml 12 May 2005 18:18:18 -0000 1.104
  @@ -59,6 +59,7 @@
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-320"> Property seperate data from different users stored using the tapestry.persist.ClientPropertyPersistenceStrategy service.</action>
         <action type="add" dev="HLS"> Store the Registry as a ServletContext attribute, so that it may be accessed from other servlets. </action>
         <action type="add" dev="HLS" fixes-bug="TAPESTRY-323"> Allow control over the ErrorHandler used when building the HiveMind Registry. </action>
  +      <action type="update" dev="HLS"> Remove &lt;inject-state&gt;, and add type attribute to &lt;inject&gt;.</action>
       </release>
       <release version="4.0-alpha-2" date="May 5 2005">
         <action type="update" dev="HLS"> Coordinate Locale changes with the hivemind.ThreadLocale service. </action>
 
 
 
  1.24      +25 -52    jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/spec.xml
 
  Index: spec.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/spec.xml,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- spec.xml 2 May 2005 14:18:37 -0000 1.23
  +++ spec.xml 12 May 2005 18:18:18 -0000 1.24
  @@ -137,7 +137,6 @@
       have been consolidated into &lt;set&gt;, which now uses a (wait for it)
       &binding-reference;.</li>
     <li>The 4.0 DTD is more liberal about the order in which elements may be specified than the 3.0 DTD.</li>
  -  <li>The &spec.inject-state; element has been added.</li>
     <li>Added the property attribute to the &spec.component; and &spec.bean; elements.</li>
     <li>Removed the type attribute from the &spec.configure; element.</li>
     <li>Added many more options for <link href="#spec.boolean-types">boolean attributes</link>.</li>
  @@ -154,7 +153,7 @@
     <title>Property Injection</title>
     
   <p>
  -Several of the specification elements are concerned with <em>property injection</em>.  For &spec.inject; and &spec.inject-state;,
  +Several of the specification elements are concerned with <em>property injection</em>.  For &spec.inject;,
   the entire element exists to describe a property injection; in others (&spec.component;, &spec.bean; and &spec.asset;),
   the injection is just one piece of the behavior defined using the element.
   </p>
  @@ -929,22 +928,6 @@
   </tr>
   
   <tr>
  -  <td>object</td>
  -  <td>string</td>
  -  <td>yes</td>
  -  <td/>
  -  <td>
  -    The <em>object reference</em> for the object to be injected.  An object
  -    reference contains a prefix, such as "service:", which defines the
  -    type of object to locate.  The string following the prefix locates the specific object to be returned.
  -    &HiveMind; provides a
  -    <link href="http://jakarta.apache.org/hivemind/hivemind/ObjectProviders.html">basic set of prefixes</link>;
  -    Tapestry adds <link href="hivemind.html#hivemind.inject">several additional prefixes</link>.
  -    
  -  </td>
  -</tr>
  -
  -<tr>
     <td>property</td>
     <td>string</td>
     <td>yes</td>
  @@ -954,56 +937,46 @@
       the type of the property; otherwise java.lang.Object will be used.
     </td>
   </tr>
  -  </table>
  -  
  -</section>
  -
   
  -<section id="spec.inject-state">
  -  <title>&lt;inject-state&gt; element</title>
  -  
  -  <p>
  -    Appears in: &spec.component-specification; and &spec.page-specification;.
  -  </p>
  -  
  -  <p>
  -  <em>Injects</em> an &aso; into a component as a property. Reading the property will obtain the state object
  -  from the application state manager (this may cause the object to be created). Updating the property
  -  will store a new value into the application state manager (overwriting the initially created one).
  -  </p>
  -  
  -  <table>
   <tr>
  -  <th>Name</th>
  -  <th>Type</th>
  -  <th>Required ?</th>
  -  <th>Default Value</th>
  -  <th>Description</th>
  -</tr>
  -
  -<tr>
  -  <td>object</td>
  +  <td>type</td>
     <td>string</td>
  -  <td>yes</td>
  -  <td/>
  +  <td>no</td>
  +  <td>object</td>
     <td>
  -    The object name of the &aso;    
  +    The type of injection, which determines how the object attribute is interpreted.
     </td>
   </tr>
   
   <tr>
  -  <td>property</td>
  +  <td>object</td>
     <td>string</td>
     <td>yes</td>
     <td/>
     <td>
  -    The name of the property to be created.  If the class provides an abstract accessor method, then that method defines
  -    the type of the property; otherwise java.lang.Object will be used.
  +    The <em>object reference</em> for the object to be injected.  
  +    
     </td>
   </tr>
  +
     </table>
     
  -</section>
  +<p>
  +For object injection, the object attribute is a reference to a HiveMind object.
  +Such an object  contains a prefix, such as "service:", which defines the
  +    type of object to locate within the HiveMind Registry.  The string following the prefix locates the specific object to be returned.
  +    &HiveMind; provides a
  +    <link href="http://jakarta.apache.org/hivemind/hivemind/ObjectProviders.html">basic set of prefixes</link>;
  +    Tapestry adds <link href="hivemind.html#hivemind.inject">several additional prefixes</link>.  This
  +    style of injection results in a read-only property.
  +</p>
  +
  +<p>
  +For state injection, the object attribute is the name of the &aso; to inject. This injection
  +will result in a read/write property.
  +</p>
  +</section>  <!-- spec.inject -->
  +
   
   <section id="spec.library">
    <title>&lt;library&gt; element</title>
 
 
 
  1.19      +0 -1      jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/common.ent
 
  Index: common.ent
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/common.ent,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- common.ent 13 Apr 2005 22:38:46 -0000 1.18
  +++ common.ent 12 May 2005 18:18:18 -0000 1.19
  @@ -31,7 +31,6 @@
   <!ENTITY spec.description '<link href="spec.html#spec.description">&lt;description&gt;</link>'>
   <!ENTITY spec.extension '<link href="spec.html#spec.extension">&lt;extension&gt;</link>'>
   <!ENTITY spec.inject '<link href="spec.html#spec.inject">&lt;inject&gt;</link>'>
  -<!ENTITY spec.inject-state '<link href="spec.html#spec.inject-state">&lt;inject-state&gt;</link>'>
   <!ENTITY spec.library '<link href="spec.html#spec.library">&lt;library&gt;</link>'>
   <!ENTITY spec.library-specification '<link href="spec.html#spec.library-specification">&lt;library-specification&gt;</link>'>
   <!ENTITY spec.listener-binding '<link href="spec.html#spec.listener-binding">&lt;listener-binding&gt;</link>'>
 
 
 
  1.9       +2 -0      jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/index.xml
 
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/index.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- index.xml 18 Apr 2005 17:09:03 -0000 1.8
  +++ index.xml 12 May 2005 18:18:18 -0000 1.9
  @@ -307,6 +307,8 @@
     A further future direction, in the Tapestry 4.0 timeframe (the far future), is to rethink the component object model
     such that the classes <em>you</em> write do not sub-class Tapestry base classes. Page and component Java classes will
     be simple POJOs (Plain Old Java Objects) and will have any Tapestry dependencies <em>injected</em> into them.
  +  Also on the table is sidelining or entirely eliminating the XML page and component specifications in favor
  +  of Java annotations.
   </p>
     
   </section>
 
 
 
  1.15      +11 -5     jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/state.xml
 
  Index: state.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/state.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- state.xml 18 Apr 2005 17:09:03 -0000 1.14
  +++ state.xml 12 May 2005 18:18:18 -0000 1.15
  @@ -409,7 +409,7 @@
   
   <note>
     The two default ASOs, "visit" and "global", are defined in the hivemind.state.FactoryObjects configuration point. Definitions
  -  in the ApplicationObjects configuration point override the definitions in FactoryObjects.
  +  in the ApplicationObjects configuration point override definitions in FactoryObjects with the same name.
   </note>
     
   </section> <!-- state.aso.defining -->
  @@ -418,7 +418,7 @@
     <title>Accessing Application State Objects</title>
     
   <p>
  -Tapestry provides an &spec.inject-state; element to support access to the application state objects. This
  +Tapestry provides an &spec.inject; element to support access to the application state objects. This
   element can be used in any page or component specification to create a new property.  Reading the property
   will obtain the corresponding state object (which will be created if necessary).  The property may be updated,
   which will store a new application state object, overwriting the automatically created one.  
  @@ -429,7 +429,7 @@
   </p>
   
   <source><![CDATA[
  -<inject-state name="registration" object="registration-data"/>
  +<inject name="registration" type="state" object="registration-data"/>
   ]]></source>
   
   <p>
  @@ -490,9 +490,15 @@
   <p>
   The application may be <em>stateless</em> even when it has persistent page properties, if those properties use the
   <em>client</em> persistence strategy (which encodes pesistent page data into URLs as query parameters). This can be a
  -very powerful approach.
  +very powerful approach, though it introduces its own problems:
   </p>
  -
  +
  +<ul>
  +  <li>The query parameters are an encoding of Java objects, and could be decoded to expose
  +    privileged information.</li>
  +  <li>The encoding of page state can result in very long strings included as part of URLs, possibly extending beyond the 3000 to 4000 character effective maximum
  +    URL length.</li>
  +</ul>
   </section> <!-- state.stateless -->
   
   </body>
 
 
 
  1.6       +17 -5     jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecificationImpl.java
 
  Index: InjectSpecificationImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecificationImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InjectSpecificationImpl.java 18 Apr 2005 17:06:40 -0000 1.5
  +++ InjectSpecificationImpl.java 12 May 2005 18:18:19 -0000 1.6
  @@ -24,16 +24,18 @@
   {
       private String _property;
   
  -    private String _objectReference;
  +    private String _object;
   
  -    public String getObjectReference()
  +    private String _type;
  +
  +    public String getObject()
       {
  -        return _objectReference;
  +        return _object;
       }
   
  -    public void setObjectReference(String locator)
  +    public void setObject(String object)
       {
  -        _objectReference = locator;
  +        _object = object;
       }
   
       public String getProperty()
  @@ -45,4 +47,14 @@
       {
           _property = name;
       }
  +
  +    public String getType()
  +    {
  +        return _type;
  +    }
  +
  +    public void setType(String type)
  +    {
  +        _type = type;
  +    }
   }
  \ No newline at end of file
 
 
 
  1.8       +0 -18     jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/IComponentSpecification.java
 
  Index: IComponentSpecification.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/IComponentSpecification.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IComponentSpecification.java 18 Apr 2005 17:06:40 -0000 1.7
  +++ IComponentSpecification.java 12 May 2005 18:18:19 -0000 1.8
  @@ -273,22 +273,4 @@
        */
   
       public List getInjectSpecifications();
  -
  -    /**
  -     * Adds a {@link org.apache.tapestry.spec.InjectStateSpecification}s.
  -     *
  -     * @since 4.0
  -     */
  -
  -    public void addInjectStateSpecification(InjectStateSpecification spec);
  -
  -    /**
  -     * Returns the list of {@link org.apache.tapestry.spec.InjectStateSpecification}s. Returns an
  -     * empty list if no specifications have been added.
  -     *
  -     * @since 4.0
  -     */
  -
  -    public List getInjectStateSpecifications();
  -
   }
  \ No newline at end of file
 
 
 
  1.11      +0 -6      jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/SpecFactory.java
 
  Index: SpecFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/SpecFactory.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SpecFactory.java 18 Apr 2005 17:06:40 -0000 1.10
  +++ SpecFactory.java 12 May 2005 18:18:19 -0000 1.11
  @@ -183,10 +183,4 @@
       {
           return new InjectSpecificationImpl();
       }
  -
  -    /** @since 4.0 */
  -    public InjectStateSpecification createInjectStateSpecification()
  -    {
  -        return new InjectStateSpecificationImpl();
  -    }
   }
  \ No newline at end of file
 
 
 
  1.6       +13 -4     jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecification.java
 
  Index: InjectSpecification.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecification.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InjectSpecification.java 18 Apr 2005 17:06:40 -0000 1.5
  +++ InjectSpecification.java 12 May 2005 18:18:19 -0000 1.6
  @@ -31,11 +31,20 @@
       public void setProperty(String property);
   
       /**
  -     * Returns the object reference used to locate the HiveMind object to be injected into the
  -     * enhanced class.
  +     * Returns the type of injection. Different injection types interpret the
  +     * {@link #getObject() object property} differently. Ultimately, the type is used to select the
  +     * correct {@link org.apache.tapestry.enhance.InjectEnhancementWorker}.
        */
   
  -    public String getObjectReference();
  +    public String getType();
   
  -    public void setObjectReference(String locator);
  +    public void setType(String type);
  +
  +    /**
  +     * Returns the string used to indentify a particular object.
  +     */
  +
  +    public String getObject();
  +
  +    public void setObject(String object);
   }
  \ No newline at end of file
 
 
 
  1.7       +0 -21     jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java
 
  Index: ComponentSpecification.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ComponentSpecification.java 18 Apr 2005 17:06:40 -0000 1.6
  +++ ComponentSpecification.java 12 May 2005 18:18:19 -0000 1.7
  @@ -150,14 +150,6 @@
       private List _injectSpecifications;
   
       /**
  -     * List of {@link InjectStateSpecification}.
  -     *
  -     * @since 4.0
  -     */
  -
  -    private List _injectStateSpecifications;
  -
  -    /**
        * @throws IllegalArgumentException
        *             if the name already exists.
        */
  @@ -594,19 +586,6 @@
           return safeList(_injectSpecifications);
       }
   
  -    public void addInjectStateSpecification(InjectStateSpecification spec)
  -    {
  -        if (_injectStateSpecifications == null)
  -            _injectStateSpecifications = new ArrayList();
  -
  -        _injectStateSpecifications.add(spec);
  -    }
  -
  -    public List getInjectStateSpecifications()
  -    {
  -        return safeList(_injectStateSpecifications);
  -    }
  -
       private List safeList(List input)
       {
           if (input == null)
 
 
 
  1.10      +4 -4      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestSpecifiedPropertyWorker.java 18 Apr 2005 17:07:50 -0000 1.9
  +++ TestSpecifiedPropertyWorker.java 12 May 2005 18:18:19 -0000 1.10
  @@ -183,10 +183,10 @@
           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.addFinalField("_$fred$initialValueBindingCreator",
  +
  +        expectedCreator);
  +        opc.setReturnValue("_$fred$initialValueBindingCreator");
           op.addField("_$fred$initialValueBinding", IBinding.class);
           op
                   .extendMethodImplementation(
 
 
 
  1.3       +12 -2     jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectMessagesWorker.java
 
  Index: TestInjectMessagesWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectMessagesWorker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestInjectMessagesWorker.java 18 Apr 2005 17:07:50 -0000 1.2
  +++ TestInjectMessagesWorker.java 12 May 2005 18:18:19 -0000 1.3
  @@ -19,6 +19,7 @@
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.ErrorLog;
   import org.apache.hivemind.Messages;
  +import org.apache.hivemind.service.BodyBuilder;
   import org.apache.hivemind.test.HiveMindTestCase;
   import org.apache.tapestry.BaseComponent;
   import org.apache.tapestry.services.ComponentMessagesSource;
  @@ -55,9 +56,18 @@
           EnhancementOperation op = (EnhancementOperation) control.getMock();
   
           op.claimProperty(w.MESSAGES_PROPERTY);
  -        op.addField("_$componentMessagesSource", ComponentMessagesSource.class, source);
  +        op.addFinalField("_$componentMessagesSource", source);
  +        control.setReturnValue("fred");
  +
  +        BodyBuilder builder = new BodyBuilder();
  +        builder.begin();
  +        builder.addln("if (_$messages == null)");
  +        builder.addln("  _$messages = fred.getMessages(this);");
  +        builder.addln("return _$messages;");
  +        builder.end();
  +
           op.addField("_$messages", Messages.class);
  -        op.addMethod(Modifier.PUBLIC, w.METHOD_SIGNATURE, w.METHOD_CODE);
  +        op.addMethod(Modifier.PUBLIC, w.METHOD_SIGNATURE, builder.toString());
   
           replayControls();
   
 
 
 
  1.3       +2 -1      jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectSpecificationWorker.java
 
  Index: TestInjectSpecificationWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectSpecificationWorker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestInjectSpecificationWorker.java 18 Apr 2005 17:07:50 -0000 1.2
  +++ TestInjectSpecificationWorker.java 12 May 2005 18:18:19 -0000 1.3
  @@ -47,7 +47,8 @@
   
           op.claimProperty("specification");
   
  -        op.addField("_$specification", IComponentSpecification.class, spec);
  +        op.addFinalField("_$specification",  spec);
  +        control.setReturnValue("_$specification");
   
           op.getAccessorMethodName("specification");
           control.setReturnValue("getSpecification");
 
 
 
  1.4       +10 -75    jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectStateWorker.java
 
  Index: TestInjectStateWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectStateWorker.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestInjectStateWorker.java 18 Apr 2005 17:07:50 -0000 1.3
  +++ TestInjectStateWorker.java 12 May 2005 18:18:19 -0000 1.4
  @@ -15,22 +15,16 @@
   package org.apache.tapestry.enhance;
   
   import java.lang.reflect.Modifier;
  -import java.util.Collections;
  -import java.util.List;
   import java.util.Map;
   
  -import org.apache.hivemind.ApplicationRuntimeException;
  -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.test.HiveMindTestCase;
  -import org.apache.tapestry.BaseComponent;
   import org.apache.tapestry.engine.state.ApplicationStateManager;
   import org.apache.tapestry.event.PageDetachListener;
  -import org.apache.tapestry.spec.IComponentSpecification;
  -import org.apache.tapestry.spec.InjectStateSpecification;
  -import org.apache.tapestry.spec.InjectStateSpecificationImpl;
  +import org.apache.tapestry.spec.InjectSpecification;
  +import org.apache.tapestry.spec.InjectSpecificationImpl;
   import org.easymock.MockControl;
   
   /**
  @@ -46,56 +40,34 @@
           return (ApplicationStateManager) newMock(ApplicationStateManager.class);
       }
   
  -    private IComponentSpecification newSpecification(List injects)
  +    private InjectSpecification newSpec(String propertyName, String objectName, Location l)
       {
  -        MockControl control = newControl(IComponentSpecification.class);
  -        IComponentSpecification spec = (IComponentSpecification) control.getMock();
  -
  -        spec.getInjectStateSpecifications();
  -        control.setReturnValue(injects);
  -
  -        return spec;
  -    }
  -
  -    private List newInjects(String propertyName, String objectName, Location l)
  -    {
  -        InjectStateSpecification spec = new InjectStateSpecificationImpl();
  +        InjectSpecification spec = new InjectSpecificationImpl();
   
           spec.setProperty(propertyName);
  -        spec.setObjectName(objectName);
  +        spec.setObject(objectName);
           spec.setLocation(l);
   
  -        return Collections.singletonList(spec);
  -    }
  -
  -    public void testNoWorkToDo()
  -    {
  -        IComponentSpecification spec = newSpecification(Collections.EMPTY_LIST);
  -        EnhancementOperation op = (EnhancementOperation) newMock(EnhancementOperation.class);
  -
  -        replayControls();
  -
  -        new InjectStateWorker().performEnhancement(op, spec);
  -
  -        verifyControls();
  +        return spec;
       }
   
       public void testSuccess()
       {
  -        IComponentSpecification spec = newSpecification(newInjects("fred", "barney", null));
  +        InjectSpecification spec = newSpec("fred", "barney", null);
           MockControl opc = newControl(EnhancementOperation.class);
           EnhancementOperation op = (EnhancementOperation) opc.getMock();
   
           ApplicationStateManager asm = newASM();
   
  -        op.addField("_$applicationStateManager", ApplicationStateManager.class, asm);
  -
           op.getPropertyType("fred");
           opc.setReturnValue(Map.class);
   
           op.claimProperty("fred");
           op.addField("_$fred", Map.class);
   
  +        op.addFinalField("_$applicationStateManager", asm);
  +        opc.setReturnValue("_$applicationStateManager");
  +
           op.getAccessorMethodName("fred");
           opc.setReturnValue("getFred");
   
  @@ -137,41 +109,4 @@
   
           verifyControls();
       }
  -
  -    public void testFailure()
  -    {
  -        Throwable ex = new ApplicationRuntimeException(EnhanceMessages.claimedProperty("fred"));
  -        Location l = fabricateLocation(22);
  -
  -        IComponentSpecification spec = newSpecification(newInjects("fred", "barney", l));
  -        MockControl opc = newControl(EnhancementOperation.class);
  -        EnhancementOperation op = (EnhancementOperation) opc.getMock();
  -
  -        ErrorLog errorLog = (ErrorLog) newMock(ErrorLog.class);
  -
  -        ApplicationStateManager asm = newASM();
  -
  -        op.addField("_$applicationStateManager", ApplicationStateManager.class, asm);
  -
  -        op.getPropertyType("fred");
  -        opc.setReturnValue(Map.class);
  -
  -        op.claimProperty("fred");
  -        opc.setThrowable(ex);
  -
  -        op.getBaseClass();
  -        opc.setReturnValue(BaseComponent.class);
  -
  -        errorLog.error(EnhanceMessages.errorAddingProperty("fred", BaseComponent.class, ex), l, ex);
  -
  -        replayControls();
  -
  -        InjectStateWorker w = new InjectStateWorker();
  -        w.setApplicationStateManager(asm);
  -        w.setErrorLog(errorLog);
  -
  -        w.performEnhancement(op, spec);
  -
  -        verifyControls();
  -    }
   }
  \ No newline at end of file
 
 
 
  1.1                  jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestDispatchToInjectWorker.java
 
  Index: TestDispatchToInjectWorker.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 java.util.Collections;
  import java.util.Map;
 
  import org.apache.hivemind.ErrorLog;
  import org.apache.hivemind.Location;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.apache.tapestry.html.BasePage;
  import org.apache.tapestry.spec.IComponentSpecification;
  import org.apache.tapestry.spec.InjectSpecification;
  import org.apache.tapestry.spec.InjectSpecificationImpl;
  import org.easymock.MockControl;
 
  /**
   * Tests for {@link org.apache.tapestry.enhance.DispatchToInjectWorker}.
   *
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class TestDispatchToInjectWorker extends HiveMindTestCase
  {
      private InjectSpecification newInjectSpecification(String propertyName, String type,
              String object)
      {
          return newInjectSpecification(propertyName, type, object, null);
      }
 
      private InjectSpecification newInjectSpecification(String propertyName, String type,
              String object, Location location)
      {
          InjectSpecification result = new InjectSpecificationImpl();
          result.setProperty(propertyName);
          result.setType(type);
          result.setObject(object);
          result.setLocation(location);
 
          return result;
      }
 
      private IComponentSpecification newSpec(InjectSpecification injectSpec)
      {
          MockControl control = newControl(IComponentSpecification.class);
          IComponentSpecification spec = (IComponentSpecification) control.getMock();
 
          spec.getInjectSpecifications();
          control.setReturnValue(Collections.singletonList(injectSpec));
 
          return spec;
      }
 
      private Map newMap(String key, Object value)
      {
          return Collections.singletonMap(key, value);
      }
 
      public void testSuccess()
      {
          EnhancementOperation op = newOp();
          InjectSpecification is = newInjectSpecification("property", "object", "service:Foo");
          InjectEnhancementWorker worker = newWorker();
          Map map = newMap("object", worker);
          IComponentSpecification spec = newSpec(is);
 
          worker.performEnhancement(op, is);
 
          replayControls();
 
          DispatchToInjectWorker d = new DispatchToInjectWorker();
          d.setInjectWorkers(map);
 
          d.performEnhancement(op, spec);
 
          verifyControls();
      }
 
      public void testUnknownType()
      {
          Location l = newLocation();
          EnhancementOperation op = newOp();
          InjectSpecification is = newInjectSpecification(
                  "injectedProperty",
                  "object",
                  "service:Foo",
                  l);
          IComponentSpecification spec = newSpec(is);
          ErrorLog log = newLog();
 
          log.error(EnhanceMessages.unknownInjectType("injectedProperty", "object"), l, null);
 
          replayControls();
 
          DispatchToInjectWorker d = new DispatchToInjectWorker();
          d.setInjectWorkers(Collections.EMPTY_MAP);
          d.setErrorLog(log);
 
          d.performEnhancement(op, spec);
 
          verifyControls();
      }
 
      public void testFailure()
      {
          Location l = newLocation();
          MockControl opc = newControl(EnhancementOperation.class);
          EnhancementOperation op = (EnhancementOperation) opc.getMock();
          InjectSpecification is = newInjectSpecification("myProperty", "object", "service:Foo", l);
          MockControl workerc = newControl(InjectEnhancementWorker.class);
          InjectEnhancementWorker worker = (InjectEnhancementWorker) workerc.getMock();
          Map map = newMap("object", worker);
          IComponentSpecification spec = newSpec(is);
          Throwable t = new RuntimeException("Simulated failure.");
          ErrorLog log = newLog();
 
          worker.performEnhancement(op, is);
          workerc.setThrowable(t);
 
          op.getBaseClass();
          opc.setReturnValue(BasePage.class);
 
          log
                  .error(
                          "Error adding property 'myProperty' to class org.apache.tapestry.html.BasePage: Simulated failure.",
                          l,
                          t);
 
          replayControls();
 
          DispatchToInjectWorker d = new DispatchToInjectWorker();
          d.setInjectWorkers(map