tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance TestInjectSpecificationWorker.java
Date Thu, 10 Feb 2005 14:27:37 GMT
hlship      2005/02/10 06:27:37

  Modified:    .        status.xml
               framework/src/descriptor/META-INF tapestry.enhance.xml
               framework/src/java/org/apache/tapestry/pageload
                        PageLoader.java
               framework/src/java/org/apache/tapestry
                        AbstractComponent.java IComponent.java
               framework/src/test/org/apache/tapestry/junit
                        TestComponentMessages.java
  Added:       framework/src/java/org/apache/tapestry/enhance
                        InjectSpecificationWorker.java
               framework/src/test/org/apache/tapestry/enhance
                        TestInjectSpecificationWorker.java
  Log:
  Inject component specifications into components as the specification property.
  
  Revision  Changes    Path
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectSpecificationWorker.java
  
  Index: InjectSpecificationWorker.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.ErrorLog;
  import org.apache.tapestry.spec.IComponentSpecification;
  
  /**
   * Injects the component's specification as the
   * {@link org.apache.tapestry.IComponent#getSpecification() specification}property.
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class InjectSpecificationWorker implements EnhancementWorker
  {
      public static final String SPECIFICATION_PROPERTY_NAME = "specification";
  
      private ErrorLog _errorLog;
  
      public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
      {
          try
          {
              injectSpecification(op, spec);
          }
          catch (Exception ex)
          {
              _errorLog.error(EnhanceMessages.errorAddingProperty(SPECIFICATION_PROPERTY_NAME,
op
                      .getBaseClass(), ex), spec.getLocation(), ex);
          }
      }
  
      private void injectSpecification(EnhancementOperation op, IComponentSpecification spec)
      {
          op.claimProperty(SPECIFICATION_PROPERTY_NAME);
  
          String fieldName = "_$" + SPECIFICATION_PROPERTY_NAME;
  
          op.addField(fieldName, IComponentSpecification.class, spec);
  
          EnhanceUtils.createSimpleAccessor(
                  op,
                  fieldName,
                  SPECIFICATION_PROPERTY_NAME,
                  IComponentSpecification.class);
      }
  
      public void setErrorLog(ErrorLog errorLog)
      {
          _errorLog = errorLog;
      }
  }
  
  
  1.69      +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- status.xml	8 Feb 2005 21:09:55 -0000	1.68
  +++ status.xml	10 Feb 2005 14:27:36 -0000	1.69
  @@ -145,6 +145,7 @@
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-265" due-to="Michael Frericks">
Fix bad link in UsersGuide/spec.xml. </action>
         <action type="update" dev="HLS"> Add new ComponentPropertySource service for
accessing component meta-data properties. </action>
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-165"> Allow control over attribute
name for components in templates. </action>
  +      <action type="update" dev="HLS"> Inject specification into components. </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.11      +11 -0     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- tapestry.enhance.xml	7 Feb 2005 19:41:19 -0000	1.10
  +++ tapestry.enhance.xml	10 Feb 2005 14:27:37 -0000	1.11
  @@ -66,6 +66,7 @@
       <!-- These can actually run in any order, so we don't specify before or after. -->
   
       <command id="inject-messages" object="service:InjectMessagesWorker"/>    
  +    <command id="inject-specification" object="service:InjectSpecificationWorker"/>
       <command id="specified-property" object="service:SpecifiedPropertyWorker"/>
       <command id="parameter" object="service:ParameterPropertyWorker"/>
       <command id="inject" object="service:InjectWorker"/>
  @@ -90,6 +91,16 @@
       
     </service-point>
     
  +  <service-point id="InjectSpecificationWorker" interface="org.apache.tapestry.enhance.EnhancementWorker">
  +    
  +    Injects the specification property into all components.
  +    
  +    <invoke-factory>
  +      <construct class="org.apache.tapestry.enhance.InjectSpecificationWorker"/>
  +    </invoke-factory>
  +    
  +  </service-point>
  +  
     <service-point id="SpecifiedPropertyWorker" interface="org.apache.tapestry.enhance.EnhancementWorker">
       
       Finds specified properties (from the specification) and constructs the corresponding
properties in the enhanced class.
  
  
  
  1.19      +0 -2      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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- PageLoader.java	7 Feb 2005 19:41:19 -0000	1.18
  +++ PageLoader.java	10 Feb 2005 14:27:37 -0000	1.19
  @@ -475,7 +475,6 @@
                       null, null);
   
           result.setNamespace(namespace);
  -        result.setSpecification(spec);
           result.setPage(page);
           result.setContainer(container);
           result.setId(id);
  @@ -520,7 +519,6 @@
               result = (IPage) cc.newInstance();
   
               result.setNamespace(namespace);
  -            result.setSpecification(spec);
               result.setPageName(pageName);
               result.setPage(result);
               result.setLocale(_locale);
  
  
  
  1.14      +2 -23     jakarta-tapestry/framework/src/java/org/apache/tapestry/AbstractComponent.java
  
  Index: AbstractComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/AbstractComponent.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractComponent.java	6 Feb 2005 15:08:50 -0000	1.13
  +++ AbstractComponent.java	10 Feb 2005 14:27:37 -0000	1.14
  @@ -23,7 +23,6 @@
   import java.util.Map;
   
   import org.apache.hivemind.ApplicationRuntimeException;
  -import org.apache.hivemind.Messages;
   import org.apache.hivemind.impl.BaseLocatable;
   import org.apache.hivemind.util.Defense;
   import org.apache.hivemind.util.PropertyUtils;
  @@ -45,12 +44,6 @@
   public abstract class AbstractComponent extends BaseLocatable implements IComponent
   {
       /**
  -     * The specification used to originally build the component.
  -     */
  -
  -    private IComponentSpecification _specification;
  -
  -    /**
        * The page that contains the component, possibly itself (if the component is in fact,
a page).
        */
   
  @@ -312,7 +305,7 @@
       {
           Defense.notNull(name, "name");
   
  -        return _specification.getParameter(name) != null;
  +        return getSpecification().getParameter(name) != null;
       }
   
       /**
  @@ -441,20 +434,6 @@
           _page = value;
       }
   
  -    public IComponentSpecification getSpecification()
  -    {
  -        return _specification;
  -    }
  -
  -    public void setSpecification(IComponentSpecification value)
  -    {
  -        if (_specification != null)
  -            throw new ApplicationRuntimeException(Tapestry
  -                    .getMessage("AbstractComponent.attempt-to-change-spec"));
  -
  -        _specification = value;
  -    }
  -
       /**
        * Renders all elements wrapped by the receiver.
        */
  @@ -545,7 +524,7 @@
           // Now, iterate over the formal parameters and add the formal parameters
           // that have a binding.
   
  -        List names = _specification.getParameterNames();
  +        List names = getSpecification().getParameterNames();
   
           int count = names.size();
   
  
  
  
  1.8       +0 -7      jakarta-tapestry/framework/src/java/org/apache/tapestry/IComponent.java
  
  Index: IComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/IComponent.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IComponent.java	6 Feb 2005 15:08:50 -0000	1.7
  +++ IComponent.java	10 Feb 2005 14:27:37 -0000	1.8
  @@ -189,13 +189,6 @@
       public IComponentSpecification getSpecification();
   
       /**
  -     * Sets the specification used by the component. This is write-once, an attempt to
change it
  -     * later will throw an {@link ApplicationRuntimeException}.
  -     */
  -
  -    public void setSpecification(IComponentSpecification value);
  -
  -    /**
        * Invoked to make the receiver render its body (the elements and components its tag
wraps
        * around, on its container's template). This method is public so that the
        * {@link org.apache.tapestry.components.RenderBody}component may operate.
  
  
  
  1.10      +3 -2      jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java
  
  Index: TestComponentMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestComponentMessages.java	8 Feb 2005 16:00:50 -0000	1.9
  +++ TestComponentMessages.java	10 Feb 2005 14:27:37 -0000	1.10
  @@ -31,6 +31,7 @@
   import org.apache.tapestry.engine.Namespace;
   import org.apache.tapestry.enhance.EnhancementOperationImpl;
   import org.apache.tapestry.enhance.InjectMessagesWorker;
  +import org.apache.tapestry.enhance.InjectSpecificationWorker;
   import org.apache.tapestry.html.BasePage;
   import org.apache.tapestry.junit.mock.c21.NullPropertySource;
   import org.apache.tapestry.services.ComponentPropertySource;
  @@ -123,12 +124,12 @@
                   specification, BasePage.class, classFactory);
   
           new InjectMessagesWorker().performEnhancement(op, specification);
  -
  +        new InjectSpecificationWorker().performEnhancement(op, specification);
  +            
           IPage result = (IPage) op.getConstructor().newInstance();
   
           result.setLocale(locale);
           result.setPage(result);
  -        result.setSpecification(specification);
   
           return result;
       }
  
  
  
  1.1                  jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectSpecificationWorker.java
  
  Index: TestInjectSpecificationWorker.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.lang.reflect.Modifier;
  
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.ErrorLog;
  import org.apache.hivemind.Location;
  import org.apache.hivemind.service.MethodSignature;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.apache.tapestry.BaseComponent;
  import org.apache.tapestry.spec.IComponentSpecification;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.tapestry.enhance.InjectSpecificationWorker}.
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class TestInjectSpecificationWorker extends HiveMindTestCase
  {
      private IComponentSpecification newSpec()
      {
          return (IComponentSpecification) newMock(IComponentSpecification.class);
      }
  
      public void testSuccess() throws Exception
      {
          MockControl control = newControl(EnhancementOperation.class);
          EnhancementOperation op = (EnhancementOperation) control.getMock();
  
          IComponentSpecification spec = newSpec();
  
          op.claimProperty("specification");
  
          op.addField("_$specification", IComponentSpecification.class, spec);
  
          op.getAccessorMethodName("specification");
          control.setReturnValue("getSpecification");
  
          op.addMethod(Modifier.PUBLIC, new MethodSignature(IComponentSpecification.class,
                  "getSpecification", null, null), "return _$specification;");
  
          replayControls();
  
          new InjectSpecificationWorker().performEnhancement(op, spec);
  
          verifyControls();
      }
  
      public void testFailure()
      {
          Location l = fabricateLocation(11);
  
          MockControl control = newControl(EnhancementOperation.class);
          EnhancementOperation op = (EnhancementOperation) control.getMock();
  
          ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
  
          Throwable ex = new ApplicationRuntimeException(EnhanceMessages
                  .claimedProperty("specification"));
  
          MockControl specc = newControl(IComponentSpecification.class);
          IComponentSpecification spec = (IComponentSpecification) specc.getMock();
  
          op.claimProperty("specification");
          control.setThrowable(ex);
  
          op.getBaseClass();
          control.setReturnValue(BaseComponent.class);
  
          spec.getLocation();
          specc.setReturnValue(l);
  
          log.error(
                  EnhanceMessages.errorAddingProperty("specification", BaseComponent.class,
ex),
                  l,
                  ex);
  
          replayControls();
  
          InjectSpecificationWorker w = new InjectSpecificationWorker();
          w.setErrorLog(log);
  
          w.performEnhancement(op, spec);
  
          verifyControls();
      }
  }
  
  

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