001    // Copyright 2007, 2008 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.tapestry.services;
016    
017    import org.apache.tapestry.Translator;
018    
019    /**
020     * A source for {@link Translator}s, either by name.
021     */
022    public interface TranslatorSource
023    {
024        /**
025         * Returns the translator with the given logical name.
026         *
027         * @param name name of translator (as configured)
028         * @return the shared translator instance
029         * @throws RuntimeException if no translator is configured for the provided name
030         */
031        Translator get(String name);
032    
033        /**
034         * Finds a {@link Translator} that is appropriate to the given type, which is usually obtained via {@link
035         * org.apache.tapestry.Binding#getBindingType()}. Performs an inheritanced-based search for the best match.
036         *
037         * @param valueType the type of value for which a default translator is needed
038         * @return the matching translator, or null if no match can be found
039         */
040        Translator findByType(Class valueType);
041    
042        /**
043         * Finds a {@link Translator} that is appropriate to the given type, which is usually obtained via {@link
044         * org.apache.tapestry.Binding#getBindingType()}. Performs an inheritanced-based search for the best match.
045         *
046         * @param valueType the type of value for which a default translator is needed
047         * @return the matching translator
048         * @throws IllegalArgumentException if no known validator matches the provided type
049         */
050        Translator getByType(Class valueType);
051    }