001// Copyright 2007, 2008, 2009, 2010 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.ComponentResources;
018import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
019
020/**
021 * Used to lookup meta data concerning a particular component. The primary source of meta data is the meta data defined
022 * for the component, accessed via {@link org.apache.tapestry5.model.ComponentModel#getMeta(String)}. This includes meta
023 * data defined by base classes. When meta-data for a particular component can not be found, a search works up the
024 * containment hierarchy (to the component's container, and the container's container, and so on). If <em>that</em>
025 * proves unfruitful, a system of defaults is provided by configuration and matched against the containing page's
026 * logical name.
027 * <p/>
028 * Finally, if no metadata is available, then {@link org.apache.tapestry5.ioc.services.SymbolSource#valueForSymbol(String)}
029 * is used to obtain a value. Generally speaking, if you are going to use this service to look up meta data, your should
030 * also make a contribution to the FactoryDefaults service; otherwise, you risk a runtime exception if a meta-data key
031 * can not be resolved.
032 */
033@UsesMappedConfiguration(String.class)
034public interface MetaDataLocator
035{
036    /**
037     * Searches for the value for the corresponding key.  The value, if located, will have symbols expanded, and will be
038     * type coerced to the desired type.
039     *
040     * @param key       the key used to locate the meta data (case insensitive)
041     * @param resources the resources of the initial component used in the search
042     * @return the value if found (in the component, the component's container, etc. or via a folder default)
043     * @throws RuntimeException if the value for the key is not present as meta data of the component, as an override,
044     *                          or as a symbol
045     */
046    <T> T findMeta(String key, ComponentResources resources, Class<T> expectedType);
047
048    /**
049     * Searches for the value for the corresponding key for a particular page name (the page will <em>not</em> be
050     * loaded).  The value, if located, will have symbols expanded, and will be type coerced to the desired type.
051     *
052     * @param key      the key used to locate the meta data (case insensitive)
053     * @param pageName the name of the page to search
054     * @return the value if found
055     * @throws RuntimeException if the value for the key is not present as meta data of the page, as an override, or as
056     *                          a symbol
057     */
058    <T> T findMeta(String key, String pageName, Class<T> expectedType);
059}