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