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());
}
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());
}
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;
}
Aggregations