private static void doReloadInjectionTargetBean(BeanManagerImpl beanManager, InjectionTargetBean<?> bean, Map<String, String> oldSignatures, BeanReloadStrategy reloadStrategy) { String signatureByStrategy = OwbClassSignatureHelper.getSignatureByStrategy(reloadStrategy, bean.getBeanClass()); String oldSignature = oldSignatures.get(bean.getBeanClass().getName()); if (reloadStrategy == BeanReloadStrategy.CLASS_CHANGE || (reloadStrategy != BeanReloadStrategy.NEVER && signatureByStrategy != null && !signatureByStrategy.equals(oldSignature))) { // Reload bean in contexts - invalidates existing instances doReloadBeanInBeanContexts(beanManager, bean); } else { // keep beans in contexts, reinitialize bean injection points doReinjectBean(beanManager, bean); } }
private static void doReinjectBean(BeanManagerImpl beanManager, InjectionTargetBean<?> bean) { try { if (!bean.getScope().equals(ApplicationScoped.class) && HaCdiCommons.isRegisteredScope(bean.getScope())) { doReinjectRegisteredBeanInstances(beanManager, bean); } else { doReinjectBeanInstance(beanManager, bean, beanManager.getContext(bean.getScope())); } } catch (ContextNotActiveException e) { LOGGER.info("No active contexts for bean '{}'", bean.getBeanClass().getName()); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void doReinjectRegisteredBeanInstances(BeanManagerImpl beanManager, InjectionTargetBean bean) { for (Object instance: HaCdiCommons.getBeanInstances(bean)) { if (instance != null) { bean.getProducer().inject(instance, beanManager.createCreationalContext(bean)); LOGGER.info("Bean '{}' injection points was reinjected.", bean.getBeanClass().getName()); } else { LOGGER.info("Unexpected 'null' bean instance in registry. bean='{}'", bean.getBeanClass().getName()); } } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void createAnnotatedTypeForExistingBeanClass(BeanManagerImpl beanManager, InjectionTargetBean bean) { WebBeansContext wbc = beanManager.getWebBeansContext(); AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory(); // Clear AnnotatedElementFactory caches annotatedElementFactory.clear(); AnnotatedType annotatedType = annotatedElementFactory.newAnnotatedType(bean.getBeanClass()); ReflectionHelper.set(bean, InjectionTargetBean.class, "annotatedType", annotatedType); // Updated members that were set by bean attributes BeanAttributesImpl attributes = BeanAttributesBuilder.forContext(wbc).newBeanAttibutes(annotatedType).build(); ReflectionHelper.set(bean, BeanAttributesImpl.class, "types", attributes.getTypes()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "qualifiers", attributes.getQualifiers()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "scope", attributes.getScope()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "name", attributes.getName()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "stereotypes", attributes.getStereotypes()); ReflectionHelper.set(bean, BeanAttributesImpl.class, "alternative", attributes.isAlternative()); InjectionTargetFactory factory = new InjectionTargetFactoryImpl(annotatedType, bean.getWebBeansContext()); InjectionTarget injectionTarget = factory.createInjectionTarget(bean); ReflectionHelper.set(bean, InjectionTargetBean.class, "injectionTarget", injectionTarget); LOGGER.debug("New annotated type created for bean '{}'", bean.getBeanClass()); }
public InterceptionFactoryBean(WebBeansContext webBeansContext) { super(webBeansContext, WebBeansType.INTERCEPTIONFACTORY, new BeanAttributesImpl<>( CollectionUtil.<Type>unmodifiableSet(InterceptionFactory.class, Object.class), AnnotationUtil.DEFAULT_AND_ANY_ANNOTATION_SET), InterceptionFactory.class, false, new SimpleProducerFactory<>(new InterceptionFactoryProducer(webBeansContext))); }
/** * delegation of serialization behavior */ public <T> T readExternal(Bean<T> bean, ObjectInput out) throws IOException, ClassNotFoundException { return (T) ((ResourceBean)bean).getActualInstance(); }
/** * Will re-inject any managed beans in the target. Will not call any other life-cycle methods * * @param ctx * @param managedBean */ @SuppressWarnings("unchecked") static void reinitialize(Context ctx, Contextual<Object> contextual) { try { ManagedBean<Object> managedBean = ManagedBean.class.cast(contextual); LOGGER.debug("Re-Initializing bean '{}' in context '{}'", managedBean, ctx); Object get = ctx.get(managedBean); if (get != null) { LOGGER.debug("Bean injection points are reinitialized '{}'", managedBean); CreationalContextImpl<Object> creationalContext = managedBean.getWebBeansContext().getCreationalContextFactory().getCreationalContext(managedBean); managedBean.getProducer().inject(get, creationalContext); } } catch (Exception e) { LOGGER.error("Error reinitializing bean '{}' in context '{}'", e, contextual, ctx); } } }
@Override protected <X> P createBean(InjectionTargetBean<X> owner, Class<T> beanClass) { return (P) new ProducerFieldBean<T>(owner, beanAttributes, beanClass, new FieldProducerFactory(annotatedMember, owner, owner.getWebBeansContext())); }
public WebBeansUtil(WebBeansContext webBeansContext) { this.webBeansContext = webBeansContext; instanceBean = new InstanceBean(webBeansContext); eventBean = new EventBean<>(webBeansContext); }
/** * {@inheritDoc} */ @Override public T create(CreationalContext<T> creationalContext) { T instance = null; instance = super.create(creationalContext); checkNullInstance(instance, producerField.getName()); checkScopeType(producerField.getName(), instance); return instance; }
@Override public String getId() { return ((OwbBean<?>) bean).getId(); }
public CdiInterceptorBean(WebBeansContext webBeansContext, AnnotatedType<T> annotatedType, BeanAttributes<T> beanAttributes, Class<T> beanClass, Set<Annotation> interceptorBindings, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods) { super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods); this.interceptorBindings = interceptorBindings; this.setEnabled(enabled); }
Object readResolve() throws ObjectStreamException { return get(); } }
public InterceptionFactoryBean getInterceptionFactoryBean() { return new InterceptionFactoryBean(webBeansContext); }
/** * Creates a new bean metadata bean. * @return new bean */ public <T> BeanMetadataBean<T> getBeanMetadataBean() { return new BeanMetadataBean<>(webBeansContext); }
/** * Creates a new decorator metadata bean. * @return new bean */ public <T> DecoratorMetadataBean<T> getDecoratorMetadataBean() { return new DecoratorMetadataBean<>(webBeansContext); }
Object readResolve() throws ObjectStreamException { return get(); } }
/** * Returns observer owner bean. * * @return the bean */ @Override @SuppressWarnings("unchecked") public Class<?> getBeanClass() { return ownerBean.getBeanClass(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void doReinjectBeanInstance(BeanManagerImpl beanManager, InjectionTargetBean bean, Context context) { Object instance = context.get(bean); if (instance != null) { bean.getProducer().inject(instance, beanManager.createCreationalContext(bean)); LOGGER.info("Bean '{}' injection points was reinjected.", bean.getBeanClass().getName()); } }
private static void doReloadBeanInBeanContexts(BeanManagerImpl beanManager, InjectionTargetBean<?> bean) { try { Map<Class<? extends Annotation>, Context> singleContextMap = getSingleContextMap(beanManager); Context context = singleContextMap.get(bean.getScope()); if (context != null) { doReloadBeanInContext(beanManager, bean, context); } else { Map<Class<? extends Annotation>, List<Context>> allContexts = getContextMap(beanManager); List<Context> ctxList = allContexts.get(bean.getScope()); if (ctxList != null) { for(Context ctx: ctxList) { doReloadBeanInContext(beanManager, bean, ctx); } } else { LOGGER.debug("No active contexts for bean '{}' in scope '{}'", bean.getBeanClass().getName(), bean.getScope()); } } } catch (ContextNotActiveException e) { LOGGER.warning("No active contexts for bean '{}'", e, bean.getBeanClass().getName()); } catch (Exception e) { LOGGER.warning("Context for '{}' failed to reload", e, bean.getBeanClass().getName()); } }