Author: marius.bogoevici
Date: 2009-11-09 06:19:41 -0500 (Mon, 09 Nov 2009)
New Revision: 4851
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/RIBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties
Log:
WELD-265, WELD-279 - moving checkType after initialization so that everything is known
about the decorators/interceptors and passivation capabilities when the check is made.
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2009-11-09
10:59:42 UTC (rev 4850)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2009-11-09
11:19:41 UTC (rev 4851)
@@ -104,6 +104,8 @@
private final ThreadLocal<T> decoratedActualInstance = new
ThreadLocal<T>();
+ private boolean hasSerializationOrInvocationInterceptorMethods;
+
private WeldMethod<?, ?> postConstruct;
private WeldMethod<?, ?> preDestroy;
@@ -143,8 +145,6 @@
{
super.initialize(environment);
checkBeanImplementation();
- initDecorators();
- checkType();
if (isInterceptionCandidate())
{
initCdiBoundInterceptors();
@@ -163,7 +163,7 @@
}
}
- protected void checkType()
+ public void checkType()
{
}
@@ -557,12 +557,16 @@
return false;
}
- public boolean hasDirectlyDefinedInterceptors()
+ public boolean hasDirectlyDefinedInterceptors()
{
if (manager.getClassDeclaredInterceptorsRegistry().getInterceptionModel(getType())
!= null)
- return
manager.getClassDeclaredInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors().size()
> 0;
+ {
+ return hasSerializationOrInvocationInterceptorMethods ||
manager.getClassDeclaredInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors().size()
> 0;
+ }
else
+ {
return false;
+ }
}
protected void initDirectlyDefinedInterceptors()
@@ -605,7 +609,13 @@
}
}
InterceptionModel<Class<?>, Class<?>> interceptionModel =
builder.build();
- if (interceptionModel.getAllInterceptors().size() > 0 || new
InterceptorClassMetadataImpl(getType()).isInterceptor())
+ InterceptorClassMetadataImpl interceptorClassMetadata = new
InterceptorClassMetadataImpl(getType());
+ hasSerializationOrInvocationInterceptorMethods =
+
!interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.AROUND_INVOKE).isEmpty()
+ ||
!interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.AROUND_TIMEOUT).isEmpty()
+ ||
!interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.PRE_PASSIVATE).isEmpty()
+ ||
!interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.POST_ACTIVATE).isEmpty();
+ if (interceptionModel.getAllInterceptors().size() > 0 ||
hasSerializationOrInvocationInterceptorMethods)
manager.getClassDeclaredInterceptorsRegistry().registerInterceptionModel(getType(),
builder.build());
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2009-11-09 10:59:42
UTC (rev 4850)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2009-11-09 11:19:41
UTC (rev 4851)
@@ -40,6 +40,8 @@
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.PassivationCapable;
import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
@@ -61,6 +63,7 @@
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.logging.messages.BeanMessage;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
+import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Names;
import org.jboss.weld.util.Reflections;
@@ -167,7 +170,7 @@
{
try
{
- if (!isInterceptionCandidate() || !hasCdiBoundInterceptors())
+ if (!isInterceptionCandidate() || !(hasCdiBoundInterceptors() ||
hasDirectlyDefinedInterceptors()))
{
getInjectionTarget().preDestroy(instance);
}
@@ -267,10 +270,48 @@
}
}
+ @Override
+ public void initializeAfterBeanDiscovery()
+ {
+ super.initializeAfterBeanDiscovery();
+ if (this.passivationCapable && this.hasDecorators())
+ {
+ for (Decorator<?> decorator : this.getDecorators())
+ {
+ if (!(PassivationCapable.class.isAssignableFrom(decorator.getClass())) ||
!Reflections.isSerializable(decorator.getBeanClass()))
+ {
+ this.passivationCapable = false;
+ break;
+ }
+ }
+ }
+ if (this.passivationCapable && hasCdiBoundInterceptors())
+ {
+ for (SerializableContextual<Interceptor<?>, ?> interceptor :
getManager().getCdiInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors())
+ {
+ if
(!(PassivationCapable.class.isAssignableFrom(interceptor.get().getClass())) ||
!Reflections.isSerializable(interceptor.get().getBeanClass()))
+ {
+ this.passivationCapable = false;
+ break;
+ }
+ }
+ }
+ if (this.passivationCapable && hasDirectlyDefinedInterceptors())
+ {
+ for (Class<?> interceptorClass :
getManager().getClassDeclaredInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors())
+ {
+ if (!Reflections.isSerializable(interceptorClass))
+ {
+ this.passivationCapable = false;
+ break;
+ }
+ }
+ }
+ }
+
private void initPassivationCapable()
{
this.passivationCapable =
Reflections.isSerializable(getAnnotatedItem().getJavaClass());
- // TODO Add in interceptor and decorator checks
}
@Override
@@ -288,11 +329,13 @@
}
+
+
/**
* Validates the type
*/
@Override
- protected void checkType()
+ public void checkType()
{
if (getAnnotatedItem().isAnonymousClass() || (getAnnotatedItem().isMemberClass()
&& !getAnnotatedItem().isStatic()))
{
@@ -303,7 +346,7 @@
throw new DefinitionException(BEAN_MUST_BE_DEPENDENT, type);
}
boolean passivating =
manager.getServices().get(MetaAnnotationStore.class).getScopeModel(scopeType).isPassivating();
- if (passivating && !Reflections.isSerializable(getBeanClass()))
+ if (passivating && !isPassivationCapable())
{
throw new DefinitionException(PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL, this);
}
@@ -315,22 +358,29 @@
}
for (Decorator<?> decorator : getDecorators())
{
+ WeldClass<?> decoratorClass;
if (decorator instanceof DecoratorImpl<?>)
{
DecoratorImpl<?> decoratorBean = (DecoratorImpl<?>)
decorator;
- for (WeldMethod<?, ?> decoratorMethod :
decoratorBean.getAnnotatedItem().getWeldMethods())
- {
- WeldMethod<?, ?> method =
getAnnotatedItem().getWeldMethod(decoratorMethod.getSignature());
- if (method != null && !method.isStatic() &&
!method.isPrivate() && method.isFinal())
- {
- throw new
DefinitionException(FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED, method, decoratorMethod);
- }
- }
+ decoratorClass = decoratorBean.getAnnotatedItem();
}
+ else if (decorator instanceof AnnotatedItemProvidingDecoratorWrapper)
+ {
+ decoratorClass = ((AnnotatedItemProvidingDecoratorWrapper)
decorator).getAnnotatedItem();
+ }
else
{
throw new ForbiddenStateException(NON_CONTAINER_DECORATOR, decorator);
}
+
+ for (WeldMethod<?, ?> decoratorMethod :
decoratorClass.getWeldMethods())
+ {
+ WeldMethod<?, ?> method =
getAnnotatedItem().getWeldMethod(decoratorMethod.getSignature());
+ if (method != null && !method.isStatic() &&
!method.isPrivate() && method.isFinal())
+ {
+ throw new DefinitionException(FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED,
method, decoratorMethod);
+ }
+ }
}
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/RIBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/RIBean.java 2009-11-09 10:59:42 UTC
(rev 4850)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/RIBean.java 2009-11-09 11:19:41 UTC
(rev 4851)
@@ -77,6 +77,11 @@
// no-op by default
}
+ public void checkType()
+ {
+
+ }
+
public abstract boolean isSpecializing();
public boolean isDependent()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-11-09
10:59:42 UTC (rev 4850)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-11-09
11:19:41 UTC (rev 4851)
@@ -165,6 +165,7 @@
if (bean instanceof RIBean<?>)
{
((RIBean<?>) bean).initializeAfterBeanDiscovery();
+ ((RIBean<?>) bean).checkType();
}
}
}
Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties
===================================================================
---
core/trunk/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties 2009-11-09
10:59:42 UTC (rev 4850)
+++
core/trunk/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties 2009-11-09
11:19:41 UTC (rev 4851)
@@ -70,7 +70,7 @@
MISSING_BINDING_ON_INTERCEPTOR=An interceptor must have at least one binding, but {0} has
none
SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED=Simple bean {0} cannot be a non-static
inner class
BEAN_MUST_BE_DEPENDENT=Managed bean {0} must be @Dependent
-PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL=Managed bean declaring a passivating scope must
have a serializable implementation class. Bean\: {0}
+PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL=Managed bean declaring a passivating scope must
be passivation capable. Bean\: {0}
FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED=Bean class which has decorators cannot be
declared final\: {0}
FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED=Decorated bean method {0} (decorated by {1})
cannot be declared final
PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED=Normal scoped managed bean implementation
class has a public field\: {0}