Package lesson05

Examples of lesson05.Translator


    }

    @Test
    public void find_by_type()
    {
        Translator t = mockTranslator("string", String.class);

        replay();

        TranslatorSource source = new TranslatorSourceImpl(newConfiguration(String.class, t));
View Full Code Here


    }

    @Test
    public void get_by_type_not_found()
    {
        Translator string = mockTranslator("string", String.class);
        Translator bool = mockTranslator("bool", Boolean.class);

        Map<Class, Translator> configuration = CollectionFactory.newMap();
        configuration.put(String.class, string);
        configuration.put(Boolean.class, bool);
View Full Code Here

public class TranslatorAlternatesSourceImplTest extends InternalBaseTestCase
{
    @Test
    public void name_mismatch()
    {
        Translator t = mockTranslator();

        train_getName(t, "barney");

        Map<String, Translator> configuration = CollectionFactory.newMap();
View Full Code Here

    public TranslatorSourceImpl(Map<Class, Translator> configuration, Map<String, Translator> alternates)
    {
        for (Map.Entry<Class, Translator> me : configuration.entrySet())
        {
            Class type = me.getKey();
            Translator translator = me.getValue();

            if (!type.equals(translator.getType()))
                throw new RuntimeException(
                        String
                                .format(
                                        "Contributed translator for type %s reports its type as %s. Please change the contribution so that the key matches that translator type.",
                                        type.getName(), translator.getType().getName()));

            String name = translator.getName();

            if (nameToTranslator.containsKey(name))
                throw new RuntimeException(
                        String
                                .format(
View Full Code Here

        registry = StrategyRegistry.newInstance(Translator.class, configuration, true);
    }

    public Translator get(String name)
    {
        Translator result = nameToTranslator.get(name);

        if (result == null)
            throw new UnknownValueException(String.format("Unknown translator type '%s'.", name), new AvailableValues(
                    "Configured translators", nameToTranslator));
View Full Code Here

        return result;
    }

    public Translator getByType(Class valueType)
    {
        Translator result = registry.get(valueType);

        if (result == null)
        {
            List<String> names = CollectionFactory.newList();
View Full Code Here

        assert locale != null;
        assert InternalUtils.isNonBlank(overrideId);
        if (propertyType == null)
            return null;

        Translator translator = findTranslator(propertyType, propertyAnnotations);

        if (translator == null)
            return null;

        return createTranslator(field, overrideId, overrideMessages, locale, translator);
View Full Code Here

    {
        assert resources != null;
        assert InternalUtils.isNonBlank(translatorName);
        Field field = (Field) resources.getComponent();

        Translator translator = translatorSource.get(translatorName);

        return createTranslator(field, resources.getId(), resources.getContainerMessages(), resources.getLocale(),
                translator);
    }
View Full Code Here

    }

    public Translator get(String name)
    {

        Translator result = translators.get(name);

        if (result == null)
            throw new RuntimeException(ServicesMessages.unknownTranslatorType(name, InternalUtils
                    .sortedKeys(translators)));
View Full Code Here

        return result;
    }

    public Translator getByType(Class valueType)
    {
        Translator result = registry.get(valueType);

        if (result == null)
        {
            List<String> names = CollectionFactory.newList();
View Full Code Here

TOP

Related Classes of lesson05.Translator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.