use of org.apache.camel.language.simple.SimpleLanguage in project camel by apache.
the class CamelMockBundleContext method getService.
public Object getService(@SuppressWarnings("rawtypes") ServiceReference reference) {
String[] classNames = (String[]) reference.getProperty(Constants.OBJECTCLASS);
String classNames0 = classNames != null ? classNames[0] : null;
String pid = (String) reference.getProperty(Constants.SERVICE_PID);
if (classNames0 != null && classNames0.equals("org.apache.camel.core.osgi.test.MyService")) {
return new MyService();
} else if (pid != null && pid.equals(SERVICE_PID_PREFIX + "org.apache.camel.core.osgi.test.MyService")) {
return new MyService();
} else if (classNames0 != null && classNames0.equals(ComponentResolver.class.getName())) {
return new ComponentResolver() {
public Component resolveComponent(String name, CamelContext context) throws Exception {
if (name.equals("file_test")) {
return new FileComponent();
}
return null;
}
};
} else if (classNames0 != null && classNames0.equals(LanguageResolver.class.getName())) {
return new LanguageResolver() {
public Language resolveLanguage(String name, CamelContext context) {
if (name.equals("simple")) {
return new SimpleLanguage();
}
return null;
}
};
} else {
return null;
}
}
use of org.apache.camel.language.simple.SimpleLanguage in project camel by apache.
the class SimpleBuilder method createPredicate.
private Predicate createPredicate(Exchange exchange) {
SimpleLanguage simple = (SimpleLanguage) exchange.getContext().resolveLanguage("simple");
try {
// resolve property placeholders
String resolve = exchange.getContext().resolvePropertyPlaceholders(text);
// and optional it be refer to an external script on the file/classpath
resolve = ResourceHelper.resolveOptionalExternalScript(exchange.getContext(), resolve);
return simple.createPredicate(resolve);
} catch (Exception e) {
throw ObjectHelper.wrapCamelExecutionException(exchange, e);
}
}
use of org.apache.camel.language.simple.SimpleLanguage in project camel by apache.
the class JndiRegistryTest method testLookupByType.
public void testLookupByType() throws Exception {
JndiRegistry jndi = new JndiRegistry(JndiTest.createInitialContext());
jndi.bind("foo", new SimpleLanguage());
jndi.bind("bar", "Hello bar");
assertEquals("Hello bar", jndi.lookup("bar"));
assertEquals("Hello bar", jndi.lookupByName("bar"));
assertEquals("Hello bar", jndi.lookupByNameAndType("bar", String.class));
assertNull(jndi.lookup("unknown"));
assertNull(jndi.lookupByName("unknown"));
try {
assertNull(jndi.lookupByNameAndType("bar", Language.class));
fail("Should throw exception");
} catch (NoSuchBeanException e) {
// expected
}
assertNotNull(jndi.lookupByNameAndType("foo", Language.class));
assertNotNull(jndi.lookupByNameAndType("foo", SimpleLanguage.class));
assertSame(jndi.lookupByNameAndType("foo", Language.class), jndi.lookupByNameAndType("foo", SimpleLanguage.class));
Map<String, ?> set = jndi.lookupByType(Language.class);
assertNotNull(set);
assertEquals(1, set.size());
String key = set.keySet().iterator().next();
assertEquals("foo", key);
assertSame(jndi.lookupByName("foo"), set.values().iterator().next());
}
use of org.apache.camel.language.simple.SimpleLanguage in project camel by apache.
the class SimpleLanguageAutoConfiguration method configureSimpleLanguage.
@Bean(name = "simple-language")
@Scope("prototype")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SimpleLanguage.class)
public SimpleLanguage configureSimpleLanguage(CamelContext camelContext, SimpleLanguageConfiguration configuration) throws Exception {
SimpleLanguage language = new SimpleLanguage();
if (CamelContextAware.class.isAssignableFrom(SimpleLanguage.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(language);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), language, parameters);
return language;
}
use of org.apache.camel.language.simple.SimpleLanguage in project camel by apache.
the class SimpleBuilder method createExpression.
private Expression createExpression(Exchange exchange) {
SimpleLanguage simple = (SimpleLanguage) exchange.getContext().resolveLanguage("simple");
try {
// resolve property placeholders
String resolve = exchange.getContext().resolvePropertyPlaceholders(text);
// and optional it be refer to an external script on the file/classpath
resolve = ResourceHelper.resolveOptionalExternalScript(exchange.getContext(), resolve);
return simple.createExpression(resolve, resultType);
} catch (Exception e) {
throw ObjectHelper.wrapCamelExecutionException(exchange, e);
}
}
Aggregations