Search in sources :

Example 6 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class JcrConverterTest method init.

@Before
public void init() throws Exception {
    converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(), new ReflectionInjector(), new DefaultFactoryFinderResolver().resolveDefaultFactoryFinder(new DefaultClassResolver()));
    ServiceHelper.startService(converter);
}
Also used : DefaultTypeConverter(org.apache.camel.impl.converter.DefaultTypeConverter) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) ReflectionInjector(org.apache.camel.util.ReflectionInjector) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver) DefaultFactoryFinderResolver(org.apache.camel.impl.DefaultFactoryFinderResolver) Before(org.junit.Before)

Example 7 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver 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;
}
Also used : DefaultTypeConverter(org.apache.camel.impl.converter.DefaultTypeConverter) Set(java.util.Set) ArrayList(java.util.ArrayList) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ServiceReference(org.osgi.framework.ServiceReference) TypeConverterLoader(org.apache.camel.spi.TypeConverterLoader) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 8 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class ModelSanityCheckerTest method discoverJaxbClasses.

private Set<Class<?>> discoverJaxbClasses() {
    PackageScanClassResolver resolver = new DefaultPackageScanClassResolver();
    String[] packages = Constants.JAXB_CONTEXT_PACKAGES.split(":");
    return resolver.findAnnotated(XmlAccessorType.class, packages);
}
Also used : PackageScanClassResolver(org.apache.camel.spi.PackageScanClassResolver) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver)

Aggregations

DefaultPackageScanClassResolver (org.apache.camel.impl.DefaultPackageScanClassResolver)8 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 DefaultTypeConverter (org.apache.camel.impl.converter.DefaultTypeConverter)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 Client (org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Client)1 Order (org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Order)1 Security (org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Security)1 DefaultClassResolver (org.apache.camel.impl.DefaultClassResolver)1 DefaultFactoryFinderResolver (org.apache.camel.impl.DefaultFactoryFinderResolver)1 PackageScanClassResolver (org.apache.camel.spi.PackageScanClassResolver)1 TypeConverterLoader (org.apache.camel.spi.TypeConverterLoader)1 ReflectionInjector (org.apache.camel.util.ReflectionInjector)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ServiceReference (org.osgi.framework.ServiceReference)1