Search in sources :

Example 1 with LanguageResolver

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

the class Activator method updateAvailableScriptLanguages.

private void updateAvailableScriptLanguages() {
    ServiceReference<LanguageResolver> ref = null;
    try {
        Collection<ServiceReference<LanguageResolver>> references = context.getServiceReferences(LanguageResolver.class, "(resolver=default)");
        if (references.size() == 1) {
            // Unregistry the old language resolver first
            if (registration != null) {
                registration.unregister();
                registration = null;
            }
            ref = references.iterator().next();
            LanguageResolver resolver = context.getService(ref);
            Dictionary props = new Hashtable();
            // Just publish the language resolve with the language we found
            props.put("language", getAvailableScriptNames());
            registration = context.registerService(LanguageResolver.class, resolver, props);
        }
    } catch (InvalidSyntaxException e) {
        LOG.error("Invalid syntax for LanguageResolver service reference filter.");
    } finally {
        if (ref != null) {
            context.ungetService(ref);
        }
    }
}
Also used : Dictionary(java.util.Dictionary) LanguageResolver(org.apache.camel.spi.LanguageResolver) Hashtable(java.util.Hashtable) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with LanguageResolver

use of org.apache.camel.spi.LanguageResolver 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 3 with LanguageResolver

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

the class OsgiLanguageResolver method resolveLanguage.

public Language resolveLanguage(String name, CamelContext context) {
    // lookup in registry first
    Language lang = ResolverHelper.lookupLanguageInRegistryWithFallback(context, name);
    if (lang != null) {
        return lang;
    }
    lang = getLanguage(name, context);
    if (lang != null) {
        return lang;
    }
    LanguageResolver resolver = getLanguageResolver("default", context);
    if (resolver != null) {
        return resolver.resolveLanguage(name, context);
    }
    throw new NoSuchLanguageException(name);
}
Also used : LanguageResolver(org.apache.camel.spi.LanguageResolver) Language(org.apache.camel.spi.Language) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Aggregations

LanguageResolver (org.apache.camel.spi.LanguageResolver)3 Language (org.apache.camel.spi.Language)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 CamelContext (org.apache.camel.CamelContext)1 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)1 FileComponent (org.apache.camel.component.file.FileComponent)1 MyService (org.apache.camel.core.osgi.test.MyService)1 SimpleLanguage (org.apache.camel.language.simple.SimpleLanguage)1 ComponentResolver (org.apache.camel.spi.ComponentResolver)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1