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/05 23:11:41 UTC
svn commit: r1429399 - 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/util/ webbeans-impl/src/t...
Author: arne
Date: Sat Jan 5 22:11:41 2013
New Revision: 1429399
URL: http://svn.apache.org/viewvc?rev=1429399&view=rev
Log:
OWB-745: Moved method from WebBeansAnnotatedTypeUtil to AbstractInjectionTargetBeanCreator
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/AbstractInjecionTargetBeanCreator.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.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=1429399&r1=1429398&r2=1429399&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 Sat Jan 5 22:11:41 2013
@@ -227,8 +227,8 @@ public final class EjbUtility
manager.getBeans().addAll(producerMethodBeans);
manager.getBeans().addAll(producerFieldBeans);
- util.defineDisposalMethods(ejbBean, ejbBean.getAnnotatedType());
-
+ EjbBeanCreatorImpl<T> ejbBeanCreator = new EjbBeanCreatorImpl<T>(ejbBean);
+ ejbBeanCreator.defineDisposalMethods();
}
private static void checkProducerMethods(Set<ProducerMethodBean<?>> producerMethodBeans, BaseEjbBean<?> bean)
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java?rev=1429399&r1=1429398&r2=1429399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java Sat Jan 5 22:11:41 2013
@@ -18,14 +18,29 @@
*/
package org.apache.webbeans.component.creation;
+import static org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.List;
import java.util.Set;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.ObserverMethod;
+import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
/**
* Abstract implementation of {@link InjectionTargetBeanCreator}.
@@ -56,7 +71,76 @@ public abstract class AbstractInjecionTa
*/
public void defineDisposalMethods()
{
- webBeansContext.getAnnotatedTypeUtil().defineDisposalMethods(getBean(), getAnnotatedType());
+ final AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
+ Set<AnnotatedMethod<? super T>> annotatedMethods = getAnnotatedType().getMethods();
+ ProducerMethodBean<?> previous = null;
+ for (AnnotatedMethod<? super T> annotatedMethod : annotatedMethods)
+ {
+ Method declaredMethod = annotatedMethod.getJavaMember();
+ AnnotatedMethod<T> annt = (AnnotatedMethod<T>)annotatedMethod;
+ List<AnnotatedParameter<T>> parameters = annt.getParameters();
+ boolean found = false;
+ for(AnnotatedParameter<T> parameter : parameters)
+ {
+ if(parameter.isAnnotationPresent(Disposes.class))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if(found)
+ {
+ WebBeansAnnotatedTypeUtil.checkProducerMethodDisposal(annotatedMethod);
+ Type type = AnnotationUtil.getAnnotatedMethodFirstParameterWithAnnotation(annotatedMethod, Disposes.class);
+ Annotation[] annot = annotationManager.getAnnotatedMethodFirstParameterQualifierWithGivenAnnotation(annotatedMethod, Disposes.class);
+
+ InjectionResolver injectionResolver = webBeansContext.getBeanManagerImpl().getInjectionResolver();
+
+ Set<Bean<?>> set = injectionResolver.implResolveByType(type, annot);
+ if (set.isEmpty())
+ {
+ throwUnsatisfiedResolutionException(type, declaredMethod, annot);
+ }
+
+ Bean<?> foundBean = set.iterator().next();
+ ProducerMethodBean<?> pr = null;
+
+ if (foundBean == null || !(foundBean instanceof ProducerMethodBean))
+ {
+ throwUnsatisfiedResolutionException(annotatedMethod.getDeclaringType().getJavaClass(), declaredMethod, annot);
+ }
+
+ pr = (ProducerMethodBean<?>) foundBean;
+
+ if (previous == null)
+ {
+ previous = pr;
+ }
+ else
+ {
+ // multiple same producer
+ if (previous.equals(pr))
+ {
+ throw new WebBeansConfigurationException("There are multiple disposal method for the producer method : " + pr.getCreatorMethod().getName() + " in class : "
+ + annotatedMethod.getDeclaringType().getJavaClass());
+ }
+ }
+
+ Method producerMethod = pr.getCreatorMethod();
+ //Disposer methods and producer methods must be in the same class
+ if(!producerMethod.getDeclaringClass().getName().equals(declaredMethod.getDeclaringClass().getName()))
+ {
+ throw new WebBeansConfigurationException("Producer method component of the disposal method : " + declaredMethod.getName() + " in class : "
+ + annotatedMethod.getDeclaringType().getJavaClass() + " must be in the same class!");
+ }
+
+ pr.setDisposalMethod(declaredMethod);
+
+ webBeansContext.getAnnotatedTypeUtil().addMethodInjectionPointMetaData(getBean(), annotatedMethod);
+
+ }
+ }
}
/**
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java?rev=1429399&r1=1429398&r2=1429399&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java Sat Jan 5 22:11:41 2013
@@ -29,7 +29,6 @@ import org.apache.webbeans.component.Pro
import org.apache.webbeans.component.ResourceBean;
import org.apache.webbeans.config.DefinitionUtil;
import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.inject.impl.InjectionPointFactory;
import org.apache.webbeans.spi.api.ResourceReference;
@@ -45,7 +44,6 @@ import javax.enterprise.inject.spi.Annot
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.ObserverMethod;
import javax.inject.Inject;
@@ -62,8 +60,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import static org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException;
-
public final class WebBeansAnnotatedTypeUtil
{
private final WebBeansContext webBeansContext;
@@ -222,81 +218,6 @@ public final class WebBeansAnnotatedType
}
@SuppressWarnings("unchecked")
- public <X> void defineDisposalMethods(AbstractInjectionTargetBean<X> bean,AnnotatedType<X> annotatedType)
- {
- final AnnotationManager annotationManager = bean.getWebBeansContext().getAnnotationManager();
- Set<AnnotatedMethod<? super X>> annotatedMethods = annotatedType.getMethods();
- ProducerMethodBean<?> previous = null;
- for (AnnotatedMethod<? super X> annotatedMethod : annotatedMethods)
- {
- Method declaredMethod = annotatedMethod.getJavaMember();
- AnnotatedMethod<X> annt = (AnnotatedMethod<X>)annotatedMethod;
- List<AnnotatedParameter<X>> parameters = annt.getParameters();
- boolean found = false;
- for(AnnotatedParameter<X> parameter : parameters)
- {
- if(parameter.isAnnotationPresent(Disposes.class))
- {
- found = true;
- break;
- }
- }
-
- if(found)
- {
- checkProducerMethodDisposal(annotatedMethod);
- Type type = AnnotationUtil.getAnnotatedMethodFirstParameterWithAnnotation(annotatedMethod, Disposes.class);
- Annotation[] annot = annotationManager.getAnnotatedMethodFirstParameterQualifierWithGivenAnnotation(annotatedMethod, Disposes.class);
-
- InjectionResolver injectionResolver = bean.getWebBeansContext().getBeanManagerImpl().getInjectionResolver();
-
- Set<Bean<?>> set = injectionResolver.implResolveByType(type, annot);
- if (set.isEmpty())
- {
- throwUnsatisfiedResolutionException(type, declaredMethod, annot);
- }
-
- Bean<?> foundBean = set.iterator().next();
- ProducerMethodBean<?> pr = null;
-
- if (foundBean == null || !(foundBean instanceof ProducerMethodBean))
- {
- throwUnsatisfiedResolutionException(annotatedMethod.getDeclaringType().getJavaClass(), declaredMethod, annot);
- }
-
- pr = (ProducerMethodBean<?>) foundBean;
-
- if (previous == null)
- {
- previous = pr;
- }
- else
- {
- // multiple same producer
- if (previous.equals(pr))
- {
- throw new WebBeansConfigurationException("There are multiple disposal method for the producer method : " + pr.getCreatorMethod().getName() + " in class : "
- + annotatedMethod.getDeclaringType().getJavaClass());
- }
- }
-
- Method producerMethod = pr.getCreatorMethod();
- //Disposer methods and producer methods must be in the same class
- if(!producerMethod.getDeclaringClass().getName().equals(declaredMethod.getDeclaringClass().getName()))
- {
- throw new WebBeansConfigurationException("Producer method component of the disposal method : " + declaredMethod.getName() + " in class : "
- + annotatedMethod.getDeclaringType().getJavaClass() + " must be in the same class!");
- }
-
- pr.setDisposalMethod(declaredMethod);
-
- addMethodInjectionPointMetaData(bean, annotatedMethod);
-
- }
- }
- }
-
- @SuppressWarnings("unchecked")
public <X> void defineInjectedMethods(AbstractInjectionTargetBean<X> bean,AnnotatedType<X> annotatedType)
{
Set<AnnotatedMethod<? super X>> annotatedMethods = annotatedType.getMethods();
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=1429399&r1=1429398&r2=1429399&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 Sat Jan 5 22:11:41 2013
@@ -44,6 +44,7 @@ import org.apache.webbeans.component.Man
import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.component.WebBeansType;
+import org.apache.webbeans.component.creation.ManagedBeanCreatorImpl;
import org.apache.webbeans.config.DefinitionUtil;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
@@ -524,7 +525,8 @@ public abstract class TestContext implem
throw new WebBeansConfigurationException("ManagedBean implementation class : " + clazz.getName() + " may not _defined as interface");
}
- ManagedBean<T> component = new ManagedBean<T>(clazz, type, anntotatedType, webBeansContext);
+ ManagedBeanCreatorImpl<T> managedBeanCreator = new ManagedBeanCreatorImpl<T>(anntotatedType, webBeansContext);
+ ManagedBean<T> component = managedBeanCreator.getBean();
component.setProducer(new InjectionTargetProducer(component));
webBeansContext.getWebBeansUtil().setInjectionTargetBeanEnableFlag(component);
@@ -567,8 +569,7 @@ public abstract class TestContext implem
producerField.setProducer(new ProducerBeansProducer(producerField));
}
-
- annotatedTypeUtil.defineDisposalMethods(component, component.getAnnotatedType());
+ managedBeanCreator.defineDisposalMethods();
annotatedTypeUtil.defineInjectedFields(component, component.getAnnotatedType());
annotatedTypeUtil.defineInjectedMethods(component, component.getAnnotatedType());
annotatedTypeUtil.defineObserverMethods(component, component.getAnnotatedType());