I feel there should be a better name for this. I could propose one
ExtendedAsset or VariableAsset but i dont know if more methods will
end up there... Is Asset2 meant to be directly used by users?

On Tue, Feb 10, 2009 at 8:06 AM,  <[email protected]> wrote:
> Author: hlship
> Date: Tue Feb 10 06:06:20 2009
> New Revision: 742861
>
> URL: http://svn.apache.org/viewvc?rev=742861&view=rev
> Log:
> Rework the recent changes to Asset to keep the Asset interface unchanged and 
> introduce a sub-interface, Asset2.
>
> Added:
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java
> Modified:
>    tapestry/tapestry5/trunk/src/site/apt/upgrade.apt
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetFactory.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetSource.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
>    
> tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
>
> Modified: tapestry/tapestry5/trunk/src/site/apt/upgrade.apt
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/upgrade.apt?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- tapestry/tapestry5/trunk/src/site/apt/upgrade.apt (original)
> +++ tapestry/tapestry5/trunk/src/site/apt/upgrade.apt Tue Feb 10 06:06:20 2009
> @@ -45,10 +45,5 @@
>   Extra public methods on module classes (methods that do not define 
> services, contribute to services,
>   or decorate or advise services) are now errors.
>
> -* Asset interface
> -
> -  The {{{apidocs/org/apache/tapestry5/Asset.html}Asset}} interface has been 
> changed incompatibly:
> -  A new method, isInvariant(), has been added. This will only affect 
> applications that have provided
> -  their own implementations of Asset.
>
>
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset.java
>  Tue Feb 10 06:06:20 2009
> @@ -22,6 +22,9 @@
>  * packaged inside JARs).
>  * <p/>
>  * An Asset's toString() will return the URL for the resource (the same value 
> as {...@link #toClientURL()}).
> + * <p/>
> + * Release 5.1.0.0 introduced {...@link org.apache.tapestry5.Asset2}, which 
> extends this interface with an additional
> + * method.
>  */
>  public interface Asset
>  {
> @@ -33,9 +36,6 @@
>      * and alternate implementation are encouraged to do so as well. In 
> addition, Tapestry ensures that context and
>      * classpath assets have a far-future expires header (to ensure aggresive 
> caching by the client).
>      * <p/>
> -     * This value is considered <em>variant</em>; because of {...@link 
> org.apache.tapestry5.services.AssetPathConverter},
> -     * it is conceivable for the return value to be different at different 
> times, depending on how the converter changes
> -     * the default path.
>      */
>     String toClientURL();
>
> @@ -44,15 +44,4 @@
>      */
>     Resource getResource();
>
> -    /**
> -     * Returns true if the Asset is invariant (meaning that it returns the 
> same value from {...@link #toClientURL()} at all
> -     * times}. Assets that are used as binding values will be cached more 
> aggresively by Tapestry is they are
> -     * invariant.
> -     *
> -     * @return true if invariant
> -     * @see org.apache.tapestry5.services.AssetPathConverter#isInvariant()
> -     * @see Binding#isInvariant()
> -     * @since 5.1.0.0
> -     */
> -    boolean isInvariant();
>  }
>
> Added: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java?rev=742861&view=auto
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java
>  (added)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/Asset2.java
>  Tue Feb 10 06:06:20 2009
> @@ -0,0 +1,39 @@
> +// Copyright 2009 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.tapestry5;
> +
> +/**
> + * Extension to {...@link org.apache.tapestry5.Asset} that adds a method to 
> determine if the asset is invariant or not.
> + * {...@link org.apache.tapestry5.services.AssetFactory} instances should 
> ideally return Asset2 objects, not Asset. This is
> + * only of primary interest to the {...@link 
> org.apache.tapestry5.internal.bindings.AssetBindingFactory}, as it determines
> + * the invariance of the binding from the asset (and assumes variant unless 
> the asset object implements this
> + * interface).
> + *
> + * @see org.apache.tapestry5.services.AssetPathConverter#isInvariant()
> + * @since 5.1.0.0
> + */
> +public interface Asset2 extends Asset
> +{
> +    /**
> +     * Returns true if the Asset is invariant (meaning that it returns the 
> same value from {...@link Asset#toClientURL()}
> +     * at all times}. Assets that are used as binding values will be cached 
> more aggresively by Tapestry is they are
> +     * invariant.
> +     *
> +     * @return true if invariant
> +     * @see org.apache.tapestry5.services.AssetPathConverter#isInvariant()
> +     * @see Binding#isInvariant()
> +     */
> +    boolean isInvariant();
> +}
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
>  Tue Feb 10 06:06:20 2009
> @@ -15,10 +15,9 @@
>  package org.apache.tapestry5.internal;
>
>  import org.apache.commons.codec.binary.Base64;
> -import org.apache.tapestry5.OptionModel;
> -import org.apache.tapestry5.SelectModel;
> -import org.apache.tapestry5.EventContext;
> +import org.apache.tapestry5.*;
>  import org.apache.tapestry5.ioc.Messages;
> +import org.apache.tapestry5.ioc.Resource;
>  import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
>  import org.apache.tapestry5.ioc.internal.util.Defense;
>  import org.apache.tapestry5.ioc.internal.util.InternalUtils;
> @@ -455,4 +454,41 @@
>
>         return true;
>     }
> +
> +    /**
> +     * Converts an Asset to an Asset2 if necessary. When actually wrapping 
> an Asset as an Asset2, the asset is assumed
> +     * to be variant (i.e., not cacheable).
> +     *
> +     * @since 5.1.0.0
> +     */
> +    public static Asset2 toAsset2(final Asset asset)
> +    {
> +        if (asset instanceof Asset2)
> +            return (Asset2) asset;
> +
> +        return new Asset2()
> +        {
> +            /** Returns false. */
> +            public boolean isInvariant()
> +            {
> +                return false;
> +            }
> +
> +            public Resource getResource()
> +            {
> +                return asset.getResource();
> +            }
> +
> +            public String toClientURL()
> +            {
> +                return asset.toClientURL();
> +            }
> +
> +            @Override
> +            public String toString()
> +            {
> +                return asset.toString();
> +            }
> +        };
> +    }
>  }
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/AssetBinding.java
>  Tue Feb 10 06:06:20 2009
> @@ -15,26 +15,28 @@
>  package org.apache.tapestry5.internal.bindings;
>
>  import org.apache.tapestry5.Asset;
> +import org.apache.tapestry5.Asset2;
> +import org.apache.tapestry5.internal.TapestryInternalUtils;
>  import org.apache.tapestry5.ioc.Location;
>
>  public class AssetBinding extends AbstractBinding
>  {
>     private final String description;
>
> -    private final Asset asset;
> +    private final Asset2 asset;
>
>     AssetBinding(Location location, String description, Asset asset)
>     {
>         super(location);
>
>         this.description = description;
> -        this.asset = asset;
> +        this.asset = TapestryInternalUtils.toAsset2(asset);
>     }
>
>     @Override
>     public Class getBindingType()
>     {
> -        return Asset.class;
> +        return Asset2.class;
>     }
>
>     public Object get()
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractAsset.java
>  Tue Feb 10 06:06:20 2009
> @@ -14,14 +14,14 @@
>
>  package org.apache.tapestry5.internal.services;
>
> -import org.apache.tapestry5.Asset;
> +import org.apache.tapestry5.Asset2;
>
>  /**
>  * Base class for assets.
>  *
>  * @since 5.1.0.0
>  */
> -public abstract class AbstractAsset implements Asset
> +public abstract class AbstractAsset implements Asset2
>  {
>     private final boolean invariant;
>
> @@ -35,6 +35,9 @@
>         return invariant;
>     }
>
> +    /**
> +     * Returns {...@link org.apache.tapestry5.Asset#toClientURL()}.
> +     */
>     @Override
>     public String toString()
>     {
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetFactory.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetFactory.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetFactory.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetFactory.java
>  Tue Feb 10 06:06:20 2009
> @@ -29,5 +29,13 @@
>      */
>     Resource getRootResource();
>
> +    /**
> +     * Creates an instance of an asset. Starting with 5.1.0.0, it is 
> preferred (but not required) that the factory
> +     * return an instance of {...@link org.apache.tapestry5.Asset2}.
> +     *
> +     * @param resource a resource within this factories domain (derived from 
> the {...@linkplain #getRootResource() root
> +     *                 resource})
> +     * @return an Asset for the resource
> +     */
>     Asset createAsset(Resource resource);
>  }
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetSource.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetSource.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetSource.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetSource.java
>  Tue Feb 10 06:06:20 2009
> @@ -27,6 +27,9 @@
>  * Assets are defined with a domain, and the domain is indicated by a prefix. 
>  The two builtin domains are "context:"
>  * (for files inside the web application context) and "classpath:" for files 
> stored on the classpath (typically, inside
>  * a JAR, such as a component library).
> + * <p/>
> + * Since 5.1.0.0, is is preferred that {...@link 
> org.apache.tapestry5.services.AssetFactory#createAsset(org.apache.tapestry5.ioc.Resource)}
> + * return an instance of {...@link org.apache.tapestry5.Asset2}.
>  */
>  @UsesMappedConfiguration(AssetFactory.class)
>  public interface AssetSource
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
>  Tue Feb 10 06:06:20 2009
> @@ -1210,4 +1210,9 @@
>     {
>         return newMock(ComponentRequestHandler.class);
>     }
> +
> +    protected final Asset2 mockAsset2()
> +    {
> +        return newMock(Asset2.class);
> +    }
>  }
>
> Modified: 
> tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
> URL: 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java?rev=742861&r1=742860&r2=742861&view=diff
> ==============================================================================
> --- 
> tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
>  (original)
> +++ 
> tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
>  Tue Feb 10 06:06:20 2009
> @@ -14,11 +14,10 @@
>
>  package org.apache.tapestry5.internal;
>
> -import org.apache.tapestry5.ComponentResources;
> -import org.apache.tapestry5.OptionModel;
> -import org.apache.tapestry5.SelectModel;
> +import org.apache.tapestry5.*;
>  import org.apache.tapestry5.internal.test.InternalBaseTestCase;
>  import org.apache.tapestry5.ioc.Messages;
> +import org.apache.tapestry5.ioc.Resource;
>  import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
>  import org.apache.tapestry5.ioc.services.ClassFactory;
>  import org.apache.tapestry5.ioc.services.PropertyAccess;
> @@ -395,4 +394,40 @@
>     {
>         assertEquals(TapestryInternalUtils.toBase64(input), expected);
>     }
> +
> +    @Test
> +    public void to_asset2_no_wrapper_needed()
> +    {
> +        Asset2 asset2 = mockAsset2();
> +
> +        replay();
> +
> +        assertSame(TapestryInternalUtils.toAsset2(asset2), asset2);
> +
> +        verify();
> +    }
> +
> +    @Test
> +    public void asset_to_asset2_wrapper()
> +    {
> +        Asset asset = mockAsset();
> +        Resource resource = mockResource();
> +        String clientURL = "clientURL";
> +
> +        train_toClientURL(asset, clientURL);
> +
> +        expect(asset.getResource()).andReturn(resource);
> +
> +        replay();
> +
> +        Asset2 asset2 = TapestryInternalUtils.toAsset2(asset);
> +
> +        assertFalse(asset2.isInvariant());
> +
> +        assertSame(asset2.toClientURL(), clientURL);
> +        assertSame(asset2.toString(), asset.toString());
> +        assertSame(asset2.getResource(), resource);
> +
> +        verify();
> +    }
>  }
>
>
>



-- 
Andreas Andreou - [email protected] - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to