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());
}
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);
}
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;
}
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());
}
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);
}
}
Aggregations