Author: arne
Date: Fri Jan 25 06:23:09 2013
New Revision: 1438338
URL: http://svn.apache.org/viewvc?rev=1438338&view=rev
Log:
OWB-770: Extracted ProducerFieldBeansBuilder and ProducerMethodBeansBuilder
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
- copied, changed from r1438245,
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
- copied, changed from r1438245,
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
Modified:
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
Modified:
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java?rev=1438338&r1=1438337&r2=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
(original)
+++
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
Fri Jan 25 06:23:09 2013
@@ -41,6 +41,8 @@ import org.apache.webbeans.component.Pro
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.component.creation.BeanAttributesBuilder;
import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
+import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
+import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.ejb.common.component.BaseEjbBean;
@@ -93,9 +95,11 @@ public final class EjbUtility
}
//Define meta-data
- Set<ProducerMethodBean<?>> producerMethodBeans =
ejbBeanCreator.defineProducerMethods(ejbBean);
+ Set<ProducerMethodBean<?>> producerMethodBeans
+ = new ProducerMethodBeansBuilder(ejbBean.getWebBeansContext(),
ejbBean.getAnnotatedType()).defineProducerMethods(ejbBean);
checkProducerMethods(producerMethodBeans, ejbBean);
- Set<ProducerFieldBean<?>> producerFieldBeans =
ejbBeanCreator.defineProducerFields(ejbBean);
+ Set<ProducerFieldBean<?>> producerFieldBeans
+ = new ProducerFieldBeansBuilder(ejbBean.getWebBeansContext(),
ejbBean.getAnnotatedType()).defineProducerFields(ejbBean);
Set<ObserverMethod<?>> observerMethods = new ObserverMethodsBuilder<T,
InjectionTargetBean<T>>(webBeansContext,
ejbBean.getAnnotatedType()).defineObserverMethods(ejbBean);
EjbValidator.validateObserverMethods(ejbBean, observerMethods);
@@ -202,9 +206,10 @@ public final class EjbUtility
}
};
- final Set<ProducerMethodBean<?>> producerMethodBeans =
ejbBeanCreator.defineProducerMethods(ejbBean);
+ final Set<ProducerMethodBean<?>> producerMethodBeans
+ = new ProducerMethodBeansBuilder(ejbBean.getWebBeansContext(),
ejbBean.getAnnotatedType()).defineProducerMethods(ejbBean);
- final Set<ProducerFieldBean<?>> producerFieldBeans =
ejbBeanCreator.defineProducerFields(ejbBean);
+ final Set<ProducerFieldBean<?>> producerFieldBeans = new
ProducerFieldBeansBuilder(ejbBean.getWebBeansContext(),
ejbBean.getAnnotatedType()).defineProducerFields(ejbBean);
checkProducerMethods(producerMethodBeans, ejbBean);
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java?rev=1438338&r1=1438337&r2=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
Fri Jan 25 06:23:09 2013
@@ -18,46 +18,22 @@
*/
package org.apache.webbeans.component.creation;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.Specializes;
-import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Inject;
-import javax.inject.Named;
import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.component.InjectionTargetBean;
-import org.apache.webbeans.component.ProducerFieldBean;
-import org.apache.webbeans.component.ProducerMethodBean;
-import org.apache.webbeans.component.ResourceBean;
-import org.apache.webbeans.component.ResourceProvider;
import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.portable.InjectionTargetImpl;
-import org.apache.webbeans.portable.ProducerFieldProducer;
-import org.apache.webbeans.portable.ProviderBasedProxyProducer;
-import org.apache.webbeans.spi.api.ResourceReference;
-import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.ClassUtil;
-import org.apache.webbeans.util.WebBeansUtil;
/**
* Abstract implementation of {@link AbstractBeanBuilder}.
@@ -98,156 +74,6 @@ public abstract class AbstractInjectionT
return
webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass);
}
- /**
- * {@inheritDoc}
- */
- public Set<ProducerFieldBean<?>>
defineProducerFields(InjectionTargetBean<T> bean)
- {
- Set<ProducerFieldBean<?>> producerBeans = new
HashSet<ProducerFieldBean<?>>();
- Set<AnnotatedField<? super T>> annotatedFields =
annotatedType.getFields();
- for(AnnotatedField<? super T> annotatedField: annotatedFields)
- {
- if(annotatedField.isAnnotationPresent(Produces.class) &&
annotatedField.getDeclaringType().equals(annotatedType))
- {
- Type genericType = annotatedField.getBaseType();
-
- if(ClassUtil.isTypeVariable(genericType))
- {
- throw new WebBeansConfigurationException("Producer
annotated field : " + annotatedField + " can not be Wildcard type or Type
variable");
- }
- if(ClassUtil.isParametrizedType(genericType))
- {
-
if(!ClassUtil.checkParametrizedType((ParameterizedType)genericType))
- {
- throw new WebBeansConfigurationException("Producer
annotated field : " + annotatedField + " can not be Wildcard type or Type
variable");
- }
- }
-
- Annotation[] anns =
AnnotationUtil.asArray(annotatedField.getAnnotations());
- Field field = annotatedField.getJavaMember();
-
- //Producer field for resource
- Annotation resourceAnnotation =
AnnotationUtil.hasOwbInjectableResource(anns);
- //Producer field for resource
- if(resourceAnnotation != null)
- {
- //Check for valid resource annotation
-
//WebBeansUtil.checkForValidResources(annotatedField.getDeclaringType().getJavaClass(),
field.getType(), field.getName(), anns);
- if(!Modifier.isStatic(field.getModifiers()))
- {
- ResourceReference<T, Annotation> resourceRef = new
ResourceReference<T, Annotation>(annotatedType.getJavaClass(), field.getName(),
-
(Class<T>)field.getType(), resourceAnnotation);
-
- //Can not define EL name
- if(annotatedField.isAnnotationPresent(Named.class))
- {
- throw new WebBeansConfigurationException("Resource
producer annotated field : " + annotatedField + " can not define EL name");
- }
-
- BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
- ResourceBeanBuilder<T, Annotation> resourceBeanCreator
- = new ResourceBeanBuilder<T, Annotation>(bean,
resourceRef, annotatedField, beanAttributes);
- ResourceBean<T, Annotation> resourceBean =
resourceBeanCreator.getBean();
- ResourceProvider<T> resourceProvider = new
ResourceProvider<T>(resourceBean.getReference(), webBeansContext);
- resourceBean.setProducer(new
ProviderBasedProxyProducer<T>(webBeansContext, resourceBean.getReturnType(),
resourceProvider));
-
-
- resourceBean.setProducerField(field);
-
- producerBeans.add(resourceBean);
- }
- }
- else
- {
- BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
- ProducerFieldBeanBuilder<T, ProducerFieldBean<T>>
producerFieldBeanCreator
- = new ProducerFieldBeanBuilder<T,
ProducerFieldBean<T>>(bean, annotatedField, beanAttributes);
- ProducerFieldBean<T> producerFieldBean =
producerFieldBeanCreator.getBean();
-
webBeansContext.getDeploymentValidationService().validateProxyable(producerFieldBean);
- producerFieldBean.setProducer(new
ProducerFieldProducer(bean, annotatedField,
producerFieldBean.getInjectionPoints()));
- producerFieldBean.setProducerField(field);
-
-
webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
producerFieldBean, anns);
- WebBeansUtil.checkProducerGenericType(producerFieldBean,
annotatedField.getJavaMember());
-
- producerBeans.add(producerFieldBean);
- }
- }
- }
-
- return producerBeans;
- }
-
- /**
- * {@inheritDoc}
- */
- public Set<ProducerMethodBean<?>>
defineProducerMethods(InjectionTargetBean<T> bean)
- {
- Set<ProducerMethodBean<?>> producerBeans = new
HashSet<ProducerMethodBean<?>>();
- Set<AnnotatedMethod<? super T>> annotatedMethods =
annotatedType.getMethods();
-
- for(AnnotatedMethod<? super T> annotatedMethod: annotatedMethods)
- {
- if(annotatedMethod.isAnnotationPresent(Produces.class) &&
annotatedMethod.getDeclaringType().equals(annotatedType))
- {
- checkProducerMethodForDeployment(annotatedMethod);
- boolean specialize = false;
- if(annotatedMethod.isAnnotationPresent(Specializes.class))
- {
- if (annotatedMethod.isStatic())
- {
- throw new WebBeansConfigurationException("Specializing
annotated producer method : " + annotatedMethod + " can not be static");
- }
-
- specialize = true;
- }
-
- BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedMethod<T>)annotatedMethod).build();
- ProducerMethodBeanBuilder<T> producerMethodBeanCreator = new
ProducerMethodBeanBuilder<T>(bean, annotatedMethod, beanAttributes);
-
- ProducerMethodBean<T> producerMethodBean =
producerMethodBeanCreator.getBean();
-
-
webBeansContext.getDeploymentValidationService().validateProxyable(producerMethodBean);
-
- if(specialize)
- {
-
producerMethodBeanCreator.configureProducerSpecialization(producerMethodBean,
(AnnotatedMethod<T>) annotatedMethod);
- }
- ProducerMethodProducerBuilder producerBuilder = new
ProducerMethodProducerBuilder(producerMethodBean);
-
producerMethodBean.setProducer(producerBuilder.build(annotatedMethod));
-
producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember());
-
-
webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
- producerMethodBean,
-
AnnotationUtil.asArray(annotatedMethod.getAnnotations()));
- WebBeansUtil.checkProducerGenericType(producerMethodBean,
annotatedMethod.getJavaMember());
- producerBeans.add(producerMethodBean);
-
- }
-
- }
-
- return producerBeans;
- }
-
- /**
- * Check producer method is ok for deployment.
- *
- * @param annotatedMethod producer method
- */
- private void checkProducerMethodForDeployment(AnnotatedMethod<? super T>
annotatedMethod)
- {
- Asserts.assertNotNull(annotatedMethod, "annotatedMethod argument can
not be null");
-
- if (annotatedMethod.isAnnotationPresent(Inject.class) ||
- annotatedMethod.isAnnotationPresent(Disposes.class) ||
- annotatedMethod.isAnnotationPresent(Observes.class))
- {
- throw new WebBeansConfigurationException("Producer annotated
method : " + annotatedMethod + " can not be annotated with"
- + "
@Initializer/@Destructor annotation or has a parameter annotated with
@Disposes/@Observes");
- }
- }
-
protected InjectionTarget<T> buildInjectionTarget(AnnotatedType<T>
annotatedType,
Set<InjectionPoint>
points,
WebBeansContext
webBeansContext,
Copied:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
(from r1438245,
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java)
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java&r1=1438245&r2=1438338&rev=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
Fri Jan 25 06:23:09 2013
@@ -23,34 +23,21 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.Specializes;
import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Inject;
import javax.inject.Named;
import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.ProducerFieldBean;
-import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.component.ResourceBean;
import org.apache.webbeans.component.ResourceProvider;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.portable.InjectionTargetImpl;
import org.apache.webbeans.portable.ProducerFieldProducer;
import org.apache.webbeans.portable.ProviderBasedProxyProducer;
import org.apache.webbeans.spi.api.ResourceReference;
@@ -66,36 +53,22 @@ import org.apache.webbeans.util.WebBeans
*
* @param <T> bean class type
*/
-public abstract class AbstractInjectionTargetBeanBuilder<T, I extends
InjectionTargetBean<T>>
+public class ProducerFieldBeansBuilder<T, I extends InjectionTargetBean<T>>
{
protected final WebBeansContext webBeansContext;
protected final AnnotatedType<T> annotatedType;
- protected final BeanAttributesImpl<T> beanAttributes;
- private boolean enabled = true;
/**
* Creates a new instance.
*
*/
- public AbstractInjectionTargetBeanBuilder(WebBeansContext webBeansContext,
AnnotatedType<T> annotatedType, BeanAttributesImpl<T> beanAttributes)
+ public ProducerFieldBeansBuilder(WebBeansContext webBeansContext,
AnnotatedType<T> annotatedType)
{
Asserts.assertNotNull(webBeansContext, "webBeansContext may not be
null");
Asserts.assertNotNull(annotatedType, "annotated type may not be null");
- Asserts.assertNotNull(beanAttributes, "beanAttributes may not be
null");
this.webBeansContext = webBeansContext;
this.annotatedType = annotatedType;
- this.beanAttributes = beanAttributes;
- }
-
- protected AnnotatedType<? super T> getSuperAnnotated()
- {
- Class<? super T> superclass =
annotatedType.getJavaClass().getSuperclass();
- if (superclass == null)
- {
- return null;
- }
- return
webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass);
}
/**
@@ -177,169 +150,4 @@ public abstract class AbstractInjectionT
return producerBeans;
}
-
- /**
- * {@inheritDoc}
- */
- public Set<ProducerMethodBean<?>>
defineProducerMethods(InjectionTargetBean<T> bean)
- {
- Set<ProducerMethodBean<?>> producerBeans = new
HashSet<ProducerMethodBean<?>>();
- Set<AnnotatedMethod<? super T>> annotatedMethods =
annotatedType.getMethods();
-
- for(AnnotatedMethod<? super T> annotatedMethod: annotatedMethods)
- {
- if(annotatedMethod.isAnnotationPresent(Produces.class) &&
annotatedMethod.getDeclaringType().equals(annotatedType))
- {
- checkProducerMethodForDeployment(annotatedMethod);
- boolean specialize = false;
- if(annotatedMethod.isAnnotationPresent(Specializes.class))
- {
- if (annotatedMethod.isStatic())
- {
- throw new WebBeansConfigurationException("Specializing
annotated producer method : " + annotatedMethod + " can not be static");
- }
-
- specialize = true;
- }
-
- BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedMethod<T>)annotatedMethod).build();
- ProducerMethodBeanBuilder<T> producerMethodBeanCreator = new
ProducerMethodBeanBuilder<T>(bean, annotatedMethod, beanAttributes);
-
- ProducerMethodBean<T> producerMethodBean =
producerMethodBeanCreator.getBean();
-
-
webBeansContext.getDeploymentValidationService().validateProxyable(producerMethodBean);
-
- if(specialize)
- {
-
producerMethodBeanCreator.configureProducerSpecialization(producerMethodBean,
(AnnotatedMethod<T>) annotatedMethod);
- }
- ProducerMethodProducerBuilder producerBuilder = new
ProducerMethodProducerBuilder(producerMethodBean);
-
producerMethodBean.setProducer(producerBuilder.build(annotatedMethod));
-
producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember());
-
-
webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
- producerMethodBean,
-
AnnotationUtil.asArray(annotatedMethod.getAnnotations()));
- WebBeansUtil.checkProducerGenericType(producerMethodBean,
annotatedMethod.getJavaMember());
- producerBeans.add(producerMethodBean);
-
- }
-
- }
-
- return producerBeans;
- }
-
- /**
- * Check producer method is ok for deployment.
- *
- * @param annotatedMethod producer method
- */
- private void checkProducerMethodForDeployment(AnnotatedMethod<? super T>
annotatedMethod)
- {
- Asserts.assertNotNull(annotatedMethod, "annotatedMethod argument can
not be null");
-
- if (annotatedMethod.isAnnotationPresent(Inject.class) ||
- annotatedMethod.isAnnotationPresent(Disposes.class) ||
- annotatedMethod.isAnnotationPresent(Observes.class))
- {
- throw new WebBeansConfigurationException("Producer annotated
method : " + annotatedMethod + " can not be annotated with"
- + "
@Initializer/@Destructor annotation or has a parameter annotated with
@Disposes/@Observes");
- }
- }
-
- protected InjectionTarget<T> buildInjectionTarget(AnnotatedType<T>
annotatedType,
- Set<InjectionPoint>
points,
- WebBeansContext
webBeansContext,
- List<AnnotatedMethod<?>>
postConstructMethods,
- List<AnnotatedMethod<?>>
preDestroyMethods)
- {
- InjectionTargetImpl<T> injectionTarget = new
InjectionTargetImpl<T>(annotatedType, points, webBeansContext,
postConstructMethods, preDestroyMethods);
-
- return injectionTarget;
- }
-
- protected abstract I createBean(Class<T> beanClass, boolean enabled);
-
- protected final I createBean(Class<T> beanClass)
- {
- I bean = createBean(beanClass, enabled);
-
- //X TODO hack to set the InjectionTarget
- InjectionTarget<T> injectionTarget
- = buildInjectionTarget(bean.getAnnotatedType(),
bean.getInjectionPoints(), webBeansContext, getPostConstructMethods(),
getPreDestroyMethods());
- bean.setProducer(injectionTarget);
-
- return bean;
- }
-
- protected List<AnnotatedMethod<?>> getPostConstructMethods()
- {
- List<AnnotatedMethod<?>> postConstructMethods = new
ArrayList<AnnotatedMethod<?>>();
- collectPostConstructMethods(annotatedType.getJavaClass(),
postConstructMethods);
- return postConstructMethods;
- }
-
- private void collectPostConstructMethods(Class<?> type,
List<AnnotatedMethod<?>> postConstructMethods)
- {
- if (type == null)
- {
- return;
- }
- collectPostConstructMethods(type.getSuperclass(),
postConstructMethods);
- for (AnnotatedMethod<?> annotatedMethod: annotatedType.getMethods())
- {
- if (annotatedMethod.getJavaMember().getDeclaringClass() == type
- && annotatedMethod.isAnnotationPresent(PostConstruct.class)
- && annotatedMethod.getParameters().isEmpty())
- {
- postConstructMethods.add(annotatedMethod);
- }
- }
- }
-
- protected List<AnnotatedMethod<?>> getPreDestroyMethods()
- {
- List<AnnotatedMethod<?>> preDestroyMethods = new
ArrayList<AnnotatedMethod<?>>();
- collectPreDestroyMethods(annotatedType.getJavaClass(),
preDestroyMethods);
- return preDestroyMethods;
- }
-
- private void collectPreDestroyMethods(Class<?> type,
List<AnnotatedMethod<?>> preDestroyMethods)
- {
- if (type == null)
- {
- return;
- }
- collectPreDestroyMethods(type.getSuperclass(), preDestroyMethods);
- for (AnnotatedMethod<?> annotatedMethod: annotatedType.getMethods())
- {
- if (annotatedMethod.getJavaMember().getDeclaringClass() == type
- && annotatedMethod.isAnnotationPresent(PreDestroy.class)
- && annotatedMethod.getParameters().isEmpty())
- {
- preDestroyMethods.add(annotatedMethod);
- }
- }
- }
-
- public boolean isEnabled()
- {
- return enabled;
- }
-
- public void defineEnabled()
- {
- enabled =
webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType,
annotatedType.getJavaClass(), beanAttributes.getStereotypes());
- }
-
- public I getBean()
- {
- I bean = createBean(annotatedType.getJavaClass());
- for (InjectionPoint injectionPoint:
webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean,
annotatedType))
- {
- bean.addInjectionPoint(injectionPoint);
- }
- return bean;
- }
}
Copied:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
(from r1438245,
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java)
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java&r1=1438245&r2=1438338&rev=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
Fri Jan 25 06:23:09 2013
@@ -18,45 +18,24 @@
*/
package org.apache.webbeans.component.creation;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.Specializes;
-import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
import javax.inject.Inject;
-import javax.inject.Named;
import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.component.InjectionTargetBean;
-import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
-import org.apache.webbeans.component.ResourceBean;
-import org.apache.webbeans.component.ResourceProvider;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.portable.InjectionTargetImpl;
-import org.apache.webbeans.portable.ProducerFieldProducer;
-import org.apache.webbeans.portable.ProviderBasedProxyProducer;
-import org.apache.webbeans.spi.api.ResourceReference;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
/**
@@ -66,116 +45,22 @@ import org.apache.webbeans.util.WebBeans
*
* @param <T> bean class type
*/
-public abstract class AbstractInjectionTargetBeanBuilder<T, I extends
InjectionTargetBean<T>>
+public class ProducerMethodBeansBuilder<T, I extends InjectionTargetBean<T>>
{
protected final WebBeansContext webBeansContext;
protected final AnnotatedType<T> annotatedType;
- protected final BeanAttributesImpl<T> beanAttributes;
- private boolean enabled = true;
/**
* Creates a new instance.
*
*/
- public AbstractInjectionTargetBeanBuilder(WebBeansContext webBeansContext,
AnnotatedType<T> annotatedType, BeanAttributesImpl<T> beanAttributes)
+ public ProducerMethodBeansBuilder(WebBeansContext webBeansContext,
AnnotatedType<T> annotatedType)
{
Asserts.assertNotNull(webBeansContext, "webBeansContext may not be
null");
Asserts.assertNotNull(annotatedType, "annotated type may not be null");
- Asserts.assertNotNull(beanAttributes, "beanAttributes may not be
null");
this.webBeansContext = webBeansContext;
this.annotatedType = annotatedType;
- this.beanAttributes = beanAttributes;
- }
-
- protected AnnotatedType<? super T> getSuperAnnotated()
- {
- Class<? super T> superclass =
annotatedType.getJavaClass().getSuperclass();
- if (superclass == null)
- {
- return null;
- }
- return
webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass);
- }
-
- /**
- * {@inheritDoc}
- */
- public Set<ProducerFieldBean<?>>
defineProducerFields(InjectionTargetBean<T> bean)
- {
- Set<ProducerFieldBean<?>> producerBeans = new
HashSet<ProducerFieldBean<?>>();
- Set<AnnotatedField<? super T>> annotatedFields =
annotatedType.getFields();
- for(AnnotatedField<? super T> annotatedField: annotatedFields)
- {
- if(annotatedField.isAnnotationPresent(Produces.class) &&
annotatedField.getDeclaringType().equals(annotatedType))
- {
- Type genericType = annotatedField.getBaseType();
-
- if(ClassUtil.isTypeVariable(genericType))
- {
- throw new WebBeansConfigurationException("Producer
annotated field : " + annotatedField + " can not be Wildcard type or Type
variable");
- }
- if(ClassUtil.isParametrizedType(genericType))
- {
-
if(!ClassUtil.checkParametrizedType((ParameterizedType)genericType))
- {
- throw new WebBeansConfigurationException("Producer
annotated field : " + annotatedField + " can not be Wildcard type or Type
variable");
- }
- }
-
- Annotation[] anns =
AnnotationUtil.asArray(annotatedField.getAnnotations());
- Field field = annotatedField.getJavaMember();
-
- //Producer field for resource
- Annotation resourceAnnotation =
AnnotationUtil.hasOwbInjectableResource(anns);
- //Producer field for resource
- if(resourceAnnotation != null)
- {
- //Check for valid resource annotation
-
//WebBeansUtil.checkForValidResources(annotatedField.getDeclaringType().getJavaClass(),
field.getType(), field.getName(), anns);
- if(!Modifier.isStatic(field.getModifiers()))
- {
- ResourceReference<T, Annotation> resourceRef = new
ResourceReference<T, Annotation>(annotatedType.getJavaClass(), field.getName(),
-
(Class<T>)field.getType(), resourceAnnotation);
-
- //Can not define EL name
- if(annotatedField.isAnnotationPresent(Named.class))
- {
- throw new WebBeansConfigurationException("Resource
producer annotated field : " + annotatedField + " can not define EL name");
- }
-
- BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
- ResourceBeanBuilder<T, Annotation> resourceBeanCreator
- = new ResourceBeanBuilder<T, Annotation>(bean,
resourceRef, annotatedField, beanAttributes);
- ResourceBean<T, Annotation> resourceBean =
resourceBeanCreator.getBean();
- ResourceProvider<T> resourceProvider = new
ResourceProvider<T>(resourceBean.getReference(), webBeansContext);
- resourceBean.setProducer(new
ProviderBasedProxyProducer<T>(webBeansContext, resourceBean.getReturnType(),
resourceProvider));
-
-
- resourceBean.setProducerField(field);
-
- producerBeans.add(resourceBean);
- }
- }
- else
- {
- BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
- ProducerFieldBeanBuilder<T, ProducerFieldBean<T>>
producerFieldBeanCreator
- = new ProducerFieldBeanBuilder<T,
ProducerFieldBean<T>>(bean, annotatedField, beanAttributes);
- ProducerFieldBean<T> producerFieldBean =
producerFieldBeanCreator.getBean();
-
webBeansContext.getDeploymentValidationService().validateProxyable(producerFieldBean);
- producerFieldBean.setProducer(new
ProducerFieldProducer(bean, annotatedField,
producerFieldBean.getInjectionPoints()));
- producerFieldBean.setProducerField(field);
-
-
webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
producerFieldBean, anns);
- WebBeansUtil.checkProducerGenericType(producerFieldBean,
annotatedField.getJavaMember());
-
- producerBeans.add(producerFieldBean);
- }
- }
- }
-
- return producerBeans;
}
/**
@@ -247,99 +132,4 @@ public abstract class AbstractInjectionT
+ "
@Initializer/@Destructor annotation or has a parameter annotated with
@Disposes/@Observes");
}
}
-
- protected InjectionTarget<T> buildInjectionTarget(AnnotatedType<T>
annotatedType,
- Set<InjectionPoint>
points,
- WebBeansContext
webBeansContext,
- List<AnnotatedMethod<?>>
postConstructMethods,
- List<AnnotatedMethod<?>>
preDestroyMethods)
- {
- InjectionTargetImpl<T> injectionTarget = new
InjectionTargetImpl<T>(annotatedType, points, webBeansContext,
postConstructMethods, preDestroyMethods);
-
- return injectionTarget;
- }
-
- protected abstract I createBean(Class<T> beanClass, boolean enabled);
-
- protected final I createBean(Class<T> beanClass)
- {
- I bean = createBean(beanClass, enabled);
-
- //X TODO hack to set the InjectionTarget
- InjectionTarget<T> injectionTarget
- = buildInjectionTarget(bean.getAnnotatedType(),
bean.getInjectionPoints(), webBeansContext, getPostConstructMethods(),
getPreDestroyMethods());
- bean.setProducer(injectionTarget);
-
- return bean;
- }
-
- protected List<AnnotatedMethod<?>> getPostConstructMethods()
- {
- List<AnnotatedMethod<?>> postConstructMethods = new
ArrayList<AnnotatedMethod<?>>();
- collectPostConstructMethods(annotatedType.getJavaClass(),
postConstructMethods);
- return postConstructMethods;
- }
-
- private void collectPostConstructMethods(Class<?> type,
List<AnnotatedMethod<?>> postConstructMethods)
- {
- if (type == null)
- {
- return;
- }
- collectPostConstructMethods(type.getSuperclass(),
postConstructMethods);
- for (AnnotatedMethod<?> annotatedMethod: annotatedType.getMethods())
- {
- if (annotatedMethod.getJavaMember().getDeclaringClass() == type
- && annotatedMethod.isAnnotationPresent(PostConstruct.class)
- && annotatedMethod.getParameters().isEmpty())
- {
- postConstructMethods.add(annotatedMethod);
- }
- }
- }
-
- protected List<AnnotatedMethod<?>> getPreDestroyMethods()
- {
- List<AnnotatedMethod<?>> preDestroyMethods = new
ArrayList<AnnotatedMethod<?>>();
- collectPreDestroyMethods(annotatedType.getJavaClass(),
preDestroyMethods);
- return preDestroyMethods;
- }
-
- private void collectPreDestroyMethods(Class<?> type,
List<AnnotatedMethod<?>> preDestroyMethods)
- {
- if (type == null)
- {
- return;
- }
- collectPreDestroyMethods(type.getSuperclass(), preDestroyMethods);
- for (AnnotatedMethod<?> annotatedMethod: annotatedType.getMethods())
- {
- if (annotatedMethod.getJavaMember().getDeclaringClass() == type
- && annotatedMethod.isAnnotationPresent(PreDestroy.class)
- && annotatedMethod.getParameters().isEmpty())
- {
- preDestroyMethods.add(annotatedMethod);
- }
- }
- }
-
- public boolean isEnabled()
- {
- return enabled;
- }
-
- public void defineEnabled()
- {
- enabled =
webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType,
annotatedType.getJavaClass(), beanAttributes.getStereotypes());
- }
-
- public I getBean()
- {
- I bean = createBean(annotatedType.getJavaClass());
- for (InjectionPoint injectionPoint:
webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean,
annotatedType))
- {
- bean.addInjectionPoint(injectionPoint);
- }
- return bean;
- }
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1438338&r1=1438337&r2=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Fri Jan 25 06:23:09 2013
@@ -65,6 +65,8 @@ import org.apache.webbeans.component.cre
import org.apache.webbeans.component.creation.DecoratorBeanBuilder;
import org.apache.webbeans.component.creation.ManagedBeanBuilder;
import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
+import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
+import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.container.InjectableBeanManager;
import org.apache.webbeans.container.InjectionResolver;
@@ -898,8 +900,8 @@ public class BeansDeployer
{
observerMethods = new ObserverMethodsBuilder<T,
InjectionTargetBean<T>>(webBeansContext,
bean.getAnnotatedType()).defineObserverMethods(bean);
}
- Set<ProducerMethodBean<?>> producerMethods =
managedBeanCreator.defineProducerMethods(bean);
- Set<ProducerFieldBean<?>> producerFields =
managedBeanCreator.defineProducerFields(bean);
+ Set<ProducerMethodBean<?>> producerMethods = new
ProducerMethodBeansBuilder(bean.getWebBeansContext(),
bean.getAnnotatedType()).defineProducerMethods(bean);
+ Set<ProducerFieldBean<?>> producerFields = new
ProducerFieldBeansBuilder(bean.getWebBeansContext(),
bean.getAnnotatedType()).defineProducerFields(bean);
//Put final InjectionTarget instance
bean.setProducer(processInjectionTargetEvent.getInjectionTarget());
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1438338&r1=1438337&r2=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Fri Jan 25 06:23:09 2013
@@ -97,6 +97,8 @@ import org.apache.webbeans.component.cre
import org.apache.webbeans.component.creation.ExtensionBeanBuilder;
import org.apache.webbeans.component.creation.ManagedBeanBuilder;
import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
+import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
+import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
import org.apache.webbeans.component.creation.ProducerMethodProducerBuilder;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
@@ -1599,8 +1601,8 @@ public final class WebBeansUtil
//Check for Enabled via Alternative
setInjectionTargetBeanEnableFlag(managedBeanCreator.getBean());
ManagedBean<T> managedBean = managedBeanCreator.getBean();
- managedBeanCreator.defineProducerMethods(managedBean);
- managedBeanCreator.defineProducerFields(managedBean);
+ new ProducerMethodBeansBuilder(managedBean.getWebBeansContext(),
managedBean.getAnnotatedType()).defineProducerMethods(managedBean);
+ new ProducerFieldBeansBuilder(managedBean.getWebBeansContext(),
managedBean.getAnnotatedType()).defineProducerFields(managedBean);
new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
managedBean.getAnnotatedType()).defineObserverMethods(managedBean);
if (managedBean instanceof InjectionTargetBean)
@@ -1729,8 +1731,8 @@ public final class WebBeansUtil
//Check for Enabled via Alternative
managedBeanCreator.defineEnabled();
ManagedBean<T> managedBean = managedBeanCreator.getBean();
- managedBeanCreator.defineProducerMethods(managedBean);
- managedBeanCreator.defineProducerFields(managedBean);
+ new ProducerMethodBeansBuilder(managedBean.getWebBeansContext(),
managedBean.getAnnotatedType()).defineProducerMethods(managedBean);
+ new ProducerFieldBeansBuilder(managedBean.getWebBeansContext(),
managedBean.getAnnotatedType()).defineProducerFields(managedBean);
new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
managedBean.getAnnotatedType()).defineObserverMethods(managedBean);
if (managedBean instanceof InjectionTargetBean)
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=1438338&r1=1438337&r2=1438338&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
Fri Jan 25 06:23:09 2013
@@ -51,6 +51,8 @@ import org.apache.webbeans.component.cre
import org.apache.webbeans.component.creation.DecoratorBeanBuilder;
import org.apache.webbeans.component.creation.ManagedBeanBuilder;
import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
+import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
+import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.context.DependentContext;
@@ -534,14 +536,14 @@ public abstract class TestContext implem
//Dropped from the speicification
//WebBeansUtil.checkSteroTypeRequirements(component,
clazz.getDeclaredAnnotations(), "Simple WebBean Component implementation class
: " + clazz.getName());
- Set<ProducerMethodBean<?>> producerMethods =
managedBeanCreator.defineProducerMethods(component);
+ Set<ProducerMethodBean<?>> producerMethods = new
ProducerMethodBeansBuilder(component.getWebBeansContext(),
component.getAnnotatedType()).defineProducerMethods(component);
for (ProducerMethodBean<?> producerMethod : producerMethods)
{
// add them one after the other to enable serialization handling
et al
manager.addBean(producerMethod);
}
- Set<ProducerFieldBean<?>> producerFields =
managedBeanCreator.defineProducerFields(component);
+ Set<ProducerFieldBean<?>> producerFields = new
ProducerFieldBeansBuilder(component.getWebBeansContext(),
component.getAnnotatedType()).defineProducerFields(component);
for (ProducerFieldBean<?> producerField : producerFields)
{
// add them one after the other to enable serialization handling
et al