@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())); assertEquals(1, applications.size()); assertEquals(RESTApp.class.getName(), applications.iterator().next()); }
public static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder) { final Collection<String> classes = new HashSet<>(); 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) { 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; }
AnnotationDeployer implements DynamicDeployer { public static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder) { final Collection<String> classes = new HashSet<>(); 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) { 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; } }
AnnotationDeployer implements DynamicDeployer { public static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder) { final Collection<String> classes = new HashSet<>(); 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) { 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; } AnnotationDeployer(); }
AnnotationDeployer implements DynamicDeployer { public static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder) { final Collection<String> classes = new HashSet<>(); 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) { 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; } AnnotationDeployer(); AppModule deploy(AppModule appModule); void deploy(final CdiBeanInfo beanInfo); WebModule deploy(WebModule webModule); static DeploymentModule getModule(); static boolean isKnownEnvironmentEntryType(final Class type); static boolean isShareableJNDINamespace(final String jndiName); static void autoJpa(final EjbModule ejbModule); static void doAutoJpa(final IAnnotationFinder finder, final org.apache.openejb.jee.jpa.unit.PersistenceUnit pu); static List<Annotated<Class<?>>> sortClasses(final List<Annotated<Class<?>>> list); static List<Class<?>> sortClassesParentFirst(final List<Class<?>> list); static List<Annotated<Method>> sortMethods(final List<Annotated<Method>> list); static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder); static boolean isInstantiable(final Class<?> clazz); static URL classLocation(final Class clazz); EnvEntriesPropertiesDeployer getEnvEntriesPropertiesDeployer(); }
AnnotationDeployer implements DynamicDeployer { public static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder) { final Collection<String> classes = new HashSet<>(); 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) { 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; } AnnotationDeployer(); AppModule deploy(AppModule appModule); void deploy(final CdiBeanInfo beanInfo); WebModule deploy(WebModule webModule); static DeploymentModule getModule(); static boolean isKnownEnvironmentEntryType(final Class type); static boolean isShareableJNDINamespace(final String jndiName); static void autoJpa(final EjbModule ejbModule); static void doAutoJpa(final IAnnotationFinder finder, final org.apache.openejb.jee.jpa.unit.PersistenceUnit pu); static List<Annotated<Class<?>>> sortClasses(final List<Annotated<Class<?>>> list); static List<Class<?>> sortClassesParentFirst(final List<Class<?>> list); static List<Annotated<Method>> sortMethods(final List<Annotated<Method>> list); static Collection<String> findRestClasses(final WebModule webModule, final IAnnotationFinder finder); static boolean isInstantiable(final Class<?> clazz); static URL classLocation(final 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; }