public StatsInterceptor(final Class<?> componentClass) { monitor = componentClass.getAnnotation(Monitor.class); final ClassFinder finder = new ClassFinder(componentClass); for (final Method method : finder.findAnnotatedMethods(Monitor.class)) { map.put(method, new Stats(method, monitor)); } enabled = monitor != null || map.size() > 0; }
@SuppressWarnings("unchecked") private void collectMatchingClasses(ClassFinder finder, Class annotation, LinkedHashSet<Class<?>> collector) { List<Class<?>> annotated = finder.findAnnotatedClasses(annotation); for (Class<?> clazz : annotated) { if( packages.isEmpty() ) { collector.add(clazz); } else { if( packages.contains(clazz.getPackage().getName()) ) { collector.add(clazz); } } } }
private void scan(Object managed, String prefix) { ClassFinder finder = new ClassFinder(managed.getClass()); List<Field> fields = finder.findAnnotatedFields(Managed.class); for (Field field : fields) { scan(new FieldMember(field, managed, prefix)); } List<Method> methods = finder.findAnnotatedMethods(Managed.class); for (Method method : methods) { scan(new MethodMember(method, managed, prefix)); } }
public ClassFinder(ClassLoader classLoader, Collection<URL> urls) { this.classLoader = classLoader; List<String> classNames = new ArrayList<String>(); for (URL location : urls) { try { if (location.getProtocol().equals("jar")) { classNames.addAll(jar(location)); } else if (location.getProtocol().equals("file")) { try { // See if it's actually a jar URL jarUrl = new URL("jar", "", location.toExternalForm() + "!/"); JarURLConnection juc = (JarURLConnection) jarUrl.openConnection(); juc.getJarFile(); classNames.addAll(jar(jarUrl)); } catch (IOException e) { classNames.addAll(file(location)); } } } catch (Exception e) { e.printStackTrace(); } } for (String className : classNames) { readClassDef(className); } }
protected ClassFinder createOpenWebBeansClassFinder(WebApp webApp, WebModule webModule) throws DeploymentException { List<Class<?>> classes = getManagedClasses(webApp, webModule); return new ClassFinder(classes); }
for (URL url : urlList) { try { ClassFinder classFinder = new ClassFinder(tempClassLoader, Collections.singletonList(url)); classes.addAll(classFinder.findAnnotatedClasses(WebService.class)); classes.addAll(classFinder.findAnnotatedClasses(WebServiceProvider.class)); } catch (Exception e) { logger.warn("Fail to search Web Service in jar [" + url + "]", e);
throw new OpenEJBException("Unable to load bean class: " + bean.getEjbClass(), e); ClassFinder classFinder = new ClassFinder(clazz); scheduleMethods.addAll(inheritedClassFinder.findAnnotatedMethods(javax.ejb.Schedules.class)); scheduleMethods.addAll(inheritedClassFinder.findAnnotatedMethods(javax.ejb.Schedule.class)); for (Class<?> interceptorsAnnotatedClass : inheritedClassFinder.findAnnotatedClasses(Interceptors.class)) { Interceptors interceptors = interceptorsAnnotatedClass.getAnnotation(Interceptors.class); EjbJar ejbJar = ejbModule.getEjbJar(); for (Method method : inheritedClassFinder.findAnnotatedMethods(Interceptors.class)) { Interceptors interceptors = method.getAnnotation(Interceptors.class); if (interceptors != null) { for (Method method : classFinder.findAnnotatedMethods(ExcludeDefaultInterceptors.class)) { InterceptorBinding binding = assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(bean)); binding.setExcludeDefaultInterceptors(true); for (Method method : classFinder.findAnnotatedMethods(ExcludeClassInterceptors.class)) { InterceptorBinding binding = assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(bean)); binding.setExcludeClassInterceptors(true);
protected final void processFieldInjections() { Object home = null; ClassFinder finder = null; List<Field> fieldList = null; finder = new ClassFinder(getClassPath()); fieldList = finder.findAnnotatedFields(EJB.class); for(Iterator fields = fieldList.iterator(); fields.hasNext();) { Field field = (Field) fields.next(); EJB ejbAnnotation = field.getAnnotation(EJB.class); if( (ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) { try { home = initialContext.lookup(ejbAnnotation.name()); // home = ejbAnnotation.beanInterface().cast(PortableRemoteObject.narrow(home, ejbAnnotation.beanInterface())); home = cast(home, ejbAnnotation.beanInterface()); field.setAccessible(true); field.set(this, home); } catch(Exception ex) { // TODO - MNour : Needs better exception handling ex.printStackTrace(); } } } }
finder = new ClassFinder(ejbModule.getClassLoader(), url); } catch (MalformedURLException e) { startupLogger.warning("startup.scrapeFailedForModule", ejbModule.getJarLocation()); finder = new ClassFinder(ejbModule.getClassLoader()); } catch (Exception e) { startupLogger.warning("Unable to scrape for @Stateful, @Stateless, @Singleton or @MessageDriven annotations. ClassFinder failed.", e); for (Class<?> beanClass : finder.findAnnotatedClasses(Singleton.class)) { Singleton singleton = beanClass.getAnnotation(Singleton.class); String ejbName = getEjbName(singleton, beanClass); for (Class<?> beanClass : finder.findAnnotatedClasses(Stateless.class)) { Stateless stateless = beanClass.getAnnotation(Stateless.class); String ejbName = getEjbName(stateless, beanClass); for (Class<?> beanClass : finder.findAnnotatedClasses(Stateful.class)) { Stateful stateful = beanClass.getAnnotation(Stateful.class); String ejbName = getEjbName(stateful, beanClass); for (Class<?> beanClass : finder.findAnnotatedClasses(ManagedBean.class)) { ManagedBean managed = beanClass.getAnnotation(ManagedBean.class); String ejbName = getEjbName(managed, beanClass); List<Class> classes = finder.findAnnotatedClasses(MessageDriven.class); for (Class<?> beanClass : classes) { MessageDriven mdb = beanClass.getAnnotation(MessageDriven.class); appExceptions = finder.findInheritedAnnotatedClasses(ApplicationException.class);
for (Class<?> clazz : classFinder.findAnnotatedClasses(EJBs.class)) { EJBs ejbs = clazz.getAnnotation(EJBs.class); ejbList.addAll(asList(ejbs.value())); for (Class<?> clazz : classFinder.findAnnotatedClasses(EJB.class)) { EJB e = clazz.getAnnotation(EJB.class); ejbList.add(e); for (Field field : classFinder.findAnnotatedFields(EJB.class)) { EJB ejb = field.getAnnotation(EJB.class); for (Method method : classFinder.findAnnotatedMethods(EJB.class)) { EJB ejb = method.getAnnotation(EJB.class); for (Class<?> clazz : classFinder.findAnnotatedClasses(Resources.class)) { Resources resources = clazz.getAnnotation(Resources.class); resourceList.addAll(asList(resources.value())); for (Class<?> clazz : classFinder.findAnnotatedClasses(Resource.class)) { Resource resource = clazz.getAnnotation(Resource.class); resourceList.add(resource); for (Field field : classFinder.findAnnotatedFields(Resource.class)) { Resource resource = field.getAnnotation(Resource.class); for (Method method : classFinder.findAnnotatedMethods(Resource.class)) { Resource resource = method.getAnnotation(Resource.class); for (Class<?> clazz : classFinder.findAnnotatedClasses(WebServiceRefs.class)) {
private Map<Object, List<Method>> findAnnotatedMethods(final Map<Object, List<Method>> map, final Class<? extends Annotation> annotation) { for (final Map.Entry<Object, ClassFinder> finder : testClassFinders.entrySet()) { final Object key = finder.getKey(); final List<Method> newAnnotatedMethods = finder.getValue().findAnnotatedMethods(annotation); List<Method> annotatedMethods = map.get(key); if (annotatedMethods == null) { annotatedMethods = newAnnotatedMethods; map.put(key, annotatedMethods); } else { annotatedMethods.addAll(newAnnotatedMethods); } } return map; }
private <A extends Annotation> void checkAttributes(AnnotationHandler<A> handler, String ejbName, EjbModule ejbModule, ClassFinder classFinder, String messageKey) { Map<String, List<MethodAttribute>> existingDeclarations = handler.getExistingDeclarations(); int xml = 0; for (List<MethodAttribute> methodAttributes : existingDeclarations.values()) { xml += methodAttributes.size(); } if (xml > 0) { ejbModule.getValidation().warn(ejbName, "xml." + messageKey, xml); } int ann = classFinder.findAnnotatedClasses(handler.getAnnotationClass()).size(); ann += classFinder.findAnnotatedMethods(handler.getAnnotationClass()).size(); if (ann > 0) { ejbModule.getValidation().warn(ejbName, "ann." + messageKey, ann); } }
for (final Field field : finder.getValue().findAnnotatedFields(RandomPort.class)) { if (!field.isAccessible()) { field.setAccessible(true); if (!finder.getValue().findAnnotatedClasses(SimpleLog.class).isEmpty()) { SystemInstance.get().setProperty("openejb.jul.forceReload", "true"); break;
public static void addWebServiceContextInjections(Holder holder, ClassFinder finder) { List<Field> fields = finder.findAnnotatedFields(Resource.class); for (Field field : fields) { Resource resource = field.getAnnotation(Resource.class); Class type = getInjectionType(resource.type(), null, field); if (WebServiceContext.class == type) { holder.addInjection(field.getDeclaringClass().getName(), new Injection(field.getDeclaringClass().getName(), getInjectionName(null, field), BINDING_WEBSERVICE_CONTEXR_JNDI_NAME, ReferenceType.RESOURCE_ENV)); } } List<Method> methods = finder.findAnnotatedMethods(Resource.class); for (Method method : methods) { Resource resource = method.getAnnotation(Resource.class); Class type = getInjectionType(resource.type(), method, null); if (WebServiceContext.class == type) { holder.addInjection(method.getDeclaringClass().getName(), new Injection(method.getDeclaringClass().getName(), getInjectionName(method, null), BINDING_WEBSERVICE_CONTEXR_JNDI_NAME, ReferenceType.RESOURCE_ENV)); } } }
for (final Field field : finder.findAnnotatedFields(RandomPort.class)) { final Class<?> type = field.getType(); if (int.class != type && URL.class != type) {
/** * Creates a ClassFinder that will search the urls in the specified classloader. * * @param classLoader source of classes to scan * @param excludeParent Allegedly excludes classes from parent classloader, whatever that might mean * @throws Exception if something goes wrong. */ public ClassFinder(ClassLoader classLoader, boolean excludeParent) throws Exception { this(classLoader, getUrls(classLoader, excludeParent)); }
public static void addWebServiceContextInjections(Holder holder, Class<?> clazz) { List<Class<?>> classes = new ArrayList<Class<?>>(); while (clazz != Object.class) { classes.add(clazz); clazz = clazz.getSuperclass(); } addWebServiceContextInjections(holder, new ClassFinder(classes)); }
URL[] urls = DeploymentLoader.getWebappUrls(file); final ClassLoader webClassLoader = webModule.getClassLoader(); finder = new ClassFinder(webClassLoader, asList(urls)); ClassFinder finder2 = new ClassFinder(webClassLoader); webModule.setFinder(finder); } catch (Exception e) { classes.addAll(finder.findAnnotatedClasses(WebService.class)); classes.addAll(finder.findAnnotatedClasses(WebServiceProvider.class));
protected final void processFieldInjections() { Object home = null; ClassFinder finder = null; List<Field> fieldList = null; finder = new ClassFinder(getClassPath()); fieldList = finder.findAnnotatedFields(EJB.class); for(final Iterator fields = fieldList.iterator(); fields.hasNext();) { final Field field = (Field) fields.next(); final EJB ejbAnnotation = field.getAnnotation(EJB.class); if( (ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) { try { home = initialContext.lookup(ejbAnnotation.name()); // home = ejbAnnotation.beanInterface().cast(PortableRemoteObject.narrow(home, ejbAnnotation.beanInterface())); home = cast(home, ejbAnnotation.beanInterface()); field.setAccessible(true); field.set(this, home); } catch(final Exception ex) { // TODO - MNour : Needs better exception handling ex.printStackTrace(); } } } }
private static void add(final ClassFinder finder, final Set<Method> methods, final Class<? extends Annotation> annotation) { final List<Method> annotatedMethods = finder.findAnnotatedMethods(annotation); for (final Method method : annotatedMethods) { SetAccessible.on(method); methods.add(method); } }