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