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