@SuppressWarnings({ "rawtypes", "unchecked" }) private static void doDefineNewManagedBean(BeanManagerImpl beanManager, String bdaId, Class<?> beanClass) { try { ClassTransformer classTransformer = getClassTransformer(); SlimAnnotatedType<?> annotatedType = classTransformer.getBackedAnnotatedType(beanClass, bdaId); boolean managedBeanOrDecorator = Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType); if (managedBeanOrDecorator) { EnhancedAnnotatedType eat = EnhancedAnnotatedTypeImpl.of(annotatedType, classTransformer); BeanAttributes attributes = BeanAttributesFactory.forBean(eat, beanManager); ManagedBean<?> bean = ManagedBean.of(attributes, eat, beanManager); ReflectionHelper.set(beanManager, beanManager.getClass(), "beanSet", Collections.synchronizedSet(new HashSet<Bean<?>>())); beanManager.addBean(bean); beanManager.getBeanResolver().clear(); bean.initializeAfterBeanDiscovery(); LOGGER.debug("Bean defined '{}'", beanClass.getName()); } else { // TODO : define session bean LOGGER.warning("Bean NOT? defined '{}', session bean?", beanClass.getName()); } } catch (Exception e) { LOGGER.debug("Bean definition failed.", e); } }
/** * Optimization which modifies CopyOnWrite structures only once instead of once for every bean. * @param beans */ public void addBeans(Collection<? extends Bean<?>> beans) { List<Bean<?>> beanList = new ArrayList<Bean<?>>(beans.size()); List<Bean<?>> transitiveBeans = new ArrayList<Bean<?>>(beans.size()); for (Bean<?> bean : beans) { addBean(bean, beanList, transitiveBeans); } // optimize so that we do not modify CopyOnWriteLists for each Bean this.enabledBeans.addAll(beanList); this.sharedBeans.addAll(transitiveBeans); for (BeanManagerImpl childActivity : childActivities) { childActivity.addBeans(beanList); } }
public void addBean(Bean<?> bean) { addBean(bean, enabledBeans, sharedBeans); }
public void addBean(Bean<?> bean) { addBean(bean, enabledBeans, sharedBeans); }
public void addBean(Bean<?> bean) { addBean(bean, enabledBeans, sharedBeans); }
public void addBean(Bean<?> bean) { addBean(bean, enabledBeans, sharedBeans); }
public void addBean(Bean<?> bean) { addBean(bean, enabledBeans, sharedBeans); }
public void addBean(Bean<?> bean) { addBean(bean, enabledBeans, sharedBeans); }
/** * Optimization which modifies CopyOnWrite structures only once instead of once for every bean. * * @param beans */ public void addBeans(Collection<? extends Bean<?>> beans) { List<Bean<?>> beanList = new ArrayList<Bean<?>>(beans.size()); List<Bean<?>> transitiveBeans = new ArrayList<Bean<?>>(beans.size()); for (Bean<?> bean : beans) { addBean(bean, beanList, transitiveBeans); } // optimize so that we do not modify CopyOnWriteLists for each Bean this.enabledBeans.addAll(beanList); this.sharedBeans.addAll(transitiveBeans); }
/** * Optimization which modifies CopyOnWrite structures only once instead of once for every bean. * * @param beans */ public void addBeans(Collection<? extends Bean<?>> beans) { List<Bean<?>> beanList = new ArrayList<Bean<?>>(beans.size()); List<Bean<?>> transitiveBeans = new ArrayList<Bean<?>>(beans.size()); for (Bean<?> bean : beans) { addBean(bean, beanList, transitiveBeans); } // optimize so that we do not modify CopyOnWriteLists for each Bean this.enabledBeans.addAll(beanList); this.sharedBeans.addAll(transitiveBeans); }
/** * Optimization which modifies CopyOnWrite structures only once instead of once for every bean. * * @param beans */ public void addBeans(Collection<? extends Bean<?>> beans) { List<Bean<?>> beanList = new ArrayList<Bean<?>>(beans.size()); List<Bean<?>> transitiveBeans = new ArrayList<Bean<?>>(beans.size()); for (Bean<?> bean : beans) { addBean(bean, beanList, transitiveBeans); } // optimize so that we do not modify CopyOnWriteLists for each Bean this.enabledBeans.addAll(beanList); this.sharedBeans.addAll(transitiveBeans); }
/** * Optimization which modifies CopyOnWrite structures only once instead of once for every bean. * * @param beans */ public void addBeans(Collection<? extends Bean<?>> beans) { List<Bean<?>> beanList = new ArrayList<Bean<?>>(beans.size()); List<Bean<?>> transitiveBeans = new ArrayList<Bean<?>>(beans.size()); for (Bean<?> bean : beans) { addBean(bean, beanList, transitiveBeans); } // optimize so that we do not modify CopyOnWriteLists for each Bean this.enabledBeans.addAll(beanList); this.sharedBeans.addAll(transitiveBeans); }
/** * Optimization which modifies CopyOnWrite structures only once instead of once for every bean. * * @param beans */ public void addBeans(Collection<? extends Bean<?>> beans) { List<Bean<?>> beanList = new ArrayList<Bean<?>>(beans.size()); List<Bean<?>> transitiveBeans = new ArrayList<Bean<?>>(beans.size()); for (Bean<?> bean : beans) { addBean(bean, beanList, transitiveBeans); } // optimize so that we do not modify CopyOnWriteLists for each Bean this.enabledBeans.addAll(beanList); this.sharedBeans.addAll(transitiveBeans); }
protected <T> void processBean(Bean<T> bean) { BeanManagerImpl beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager(); if (bean instanceof Interceptor<?>) { beanManager.addInterceptor((Interceptor<?>) bean); } else if (bean instanceof Decorator<?>) { beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) bean, beanManager)); } else { beanManager.addBean(bean); } containerLifecycleEvents.fireProcessBean(beanManager, bean); }
private <E extends Extension> void deployBean(Metadata<E> extension, ClassTransformer classTransformer) { // Locate the BeanDeployment for this extension BeanDeployment beanDeployment = DeploymentStructures.getOrCreateBeanDeployment(deployment, beanManager, bdaMapping, contexts, extension.getValue() .getClass()); EnhancedAnnotatedType<E> enchancedAnnotatedType = getEnhancedAnnotatedType(classTransformer, extension, beanDeployment); if (enchancedAnnotatedType != null) { ExtensionBean<E> bean = new ExtensionBean<E>(beanDeployment.getBeanManager(), enchancedAnnotatedType, extension); Set<ObserverInitializationContext<?, ?>> observerMethodInitializers = new HashSet<ObserverInitializationContext<?, ?>>(); createObserverMethods(bean, beanDeployment.getBeanManager(), enchancedAnnotatedType, observerMethodInitializers); beanDeployment.getBeanManager().addBean(bean); beanDeployment.getBeanDeployer().addExtension(bean); for (ObserverInitializationContext<?, ?> observerMethodInitializer : observerMethodInitializers) { observerMethodInitializer.initialize(); beanDeployment.getBeanManager().addObserver(observerMethodInitializer.getObserver()); containerLifecycleEventObservers.processObserverMethod(observerMethodInitializer.getObserver()); } BootstrapLogger.LOG.extensionBeanDeployed(bean); } }
protected Collection<ContextHolder<? extends Context>> createContexts(ServiceRegistry services) { List<ContextHolder<? extends Context>> contexts = new ArrayList<ContextHolder<? extends Context>>(); BeanIdentifierIndex beanIdentifierIndex = services.get(BeanIdentifierIndex.class); /* * Register a full set of bound and unbound contexts. Although we may not use all of * these (e.g. if we are running in a servlet environment) they may be * useful for an application. */ Set<Annotation> boundQualifires = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(BoundLiteral.INSTANCE).build(); Set<Annotation> unboundQualifiers = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(UnboundLiteral.INSTANCE).build(); contexts.add(new ContextHolder<ApplicationContext>(new ApplicationContextImpl(contextId), ApplicationContext.class, unboundQualifiers)); contexts.add(new ContextHolder<SingletonContext>(new SingletonContextImpl(contextId), SingletonContext.class, unboundQualifiers)); contexts.add(new ContextHolder<BoundSessionContext>(new BoundSessionContextImpl(contextId, beanIdentifierIndex), BoundSessionContext.class, boundQualifires)); contexts.add(new ContextHolder<BoundConversationContext>(new BoundConversationContextImpl(contextId, services), BoundConversationContext.class, boundQualifires)); contexts.add(new ContextHolder<BoundRequestContext>(new BoundRequestContextImpl(contextId), BoundRequestContext.class, boundQualifires)); contexts.add(new ContextHolder<RequestContext>(new RequestContextImpl(contextId), RequestContext.class, unboundQualifiers)); contexts.add(new ContextHolder<DependentContext>(new DependentContextImpl(services.get(ContextualStore.class)), DependentContext.class, unboundQualifiers)); services.get(WeldModules.class).postContextRegistration(contextId, services, contexts); /* * Register the contexts with the bean manager and add the beans to the * deployment manager so that they are easily accessible (contexts are app * scoped) */ for (ContextHolder<? extends Context> context : contexts) { deploymentManager.addContext(context.getContext()); deploymentManager.addBean(ContextBean.of(context, deploymentManager)); } return contexts; }
private <E extends Extension> void deployBean(Metadata<E> extension, ClassTransformer classTransformer) { // Locate the BeanDeployment for this extension BeanDeployment beanDeployment = DeploymentStructures.getOrCreateBeanDeployment(deployment, beanManager, bdaMapping, contexts, extension.getValue() .getClass()); // Do not register synthetic extension as a bean, only register container lifecycle observer methods if (extension.getValue() instanceof SyntheticExtension) { SyntheticExtension synthetic = (SyntheticExtension) extension.getValue(); synthetic.initialize(beanDeployment.getBeanManager()); for (ObserverMethod<?> observer : synthetic.getObservers()) { beanDeployment.getBeanManager().addObserver(observer); containerLifecycleEventObservers.processObserverMethod(observer); } return; } EnhancedAnnotatedType<E> enchancedAnnotatedType = getEnhancedAnnotatedType(classTransformer, extension, beanDeployment); if (enchancedAnnotatedType != null) { ExtensionBean<E> bean = new ExtensionBean<E>(beanDeployment.getBeanManager(), enchancedAnnotatedType, extension); Set<ObserverInitializationContext<?, ?>> observerMethodInitializers = new HashSet<ObserverInitializationContext<?, ?>>(); createObserverMethods(bean, beanDeployment.getBeanManager(), enchancedAnnotatedType, observerMethodInitializers); beanDeployment.getBeanManager().addBean(bean); beanDeployment.getBeanDeployer().addExtension(bean); for (ObserverInitializationContext<?, ?> observerMethodInitializer : observerMethodInitializers) { observerMethodInitializer.initialize(); beanDeployment.getBeanManager().addObserver(observerMethodInitializer.getObserver()); containerLifecycleEventObservers.processObserverMethod(observerMethodInitializer.getObserver()); } BootstrapLogger.LOG.extensionBeanDeployed(bean); } }
private <E extends Extension> void deployBean(Metadata<E> extension, ClassTransformer classTransformer) { // Locate the BeanDeployment for this extension BeanDeployment beanDeployment = DeploymentStructures.getOrCreateBeanDeployment(deployment, beanManager, bdaMapping, contexts, extension.getValue() .getClass()); // Do not register synthetic extension as a bean, only register container lifecycle observer methods if (extension.getValue() instanceof SyntheticExtension) { SyntheticExtension synthetic = (SyntheticExtension) extension.getValue(); synthetic.initialize(beanDeployment.getBeanManager()); for (ObserverMethod<?> observer : synthetic.getObservers()) { beanDeployment.getBeanManager().addObserver(observer); containerLifecycleEventObservers.processObserverMethod(observer); } return; } EnhancedAnnotatedType<E> enchancedAnnotatedType = getEnhancedAnnotatedType(classTransformer, extension, beanDeployment); if (enchancedAnnotatedType != null) { ExtensionBean<E> bean = new ExtensionBean<E>(beanDeployment.getBeanManager(), enchancedAnnotatedType, extension); Set<ObserverInitializationContext<?, ?>> observerMethodInitializers = new HashSet<ObserverInitializationContext<?, ?>>(); createObserverMethods(bean, beanDeployment.getBeanManager(), enchancedAnnotatedType, observerMethodInitializers); beanDeployment.getBeanManager().addBean(bean); beanDeployment.getBeanDeployer().addExtension(bean); for (ObserverInitializationContext<?, ?> observerMethodInitializer : observerMethodInitializers) { observerMethodInitializer.initialize(); beanDeployment.getBeanManager().addObserver(observerMethodInitializer.getObserver()); containerLifecycleEventObservers.processObserverMethod(observerMethodInitializer.getObserver()); } BootstrapLogger.LOG.extensionBeanDeployed(bean); } }
private <E extends Extension> void deployBean(Metadata<E> extension, ClassTransformer classTransformer) { // Locate the BeanDeployment for this extension BeanDeployment beanDeployment = DeploymentStructures.getOrCreateBeanDeployment(deployment, beanManager, bdaMapping, contexts, extension.getValue() .getClass()); // Do not register synthetic extension as a bean, only register container lifecycle observer methods if (extension.getValue() instanceof SyntheticExtension) { SyntheticExtension synthetic = (SyntheticExtension) extension.getValue(); synthetic.initialize(beanDeployment.getBeanManager()); for (ObserverMethod<?> observer : synthetic.getObservers()) { beanDeployment.getBeanManager().addObserver(observer); containerLifecycleEventObservers.processObserverMethod(observer); } return; } EnhancedAnnotatedType<E> enchancedAnnotatedType = getEnhancedAnnotatedType(classTransformer, extension, beanDeployment); if (enchancedAnnotatedType != null) { ExtensionBean<E> bean = new ExtensionBean<E>(beanDeployment.getBeanManager(), enchancedAnnotatedType, extension); Set<ObserverInitializationContext<?, ?>> observerMethodInitializers = new HashSet<ObserverInitializationContext<?, ?>>(); createObserverMethods(bean, beanDeployment.getBeanManager(), enchancedAnnotatedType, observerMethodInitializers); beanDeployment.getBeanManager().addBean(bean); beanDeployment.getBeanDeployer().addExtension(bean); for (ObserverInitializationContext<?, ?> observerMethodInitializer : observerMethodInitializers) { observerMethodInitializer.initialize(); beanDeployment.getBeanManager().addObserver(observerMethodInitializer.getObserver()); containerLifecycleEventObservers.processObserverMethod(observerMethodInitializer.getObserver()); } BootstrapLogger.LOG.extensionBeanDeployed(bean); } }
private <E extends Extension> void deployBean(Metadata<E> extension, ClassTransformer classTransformer) { // Locate the BeanDeployment for this extension BeanDeployment beanDeployment = DeploymentStructures.getOrCreateBeanDeployment(deployment, beanManager, bdaMapping, contexts, extension.getValue() .getClass()); // Do not register synthetic extension as a bean, only register container lifecycle observer methods if (extension.getValue() instanceof SyntheticExtension) { SyntheticExtension synthetic = (SyntheticExtension) extension.getValue(); synthetic.initialize(beanDeployment.getBeanManager()); for (ObserverMethod<?> observer : synthetic.getObservers()) { beanDeployment.getBeanManager().addObserver(observer); containerLifecycleEventObservers.processObserverMethod(observer); } return; } EnhancedAnnotatedType<E> enchancedAnnotatedType = getEnhancedAnnotatedType(classTransformer, extension, beanDeployment); if (enchancedAnnotatedType != null) { ExtensionBean<E> bean = new ExtensionBean<E>(beanDeployment.getBeanManager(), enchancedAnnotatedType, extension); Set<ObserverInitializationContext<?, ?>> observerMethodInitializers = new HashSet<ObserverInitializationContext<?, ?>>(); createObserverMethods(bean, beanDeployment.getBeanManager(), enchancedAnnotatedType, observerMethodInitializers); beanDeployment.getBeanManager().addBean(bean); beanDeployment.getBeanDeployer().addExtension(bean); for (ObserverInitializationContext<?, ?> observerMethodInitializer : observerMethodInitializers) { observerMethodInitializer.initialize(); beanDeployment.getBeanManager().addObserver(observerMethodInitializer.getObserver()); containerLifecycleEventObservers.processObserverMethod(observerMethodInitializer.getObserver()); } BootstrapLogger.LOG.extensionBeanDeployed(bean); } }