You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/05/13 13:41:40 UTC

cvs commit: jakarta-tapestry/src/documentation/content/xdocs/UsersGuide upgrade.xml template.xml

hlship      2005/05/13 04:41:40

  Modified:    framework/src/test/org/apache/tapestry/enhance
                        TestEnhancementOperation.java
               framework/src/java/org/apache/tapestry/enhance
                        EnhancementOperationImpl.java
               src/documentation/content/xdocs/UsersGuide upgrade.xml
                        template.xml
  Log:
  Handle conflicting names when adding final fields to an enhanced class.
  
  Revision  Changes    Path
  1.14      +59 -2     jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java
  
  Index: TestEnhancementOperation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TestEnhancementOperation.java	18 Apr 2005 17:07:50 -0000	1.13
  +++ TestEnhancementOperation.java	13 May 2005 11:41:40 -0000	1.14
  @@ -15,6 +15,7 @@
   package org.apache.tapestry.enhance;
   
   import java.lang.reflect.Modifier;
  +import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
   import java.util.Set;
  @@ -23,6 +24,7 @@
   import org.apache.hivemind.ClassResolver;
   import org.apache.hivemind.Location;
   import org.apache.hivemind.impl.DefaultClassResolver;
  +import org.apache.hivemind.service.BodyBuilder;
   import org.apache.hivemind.service.ClassFab;
   import org.apache.hivemind.service.ClassFactory;
   import org.apache.hivemind.service.MethodSignature;
  @@ -39,6 +41,7 @@
   import org.apache.tapestry.services.ComponentConstructor;
   import org.apache.tapestry.spec.IComponentSpecification;
   import org.easymock.MockControl;
  +import org.easymock.internal.ArrayMatcher;
   
   /**
    * Tests for {@link org.apache.tapestry.enhance.EnhancementOperationImpl}.
  @@ -372,6 +375,60 @@
           verifyControls();
       }
   
  +    public void testAddFinalField()
  +    {
  +        IComponentSpecification spec = newSpec();
  +
  +        MockControl cfc = newControl(ClassFactory.class);
  +        ClassFactory cf = (ClassFactory) cfc.getMock();
  +
  +        MockControl fabc = newControl(ClassFab.class);
  +        ClassFab fab = (ClassFab) fabc.getMock();
  +
  +        cf.newClass("$BaseComponent_97", BaseComponent.class);
  +
  +        cfc.setReturnValue(fab);
  +
  +        // String because "FRED_VALUE" is a String
  +
  +        fab.addField("fred", String.class);
  +
  +        replayControls();
  +
  +        EnhancementOperationImpl eo = new EnhancementOperationImpl(new DefaultClassResolver(),
  +                spec, BaseComponent.class, cf);
  +
  +        assertEquals("fred", eo.addFinalField("fred", "FRED_VALUE"));
  +
  +        verifyControls();
  +
  +        HashMap map = new HashMap();
  +
  +        fab.addField("fred$0", HashMap.class);
  +
  +        replayControls();
  +
  +        assertEquals("fred$0", eo.addFinalField("fred", map));
  +
  +        verifyControls();
  +
  +        BodyBuilder body = new BodyBuilder();
  +        body.begin();
  +        body.addln("fred = $1;");
  +        body.addln("fred$0 = $2;");
  +        body.end();
  +
  +        fab.addConstructor(new Class[]
  +        { String.class, HashMap.class }, null, body.toString());
  +        fabc.setMatcher(new ArrayMatcher());
  +
  +        replayControls();
  +
  +        eo.finalizeEnhancedClass();
  +
  +        verifyControls();
  +    }
  +
       public void testAddMethod()
       {
           Class baseClass = Insert.class;
  @@ -429,7 +486,7 @@
   
       public void testGetClassReference() throws Exception
       {
  -        Location l = fabricateLocation(99);
  +        Location l = newLocation();
           MockControl specControl = newControl(IComponentSpecification.class);
   
           IComponentSpecification spec = (IComponentSpecification) specControl.getMock();
  @@ -487,7 +544,7 @@
   
       public void testComponentConstructorFailure()
       {
  -        Location l = fabricateLocation(13);
  +        Location l = newLocation();
   
           ComponentConstructor cc = new ComponentConstructorImpl(BaseComponent.class
                   .getConstructors()[0], new Object[]
  
  
  
  1.18      +17 -6     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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- EnhancementOperationImpl.java	12 May 2005 18:18:18 -0000	1.17
  +++ EnhancementOperationImpl.java	13 May 2005 11:41:40 -0000	1.18
  @@ -41,6 +41,7 @@
   import org.apache.hivemind.util.ToStringBuilder;
   import org.apache.tapestry.services.ComponentConstructor;
   import org.apache.tapestry.spec.IComponentSpecification;
  +import org.apache.tapestry.util.IdAllocator;
   
   /**
    * Implementation of {@link org.apache.tapestry.enhance.EnhancementOperation}that knows how to
  @@ -93,6 +94,12 @@
   
       private BodyBuilder _constructorBuilder;
   
  +    /**
  +     * Makes sure that names created by {@link #addFinalField(String, Object)} have unique names.
  +     */
  +
  +    private final IdAllocator _idAllocator = new IdAllocator();
  +
       public EnhancementOperationImpl(ClassResolver classResolver,
               IComponentSpecification specification, Class baseClass, ClassFactory classFactory)
       {
  @@ -237,25 +244,29 @@
               return existing;
   
           // TODO: Should be ensure that the name is unique?
  -
           // Add a new field using the object's actual type.
   
           Class type = value.getClass();
   
  +        // Make sure that the field has a unique name (at least, among anything added
  +        // via addFinalField().
  +
  +        String uniqueName = _idAllocator.allocateId(fieldName);
  +
           // 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);
  +        _classFab.addField(uniqueName, type);
   
           int parameterIndex = addConstructorParameter(type, value);
   
  -        constructorBuilder().addln("{0} = ${1};", fieldName, Integer.toString(parameterIndex));
  +        constructorBuilder().addln("{0} = ${1};", uniqueName, Integer.toString(parameterIndex));
   
           // Remember the mapping from the value to the field name.
   
  -        _finalFields.put(value, fieldName);
  +        _finalFields.put(value, uniqueName);
   
  -        return fieldName;
  +        return uniqueName;
       }
   
       public Class convertTypeName(String type)
  @@ -403,7 +414,7 @@
           return new ComponentConstructorImpl(c, params, _specification.getLocation());
       }
   
  -    private void finalizeEnhancedClass()
  +    void finalizeEnhancedClass()
       {
           finalizeIncompleteMethods();
   
  
  
  
  1.10      +61 -4     jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/upgrade.xml
  
  Index: upgrade.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/upgrade.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- upgrade.xml	6 May 2005 17:29:10 -0000	1.9
  +++ upgrade.xml	13 May 2005 11:41:40 -0000	1.10
  @@ -38,6 +38,22 @@
   Tapestry 4.0 still supports the Tapestry 3.0 DTDs (with minor exceptions). 
   </p>
   
  +<section id="upgrade.servlet-path">
  +  <title>Defining the servlet path</title>
  +  
  +<p>
  +In Tapestry 3.0, the framework could automatically determine the servlet path (used when constructing new URLs), because there was only a
  +single mapping.  The convention was to map the servlet to "/app", but any path-based mapping would automatically work.
  +</p>  
  +
  +<p>
  +Because of <link href="friendly-urls.html">friendly URLs</link>, there are any number of
  +possible servlet mappings in Tapestry 4.0, so you must inform Tapestry what the correct
  +mapping is.  It is necessary to define, to Tapestry, what this mapping is,
  +using the org.apache.tapestry.servlet-path &configuration-property;.
  +</p>
  +  
  +</section> <!-- upgrade.servlet-path -->
   
   <section id="upgrade.service">
     <title>Defining Engine Services</title>
  @@ -49,15 +65,37 @@
     
   <p>
   Engine services are now defined using HiveMind, in the <code>tapestry.services.ApplicationServices</code> configuration point.
  +The following is the chart service from the Workbench example:
   </p>
   
  +<source><![CDATA[
  +  <contribution configuration-id="tapestry.services.ApplicationServices">
  +    <service name="chart" object="service:Chart"/>
  +  </contribution>
  +
  +  <service-point id="Chart" interface="org.apache.tapestry.engine.IEngineService">
  +    <invoke-factory>
  +      <construct class="chart.ChartService">
  +        <set-object property="exceptionReporter" value="infrastructure:requestExceptionReporter"/>
  +        <set-object property="response" value="infrastructure:response"/>
  +        <set-object property="linkFactory" value="infrastructure:linkFactory"/>
  +      </construct>
  +    </invoke-factory>
  +  </service-point>]]>
  +</source>
  +
   <p>
  -The &lt;service&gt; element in a Tapestry 3.0 DTD is now ignored.
  +The &lt;service&gt; element in a Tapestry 3.0 DTD is now <strong>ignored</strong>.
   </p>
   
   <p>
   The &IEngineService; interface has changed in non-backwards compatible ways. If your application created
  -custom engine services, you will have to make changes to your code.
  +custom engine services, you will have to make changes to your code. If your custom service was
  +based on the <code>org.apache.tapestry.engine.AbstractService</code> class, that class has been removed
  +so you will have significant rewrites. As a suggested course of action, find the service
  +that the original service was based on, and build a new service based on that Tapestry service.
  +For example, if the original service was based on <code>org.apache.tapestry.asset.AssetService</code>, then
  +get the source for the AssetService, and model your service after the new implementation.
   </p>
   
   </section>  <!-- upgrade.service -->
  @@ -236,9 +274,28 @@
   </source>
     
   <p>
  -The advantage in 4.0 is that it is easier to specify simple strings as defaults; it is also possible to use other binding prefixes
  -(such as message:, or a user-supplied prefix).
  +  If you <em>don't</em> specify a prefix, then the default-binding (if any) for the parameter is used as the prefix for the default-value,
  +  just as it would be for any binding of the parameter. If the default-binding attribute
  +  is not set, then no prefix will be interpreted as an OGNL expression (so, really, the "ognl:" could be omitted in the example above).
  +  All of this comes in handy for more a more complex example:
   </p>
  +
  +<source><![CDATA[
  +  <parameter name="bar" type="java.lang.String" 
  +    default-value="messages.getMessage('default-bar')"/>      <!-- 3.0 -->
  +  
  +  <parameter name="bar" default-value="message:default-bar"/> <!-- 4.0 --> 
  +  
  +  
  +  <parameter name="baz" type="org.apache.tapestry.IAsset"
  +    default-value="assets.defaultBaz"/>                       <!-- 3.0 -->
  +    
  +  <parameter name="baz" default-binding="asset"
  +    default-value="defaultBaz"/>                              <!-- 4.0 -->
  +]]></source>
  +  
  +  
  +  
     
   </section>
   
  
  
  
  1.16      +1 -1      jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/template.xml
  
  Index: template.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/template.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- template.xml	1 Apr 2005 16:04:57 -0000	1.15
  +++ template.xml	13 May 2005 11:41:40 -0000	1.16
  @@ -289,7 +289,7 @@
   		<title>Specifying parameters</title>
   		
   <p>
  -Components are configured by <em><link href="binding.html">binding</link></em> their parameters.  In
  +Components are configured by <em><link href="bindings.html">binding</link></em> their parameters.  In
   a page or component specification, the &spec.binding; element is used to
   bind component parameters.
   </p>
  
  
  

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