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 11:27:40 UTC
svn commit: r1429493 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/creation/
main/java/org/apache/webbeans/config/ test/java/org/apache/webbeans/test/
Author: arne
Date: Sun Jan 6 10:27:40 2013
New Revision: 1429493
URL: http://svn.apache.org/viewvc?rev=1429493&view=rev
Log:
OWB-745: moved DefinitionUtil.defineScopeType() to AbstractBeanCreator
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanCreator.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/config/DefinitionUtil.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/AbstractBeanCreator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanCreator.java?rev=1429493&r1=1429492&r2=1429493&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanCreator.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanCreator.java Sun Jan 6 10:27:40 2013
@@ -25,20 +25,26 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import javax.enterprise.context.NormalScope;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.util.Nonbinding;
import javax.inject.Named;
+import javax.inject.Scope;
import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.annotation.AnyLiteral;
import org.apache.webbeans.annotation.DefaultLiteral;
+import org.apache.webbeans.annotation.DependentScopeLiteral;
import org.apache.webbeans.annotation.NamedLiteral;
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.InjectionTargetBean;
+import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.config.DefinitionUtil;
+import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
+import org.apache.webbeans.container.ExternalScope;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.util.AnnotationUtil;
@@ -196,7 +202,199 @@ public class AbstractBeanCreator<T> impl
*/
public void defineScopeType(String errorMessage, boolean allowLazyInit)
{
- definitionUtil.defineScopeType(bean, AnnotationUtil.getAnnotationsFromSet(annotated.getAnnotations()), errorMessage, false);
+ Annotation[] annotations = AnnotationUtil.getAnnotationsFromSet(annotated.getAnnotations());
+ boolean found = false;
+
+ List<ExternalScope> additionalScopes = getBean().getWebBeansContext().getBeanManagerImpl().getAdditionalScopes();
+
+ for (Annotation annotation : annotations)
+ {
+ Class<? extends Annotation> annotationType = annotation.annotationType();
+
+ /*Normal scope*/
+ Annotation var = annotationType.getAnnotation(NormalScope.class);
+ /*Pseudo scope*/
+ Annotation pseudo = annotationType.getAnnotation(Scope.class);
+
+ if (var == null && pseudo == null)
+ {
+ // check for additional scopes registered via a CDI Extension
+ for (ExternalScope additionalScope : additionalScopes)
+ {
+ if (annotationType.equals(additionalScope.getScope()))
+ {
+ // create a proxy which implements the given annotation
+ Annotation scopeAnnotation = additionalScope.getScopeAnnotation();
+
+ if (additionalScope.isNormal())
+ {
+ var = scopeAnnotation;
+ }
+ else
+ {
+ pseudo = scopeAnnotation;
+ }
+ }
+ }
+ }
+
+ if (var != null)
+ {
+ if(pseudo != null)
+ {
+ throw new WebBeansConfigurationException("Not to define both @Scope and @NormalScope on bean : " + getBean());
+ }
+
+ if (found)
+ {
+ throw new WebBeansConfigurationException(errorMessage);
+ }
+
+ found = true;
+ getBean().setImplScopeType(annotation);
+ }
+ else
+ {
+ if(pseudo != null)
+ {
+ if (found)
+ {
+ throw new WebBeansConfigurationException(errorMessage);
+ }
+
+ found = true;
+ getBean().setImplScopeType(annotation);
+ }
+ }
+ }
+
+ if (!found)
+ {
+ defineDefaultScopeType(errorMessage, allowLazyInit);
+ }
+ }
+
+
+ private void defineDefaultScopeType(String exceptionMessage, boolean allowLazyInit)
+ {
+ // Frist look for inherited scope
+ IBeanInheritedMetaData metaData = null;
+ if(getBean() instanceof InjectionTargetBean)
+ {
+ metaData = ((InjectionTargetBean<?>)getBean()).getInheritedMetaData();
+ }
+ boolean found = false;
+ if (metaData != null)
+ {
+ Annotation inheritedScope = metaData.getInheritedScopeType();
+ if (inheritedScope != null)
+ {
+ found = true;
+ getBean().setImplScopeType(inheritedScope);
+ }
+ }
+
+ if (!found)
+ {
+ Set<Class<? extends Annotation>> stereos = getBean().getStereotypes();
+ if (stereos.size() == 0)
+ {
+ getBean().setImplScopeType(new DependentScopeLiteral());
+
+ if (allowLazyInit && getBean() instanceof ManagedBean && isPurePojoBean(getBean().getWebBeansContext(), getBean().getBeanClass()))
+ {
+ // take the bean as Dependent but we could lazily initialize it
+ // because the bean doesn't contains any CDI feature
+ ((ManagedBean) getBean()).setFullInit(false);
+ }
+ }
+ else
+ {
+ Annotation defined = null;
+ Set<Class<? extends Annotation>> anns = getBean().getStereotypes();
+ for (Class<? extends Annotation> stero : anns)
+ {
+ boolean containsNormal = AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), NormalScope.class);
+
+ if (AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), NormalScope.class) ||
+ AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), Scope.class))
+ {
+ Annotation next;
+
+ if(containsNormal)
+ {
+ next = AnnotationUtil.getMetaAnnotations(stero.getDeclaredAnnotations(), NormalScope.class)[0];
+ }
+ else
+ {
+ next = AnnotationUtil.getMetaAnnotations(stero.getDeclaredAnnotations(), Scope.class)[0];
+ }
+
+ if (defined == null)
+ {
+ defined = next;
+ }
+ else
+ {
+ if (!defined.equals(next))
+ {
+ throw new WebBeansConfigurationException(exceptionMessage);
+ }
+ }
+ }
+ }
+
+ if (defined != null)
+ {
+ getBean().setImplScopeType(defined);
+ }
+ else
+ {
+ getBean().setImplScopeType(new DependentScopeLiteral());
+
+ if (allowLazyInit && getBean() instanceof ManagedBean && isPurePojoBean(getBean().getWebBeansContext(), getBean().getBeanClass()))
+ {
+ // take the bean as Dependent but we could lazily initialize it
+ // because the bean doesn't contains any CDI feature
+ ((ManagedBean) getBean()).setFullInit(false);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * TODO this should get improved.
+ * It might be enough to check for instanceof Produces and Decorates
+ *
+ *
+ * Check if the bean uses CDI features
+ * @param cls the Class to check
+ * @return <code>false</code> if the bean uses CDI annotations which define other beans somewhere
+ */
+ private boolean isPurePojoBean(WebBeansContext webBeansContext, Class<?> cls)
+ {
+ Class<?> superClass = cls.getSuperclass();
+
+ if ( superClass == Object.class || !isPurePojoBean(webBeansContext, superClass))
+ {
+ return false;
+ }
+
+ Set<String> annotations = webBeansContext.getScannerService().getAllAnnotations(cls.getSimpleName());
+ if (annotations != null)
+ {
+ for (String ann : annotations)
+ {
+ if (ann.startsWith("javax.inject") || ann.startsWith("javax.enterprise") || ann.startsWith("javax.interceptors"))
+ {
+ return false;
+ }
+ }
+
+ }
+
+ return true;
}
/**
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=1429493&r1=1429492&r2=1429493&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 10:27:40 2013
@@ -405,7 +405,7 @@ public abstract class AbstractInjecionTa
{
producerFieldBean.getTypes().addAll(annotatedField.getTypeClosure());
}
- definitionUtil.defineScopeType(producerFieldBean, anns, "Annotated producer field: " + annotatedField + "must declare default @Scope annotation", false);
+ producerFieldBeanCreator.defineScopeType("Annotated producer field: " + annotatedField + "must declare default @Scope annotation", false);
webBeansContext.getWebBeansUtil().checkUnproxiableApiType(producerFieldBean,
producerFieldBean.getScope());
WebBeansUtil.checkProducerGenericType(producerFieldBean,annotatedField.getJavaMember());
@@ -475,10 +475,8 @@ public abstract class AbstractInjecionTa
{
producerMethodBean.getTypes().addAll(annotatedMethod.getTypeClosure());
}
- definitionUtil.defineScopeType(producerMethodBean,
- AnnotationUtil.getAnnotationsFromSet(annotatedMethod.getAnnotations()),
- "Annotated producer method : " + annotatedMethod + "must declare default @Scope annotation",
- false);
+ producerMethodBeanCreator.defineScopeType("Annotated producer method : " + annotatedMethod
+ + "must declare default @Scope annotation", false);
webBeansContext.getWebBeansUtil().checkUnproxiableApiType(producerMethodBean,
producerMethodBean.getScope());
WebBeansUtil.checkProducerGenericType(producerMethodBean,annotatedMethod.getJavaMember());
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=1429493&r1=1429492&r2=1429493&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Sun Jan 6 10:27:40 2013
@@ -25,27 +25,21 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import javax.enterprise.context.NormalScope;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Named;
-import javax.inject.Scope;
import org.apache.webbeans.annotation.AnnotationManager;
-import org.apache.webbeans.annotation.DependentScopeLiteral;
import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.EnterpriseBeanMarker;
import org.apache.webbeans.component.InjectionTargetBean;
-import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.component.OwbBean;
import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
-import org.apache.webbeans.container.ExternalScope;
import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
import org.apache.webbeans.event.EventUtil;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.intercept.InterceptorData;
import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
-import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
@@ -62,87 +56,6 @@ public final class DefinitionUtil
this.webBeansContext = webBeansContext;
}
- /**
- * Configure web beans component scope type.
- *
- * @param <T> generic class type
- * @param component configuring web beans component
- * @param annotations annotations
- */
- public <T> void defineScopeType(AbstractOwbBean<T> component, Annotation[] annotations,
- String exceptionMessage, boolean allowLazyInit)
- {
- boolean found = false;
-
- List<ExternalScope> additionalScopes = component.getWebBeansContext().getBeanManagerImpl().getAdditionalScopes();
-
- for (Annotation annotation : annotations)
- {
- Class<? extends Annotation> annotationType = annotation.annotationType();
-
- /*Normal scope*/
- Annotation var = annotationType.getAnnotation(NormalScope.class);
- /*Pseudo scope*/
- Annotation pseudo = annotationType.getAnnotation(Scope.class);
-
- if (var == null && pseudo == null)
- {
- // check for additional scopes registered via a CDI Extension
- for (ExternalScope additionalScope : additionalScopes)
- {
- if (annotationType.equals(additionalScope.getScope()))
- {
- // create a proxy which implements the given annotation
- Annotation scopeAnnotation = additionalScope.getScopeAnnotation();
-
- if (additionalScope.isNormal())
- {
- var = scopeAnnotation;
- }
- else
- {
- pseudo = scopeAnnotation;
- }
- }
- }
- }
-
- if (var != null)
- {
- if(pseudo != null)
- {
- throw new WebBeansConfigurationException("Not to define both @Scope and @NormalScope on bean : " + component);
- }
-
- if (found)
- {
- throw new WebBeansConfigurationException(exceptionMessage);
- }
-
- found = true;
- component.setImplScopeType(annotation);
- }
- else
- {
- if(pseudo != null)
- {
- if (found)
- {
- throw new WebBeansConfigurationException(exceptionMessage);
- }
-
- found = true;
- component.setImplScopeType(annotation);
- }
- }
- }
-
- if (!found)
- {
- defineDefaultScopeType(component, exceptionMessage, allowLazyInit);
- }
- }
-
public <T> void defineStereoTypes(OwbBean<?> component, Annotation[] anns)
{
final AnnotationManager annotationManager = component.getWebBeansContext().getAnnotationManager();
@@ -189,130 +102,6 @@ public final class DefinitionUtil
}
- private void defineDefaultScopeType(OwbBean<?> component, String exceptionMessage, boolean allowLazyInit)
- {
- // Frist look for inherited scope
- IBeanInheritedMetaData metaData = null;
- if(component instanceof InjectionTargetBean)
- {
- metaData = ((InjectionTargetBean<?>)component).getInheritedMetaData();
- }
- boolean found = false;
- if (metaData != null)
- {
- Annotation inheritedScope = metaData.getInheritedScopeType();
- if (inheritedScope != null)
- {
- found = true;
- component.setImplScopeType(inheritedScope);
- }
- }
-
- if (!found)
- {
- Set<Class<? extends Annotation>> stereos = component.getStereotypes();
- if (stereos.size() == 0)
- {
- component.setImplScopeType(new DependentScopeLiteral());
-
- if (allowLazyInit && component instanceof ManagedBean && isPurePojoBean(component.getWebBeansContext(), component.getBeanClass()))
- {
- // take the bean as Dependent but we could lazily initialize it
- // because the bean doesn't contains any CDI feature
- ((ManagedBean) component).setFullInit(false);
- }
- }
- else
- {
- Annotation defined = null;
- Set<Class<? extends Annotation>> anns = component.getStereotypes();
- for (Class<? extends Annotation> stero : anns)
- {
- boolean containsNormal = AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), NormalScope.class);
-
- if (AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), NormalScope.class) ||
- AnnotationUtil.hasMetaAnnotation(stero.getDeclaredAnnotations(), Scope.class))
- {
- Annotation next;
-
- if(containsNormal)
- {
- next = AnnotationUtil.getMetaAnnotations(stero.getDeclaredAnnotations(), NormalScope.class)[0];
- }
- else
- {
- next = AnnotationUtil.getMetaAnnotations(stero.getDeclaredAnnotations(), Scope.class)[0];
- }
-
- if (defined == null)
- {
- defined = next;
- }
- else
- {
- if (!defined.equals(next))
- {
- throw new WebBeansConfigurationException(exceptionMessage);
- }
- }
- }
- }
-
- if (defined != null)
- {
- component.setImplScopeType(defined);
- }
- else
- {
- component.setImplScopeType(new DependentScopeLiteral());
-
- if (allowLazyInit && component instanceof ManagedBean && isPurePojoBean(component.getWebBeansContext(), component.getBeanClass()))
- {
- // take the bean as Dependent but we could lazily initialize it
- // because the bean doesn't contains any CDI feature
- ((ManagedBean) component).setFullInit(false);
- }
- }
- }
- }
-
- }
-
- /**
- * TODO this should get improved.
- * It might be enough to check for instanceof Produces and Decorates
- *
- *
- * Check if the bean uses CDI features
- * @param cls the Class to check
- * @return <code>false</code> if the bean uses CDI annotations which define other beans somewhere
- */
- private static boolean isPurePojoBean(WebBeansContext webBeansContext, Class<?> cls)
- {
- Class<?> superClass = cls.getSuperclass();
-
- if ( superClass == Object.class || !isPurePojoBean(webBeansContext, superClass))
- {
- return false;
- }
-
- Set<String> annotations = webBeansContext.getScannerService().getAllAnnotations(cls.getSimpleName());
- if (annotations != null)
- {
- for (String ann : annotations)
- {
- if (ann.startsWith("javax.inject") || ann.startsWith("javax.enterprise") || ann.startsWith("javax.interceptors"))
- {
- return false;
- }
- }
-
- }
-
- return true;
- }
-
-
/**
* Configure web beans component name.
*
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=1429493&r1=1429492&r2=1429493&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 10:27:40 2013
@@ -537,8 +537,8 @@ public abstract class TestContext implem
Annotation[] clazzAnns = clazz.getDeclaredAnnotations();
defineApiTypes(component, clazz);
- definitionUtil.defineScopeType(component, clazzAnns, "Simple WebBean Component implementation class : " + clazz.getName()
- + " stereotypes must declare same @Scope annotations", false);
+ managedBeanCreator.defineScopeType("Simple WebBean Component implementation class : " + clazz.getName()
+ + " stereotypes must declare same @Scope annotations", false);
// we fully initialize the bean in this case.
component.setFullInit(true);