001// Copyright 2010-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.internal.services;
016
017import org.apache.tapestry5.commons.Resource;
018import org.apache.tapestry5.internal.structure.Page;
019import org.apache.tapestry5.services.dynamic.DynamicTemplate;
020import org.apache.tapestry5.services.pageload.ComponentRequestSelectorAnalyzer;
021import org.apache.tapestry5.services.pageload.ComponentResourceSelector;
022
023import java.util.Set;
024
025/**
026 * Access to localized page instances (which are now shared singletons, starting in release 5.2).
027 * This service is a wrapper around the {@link PageLoader} that caches the loaded pages.
028 *
029 * @since 5.2.0
030 */
031public interface PageSource
032{
033    /**
034     * Clears the source's cache of loaded pages. This occurs when an outside change to the world invalidates
035     * created page instances. Introduced to handle the case where a page has a {@link DynamicTemplate}, but the
036     * underlying {@link Resource} is noticed to have changed.
037     *
038     * @since 5.3
039     */
040    void clearCache();
041
042    /**
043     * Returns a loaded instance of the indicated page, using the Locale and other information
044     * from the {@link ComponentResourceSelector} obtained from the {@link ComponentRequestSelectorAnalyzer}.
045     *
046     * @param canonicalPageName
047     * @return existing, or newly created, page instance
048     */
049    Page getPage(String canonicalPageName);
050
051    /**
052     * Returns all currently loaded pages. This will include any previously loaded pages not yet reclaimed by the
053     * garbage collector, and may include the same page loaded for different {@link ComponentResourceSelector}s. This is needed
054     * for reporting purposes only.
055     *
056     * @see org.apache.tapestry5.corelib.pages.PageCatalog
057     * @since 5.3
058     */
059    Set<Page> getAllPages();
060}