use of org.apache.camel.spi.TypeConverterLoader in project camel by apache.
the class OsgiTypeConverter method createRegistry.
protected DefaultTypeConverter createRegistry() {
// base the osgi type converter on the default type converter
DefaultTypeConverter answer = new DefaultTypeConverter(new DefaultPackageScanClassResolver() {
@Override
public Set<ClassLoader> getClassLoaders() {
// we don't need any classloaders as we use OSGi service tracker instead
return Collections.emptySet();
}
}, injector, factoryFinder);
// inject CamelContext
answer.setCamelContext(camelContext);
try {
// only load the core type converters, as OSGi activator will keep track on bundles
// being installed/uninstalled and load type converters as part of that process
answer.loadCoreTypeConverters();
} catch (Exception e) {
throw new RuntimeCamelException("Error loading CoreTypeConverter due: " + e.getMessage(), e);
}
// Load the type converters the tracker has been tracking
// Here we need to use the ServiceReference to check the ranking
ServiceReference<TypeConverterLoader>[] serviceReferences = this.tracker.getServiceReferences();
if (serviceReferences != null) {
ArrayList<ServiceReference<TypeConverterLoader>> servicesList = new ArrayList<ServiceReference<TypeConverterLoader>>(Arrays.asList(serviceReferences));
// Just make sure we install the high ranking fallback converter at last
Collections.sort(servicesList);
for (ServiceReference<TypeConverterLoader> sr : servicesList) {
try {
LOG.debug("loading type converter from bundle: {}", sr.getBundle().getSymbolicName());
((TypeConverterLoader) this.tracker.getService(sr)).load(answer);
} catch (Throwable t) {
throw new RuntimeCamelException("Error loading type converters from service: " + sr + " due: " + t.getMessage(), t);
}
}
}
LOG.trace("Created TypeConverter: {}", answer);
return answer;
}
use of org.apache.camel.spi.TypeConverterLoader in project camel by apache.
the class OsgiTypeConverter method addingService.
public Object addingService(ServiceReference<TypeConverterLoader> serviceReference) {
LOG.trace("AddingService: {}, Bundle: {}", serviceReference, serviceReference.getBundle());
TypeConverterLoader loader = bundleContext.getService(serviceReference);
try {
LOG.debug("loading type converter from bundle: {}", serviceReference.getBundle().getSymbolicName());
if (delegate != null) {
loader.load(delegate);
}
} catch (Throwable t) {
throw new RuntimeCamelException("Error loading type converters from service: " + serviceReference + " due: " + t.getMessage(), t);
}
return loader;
}
Aggregations