Search in sources :

Example 1 with AnnotationFinder

use of org.apache.xbean.finder.AnnotationFinder in project tomee by apache.

the class AnnotationDeployerTest method testSortMethods.

@Test
public void testSortMethods() throws Exception {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link();
    final List<Annotated<Method>> classes = finder.findMetaAnnotatedMethods(Resource.class);
    assertTrue(classes.size() >= 3);
    final List<Annotated<Method>> sorted = AnnotationDeployer.sortMethods(classes);
    assertTrue(sorted.size() >= 3);
    assertEquals(Emerald.class, sorted.get(0).get().getDeclaringClass());
    assertEquals(Green.class, sorted.get(1).get().getDeclaringClass());
    assertEquals(Color.class, sorted.get(2).get().getDeclaringClass());
}
Also used : Annotated(org.apache.xbean.finder.Annotated) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) Test(org.junit.Test)

Example 2 with AnnotationFinder

use of org.apache.xbean.finder.AnnotationFinder in project tomee by apache.

the class AnnotationDeployerTest method testSortClasses.

@Test
public void testSortClasses() throws Exception {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link();
    final List<Annotated<Class<?>>> classes = finder.findMetaAnnotatedClasses(Resource.class);
    assertTrue(classes.size() >= 3);
    final List<Annotated<Class<?>>> sorted = AnnotationDeployer.sortClasses(classes);
    assertTrue(sorted.size() >= 3);
    assertEquals(Emerald.class, sorted.get(0).get());
    assertEquals(Green.class, sorted.get(1).get());
    assertEquals(Color.class, sorted.get(2).get());
}
Also used : Annotated(org.apache.xbean.finder.Annotated) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) Test(org.junit.Test)

Example 3 with AnnotationFinder

use of org.apache.xbean.finder.AnnotationFinder in project tomee by apache.

the class AnnotationDeployerTest method findRestClasses.

@Test
public void findRestClasses() throws Exception {
    final WebApp webApp = new WebApp();
    webApp.setContextRoot("/");
    webApp.setId("web");
    webApp.setVersion("2.5");
    WebModule webModule = new WebModule(webApp, webApp.getContextRoot(), Thread.currentThread().getContextClassLoader(), "myapp", webApp.getId());
    webModule.setFinder(new AnnotationFinder(new ClassesArchive(RESTClass.class, RESTMethod.class, RESTApp.class)).link());
    final AnnotationDeployer annotationDeployer = new AnnotationDeployer();
    webModule = annotationDeployer.deploy(webModule);
    final Set<String> classes = webModule.getRestClasses();
    final Set<String> applications = webModule.getRestApplications();
    assertEquals(1, classes.size());
    assertTrue(classes.contains(RESTClass.class.getName()));
    // assertTrue(classes.contains(RESTMethod.class.getName()));
    assertEquals(1, applications.size());
    assertEquals(RESTApp.class.getName(), applications.iterator().next());
}
Also used : ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) WebApp(org.apache.openejb.jee.WebApp) Test(org.junit.Test)

Example 4 with AnnotationFinder

use of org.apache.xbean.finder.AnnotationFinder in project tomee by apache.

the class FinderFactory method urlByClass.

public static Map<String, String> urlByClass(final IAnnotationFinder finder) {
    final IAnnotationFinder limitedFinder;
    if (finder instanceof FinderFactory.ModuleLimitedFinder) {
        limitedFinder = ((FinderFactory.ModuleLimitedFinder) finder).getDelegate();
    } else {
        limitedFinder = finder;
    }
    if (limitedFinder instanceof AnnotationFinder) {
        final Archive archive = ((AnnotationFinder) limitedFinder).getArchive();
        if (archive instanceof WebappAggregatedArchive) {
            final Map<URL, List<String>> index = ((WebappAggregatedArchive) archive).getClassesMap();
            final Map<String, String> urlByClasses = new HashMap<String, String>();
            for (final Map.Entry<URL, List<String>> entry : index.entrySet()) {
                final String url = entry.getKey().toExternalForm();
                for (final String current : entry.getValue()) {
                    urlByClasses.put(current, url);
                }
            }
            return urlByClasses;
        }
    }
    return Collections.emptyMap();
}
Also used : ClasspathArchive(org.apache.xbean.finder.archive.ClasspathArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Archive(org.apache.xbean.finder.archive.Archive) IAnnotationFinder(org.apache.xbean.finder.IAnnotationFinder) HashMap(java.util.HashMap) URL(java.net.URL) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) IAnnotationFinder(org.apache.xbean.finder.IAnnotationFinder)

Example 5 with AnnotationFinder

use of org.apache.xbean.finder.AnnotationFinder in project tomee by apache.

the class ApplicationComposerDeployer method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    if (!appModule.isStandaloneModule()) {
        return appModule;
    }
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        if (ejbModule.getFinder() == null) {
            continue;
        }
        WebModule webModule = null;
        for (final WebModule web : appModule.getWebModules()) {
            if (!web.getModuleId().equals(ejbModule.getModuleId())) {
                continue;
            }
            webModule = web;
            break;
        }
        if (webModule == null) {
            continue;
        }
        for (final Class<?> clazz : ejbModule.getFinder().findAnnotatedClasses(ApplicationComposer.class)) {
            final ApplicationComposer applicationComposer = clazz.getAnnotation(ApplicationComposer.class);
            final Descriptor descriptor = clazz.getAnnotation(Descriptor.class);
            if (descriptor != null) {
                configureDescriptor(appModule, descriptor);
            }
            final Descriptors descriptors = clazz.getAnnotation(Descriptors.class);
            if (descriptors != null) {
                for (final Descriptor d : descriptors.value()) {
                    configureDescriptor(appModule, descriptor);
                }
            }
            final Classes classes = clazz.getAnnotation(Classes.class);
            if (classes != null) {
                configureClasses(webModule, ejbModule, applicationComposer, classes);
            }
            Object instance = null;
            final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(org.apache.openejb.util.Classes.ancestors(clazz)));
            for (final Method m : finder.findAnnotatedMethods(org.apache.openejb.testing.Module.class)) {
                instance = configureModule(appModule, ejbModule, clazz, instance, m);
            }
            for (final Method m : finder.findAnnotatedMethods(Configuration.class)) {
                instance = configureConfiguration(appModule, clazz, instance, m);
            }
            final JaxrsProviders jaxrsProviders = clazz.getAnnotation(JaxrsProviders.class);
            if (jaxrsProviders != null) {
                for (final Class<?> c : jaxrsProviders.value()) {
                    webModule.getJaxrsProviders().add(c.getName());
                }
            }
        }
    }
    return appModule;
}
Also used : Method(java.lang.reflect.Method) JaxrsProviders(org.apache.openejb.testing.JaxrsProviders) ApplicationComposer(org.apache.openejb.api.configuration.ApplicationComposer) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Descriptor(org.apache.openejb.testing.Descriptor) Descriptors(org.apache.openejb.testing.Descriptors) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) Classes(org.apache.openejb.testing.Classes)

Aggregations

AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)18 ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)13 URL (java.net.URL)6 AppModule (org.apache.openejb.config.AppModule)6 EjbModule (org.apache.openejb.config.EjbModule)6 EjbJar (org.apache.openejb.jee.EjbJar)6 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 IAnnotationFinder (org.apache.xbean.finder.IAnnotationFinder)4 Archive (org.apache.xbean.finder.archive.Archive)4 FileArchive (org.apache.xbean.finder.archive.FileArchive)4 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 MalformedURLException (java.net.MalformedURLException)2 Iterator (java.util.Iterator)2 List (java.util.List)2