Java 类org.apache.camel.impl.DefaultPackageScanClassResolver 实例源码

项目:Camel    文件:DefaultPackageScanClassResolverTest.java   
public void testFindByFilterPackageInJarUrl() throws Exception {
    ClassLoader savedClassLoader = null;
    try {
        savedClassLoader = Thread.currentThread().getContextClassLoader();
        URL url = getClass().getResource("/package_scan_test.jar");

        URL urls[] = {new URL("jar:" + url.toString() + "!/")};
        URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);

        Thread.currentThread().setContextClassLoader(classLoader);

        // recreate resolver since we mess with context class loader
        resolver = new DefaultPackageScanClassResolver();

        filter.addIncludePattern("a.*.c.*");
        resolver.addFilter(filter);
        Set<Class<?>> scanned = resolver.findByFilter(filter, "a.b.c");
        assertEquals(1, scanned.size());
        assertEquals("class a.b.c.Test", scanned.iterator().next().toString());            
    } finally {
        if (savedClassLoader != null) {
            Thread.currentThread().setContextClassLoader(savedClassLoader);
        } 
    }
}
项目:Camel    文件:DefaultPackageScanClassResolverTest.java   
public void testFindByFilterPackageInJarUrlWithPlusChars() throws Exception {
    ClassLoader savedClassLoader = null;
    try {
        savedClassLoader = Thread.currentThread().getContextClassLoader();
        URL url = getClass().getResource("/package+scan+test.jar");

        URL urls[] = {new URL("jar:" + url.toString() + "!/")};
        URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);

        Thread.currentThread().setContextClassLoader(classLoader);

        // recreate resolver since we mess with context class loader
        resolver = new DefaultPackageScanClassResolver();

        filter.addIncludePattern("a.*.c.*");
        resolver.addFilter(filter);
        Set<Class<?>> scanned = resolver.findByFilter(filter, "a.b.c");
        assertEquals(1, scanned.size());
        assertEquals("class a.b.c.Test", scanned.iterator().next().toString());
    } finally {
        if (savedClassLoader != null) {
            Thread.currentThread().setContextClassLoader(savedClassLoader);
        }
    }
}
项目:Camel    文件:AnnotationModuleLoaderTest.java   
@Test
public void testLoadModels() throws Exception {
    AnnotationModelLoader loader = new AnnotationModelLoader(new DefaultPackageScanClassResolver());
    Set<Class<?>> classes = loader.loadModels("org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink");
    assertNotNull("The findForFormattingOptions classes should not be null ", classes);
    assertEquals("There should have 3 classes", 3, classes.size());
    assertTrue(classes.contains(Client.class));
    assertTrue(classes.contains(Order.class));
    assertTrue(classes.contains(Security.class));
}
项目:Camel    文件:DefaultPackageResolverConfigureTest.java   
public void testSetAcceptableSchema() throws Exception {
    DefaultPackageScanClassResolver resolver = (DefaultPackageScanClassResolver)context.getPackageScanClassResolver();
    assertNotNull(resolver);
    // just check the accept schema
    assertTrue("We should accept the test:!", resolver.isAcceptableScheme("test://test"));
    assertTrue("We should accept the test2:!", resolver.isAcceptableScheme("test2://test"));

}
项目:Camel    文件:ModelSanityCheckerTest.java   
private Set<Class<?>> discoverJaxbClasses() {
    PackageScanClassResolver resolver = new DefaultPackageScanClassResolver();
    String[] packages = Constants.JAXB_CONTEXT_PACKAGES.split(":");
    return resolver.findAnnotated(XmlAccessorType.class, packages);
}
项目:Camel    文件:JcrConverterTest.java   
@Before
public void init() throws Exception {
    converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(),
            new ReflectionInjector(), new DefaultFactoryFinderResolver().resolveDefaultFactoryFinder(new DefaultClassResolver()));
    ServiceHelper.startService(converter);
}
项目:Camel    文件:OsgiTypeConverter.java   
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;
}
项目:Camel    文件:DefaultPackageScanClassResolverTest.java   
public void setUp() throws Exception {
    super.setUp();
    resolver = new DefaultPackageScanClassResolver();
    annotations.add(org.apache.camel.spring.scan.ScannableOne.class);
    annotations.add(org.apache.camel.spring.scan.ScannableTwo.class);
}