You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ar...@apache.org on 2013/01/24 22:42:04 UTC
svn commit: r1438210 - in /openwebbeans/trunk:
webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/
webbeans-impl/src/main/java/org/apache/webbeans/component/creation/
webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/ webbeans-imp...
Author: arne
Date: Thu Jan 24 21:42:03 2013
New Revision: 1438210
URL: http://svn.apache.org/viewvc?rev=1438210&view=rev
Log:
OWB-770: Moved creation of InjectionPoints to InjectionPointFactory
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/AbstractBeanBuilder.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/component/creation/DecoratorBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.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=1438210&r1=1438209&r2=1438210&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 Thu Jan 24 21:42:03 2013
@@ -96,9 +96,6 @@ public final class EjbUtility
Set<ProducerMethodBean<?>> producerMethodBeans = ejbBeanCreator.defineProducerMethods(ejbBean);
checkProducerMethods(producerMethodBeans, ejbBean);
Set<ProducerFieldBean<?>> producerFieldBeans = ejbBeanCreator.defineProducerFields(ejbBean);
- ejbBeanCreator.defineInjectedFields();
- ejbBeanCreator.defineInjectedMethods();
- ejbBeanCreator.defineDisposalMethods();
Set<ObserverMethod<?>> observerMethods = ejbBeanCreator.defineObserverMethods(ejbBean);
//Fires ProcessInjectionTarget
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1438210&r1=1438209&r2=1438210&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java Thu Jan 24 21:42:03 2013
@@ -23,11 +23,8 @@ import static org.apache.webbeans.util.I
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.HashSet;
-import java.util.Set;
import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedMember;
import javax.enterprise.inject.spi.Bean;
import org.apache.webbeans.component.BeanAttributesImpl;
@@ -52,8 +49,6 @@ public abstract class AbstractBeanBuilde
private BeanAttributesImpl<T> beanAttributes;
- private Set<AnnotatedMember<? super T>> injectionPoints = new HashSet<AnnotatedMember<? super T>>();
-
/**
* Creates a bean instance.
*
@@ -82,19 +77,6 @@ public abstract class AbstractBeanBuilde
//Sub-class can override this
}
- protected void addInjectionPoint(AnnotatedMember<? super T> member)
- {
- injectionPoints.add(member);
- }
-
- /**
- * @return the AnnotatedMember of all found injection points <i>before</i> InjectionPoint will be constructed from it.
- */
- protected Set<AnnotatedMember<? super T>> getInjectionPointsAnnotated()
- {
- return injectionPoints;
- }
-
/**
* Checks the unproxiable condition.
* @throws org.apache.webbeans.exception.WebBeansConfigurationException if bean is not proxied by the container
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=1438210&r1=1438209&r2=1438210&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 Thu Jan 24 21:42:03 2013
@@ -24,7 +24,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -49,7 +48,6 @@ import javax.enterprise.inject.spi.Obser
import javax.inject.Inject;
import javax.inject.Named;
-import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.ProducerFieldBean;
@@ -163,155 +161,6 @@ public abstract class AbstractInjectionT
return result;
}
- public void defineDisposalMethods()
- {
- Set<AnnotatedMethod<? super T>> annotatedMethods = getAnnotated().getMethods();
-
- for (AnnotatedMethod<? super T> annotatedMethod : annotatedMethods)
- {
- for (AnnotatedParameter<? super T> annotatedParameter : annotatedMethod.getParameters())
- {
- if (annotatedParameter.isAnnotationPresent(Disposes.class))
- {
- addInjectionPoint(annotatedMethod);
- }
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void defineInjectedFields()
- {
- AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
-
- Set<AnnotatedField<? super T>> annotatedFields = getAnnotated().getFields();
- for(AnnotatedField<? super T> annotatedField: annotatedFields)
- {
- if(Modifier.isPublic(annotatedField.getJavaMember().getModifiers()) && !annotatedField.isStatic())
- {
- if(webBeansContext.getBeanManagerImpl().isNormalScope(getBeanAttributes().getScope()))
- {
- throw new WebBeansConfigurationException("If bean has a public field, bean scope must be defined as @Scope. Bean is : "
- + getBeanType().getName());
- }
- }
-
- if(!annotatedField.isAnnotationPresent(Inject.class))
- {
- continue;
- }
-
- if (annotatedField.isAnnotationPresent(Produces.class))
- {
- throw new WebBeansConfigurationException("Injection fields can not be annotated with @Produces");
- }
-
- Field field = annotatedField.getJavaMember();
- Annotation[] anns = AnnotationUtil.asArray(annotatedField.getAnnotations());
- if(Modifier.isPublic(field.getModifiers()))
- {
- if(!getBeanAttributes().getScope().equals(Dependent.class))
- {
- throw new WebBeansConfigurationException("Error in annotated field : " + annotatedField
- +" while definining injected field. If bean has a public modifier injection point, bean scope must be defined as @Dependent");
- }
- }
-
- Annotation[] qualifierAnns = annotationManager.getQualifierAnnotations(anns);
-
- if (qualifierAnns.length > 0)
- {
- if (qualifierAnns.length > 0)
- {
- annotationManager.checkForNewQualifierForDeployment(annotatedField.getBaseType(), annotatedField.getDeclaringType().getJavaClass(), field.getName(), anns);
- }
-
- int mod = field.getModifiers();
-
- if (!Modifier.isStatic(mod) && !Modifier.isFinal(mod))
- {
- addInjectionPoint(annotatedField);
- }
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void defineInjectedMethods()
- {
- Set<AnnotatedMethod<? super T>> annotatedMethods = getAnnotated().getMethods();
-
- for (AnnotatedMethod<? super T> annotatedMethod : annotatedMethods)
- {
- boolean isInitializer = annotatedMethod.isAnnotationPresent(Inject.class);
-
- if (isInitializer)
- {
- //Do not support static
- if(annotatedMethod.isStatic())
- {
- continue;
- }
-
- checkForInjectedInitializerMethod((AnnotatedMethod<T>)annotatedMethod);
- }
- else
- {
- continue;
- }
-
- Method method = annotatedMethod.getJavaMember();
-
- if (!Modifier.isStatic(method.getModifiers()))
- {
- addInjectionPoint(annotatedMethod);
- }
- }
- }
-
- /**
- * add the definitions for a @Initializer method.
- */
- private void checkForInjectedInitializerMethod(AnnotatedMethod<T> annotatedMethod)
- {
- Method method = annotatedMethod.getJavaMember();
-
- TypeVariable<?>[] args = method.getTypeParameters();
- if(args.length > 0)
- {
- throw new WebBeansConfigurationException("Error in defining injected methods in annotated method : " + annotatedMethod+
- ". Reason : Initializer methods must not be generic.");
- }
-
- if (annotatedMethod.isAnnotationPresent(Produces.class))
- {
- throw new WebBeansConfigurationException("Error in defining injected methods in annotated method : " + annotatedMethod+
- ". Reason : Initializer method can not be annotated with @Produces.");
-
- }
-
- AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
-
- List<AnnotatedParameter<T>> annotatedParameters = annotatedMethod.getParameters();
- for (AnnotatedParameter<T> annotatedParameter : annotatedParameters)
- {
- annotationManager.checkForNewQualifierForDeployment(annotatedParameter.getBaseType(), annotatedMethod.getDeclaringType().getJavaClass(),
- method.getName(), AnnotationUtil.asArray(annotatedParameter.getAnnotations()));
-
- if(annotatedParameter.isAnnotationPresent(Disposes.class) ||
- annotatedParameter.isAnnotationPresent(Observes.class))
- {
- throw new WebBeansConfigurationException("Error in defining injected methods in annotated method : " + annotatedMethod+
- ". Reason : Initializer method parameters does not contain @Observes or @Dispose annotations.");
-
- }
- }
- }
-
/**
* {@inheritDoc}
*/
@@ -349,9 +198,6 @@ public abstract class AbstractInjectionT
}
}
- //Add injection point data
- addInjectionPoint(annotatedMethod);
-
//Looking for ObserverMethod
ObserverMethod<?> definedObserver = webBeansContext.getBeanManagerImpl().getNotificationManager().getObservableMethodForAnnotatedMethod(annotatedMethod, bean);
if(definedObserver != null)
@@ -501,7 +347,6 @@ public abstract class AbstractInjectionT
producerMethodBeanCreator.checkUnproxiableApiType();
- producerMethodBeanCreator.addInjectionPoint(annotatedMethod);
ProducerMethodBean<T> producerMethodBean = producerMethodBeanCreator.getBean();
if(specialize)
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java?rev=1438210&r1=1438209&r2=1438210&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java Thu Jan 24 21:42:03 2013
@@ -164,8 +164,6 @@ public class DecoratorBeanBuilder<T> ext
checkDecoratorConditions();
defineConstructor();
- defineInjectedMethods();
- defineInjectedFields();
defineDecoratedTypes();
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1438210&r1=1438209&r2=1438210&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java Thu Jan 24 21:42:03 2013
@@ -122,8 +122,6 @@ public abstract class InterceptorBeanBui
{
defineConstructor();
defineInterceptorMethods();
- defineInjectedMethods();
- defineInjectedFields();
}
/**
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java?rev=1438210&r1=1438209&r2=1438210&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java Thu Jan 24 21:42:03 2013
@@ -89,9 +89,6 @@ public class ManagedBeanBuilder<T, M ext
checkCreateConditions();
defineConstructor();
- defineInjectedFields();
- defineInjectedMethods();
- defineDisposalMethods();
return getBean();
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=1438210&r1=1438209&r2=1438210&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java Thu Jan 24 21:42:03 2013
@@ -19,7 +19,10 @@
package org.apache.webbeans.inject.impl;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -28,6 +31,8 @@ import java.util.List;
import java.util.Set;
import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
@@ -39,8 +44,10 @@ import javax.enterprise.inject.spi.Injec
import javax.inject.Inject;
import javax.inject.Named;
+import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.annotation.NamedLiteral;
import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
@@ -65,6 +72,14 @@ public class InjectionPointFactory
}
for (AnnotatedField<? super X> field: annotatedType.getFields())
{
+ if (owner != null && Modifier.isPublic(field.getJavaMember().getModifiers()) && !field.isStatic())
+ {
+ if (webBeansContext.getBeanManagerImpl().isNormalScope(owner.getScope()))
+ {
+ throw new WebBeansConfigurationException("If bean has a public field, bean scope must be defined as @Scope. Bean is : "
+ + owner.getBeanClass().getName());
+ }
+ }
if (field.isAnnotationPresent(Inject.class))
{
injectionPoints.add(buildInjectionPoint(owner, field));
@@ -72,8 +87,9 @@ public class InjectionPointFactory
}
for (AnnotatedMethod<? super X> method: annotatedType.getMethods())
{
- if (method.isAnnotationPresent(Inject.class))
+ if (method.isAnnotationPresent(Inject.class) && !Modifier.isStatic(method.getJavaMember().getModifiers()))
{
+ checkForInjectedInitializerMethod(method);
buildInjectionPoints(owner, method, injectionPoints);
}
}
@@ -139,4 +155,42 @@ public class InjectionPointFactory
{
return new InjectionPointImpl(owner, type, Arrays.asList(bindings), parameter);
}
+
+ /**
+ * add the definitions for a @Initializer method.
+ */
+ private void checkForInjectedInitializerMethod(AnnotatedMethod<?> annotatedMethod)
+ {
+ Method method = annotatedMethod.getJavaMember();
+
+ TypeVariable<?>[] args = method.getTypeParameters();
+ if(args.length > 0)
+ {
+ throw new WebBeansConfigurationException("Error in defining injected methods in annotated method : " + annotatedMethod+
+ ". Reason : Initializer methods must not be generic.");
+ }
+
+ if (annotatedMethod.isAnnotationPresent(Produces.class))
+ {
+ throw new WebBeansConfigurationException("Error in defining injected methods in annotated method : " + annotatedMethod+
+ ". Reason : Initializer method can not be annotated with @Produces.");
+
+ }
+
+ AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
+
+ for (AnnotatedParameter<?> annotatedParameter : annotatedMethod.getParameters())
+ {
+ annotationManager.checkForNewQualifierForDeployment(annotatedParameter.getBaseType(), annotatedMethod.getDeclaringType().getJavaClass(),
+ method.getName(), AnnotationUtil.asArray(annotatedParameter.getAnnotations()));
+
+ if(annotatedParameter.isAnnotationPresent(Disposes.class) ||
+ annotatedParameter.isAnnotationPresent(Observes.class))
+ {
+ throw new WebBeansConfigurationException("Error in defining injected methods in annotated method : " + annotatedMethod+
+ ". Reason : Initializer method parameters does not contain @Observes or @Dispose annotations.");
+
+ }
+ }
+ }
}
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=1438210&r1=1438209&r2=1438210&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 Thu Jan 24 21:42:03 2013
@@ -436,8 +436,6 @@ public final class WebBeansUtil
BeanAttributesImpl<T> newBeanAttributes = new BeanAttributesImpl<T>(defaultBeanAttributes.getTypes(), Collections.<Annotation>singleton(new NewLiteral(type)));
// TODO replace this by InjectionPointBuilder
ManagedBeanBuilder<T, ManagedBean<T>> beanBuilder = new ManagedBeanBuilder<T, ManagedBean<T>>(webBeansContext, annotatedType, newBeanAttributes);
- beanBuilder.defineInjectedFields();
- beanBuilder.defineInjectedMethods();
beanBuilder.defineConstructor();
NewManagedBean<T> newBean
= new NewManagedBean<T>(webBeansContext, WebBeansType.MANAGED, annotatedType, newBeanAttributes, type, beanBuilder.getBean().getInjectionPoints());
@@ -1603,9 +1601,6 @@ public final class WebBeansUtil
setInjectionTargetBeanEnableFlag(managedBeanCreator.getBean());
managedBeanCreator.checkCreateConditions();
managedBeanCreator.defineConstructor();
- managedBeanCreator.defineInjectedFields();
- managedBeanCreator.defineInjectedMethods();
- managedBeanCreator.defineDisposalMethods();
ManagedBean<T> managedBean = managedBeanCreator.getBean();
managedBeanCreator.defineProducerMethods(managedBean);
managedBeanCreator.defineProducerFields(managedBean);
@@ -1738,9 +1733,6 @@ public final class WebBeansUtil
managedBeanCreator.defineEnabled();
managedBeanCreator.checkCreateConditions();
managedBeanCreator.defineConstructor();
- managedBeanCreator.defineInjectedFields();
- managedBeanCreator.defineInjectedMethods();
- managedBeanCreator.defineDisposalMethods();
ManagedBean<T> managedBean = managedBeanCreator.getBean();
managedBeanCreator.defineProducerMethods(managedBean);
managedBeanCreator.defineProducerFields(managedBean);
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=1438210&r1=1438209&r2=1438210&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 Thu Jan 24 21:42:03 2013
@@ -528,9 +528,6 @@ public abstract class TestContext implem
managedBeanCreator.checkCreateConditions();
managedBeanCreator.defineEnabled();
managedBeanCreator.defineConstructor();
- managedBeanCreator.defineInjectedFields();
- managedBeanCreator.defineInjectedMethods();
- managedBeanCreator.defineDisposalMethods();
ManagedBean<T> component = managedBeanCreator.getBean();
List<AnnotatedMethod<?>> postConstructMethods
= webBeansContext.getInterceptorUtil().getLifecycleMethods(component.getAnnotatedType(), PostConstruct.class, true);