001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005//     http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.services;
014
015import org.apache.tapestry5.Asset;
016import org.apache.tapestry5.ioc.Resource;
017
018/**
019 * Used by {@link AssetSource} to create new {@link Asset}s as needed.
020 *
021 * Starting in Tapestry 5.4, the built-in implementations of this interface (for context assets, and for classpath assets)
022 * were changed so that when underlying resources changed, the client URLs for Assets are discarded; this is necessitated by two factors:
023 * 1) the {@linkplain org.apache.tapestry5.Asset#toClientURL() client URL}
024 * for an Asset now includes a checksum based on the content of the underlying resource, so a change to resource content
025 * (during development) results in a change to the URL.
026 * 2) {@link org.apache.tapestry5.services.javascript.JavaScriptStack} (especially the {@link org.apache.tapestry5.services.javascript.ExtensibleJavaScriptStack} implementation)
027 * made no provision for rebuilding the Assets post-construction, and there is no backwards compatible way to
028 * introduce this concept (and JavaScriptStacks are something many applications and third-party libraries make use of).
029 * So, starting in Tapestry 5.4, the implementations of {@link Asset} should be
030 *
031 * @see org.apache.tapestry5.services.AssetSource
032 */
033public interface AssetFactory
034{
035    /**
036     * Returns the Resource representing the root folder of the domain this factory is responsible for.
037     */
038    Resource getRootResource();
039
040    /**
041     * Creates an instance of an asset. Starting with 5.1.0.0, it is preferred (but not required) that the factory
042     * return an instance of {@link org.apache.tapestry5.Asset2}.
043     *
044     * @param resource
045     *         a resource within this factories domain (derived from the {@linkplain #getRootResource() root
046     *         resource})
047     * @return an Asset for the resource
048     */
049    Asset createAsset(Resource resource);
050}