Search in sources :

Example 1 with Annotated

use of org.apache.xbean.finder.Annotated 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 2 with Annotated

use of org.apache.xbean.finder.Annotated 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 3 with Annotated

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

the class AnnotationDeployer method findRestClasses.

public static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder) {
    final Collection<String> classes = new HashSet<>();
    // annotations on classes
    final List<Annotated<Class<?>>> annotatedClasses = finder.findMetaAnnotatedClasses(Path.class);
    for (final Annotated<Class<?>> aClazz : annotatedClasses) {
        final Class<?> clazz = aClazz.get();
        if (isInstantiable(clazz)) {
            if (!isEJB(clazz)) {
                classes.add(clazz.getName());
            } else {
                webModule.getEjbRestServices().add(clazz.getName());
            }
        } else if (clazz.isInterface()) {
            final Class api = clazz;
            final List impl = finder.findImplementations((Class<?>) api);
            if (impl != null && impl.size() == 1) {
                // single impl so that's the service
                final Class implClass = (Class) impl.iterator().next();
                final String name = implClass.getName();
                if (!isEJB(implClass)) {
                    classes.add(name);
                } else {
                    webModule.getEjbRestServices().add(name);
                }
            }
        } else if (isEJB(clazz) && DynamicSubclass.isDynamic(clazz)) {
            classes.add(clazz.getName());
        }
    }
    if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.jaxrs.scanning.methods", "false"))) {
        final List<Annotated<Method>> methods = finder.findMetaAnnotatedMethods(Path.class);
        for (final Annotated<Method> aMethod : methods) {
            final Method method = aMethod.get();
            final Class<?> clazz = method.getDeclaringClass();
            if (isInstantiable(clazz)) {
                if (!isEJB(clazz)) {
                    classes.add(clazz.getName());
                } else {
                    webModule.getEjbRestServices().add(clazz.getName());
                }
            } else if (isEJB(clazz) && DynamicSubclass.isDynamic(clazz)) {
                classes.add(clazz.getName());
            }
        }
    }
    return classes;
}
Also used : Annotated(org.apache.xbean.finder.Annotated) MetaAnnotatedClass(org.apache.xbean.finder.MetaAnnotatedClass) Arrays.asList(java.util.Arrays.asList) ExcludeList(org.apache.openejb.jee.ExcludeList) ArrayList(java.util.ArrayList) List(java.util.List) AsyncMethod(org.apache.openejb.jee.AsyncMethod) NamedMethod(org.apache.openejb.jee.NamedMethod) RemoveMethod(org.apache.openejb.jee.RemoveMethod) Method(java.lang.reflect.Method) ConcurrentMethod(org.apache.openejb.jee.ConcurrentMethod) InitMethod(org.apache.openejb.jee.InitMethod) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Annotated (org.apache.xbean.finder.Annotated)3 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)2 ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 AsyncMethod (org.apache.openejb.jee.AsyncMethod)1 ConcurrentMethod (org.apache.openejb.jee.ConcurrentMethod)1 ExcludeList (org.apache.openejb.jee.ExcludeList)1 InitMethod (org.apache.openejb.jee.InitMethod)1 NamedMethod (org.apache.openejb.jee.NamedMethod)1 RemoveMethod (org.apache.openejb.jee.RemoveMethod)1 MetaAnnotatedClass (org.apache.xbean.finder.MetaAnnotatedClass)1