Skip to content
Permalink
Browse files

CDI-136

  • Loading branch information...
jharting committed Nov 3, 2011
1 parent 129e820 commit 492a517f6fee29886414630224a8b775a28dc662
@@ -22,6 +22,7 @@
import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
import org.jboss.interceptor.spi.model.InterceptionModel;
import org.jboss.interceptor.util.InterceptionUtils;
import org.jboss.weld.Container;
import org.jboss.weld.bean.interceptor.SerializableContextualInterceptorReference;
import org.jboss.weld.bean.interceptor.WeldInterceptorClassMetadata;
import org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler;
@@ -66,6 +67,7 @@
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.InterceptionType;
import javax.enterprise.inject.spi.Interceptor;
import javax.enterprise.inject.spi.PassivationCapable;
import javax.inject.Scope;
import java.beans.Introspector;
import java.lang.annotation.Annotation;
@@ -257,6 +259,9 @@

protected WeldConstructor<T> constructorForEnhancedSubclass;

private boolean passivationCapableBean;
private boolean passivationCapableDependency;

/**
* Constructor
*
@@ -279,9 +284,21 @@ protected AbstractClassBean(WeldClass<T> type, String idSuffix, BeanManagerImpl
public void initialize(BeanDeployerEnvironment environment) {
super.initialize(environment);
checkBeanImplementation();
initPassivationCapable();
initTargetClassInterceptors();
}

private void initPassivationCapable() {
this.passivationCapableBean = getWeldAnnotated().isSerializable();
if (Container.instance().services().get(MetaAnnotationStore.class).getScopeModel(getScope()).isNormal()) {
this.passivationCapableDependency = true;
} else if (getScope().equals(Dependent.class) && passivationCapableBean) {
this.passivationCapableDependency = true;
} else {
this.passivationCapableDependency = false;
}
}

protected void initInterceptionModelForType() {
ClassMetadata<?> classMetadata = beanManager.getInterceptorMetadataReader().getClassMetadata(getType());

@@ -384,10 +401,26 @@ public void initializeAfterBeanDiscovery() {
initInterceptionModelForType();
}
initDecorators();
super.initializeAfterBeanDiscovery();
if (isSubclassed()) {
initEnhancedSubclass();
}
if (this.passivationCapableBean && this.hasDecorators()) {
for (Decorator<?> decorator : this.getDecorators()) {
if (!(PassivationCapable.class.isAssignableFrom(decorator.getClass())) || !((WeldDecorator<?>) decorator).getWeldAnnotated().isSerializable()) {
this.passivationCapableBean = false;
break;
}
}
}
if (this.passivationCapableBean && hasInterceptors()) {
for (InterceptorMetadata<?> interceptorMetadata : getBeanManager().getInterceptorModelRegistry().get(getType()).getAllInterceptors()) {
if (!Reflections.isSerializable(interceptorMetadata.getInterceptorClass().getJavaClass())) {
this.passivationCapableBean = false;
break;
}
}
}
super.initializeAfterBeanDiscovery();
}

public void initDecorators() {
@@ -652,4 +685,14 @@ protected void initEnhancedSubclass() {
return new InterceptedSubclassFactory<T>(getType(), Collections.<Type>emptySet(), this, enhancedMethodSignatures).getProxyClass();
}

@Override
public boolean isPassivationCapableBean() {
return passivationCapableBean;
}

@Override
public boolean isPassivationCapableDependency() {
return passivationCapableDependency;
}

}
@@ -16,11 +16,32 @@
*/
package org.jboss.weld.bean;

import static org.jboss.weld.logging.Category.BEAN;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.BeanMessage.BEAN_MUST_BE_DEPENDENT;
import static org.jboss.weld.logging.messages.BeanMessage.DELEGATE_INJECTION_POINT_NOT_FOUND;
import static org.jboss.weld.logging.messages.BeanMessage.ERROR_DESTROYING;
import static org.jboss.weld.logging.messages.BeanMessage.FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.FINAL_BEAN_CLASS_WITH_INTERCEPTORS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
import static org.jboss.weld.logging.messages.BeanMessage.PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL;
import static org.jboss.weld.logging.messages.BeanMessage.PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN;
import static org.jboss.weld.util.reflection.Reflections.cast;

import java.util.Set;

import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyObject;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;

import org.jboss.interceptor.proxy.DefaultInvocationContextFactory;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
import org.jboss.interceptor.util.InterceptionUtils;
import org.jboss.weld.Container;
import org.jboss.weld.bean.interceptor.WeldInterceptorClassMetadata;
@@ -44,33 +65,10 @@
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.reflection.Formats;
import org.jboss.weld.util.reflection.Reflections;
import org.slf4j.cal10n.LocLogger;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLogger.Level;

import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.PassivationCapable;
import java.util.Set;

import static org.jboss.weld.logging.Category.BEAN;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.BeanMessage.BEAN_MUST_BE_DEPENDENT;
import static org.jboss.weld.logging.messages.BeanMessage.DELEGATE_INJECTION_POINT_NOT_FOUND;
import static org.jboss.weld.logging.messages.BeanMessage.ERROR_DESTROYING;
import static org.jboss.weld.logging.messages.BeanMessage.FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.FINAL_BEAN_CLASS_WITH_INTERCEPTORS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
import static org.jboss.weld.logging.messages.BeanMessage.PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL;
import static org.jboss.weld.logging.messages.BeanMessage.PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN;
import static org.jboss.weld.util.reflection.Reflections.cast;

/**
* Represents a simple bean
*
@@ -228,8 +226,6 @@ protected T work() {

private ManagedBean<?> specializedBean;

private boolean passivationCapableBean;
private boolean passivationCapableDependency;
private final boolean proxiable;

/**
@@ -313,7 +309,6 @@ public void initialize(BeanDeployerEnvironment environment) {
initPostConstruct();
initPreDestroy();
initEEInjectionPoints();
initPassivationCapable();
setInjectionTarget(new ManagedBeanInjectionTarget<T>(this));
}
}
@@ -328,51 +323,6 @@ protected T createInstance(CreationalContext<T> ctx) {
}
}

@Override
public void initializeAfterBeanDiscovery() {
if (isInterceptionCandidate() && !beanManager.getInterceptorModelRegistry().containsKey(getType())) {
initInterceptionModelForType();
}
if (this.passivationCapableBean && this.hasDecorators()) {
for (Decorator<?> decorator : this.getDecorators()) {
if (!(PassivationCapable.class.isAssignableFrom(decorator.getClass())) || !((WeldDecorator<?>) decorator).getWeldAnnotated().isSerializable()) {
this.passivationCapableBean = false;
break;
}
}
}
if (this.passivationCapableBean && hasInterceptors()) {
for (InterceptorMetadata<?> interceptorMetadata : getBeanManager().getInterceptorModelRegistry().get(getType()).getAllInterceptors()) {
if (!Reflections.isSerializable(interceptorMetadata.getInterceptorClass().getJavaClass())) {
this.passivationCapableBean = false;
break;
}
}
}
super.initializeAfterBeanDiscovery();
}

private void initPassivationCapable() {
this.passivationCapableBean = getWeldAnnotated().isSerializable();
if (Container.instance().services().get(MetaAnnotationStore.class).getScopeModel(getScope()).isNormal()) {
this.passivationCapableDependency = true;
} else if (getScope().equals(Dependent.class) && passivationCapableBean) {
this.passivationCapableDependency = true;
} else {
this.passivationCapableDependency = false;
}
}

@Override
public boolean isPassivationCapableBean() {
return passivationCapableBean;
}

@Override
public boolean isPassivationCapableDependency() {
return passivationCapableDependency;
}

private void initEEInjectionPoints() {
this.ejbInjectionPoints = Beans.getEjbInjectionPoints(this, getWeldAnnotated(), getBeanManager());
this.persistenceContextInjectionPoints = Beans.getPersistenceContextInjectionPoints(this, getWeldAnnotated(), getBeanManager());
@@ -44,6 +44,7 @@
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.jlr.MethodSignatureImpl;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.AnnotatedTypes;
@@ -78,6 +79,7 @@
import static org.jboss.weld.logging.messages.BeanMessage.GENERIC_SESSION_BEAN_MUST_BE_DEPENDENT;
import static org.jboss.weld.logging.messages.BeanMessage.MESSAGE_DRIVEN_BEANS_CANNOT_BE_MANAGED;
import static org.jboss.weld.logging.messages.BeanMessage.OBSERVER_METHOD_MUST_BE_STATIC_OR_BUSINESS;
import static org.jboss.weld.logging.messages.BeanMessage.PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.SCOPE_NOT_ALLOWED_ON_SINGLETON_BEAN;
@@ -349,16 +351,10 @@ protected void checkType() {
if (!getScope().equals(Dependent.class) && getWeldAnnotated().isGeneric()) {
throw new DefinitionException(GENERIC_SESSION_BEAN_MUST_BE_DEPENDENT, this);
}
}

@Override
public boolean isPassivationCapableBean() {
return getEjbDescriptor().isStateful();
}

@Override
public boolean isPassivationCapableDependency() {
return true;
boolean passivating = beanManager.getServices().get(MetaAnnotationStore.class).getScopeModel(scope).isPassivating();
if (passivating && !isPassivationCapableBean()) {
throw new DefinitionException(PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL, this);
}
}

public InternalEjbDescriptor<T> getEjbDescriptor() {
@@ -25,7 +25,6 @@
import org.jboss.weld.bean.DecoratorImpl;
import org.jboss.weld.bean.InterceptorImpl;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bean.SessionBean;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.IllegalArgumentException;
@@ -127,8 +126,6 @@
public static boolean isPassivatingScope(Bean<?> bean, BeanManagerImpl manager) {
if (bean == null) {
return false;
} else if (bean instanceof SessionBean<?>) {
return ((SessionBean<?>) bean).getEjbDescriptor().isStateful();
} else {
return manager.getServices().get(MetaAnnotationStore.class).getScopeModel(bean.getScope()).isPassivating();
}
@@ -70,7 +70,7 @@ UNABLE_TO_PROCESS=Unable to process {0}
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 be passivation capable. Bean: {0}
PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL=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}
@@ -93,6 +93,37 @@
<exclude name="testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoProducerMethodParameterWithPassivatingScopeFails"/>
</methods>
</class>
<!-- CDI-136 -->
<class name="org.jboss.jsr299.tck.tests.context.passivating.PassivatingContextTest">
<methods>
<exclude name="testBeanWithNonSerializableImplementationInjectedIntoTransientFieldOK"/>
<exclude name="testInjectionOfDependentPrimitiveProductIntoNormalBean"/>
<exclude name="testInjectionOfDependentSerializableProductIntoNormalBean"/>
<exclude name="testManagedBeanWithSerializableDecoratorOK"/>
<exclude name="testManagedBeanWithSerializableImplementationClassOK"/>
<exclude name="testManagedBeanWithSerializableInterceptorClassOK"/>
<exclude name="testNonSerializableProducerFieldDeclaredPassivatingThrowsIllegalProductException"/>
<exclude name="testPassivatingScopeProducerMethodReturnsUnserializableObjectNotOk"/>
<exclude name="testPassivationCapableProducerFieldIsOK"/>
<exclude name="testPassivationCapableProducerMethodIsOK"/>
<exclude name="testPassivationOccurs"/>
</methods>
</class>
<class name="org.jboss.jsr299.tck.tests.implementation.enterprise.newBean.NewEnterpriseBeanTest">
<methods>
<exclude name="testForEachEnterpriseBeanANewBeanExists"/>
<exclude name="testNewBeanHasNoBeanELName"/>
<exclude name="testNewBeanHasNoObservers"/>
<exclude name="testNewBeanHasNoStereotypes"/>
<exclude name="testNewBeanIsDependentScoped"/>
<exclude name="testNewBeanIsHasOnlyNewBinding"/>
</methods>
</class>
<class name="org.jboss.jsr299.tck.tests.context.passivating.broken.enterpriseBeanWithNonPassivatingDecorator.EnterpriseBeanWithNonPassivatingDecoratorTest">
<methods>
<exclude name="testEnterpriseBeanWithNonPassivatingDecoratorFails"/>
</methods>
</class>

<!-- Issues in Weld (the RI) -->

@@ -0,0 +1,42 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.weld.tests.contexts.passivating.enterprise;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.interceptor.InterceptorBinding;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Documented
public @interface Digital {

}

0 comments on commit 492a517

Please sign in to comment.
You can’t perform that action at this time.