AnnotationDeployer implements DynamicDeployer { private static Collection<String> findRestClasses(WebModule webModule, IAnnotationFinder finder) { Collection<String> classes = new HashSet<String>(); List<Annotated<Class<?>>> annotatedClasses = finder.findMetaAnnotatedClasses(Path.class); for (Annotated<Class<?>> aClazz : annotatedClasses) { Class<?> clazz = aClazz.get(); int modifiers = clazz.getModifiers(); if (!Modifier.isAbstract(modifiers)) { if (!isEJB(clazz)) { classes.add(clazz.getName()); } else { webModule.getEjbRestServices().add(clazz.getName()); } } } List<Annotated<Method>> methods = finder.findMetaAnnotatedMethods(Path.class); for (Annotated<Method> aMethod : methods) { Method method = aMethod.get(); Class<?> clazz = method.getDeclaringClass(); int modifiers = clazz.getModifiers(); if (!Modifier.isAbstract(modifiers)) { if (!isEJB(clazz)) { classes.add(clazz.getName()); } else { webModule.getEjbRestServices().add(clazz.getName()); } } } return classes; } AnnotationDeployer(); AppModule deploy(AppModule appModule); void deploy(CdiBeanInfo beanInfo); WebModule deploy(WebModule webModule); static DeploymentModule getModule(); static boolean isKnownEnvironmentEntryType(Class type); static boolean isShareableJNDINamespace(String jndiName); static List<Annotated<Class<?>>> sortClasses(List<Annotated<Class<?>>> list); static List<Class<?>> sortClassesParentFirst(List<Class<?>> list); static List<Annotated<Method>> sortMethods(List<Annotated<Method>> list); static URL classLocation(Class clazz); EnvEntriesPropertiesDeployer getEnvEntriesPropertiesDeployer(); static final Logger logger; static final Logger startupLogger; static final String OPENEJB_JPA_AUTO_SCAN; static final String OPENEJB_JPA_AUTO_SCAN_PACKAGE; static final Set<String> knownResourceEnvTypes; static final Set<String> knownEnvironmentEntries; }
@Test public void findRestClasses() throws Exception { 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()); AnnotationDeployer annotationDeployer = new AnnotationDeployer(); webModule = annotationDeployer.deploy(webModule); Set<String> classes = webModule.getRestClasses(); Set<String> applications = webModule.getRestApplications(); assertEquals(2, 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()); }