    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.internal.services;
    014
    015import org.apache.tapestry5.internal.parser.ComponentTemplate;
    016import org.apache.tapestry5.model.ComponentModel;
    017import org.apache.tapestry5.services.InvalidationEventHub;
    018import org.apache.tapestry5.services.pageload.ComponentResourceSelector;
    019
    020/**
    021 * Provides access to cached {@link org.apache.tapestry5.internal.parser.ComponentTemplate}s. The source acts as a
    022 * invalidation event hub, and will broadcast invalidation events when any loaded template resource changes. The
    023 * listener for these invalidation events is the page source, which stores cached page instances.
    024 *
    025 * Any search for a template will end with success (a non-null template), but the template returned may be the
    026 * {@link ComponentTemplate#isMissing() missing template}.
    027 */
    028public interface ComponentTemplateSource
    029{
    030    /**
    031     * Provides access to a template. The template will be parsed as necessary. If no template for the exact component
    032     * is found, then the template for the component's parent is returned. In this way, it is possible for a component
    033     * to extend the behavior of its super-class without duplicating the super-class component's template.
    034     *
    035     * In some cases, the empty template will be returned.
    036     *
    037     * @param componentModel
    038     *            model for the component whose template is to be accessed
    039     * @param selector
    040     *            defines locale and other information needed to locate template
    041     * @return the cached template instance
    042     */
    043    ComponentTemplate getTemplate(ComponentModel componentModel, ComponentResourceSelector selector);
    044
    045    /**
    046     * Event hub used to notify listeners that underlying component template files have changed.
    047     *
    048     * @see org.apache.tapestry5.services.ComponentTemplates
    049     * @since 5.1.0.0
    050     */
    051    InvalidationEventHub getInvalidationEventHub();
    052}