/** * Binds all classes annotated with ManagedBean in the given package. * * @param packageName - the name of the package to search in */ private void bindAllManagedBeans(String packageName) { Iterable<Class<?>> managedBeanClasses = new Reflections(packageName).getTypesAnnotatedWith(ManagedBean.class); for (Class<?> managedBeanClass : managedBeanClasses) { bind(managedBeanClass).to(managedBeanClass); } }
private SessionType getSessionType(final Class<?> clazz) { if (clazz.isAnnotationPresent(Stateful.class)) { return SessionType.STATEFUL; } if (clazz.isAnnotationPresent(Stateless.class)) { return SessionType.STATELESS; } if (clazz.isAnnotationPresent(Singleton.class)) { return SessionType.SINGLETON; } if (clazz.isAnnotationPresent(ManagedBean.class)) { return SessionType.MANAGED; } return null; }
private boolean isIgnoredReferenceType(final String typeName, final ClassLoader loader) { if (ignoredReferenceTypes.contains(typeName)) { return true; } else if (loader != null) { try { final Class<?> type = loader.loadClass(typeName); return type.isAnnotationPresent(ManagedBean.class); } catch (final ClassNotFoundException e) { // ignore } } return false; }
public void updateContext(Collection<Class> classes) { if (beanFactory != null) { boolean needToRefreshRemotingContext = false; for (Class clazz : classes) { Service serviceAnnotation = (Service) clazz.getAnnotation(Service.class); ManagedBean managedBeanAnnotation = (ManagedBean) clazz.getAnnotation(ManagedBean.class); Component componentAnnotation = (Component) clazz.getAnnotation(Component.class); Controller controllerAnnotation = (Controller) clazz.getAnnotation(Controller.class); String beanName = null; if (serviceAnnotation != null) { beanName = serviceAnnotation.value(); } else if (managedBeanAnnotation != null) { beanName = managedBeanAnnotation.value(); } else if (componentAnnotation != null) { beanName = componentAnnotation.value(); } else if (controllerAnnotation != null) { beanName = controllerAnnotation.value(); } if (StringUtils.isNotBlank(beanName)) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(clazz); Scope scope = (Scope) clazz.getAnnotation(Scope.class); if (scope != null) { beanDefinition.setScope(scope.value()); } beanFactory.registerBeanDefinition(beanName, beanDefinition); } if (StringUtils.isNotBlank(beanName)) { needToRefreshRemotingContext = true; } } if (needToRefreshRemotingContext) { ApplicationContext remotingContext = RemotingContextHolder.getRemotingApplicationContext(); if (remotingContext != null && remotingContext instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) remotingContext).refresh(); } } } }
private String getEjbName(final ManagedBean managed, final Class<?> beanClass) { return managed.value().isEmpty() ? beanClass.getSimpleName() : managed.value(); }
private static boolean isEJB(final Class<?> clazz) { return clazz.isAnnotationPresent(Stateless.class) || clazz.isAnnotationPresent(Singleton.class) || clazz.isAnnotationPresent(ManagedBean.class) // what a weird idea! || clazz.isAnnotationPresent(Stateful.class); // what another weird idea! }