/** * Creates a producer method Web Bean * * @param method The underlying method abstraction * @param declaringBean The declaring bean abstraction * @param beanManager the current manager * @return A producer Web Bean */ public static <X, T> ProducerMethod<X, T> of(BeanAttributes<T> attributes, EnhancedAnnotatedMethod<T, ? super X> method, AbstractClassBean<X> declaringBean, DisposalMethod<X, ?> disposalMethod, BeanManagerImpl beanManager, ServiceRegistry services) { return new ProducerMethod<X, T>(createId(attributes, method, declaringBean), attributes, method, declaringBean, disposalMethod, beanManager, services); }
private ProcessProducerMethodImpl(BeanManagerImpl beanManager, ProducerMethod<T, X> bean) { super(beanManager, ProcessProducerMethod.class, new Type[]{bean.getAnnotated().getBaseType(), bean.getAnnotated().getDeclaringType().getBaseType()}, bean); }
@Override public Iterable<ProducerMethod<?, ?>> transform(ProducerMethod<?, ?> bean, BeanDeployerEnvironment environment) { return environment.getProducerMethod(bean.getBeanClass().getSuperclass(), bean.getEnhancedAnnotated().getSignature()); } };
@Override public String toString() { return "Producer Method [" + Formats.formatType(getAnnotated().getBaseType()) + "] with qualifiers [" + Formats.formatAnnotations(getQualifiers()) + "] declared as [" + getAnnotated() + "]"; }
public void validateMetadataInjectionPoint(InjectionPoint ij, Bean<?> bean, MessageCallback<DefinitionException> messageCallback) { // metadata injection points if (ij.getType().equals(InjectionPoint.class) && bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(bean.getScope())) { throw ValidatorLogger.LOG.injectionIntoNonDependentBean(ij, Formats.formatAsStackTraceElement(ij)); } Class<?> rawType = Reflections.getRawType(ij.getType()); if (Bean.class.equals(rawType) || Interceptor.class.equals(rawType) || Decorator.class.equals(rawType)) { if (bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (bean instanceof AbstractClassBean<?>) { checkBeanMetadataInjectionPoint(bean, ij, AnnotatedTypes.getDeclaringAnnotatedType(ij.getAnnotated()).getBaseType()); } if (bean instanceof ProducerMethod<?, ?>) { ProducerMethod<?, ?> producerMethod = Reflections.cast(bean); checkBeanMetadataInjectionPoint(bean, ij, producerMethod.getAnnotated().getBaseType()); } } }
@Override protected void specialize() { Set<? extends AbstractBean<?, ?>> specializedBeans = getSpecializedBeans(); if (specializedBeans.isEmpty()) { throw BeanLogger.LOG.producerMethodNotSpecializing(this, Formats.formatAsStackTraceElement(annotatedMethod.getJavaMember())); } }
public AnnotatedMethod<T> getAnnotatedProducerMethod() { checkWithinObserverNotification(); if (getBean().getAnnotated() != null) { return cast(getBean().getAnnotated()); } else { return null; } }
protected <X, T> void createProducerMethod(AbstractClassBean<X> declaringBean, EnhancedAnnotatedMethod<T, ? super X> annotatedMethod) { BeanAttributes<T> attributes = BeanAttributesFactory.forBean(annotatedMethod, getManager()); DisposalMethod<X, ?> disposalMethod = resolveDisposalMethod(attributes, declaringBean); ProducerMethod<? super X, T> bean = ProducerMethod.of(attributes, annotatedMethod, declaringBean, disposalMethod, manager, services); containerLifecycleEvents.preloadProcessBeanAttributes(bean.getType()); containerLifecycleEvents.preloadProcessBean(ProcessProducerMethod.class, annotatedMethod.getBaseType(), bean.getBeanClass()); containerLifecycleEvents.preloadProcessProducer(bean.getBeanClass(), annotatedMethod.getBaseType()); getEnvironment().addProducerMethod(bean); }
protected ProducerMethod(BeanIdentifier identifier, BeanAttributes<T> attributes, EnhancedAnnotatedMethod<T, ? super X> method, AbstractClassBean<X> declaringBean, DisposalMethod<X, ?> disposalMethod, BeanManagerImpl beanManager, ServiceRegistry services) { super(attributes, identifier, declaringBean, beanManager, services); this.enhancedAnnotatedMethod = method; this.annotatedMethod = method.slim(); initType(); this.proxiable = Proxies.isTypesProxyable(method.getTypeClosure(), beanManager.getServices()); setProducer(new ProducerMethodProducer<X, T>(method, disposalMethod) { @Override public BeanManagerImpl getBeanManager() { return ProducerMethod.this.beanManager; } @Override public Bean<X> getDeclaringBean() { return ProducerMethod.this.getDeclaringBean(); } @Override public Bean<T> getBean() { return ProducerMethod.this; } }); }
@Override public Bean<X> getDeclaringBean() { return ProducerMethod.this.getDeclaringBean(); }
public void validateMetadataInjectionPoint(InjectionPoint ij, Bean<?> bean, MessageCallback<DefinitionException> messageCallback) { // metadata injection points if (ij.getType().equals(InjectionPoint.class) && bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(bean.getScope())) { throw ValidatorLogger.LOG.injectionIntoNonDependentBean(ij, Formats.formatAsStackTraceElement(ij)); } Class<?> rawType = Reflections.getRawType(ij.getType()); if (Bean.class.equals(rawType) || Interceptor.class.equals(rawType) || Decorator.class.equals(rawType)) { if (bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (bean instanceof AbstractClassBean<?>) { checkBeanMetadataInjectionPoint(bean, ij, AnnotatedTypes.getDeclaringAnnotatedType(ij.getAnnotated()).getBaseType()); } if (bean instanceof ProducerMethod<?, ?>) { ProducerMethod<?, ?> producerMethod = Reflections.cast(bean); checkBeanMetadataInjectionPoint(bean, ij, producerMethod.getAnnotated().getBaseType()); } } }
@Override protected void specialize() { Set<? extends AbstractBean<?, ?>> specializedBeans = getSpecializedBeans(); if (specializedBeans.isEmpty()) { throw BeanLogger.LOG.producerMethodNotSpecializing(this, Formats.formatAsStackTraceElement(annotatedMethod.getJavaMember())); } }
@Override public String toString() { return "Producer Method [" + Formats.formatType(getAnnotated().getBaseType()) + "] with qualifiers [" + Formats.formatAnnotations(getQualifiers()) + "] declared as [" + getAnnotated() + "]"; }
public AnnotatedMethod<T> getAnnotatedProducerMethod() { checkWithinObserverNotification(); if (getBean().getAnnotated() != null) { return cast(getBean().getAnnotated()); } else { return null; } }
protected <X, T> void createProducerMethod(AbstractClassBean<X> declaringBean, EnhancedAnnotatedMethod<T, ? super X> annotatedMethod) { BeanAttributes<T> attributes = BeanAttributesFactory.forBean(annotatedMethod, getManager()); DisposalMethod<X, ?> disposalMethod = resolveDisposalMethod(attributes, declaringBean); ProducerMethod<? super X, T> bean = ProducerMethod.of(attributes, annotatedMethod, declaringBean, disposalMethod, manager, services); containerLifecycleEvents.preloadProcessBeanAttributes(bean.getType()); containerLifecycleEvents.preloadProcessBean(ProcessProducerMethod.class, annotatedMethod.getBaseType(), bean.getBeanClass()); containerLifecycleEvents.preloadProcessProducer(bean.getBeanClass(), annotatedMethod.getBaseType()); getEnvironment().addProducerMethod(bean); }
protected ProducerMethod(BeanIdentifier identifier, BeanAttributes<T> attributes, EnhancedAnnotatedMethod<T, ? super X> method, AbstractClassBean<X> declaringBean, DisposalMethod<X, ?> disposalMethod, BeanManagerImpl beanManager, ServiceRegistry services) { super(attributes, identifier, declaringBean, beanManager, services); this.enhancedAnnotatedMethod = method; this.annotatedMethod = method.slim(); initType(); this.proxiable = Proxies.isTypesProxyable(method.getTypeClosure(), beanManager.getServices()); setProducer(new ProducerMethodProducer<X, T>(method, disposalMethod) { @Override public BeanManagerImpl getBeanManager() { return ProducerMethod.this.beanManager; } @Override public Bean<X> getDeclaringBean() { return ProducerMethod.this.getDeclaringBean(); } @Override public Bean<T> getBean() { return ProducerMethod.this; } }); }
@Override public Bean<X> getDeclaringBean() { return ProducerMethod.this.getDeclaringBean(); }
public void validateMetadataInjectionPoint(InjectionPoint ij, Bean<?> bean, MessageCallback<DefinitionException> messageCallback) { // metadata injection points if (ij.getType().equals(InjectionPoint.class) && bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(bean.getScope())) { throw ValidatorLogger.LOG.injectionIntoNonDependentBean(ij, Formats.formatAsStackTraceElement(ij)); } Class<?> rawType = Reflections.getRawType(ij.getType()); if (Bean.class.equals(rawType) || Interceptor.class.equals(rawType) || Decorator.class.equals(rawType)) { if (bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (bean instanceof AbstractClassBean<?>) { checkBeanMetadataInjectionPoint(bean, ij, AnnotatedTypes.getDeclaringAnnotatedType(ij.getAnnotated()).getBaseType()); } if (bean instanceof ProducerMethod<?, ?>) { ProducerMethod<?, ?> producerMethod = Reflections.cast(bean); checkBeanMetadataInjectionPoint(bean, ij, producerMethod.getAnnotated().getBaseType()); } } }
private ProcessProducerMethodImpl(BeanManagerImpl beanManager, ProducerMethod<T, X> bean) { super(beanManager, ProcessProducerMethod.class, new Type[]{bean.getAnnotated().getBaseType(), bean.getAnnotated().getDeclaringType().getBaseType()}, bean); }
@Override protected void specialize() { Set<? extends AbstractBean<?, ?>> specializedBeans = getSpecializedBeans(); if (specializedBeans.isEmpty()) { throw BeanLogger.LOG.producerMethodNotSpecializing(this, Formats.formatAsStackTraceElement(annotatedMethod.getJavaMember())); } }