Search in sources :

Example 1 with SimpleLanguage

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;
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) LanguageResolver(org.apache.camel.spi.LanguageResolver) SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage) Language(org.apache.camel.spi.Language) MyService(org.apache.camel.core.osgi.test.MyService) FileComponent(org.apache.camel.component.file.FileComponent) ComponentResolver(org.apache.camel.spi.ComponentResolver) SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage)

Example 2 with SimpleLanguage

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);
    }
}
Also used : SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage)

Example 3 with SimpleLanguage

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());
}
Also used : SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage) Language(org.apache.camel.spi.Language) NoSuchBeanException(org.apache.camel.NoSuchBeanException) SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage)

Example 4 with SimpleLanguage

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;
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with SimpleLanguage

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);
    }
}
Also used : SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage)

Aggregations

SimpleLanguage (org.apache.camel.language.simple.SimpleLanguage)5 Language (org.apache.camel.spi.Language)2 HashMap (java.util.HashMap)1 CamelContext (org.apache.camel.CamelContext)1 CamelContextAware (org.apache.camel.CamelContextAware)1 NoSuchBeanException (org.apache.camel.NoSuchBeanException)1 FileComponent (org.apache.camel.component.file.FileComponent)1 MyService (org.apache.camel.core.osgi.test.MyService)1 ComponentResolver (org.apache.camel.spi.ComponentResolver)1 LanguageResolver (org.apache.camel.spi.LanguageResolver)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Scope (org.springframework.context.annotation.Scope)1