tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rlewissh...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry AbstractComponent.java
Date Fri, 26 Dec 2003 23:30:07 GMT
rlewisshell    2003/12/26 15:30:07

  Modified:    framework/src/org/apache/tapestry/enhance
                        ComponentClassFactory.java
               web      new.html
               junit/mock-scripts TestEnhancedParameterProperties.xml
               framework/src/org/apache/tapestry AbstractComponent.java
  Added:       junit/src/org/apache/tapestry/junit/mock/c12
                        InsertFinal.java
               junit/context12/WEB-INF InsertFinal.jwc
               junit/context12 Four.html
  Log:
  Custom parameter binding properties only enhanced if abstract
  
  Revision  Changes    Path
  1.20      +40 -24    jakarta-tapestry/framework/src/org/apache/tapestry/enhance/ComponentClassFactory.java
  
  Index: ComponentClassFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/enhance/ComponentClassFactory.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ComponentClassFactory.java	19 Dec 2003 17:55:43 -0000	1.19
  +++ ComponentClassFactory.java	26 Dec 2003 23:30:07 -0000	1.20
  @@ -190,33 +190,39 @@
           return _enhancedClass != null && _enhancedClass.hasModifications();
       }
   
  -    /**
  -     *  Returns true if the {@link PropertyDescriptor} is null, or
  -     *  (if non-null), if either accessor method is abstract (or missing).
  -     * 
  -     **/
  -
  -    public boolean isAbstract(PropertyDescriptor pd)
  -    {
  -        if (pd == null)
  -            return true;
  -
  -        return isAbstract(pd.getReadMethod()) || isAbstract(pd.getWriteMethod());
  -    }
  +	/**
  +	 * @return true if pd is not null and both read/write methods are implemented
  +	 */
  +	public boolean isImplemented(PropertyDescriptor pd)
  +	{
  +		if (pd == null)
  +			return false;
  +		
  +		return isImplemented(pd.getReadMethod()) && isImplemented(pd.getWriteMethod());
  +	}
   
       /**
  -     *  Returns true if the method is null, or is abstract.
  -     * 
  -     **/
  -
  +     * @return true if m is not null and is abstract.
  +     */
       public boolean isAbstract(Method m)
       {
           if (m == null)
  -            return true;
  +            return false;
   
           return Modifier.isAbstract(m.getModifiers());
       }
   
  +	/**
  +	 * @return true if m is not null and not abstract  
  +	 */
  +	public boolean isImplemented(Method m)
  +	{
  +		if (m == null)
  +		    return false;
  +		
  +		return !Modifier.isAbstract(m.getModifiers()); 
  +	}
  +
       /**
        *  Given a class name, returns the corresponding class.  In addition,
        *  scalar types, arrays of scalar types, java.lang.Object[] and
  @@ -317,7 +323,7 @@
           Method write = d.getWriteMethod();
           Method read = d.getReadMethod();
   
  -        if (!isAbstract(write))
  +        if (isImplemented(write))
               throw new ApplicationRuntimeException(
                   Tapestry.format(
                       "ComponentClassFactory.non-abstract-write",
  @@ -326,7 +332,7 @@
                   location,
                   null);
   
  -        if (!isAbstract(read))
  +        if (isImplemented(read))
               throw new ApplicationRuntimeException(
                   Tapestry.format(
                       "ComponentClassFactory.non-abstract-read",
  @@ -342,7 +348,7 @@
       {
           PropertyDescriptor pd = getPropertyDescriptor(propertyName);
   
  -        return isAbstract(pd);
  +        return !isImplemented(pd);
       }
   
       /**
  @@ -436,7 +442,17 @@
           String propertyName = parameterName + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
           PropertyDescriptor pd = getPropertyDescriptor(propertyName);
   
  -        if (!isAbstract(pd))
  +		// only enhance custom parameter binding properties if they are declared abstract
  +		if (ps.getDirection() == Direction.CUSTOM)
  +		{
  +		    if (pd == null)
  +			    return;
  +			
  +			if (!(isAbstract(pd.getReadMethod()) || isAbstract(pd.getWriteMethod())))
  +			    return;
  +		}
  +			
  +        if (isImplemented(pd))
               return;
   
           // Need to create the property.
  @@ -502,7 +518,7 @@
   
           PropertyDescriptor pd = getPropertyDescriptor(propertyName);
   
  -        if (!isAbstract(pd))
  +        if (isImplemented(pd))
           {
               // Make sure the property is at least the right type.
   
  
  
  
  1.210     +2 -1      jakarta-tapestry/web/new.html
  
  Index: new.html
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/web/new.html,v
  retrieving revision 1.209
  retrieving revision 1.210
  diff -u -r1.209 -r1.210
  --- new.html	21 Dec 2003 23:55:08 -0000	1.209
  +++ new.html	26 Dec 2003 23:30:07 -0000	1.210
  @@ -25,6 +25,7 @@
   <li>Made DateValidator's getEffectiveFormat()/getEffectiveDisplayFormat() public
[rlewisshell]</li>
   <li>Updated to use DocBook 1.62.4 XSL stylesheets for documentation generation [rlewisshell]</li>
   <li>Moved info priority logging to debug priority [rlewisshell]</li>
  +<li>Custom parameter binding properties only enhanced if abstract [rlewisshell]</li>
   </ul>
   
   <pre>
  
  
  
  1.1                  jakarta-tapestry/junit/src/org/apache/tapestry/junit/mock/c12/InsertFinal.java
  
  Index: InsertFinal.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation", "Tapestry" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" 
   *    or "Tapestry", nor may "Apache" or "Tapestry" appear in their 
   *    name, without prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.tapestry.junit.mock.c12;
  
  import org.apache.tapestry.AbstractComponent;
  import org.apache.tapestry.IMarkupWriter;
  import org.apache.tapestry.IRequestCycle;
  
  /**
   *  Used to verify that the enhancer does not enhance custom
   *  parameter binding properties, unless they are abstract. This
   *  class is final so it is not possible to extend/enhance - as
   *  long as the component works, the class can not have been 
   *  enhanced.
   *
   *  @author Richard Lewis-Shell
   *  @version $Id: InsertFinal.java,v 1.1 2003/12/26 23:30:07 rlewisshell Exp $
   *
   **/
  
  public final class InsertFinal extends AbstractComponent
  {
  	protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
      {
      	writer.print(getBinding("final").getString());
      }
  
  }
  
  
  
  1.4       +7 -1      jakarta-tapestry/junit/mock-scripts/TestEnhancedParameterProperties.xml
  
  Index: TestEnhancedParameterProperties.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/mock-scripts/TestEnhancedParameterProperties.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestEnhancedParameterProperties.xml	18 Mar 2003 20:55:29 -0000	1.3
  +++ TestEnhancedParameterProperties.xml	26 Dec 2003 23:30:07 -0000	1.4
  @@ -59,4 +59,10 @@
   		</assert-output>
   	</request>
   		
  +    <request>
  +		<parameter name="service" value="page/Four"/>
  +		
  +		<assert-output name="Final">banana</assert-output>
  +    </request>
  +
    </mock-test>
  
  
  
  1.1                  jakarta-tapestry/junit/context12/WEB-INF/InsertFinal.jwc
  
  Index: InsertFinal.jwc
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!-- $Id: InsertInteger.jwc,v 1.4 2003/06/01 05:05:11 hlship Exp $ -->
  <!DOCTYPE component-specification PUBLIC 
    "-//Apache Software Foundation//Tapestry Specification 3.0//EN" 
    "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
    
  <component-specification class="org.apache.tapestry.junit.mock.c12.InsertFinal"
  		allow-body="no" allow-informal-parameters="no">
  
    <parameter name="final" type="java.lang.String" direction="custom"/>
  		
  </component-specification>
  
  
  
  1.1                  jakarta-tapestry/junit/context12/Four.html
  
  Index: Four.html
  ===================================================================
  <span jwcid="@InsertFinal" final="banana"/>
  
  
  1.18      +66 -48    jakarta-tapestry/framework/src/org/apache/tapestry/AbstractComponent.java
  
  Index: AbstractComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/AbstractComponent.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractComponent.java	17 Oct 2003 18:53:51 -0000	1.17
  +++ AbstractComponent.java	26 Dec 2003 23:30:07 -0000	1.18
  @@ -78,6 +78,8 @@
   import org.apache.tapestry.spec.BaseLocatable;
   import org.apache.tapestry.spec.IComponentSpecification;
   import org.apache.tapestry.util.prop.OgnlUtils;
  +import org.apache.tapestry.util.prop.PropertyFinder;
  +import org.apache.tapestry.util.prop.PropertyInfo;
   
   /**
    *  Abstract base class implementing the {@link IComponent} interface.
  @@ -498,33 +500,39 @@
           return getPage().getEngine().getResourceResolver();
       }
   
  -    /**
  -     *  Returns the named binding, or null if it doesn't exist.
  -     *
  -     *  All components are expected to have a read/write accessor for each
  -     *  formal parameter (such accessors are fabricated as needed).  Formal
  -     *  parameters are accessed via this property, informal parameters are
  -     *  stored in a Map.
  -     *
  -     *  @see #setBinding(String,IBinding)
  -     *
  -     **/
  +	/**
  +	 *  Returns the named binding, or null if it doesn't exist.
  +	 *
  +	 *  <p>This method looks for a JavaBeans property with an
  +	 *  appropriate name, of type {@link IBinding}.  The property
  +	 *  should be named <code><i>name</i>Binding</code>.  If it exists
  +	 *  and is both readable and writable, then it is accessor method
  +	 *  is invoked.  Components which implement such methods can
  +	 *  access their own binding through their instance variables
  +	 *  instead of invoking this method, a performance optimization.
  +	 *
  +	 *  @see #setBinding(String,IBinding)
  +	 *
  +	 **/
  +
  +	public IBinding getBinding(String name)
  +	{
  +		String bindingPropertyName = name + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  +		PropertyInfo info = PropertyFinder.getPropertyInfo(getClass(), bindingPropertyName);
  +
  +		if (info != null && info.isReadWrite() && info.getType().equals(IBinding.class))
  +		{
  +			IResourceResolver resolver = getPage().getEngine().getResourceResolver();
   
  -    public IBinding getBinding(String name)
  -    {
  -        if (_specification.getParameter(name) != null)
  -        {
  -            IResourceResolver resolver = getResourceResolver();
  -            String bindingPropertyName = name + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  +			return (IBinding) OgnlUtils.get(bindingPropertyName, resolver, this);
  +		}
   
  -            return (IBinding) OgnlUtils.get(bindingPropertyName, resolver, this);
  -        }
  +		if (_bindings == null)
  +			return null;
   
  -        if (_bindings == null)
  -            return null;
  +		return (IBinding) _bindings.get(name);
  +	}
   
  -        return (IBinding) _bindings.get(name);
  -    }
   
       /**
        *  Return's the page's change observer.  In practical terms, this
  @@ -657,33 +665,43 @@
               _body[i].render(writer, cycle);
       }
   
  -    /**
  -     *  Adds the binding with the given name, replacing any existing binding
  -     *  with that name.
  -     *
  -     *  <p>Formal parameters will have an read/write property.
  -     *
  -     *  <p>Informal parameters should <em>not</em> be stored in
  -     *  instance variables if @link
  -     *  #generateAttribute(IMarkupWriter, String[]) is to be used.
  -     *  It relies on using the collection of bindings (to store informal parameters).
  -     **/
  +	/**
  +	 *  Adds the binding with the given name, replacing any existing binding
  +	 *  with that name.
  +	 *
  +	 *  <p>This method checks to see if a matching JavaBeans property
  +	 *  (with a name of <code><i>name</i>Binding</code> and a type
of
  +	 *  {@link IBinding}) exists.  If so, that property is updated.
  +	 *  An optimized component can simply implement accessor and
  +	 *  mutator methods and then access its bindings via its own
  +	 *  instance variables, rather than going through {@link
  +	 *  #getBinding(String)}.
  +	 *
  +	 *  <p>Informal parameters should <em>not</em> be stored in
  +	 *  instance variables if {@link
  +	 *  #renderInformalParameters(IMarkupWriter, IRequestCycle)} is to be used.
  +	 *  It relies on using the collection of bindings (to store informal parameters).
  +	 **/
  +
  +	public void setBinding(String name, IBinding binding)
  +	{
  +		String bindingPropertyName = name + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  +
  +		PropertyInfo info = PropertyFinder.getPropertyInfo(getClass(), bindingPropertyName);
  +
  +		if (info != null && info.isReadWrite() && info.getType().equals(IBinding.class))
  +		{
  +			IResourceResolver resolver = getPage().getEngine().getResourceResolver();
  +			OgnlUtils.set(bindingPropertyName, resolver, this, binding);
  +			return;
  +		}
   
  -    public void setBinding(String name, IBinding binding)
  -    {
  -        if (_specification.getParameter(name) != null)
  -        {
  -            String bindingPropertyName = name + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
  -            IResourceResolver resolver = getResourceResolver();
  -            OgnlUtils.set(bindingPropertyName, resolver, this, binding);
  -            return;
  -        }
  +		if (_bindings == null)
  +			_bindings = new HashMap(MAP_SIZE);
   
  -        if (_bindings == null)
  -            _bindings = new HashMap(MAP_SIZE);
  +		_bindings.put(name, binding);
  +	}
   
  -        _bindings.put(name, binding);
  -    }
   
       public String toString()
       {
  
  
  

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