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/06 16:00:13 UTC
svn commit: r1429536 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/creation/
main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/util/
test/java/org/apache/webbeans/test/
Author: arne
Date: Sun Jan 6 15:00:13 2013
New Revision: 1429536
URL: http://svn.apache.org/viewvc?rev=1429536&view=rev
Log:
OWB-745: Removed WebBeansAnnotatedTypeUtil
Removed:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
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=1429536&r1=1429535&r2=1429536&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 Sun Jan 6 15:00:13 2013
@@ -26,6 +26,7 @@ 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.HashSet;
import java.util.List;
import java.util.Set;
@@ -59,7 +60,6 @@ import org.apache.webbeans.spi.api.Resou
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
-import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
import org.apache.webbeans.util.WebBeansUtil;
/**
@@ -118,7 +118,7 @@ public abstract class AbstractInjecionTa
if(found)
{
- WebBeansAnnotatedTypeUtil.checkProducerMethodDisposal(annotatedMethod);
+ checkProducerMethodDisposal((AnnotatedMethod<T>) annotatedMethod);
Type type = AnnotationUtil.getAnnotatedMethodFirstParameterWithAnnotation(annotatedMethod, Disposes.class);
Annotation[] annot = annotationManager.getAnnotatedMethodFirstParameterQualifierWithGivenAnnotation(annotatedMethod, Disposes.class);
@@ -171,6 +171,36 @@ public abstract class AbstractInjecionTa
}
/**
+ * CheckProducerMethodDisposal.
+ * @param annotatedMethod disposal method
+ */
+ private void checkProducerMethodDisposal(AnnotatedMethod<T> annotatedMethod)
+ {
+ List<AnnotatedParameter<T>> parameters = annotatedMethod.getParameters();
+ boolean found = false;
+ for(AnnotatedParameter<T> parameter : parameters)
+ {
+ if(parameter.isAnnotationPresent(Disposes.class))
+ {
+ if(found)
+ {
+ throw new WebBeansConfigurationException("Error in definining disposal method of annotated method : " + annotatedMethod
+ + ". Multiple disposes annotation.");
+ }
+ found = true;
+ }
+ }
+
+ if(annotatedMethod.isAnnotationPresent(Inject.class)
+ || AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, Observes.class)
+ || annotatedMethod.isAnnotationPresent(Produces.class))
+ {
+ throw new WebBeansConfigurationException("Error in definining disposal method of annotated method : " + annotatedMethod
+ + ". Disposal methods can not be annotated with" + " @Initializer/@Destructor/@Produces annotation or has a parameter annotated with @Observes.");
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
public void defineInjectedFields()
@@ -249,7 +279,7 @@ public abstract class AbstractInjecionTa
continue;
}
- WebBeansAnnotatedTypeUtil.checkForInjectedInitializerMethod(getBean(), (AnnotatedMethod<T>)annotatedMethod);
+ checkForInjectedInitializerMethod((AnnotatedMethod<T>)annotatedMethod);
}
else
{
@@ -267,6 +297,45 @@ public abstract class AbstractInjecionTa
}
/**
+ * 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 = getBean().getWebBeansContext().getAnnotationManager();
+
+ List<AnnotatedParameter<T>> annotatedParameters = annotatedMethod.getParameters();
+ for (AnnotatedParameter<T> annotatedParameter : annotatedParameters)
+ {
+ annotationManager.checkForNewQualifierForDeployment(annotatedParameter.getBaseType(), annotatedMethod.getDeclaringType().getJavaClass(),
+ method.getName(), AnnotationUtil.getAnnotationsFromSet(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}
*/
public Set<ObserverMethod<?>> defineObserverMethods()
@@ -289,7 +358,7 @@ public abstract class AbstractInjecionTa
if(found)
{
- WebBeansAnnotatedTypeUtil.checkObserverMethodConditions(annotatedMethod, annotatedMethod.getDeclaringType().getJavaClass());
+ checkObserverMethodConditions((AnnotatedMethod<T>) annotatedMethod, annotatedMethod.getDeclaringType().getJavaClass());
if (getBean().getScope().equals(Dependent.class))
{
//Check Reception
@@ -321,6 +390,34 @@ public abstract class AbstractInjecionTa
return definedObservers;
}
+ private void checkObserverMethodConditions(AnnotatedMethod<T> annotatedMethod, Class<?> clazz)
+ {
+ Asserts.assertNotNull(annotatedMethod, "annotatedMethod parameter can not be null");
+ Asserts.nullCheckForClass(clazz);
+
+ Method candidateObserverMethod = annotatedMethod.getJavaMember();
+
+ if (AnnotationUtil.hasAnnotatedMethodMultipleParameterAnnotation(annotatedMethod, Observes.class))
+ {
+ throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName() + " in class : " + clazz.getName()
+ + " can not define two parameters with annotated @Observes");
+ }
+
+ if (annotatedMethod.isAnnotationPresent(Produces.class)
+ || annotatedMethod.isAnnotationPresent(Inject.class))
+ {
+ throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName() + " in class : " + clazz.getName()
+ + " can not annotated with annotation in the list {@Produces, @Initializer, @Destructor}");
+
+ }
+
+ if (AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, Disposes.class))
+ {
+ throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName() + " in class : "
+ + clazz.getName() + " can not annotated with annotation @Disposes");
+ }
+ }
+
/**
* {@inheritDoc}
*/
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1429536&r1=1429535&r2=1429536&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java Sun Jan 6 15:00:13 2013
@@ -53,7 +53,6 @@ import org.apache.webbeans.spi.ScannerSe
import org.apache.webbeans.spi.SecurityService;
import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
import org.apache.webbeans.util.ClassUtil;
-import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
import org.apache.webbeans.util.WebBeansUtil;
/**
@@ -86,7 +85,6 @@ public class WebBeansContext
private final ResolutionUtil resolutionUtil = new ResolutionUtil(this);
private final InjectionPointFactory injectionPointFactory = new InjectionPointFactory(this);
private final InterceptorUtil interceptorUtil = new InterceptorUtil(this);
- private final WebBeansAnnotatedTypeUtil annotatedTypeUtil = new WebBeansAnnotatedTypeUtil();
private final SecurityService securityService;
private final LoaderService loaderService;
private ScannerService scannerService;
@@ -227,11 +225,6 @@ public class WebBeansContext
return interceptorUtil;
}
- public WebBeansAnnotatedTypeUtil getAnnotatedTypeUtil()
- {
- return annotatedTypeUtil;
- }
-
public InjectionPointFactory getInjectionPointFactory()
{
return injectionPointFactory;
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=1429536&r1=1429535&r2=1429536&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 Sun Jan 6 15:00:13 2013
@@ -76,7 +76,6 @@ import org.apache.webbeans.test.sterotyp
import org.apache.webbeans.test.sterotype.StereoWithSessionScope2;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
-import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
import org.apache.webbeans.util.WebBeansUtil;
import org.apache.webbeans.xml.WebBeansXMLConfigurator;