001    // Copyright 2011 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    
015    package org.apache.tapestry5.services.pageload;
016    
017    import java.util.List;
018    
019    import org.apache.tapestry5.ioc.Resource;
020    import org.apache.tapestry5.ioc.util.LocalizedNameGenerator;
021    import org.apache.tapestry5.model.ComponentModel;
022    
023    /**
024     * A central service that encapsulates the rules for locating resources for components. The service can be
025     * overridden, or simply decorated, to implement customized rules for locating templates across
026     * one or more {@linkplain ComponentResourceSelector#getAxis(Class) axes}; this is the approach used to skin
027     * Tapestry applications.
028     * 
029     * @since 5.3
030     */
031    public interface ComponentResourceLocator
032    {
033        /**
034         * Locates the template for a component (including pages and base classes). The implementation takes into
035         * account the locale and other axes specified by the selector. If the method returns null, then the component
036         * will have no template (which is common for components, but rare for pages).
037         * 
038         * @param model
039         *            defines the component, including its {@linkplain ComponentModel#getBaseResource() base resource}.
040         * @param selector
041         *            used to identify locale, etc., for the template
042         * @return Resource for component template, or null if not found
043         */
044        Resource locateTemplate(ComponentModel model, ComponentResourceSelector selector);
045    
046        /**
047         * Locates the properties files that make up the message catalog for a specific component. The properties
048         * files are returned in order of specificity: the properties provided by the first resource override
049         * properties in later resources. Only resources specific to the class associated with the model
050         * should be concerned (message inheritance from base classes is handled by Tapestry).
051         * 
052         * @param baseResource
053         *            the resource for the base component properties file (i.e., with the ".properties" file extension)
054         * @param selector
055         *            defined the locale and other axes used to locate individual properties files
056         * @return list of properties file Resources
057         * @see LocalizedNameGenerator
058         */
059        List<Resource> locateMessageCatalog(Resource baseResource, ComponentResourceSelector selector);
060    }