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