public void addDisposesMethod(DisposalMethod<?, ?> bean) { allDisposalBeans.add(bean); addNewBeansFromInjectionPoints(bean.getInjectionPoints()); }
public static <X, T> DisposalMethod<X, T> of(BeanManagerImpl manager, EnhancedAnnotatedMethod<T, ? super X> method, AbstractClassBean<X> declaringBean) { return new DisposalMethod<X, T>(manager, method, declaringBean); }
protected DisposalMethod(BeanManagerImpl beanManager, EnhancedAnnotatedMethod<T, ? super X> enhancedAnnotatedMethod, AbstractClassBean<X> declaringBean) { this.disposalMethodInjectionPoint = InjectionPointFactory.instance().createMethodInjectionPoint(MethodInjectionPointType.DISPOSER, enhancedAnnotatedMethod, declaringBean, declaringBean.getBeanClass(), Disposes.class, beanManager); this.beanManager = beanManager; this.declaringBean = declaringBean; EnhancedAnnotatedParameter<?, ? super X> enhancedDisposesParameter = getEnhancedDisposesParameter(enhancedAnnotatedMethod); this.disposesParameter = enhancedDisposesParameter.slim(); this.requiredQualifiers = getRequiredQualifiers(enhancedDisposesParameter); checkDisposalMethod(enhancedAnnotatedMethod, declaringBean); this.invocationStrategy = MethodInvocationStrategy.forDisposer(disposalMethodInjectionPoint, beanManager); }
validateGeneralBean(bean, beanManager); if (bean instanceof NewBean) { return; validateDecorators(beanManager, (DecorableBean<?>) bean); if (classBean.hasInterceptors()) { validateInterceptors(beanManager, classBean); AbstractProducerBean<?, ?, ?> producerBean = Reflections.<AbstractProducerBean<?, ?, ?>> cast(bean); if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) { AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>> cast(producerBean .getProducer()); if (producer.getDisposalMethod() != null) { for (InjectionPoint ip : producer.getDisposalMethod().getInjectionPoints()) { validateInjectionPointForDefinitionErrors(ip, null, beanManager);
Class<?> rawType = Reflections.getRawType(ip.getType()); if (Bean.class.equals(rawType) || Interceptor.class.equals(rawType) || Decorator.class.equals(rawType)) { Validator.checkBeanMetadataInjectionPoint(this, ip, getDisposesParameter().getBaseType());
@Override public String toString() { return "Disposer method [" + getDisposesParameter().getDeclaringCallable() + "]"; }
public Type getGenericType() { return getDisposesParameter().getBaseType(); }
private boolean isInjectedIntoDisposer(Bean<?> bean, Collection<Bean<?>> beans) { for (Bean<?> producerCandidate : beans) { if (producerCandidate instanceof AbstractProducerBean) { AbstractProducerBean<?, ?, ?> producerBean = cast(producerCandidate); if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) { AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>> cast(producerBean.getProducer()); if (producer.getDisposalMethod() != null) { BeanManager beanManager = getBeanManager(bean); for (InjectionPoint injectionPoint : producer.getDisposalMethod().getInjectionPoints()) { if (bean.equals(beanManager.resolve(beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]))))) { return true; } } } } } } return false; }
if (producerBean.getDeclaringBean() != null) { beanBuilder.add(DECLARING_BEAN, createSimpleBeanJson(producerBean.getDeclaringBean(), probe)); if (producerBean.getProducer() instanceof ProducerMethodProducer) { ProducerMethodProducer<?, ?> producer = (ProducerMethodProducer<?, ?>) producerBean.getProducer(); if (producer.getDisposalMethod() != null) { beanBuilder.add(DISPOSAL_METHOD, annotatedMethodToString(producer.getDisposalMethod().getAnnotated(), bean.getBeanClass())); ProducerFieldProducer<?, ?> producer = (ProducerFieldProducer<?, ?>) producerBean.getProducer(); if (producer.getDisposalMethod() != null) { beanBuilder.add(DISPOSAL_METHOD, annotatedMethodToString(producer.getDisposalMethod().getAnnotated(), bean.getBeanClass())); InterceptionModel interceptionModel = abstractClassBean.getInterceptors(); List<Decorator<?>> decorators = abstractClassBean.getDecorators(); if (!decorators.isEmpty()) { JsonArrayBuilder decoratorsBuilder = Json.arrayBuilder();
public AnnotatedParameter<T> getAnnotatedDisposedParameter() { checkWithinObserverNotification(); if (getBean().getProducer() instanceof AbstractMemberProducer<?, ?>) { AbstractMemberProducer<?, ?> producer = (AbstractMemberProducer<?, ?>) getBean().getProducer(); if (producer.getDisposalMethod() != null) { return cast(producer.getDisposalMethod().getDisposesParameter()); } } return null; } }
public void dispose(T instance) { if (disposalMethod != null) { // CreationalContext is only created if we need it to obtain the receiver // MethodInvocationStrategy takes care of creating CC for parameters, if needed if (disposalMethod.getAnnotated().isStatic()) { disposalMethod.invokeDisposeMethod(null, instance, null); } else { WeldCreationalContext<X> ctx = null; try { Object receiver = ContextualInstance.getIfExists(getDeclaringBean(), getBeanManager()); if (receiver == null) { ctx = getBeanManager().createCreationalContext(null); // Create child CC so that a dependent reciever may be destroyed after the disposer method completes receiver = ContextualInstance.get(getDeclaringBean(), getBeanManager(), ctx.getCreationalContext(getDeclaringBean())); } if (receiver != null) { disposalMethod.invokeDisposeMethod(receiver, instance, ctx); } } finally { if (ctx != null) { ctx.release(); } } } } }
@Override protected boolean matches(Resolvable resolvable, DisposalMethod<?, ?> disposer) { return resolvable.getDeclaringBean().equals(disposer.getDeclaringBean()) && rules.matches(disposer.getGenericType(), resolvable.getTypes()) && Beans.containsAllQualifiers(disposer.getRequiredQualifiers(), resolvable.getQualifiers()); }
validateGeneralBean(bean, beanManager); if (bean instanceof NewBean) { return; validateDecorators(beanManager, (DecorableBean<?>) bean); if (classBean.hasInterceptors()) { validateInterceptors(beanManager, classBean); AbstractProducerBean<?, ?, ?> producerBean = Reflections.<AbstractProducerBean<?, ?, ?>> cast(bean); if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) { AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>> cast(producerBean .getProducer()); if (producer.getDisposalMethod() != null) { for (InjectionPoint ip : producer.getDisposalMethod().getInjectionPoints()) { validateInjectionPointForDefinitionErrors(ip, null, beanManager);
Class<?> rawType = Reflections.getRawType(ip.getType()); if (Bean.class.equals(rawType) || Interceptor.class.equals(rawType) || Decorator.class.equals(rawType)) { Validator.checkBeanMetadataInjectionPoint(this, ip, getDisposesParameter().getBaseType());
@Override public String toString() { return "Disposer method [" + getDisposesParameter().getDeclaringCallable() + "]"; }
public Type getGenericType() { return getDisposesParameter().getBaseType(); }
private boolean isInjectedIntoDisposer(Bean<?> bean, Collection<Bean<?>> beans) { for (Bean<?> producerCandidate : beans) { if (producerCandidate instanceof AbstractProducerBean) { AbstractProducerBean<?, ?, ?> producerBean = cast(producerCandidate); if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) { AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>> cast(producerBean.getProducer()); if (producer.getDisposalMethod() != null) { BeanManager beanManager = getBeanManager(bean); for (InjectionPoint injectionPoint : producer.getDisposalMethod().getInjectionPoints()) { if (bean.equals(beanManager.resolve(beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]))))) { return true; } } } } } } return false; }
if (producerBean.getDeclaringBean() != null) { beanBuilder.add(DECLARING_BEAN, createSimpleBeanJson(producerBean.getDeclaringBean(), probe)); if (producerBean.getProducer() instanceof ProducerMethodProducer) { ProducerMethodProducer<?, ?> producer = (ProducerMethodProducer<?, ?>) producerBean.getProducer(); if (producer.getDisposalMethod() != null) { beanBuilder.add(DISPOSAL_METHOD, annotatedMethodToString(producer.getDisposalMethod().getAnnotated(), bean.getBeanClass())); ProducerFieldProducer<?, ?> producer = (ProducerFieldProducer<?, ?>) producerBean.getProducer(); if (producer.getDisposalMethod() != null) { beanBuilder.add(DISPOSAL_METHOD, annotatedMethodToString(producer.getDisposalMethod().getAnnotated(), bean.getBeanClass())); InterceptionModel interceptionModel = abstractClassBean.getInterceptors(); List<Decorator<?>> decorators = abstractClassBean.getDecorators(); if (!decorators.isEmpty()) { JsonArrayBuilder decoratorsBuilder = Json.arrayBuilder();
public AnnotatedParameter<T> getAnnotatedDisposedParameter() { checkWithinObserverNotification(); if (getBean().getProducer() instanceof AbstractMemberProducer<?, ?>) { AbstractMemberProducer<?, ?> producer = (AbstractMemberProducer<?, ?>) getBean().getProducer(); if (producer.getDisposalMethod() != null) { return cast(producer.getDisposalMethod().getDisposesParameter()); } } return null; } }
public void dispose(T instance) { if (disposalMethod != null) { // CreationalContext is only created if we need it to obtain the receiver // MethodInvocationStrategy takes care of creating CC for parameters, if needed if (disposalMethod.getAnnotated().isStatic()) { disposalMethod.invokeDisposeMethod(null, instance, null); } else { WeldCreationalContext<X> ctx = null; try { Object receiver = ContextualInstance.getIfExists(getDeclaringBean(), getBeanManager()); if (receiver == null) { ctx = getBeanManager().createCreationalContext(null); // Create child CC so that a dependent reciever may be destroyed after the disposer method completes receiver = ContextualInstance.get(getDeclaringBean(), getBeanManager(), ctx.getCreationalContext(getDeclaringBean())); } if (receiver != null) { disposalMethod.invokeDisposeMethod(receiver, instance, ctx); } } finally { if (ctx != null) { ctx.release(); } } } } }