Search in sources :

Example 36 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class LanguageCamelContextAwareTest method testLanguageCamelContextAware.

public void testLanguageCamelContextAware() throws Exception {
    Language lan = context.resolveLanguage("my");
    assertNotNull(lan);
    MyLanguage me = assertIsInstanceOf(MyLanguage.class, lan);
    assertNotNull(me.getCamelContext());
}
Also used : Language(org.apache.camel.spi.Language)

Example 37 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class ContextTestSupport method assertExpression.

/**
     * Asserts that the given language name and expression evaluates to the
     * given value on a specific exchange
     */
protected void assertExpression(Exchange exchange, String languageName, String expressionText, Object expectedValue) {
    Language language = assertResolveLanguage(languageName);
    Expression expression = language.createExpression(expressionText);
    assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
    assertExpression(expression, exchange, expectedValue);
}
Also used : Language(org.apache.camel.spi.Language)

Example 38 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class ContextTestSupport method assertResolveLanguage.

/**
     * Asserts that the language name can be resolved
     */
protected Language assertResolveLanguage(String languageName) {
    Language language = context.resolveLanguage(languageName);
    assertNotNull("No language found for name: " + languageName, language);
    return language;
}
Also used : Language(org.apache.camel.spi.Language)

Example 39 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class DefaultCamelContextResolverTest method testLanguageWithBothNames.

@Test
public void testLanguageWithBothNames() throws Exception {
    Language language = context.resolveLanguage("blue");
    assertNotNull("Language not found in registry", language);
    assertTrue("Wrong instance type of the Language", language instanceof SampleLanguage);
    assertFalse("Here we should NOT have the fallback Language", ((SampleLanguage) language).isFallback());
}
Also used : Language(org.apache.camel.spi.Language) Test(org.junit.Test)

Example 40 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class DefaultLanguageResolver method resolveLanguage.

public Language resolveLanguage(String name, CamelContext context) {
    // lookup in registry first
    Language languageReg = ResolverHelper.lookupLanguageInRegistryWithFallback(context, name);
    if (languageReg != null) {
        return languageReg;
    }
    Class<?> type = null;
    try {
        type = findLanguage(name, context);
    } catch (NoFactoryAvailableException e) {
    // ignore
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid URI, no Language registered for scheme: " + name, e);
    }
    if (type != null) {
        if (Language.class.isAssignableFrom(type)) {
            return (Language) context.getInjector().newInstance(type);
        } else {
            throw new IllegalArgumentException("Resolving language: " + name + " detected type conflict: Not a Language implementation. Found: " + type.getName());
        }
    } else {
        // no specific language found then try fallback
        return noSpecificLanguageFound(name, context);
    }
}
Also used : Language(org.apache.camel.spi.Language) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Aggregations

Language (org.apache.camel.spi.Language)44 Expression (org.apache.camel.Expression)15 Test (org.junit.Test)13 Exchange (org.apache.camel.Exchange)6 CamelContext (org.apache.camel.CamelContext)5 Predicate (org.apache.camel.Predicate)5 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)4 SqlTest (org.apache.camel.builder.sql.SqlTest)4 DefaultExchange (org.apache.camel.impl.DefaultExchange)4 File (java.io.File)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 IOException (java.io.IOException)2 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 LanguageResolver (org.apache.camel.spi.LanguageResolver)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1