Skip to content

Commit

Permalink
WELD-6
Browse files Browse the repository at this point in the history
  • Loading branch information
drallen committed Jan 4, 2010
1 parent 62b6a94 commit c840487
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 109 deletions.
96 changes: 49 additions & 47 deletions impl/src/main/java/org/jboss/weld/Validator.java
Expand Up @@ -71,9 +71,11 @@
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.AbstractProducerBean;
import org.jboss.weld.bean.DisposalMethod;
import org.jboss.weld.bean.InterceptorImpl;
import org.jboss.weld.bean.NewManagedBean;
import org.jboss.weld.bean.NewSessionBean;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bean.WeldDecorator;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.introspector.WeldAnnotated;
Expand All @@ -92,11 +94,11 @@
* Checks a list of beans for DeploymentExceptions and their subclasses
*
* @author Nicklas Karlsson
*
* @author David Allen
*/
public class Validator implements Service
{

private void validateBean(Bean<?> bean, BeanManagerImpl beanManager)
{
for (InjectionPoint ij : bean.getInjectionPoints())
Expand All @@ -109,11 +111,10 @@ private void validateBean(Bean<?> bean, BeanManagerImpl beanManager)
throw new UnproxyableResolutionException(NOT_PROXYABLE, bean);
}
}

/**
* Validate an RIBean.
*
* This includes validating whether two beans specialize the same bean
* Validate an RIBean. This includes validating whether two beans specialize
* the same bean
*
* @param bean the bean to validate
* @param beanManager the current manager
Expand All @@ -133,7 +134,7 @@ private void validateRIBean(RIBean<?> bean, BeanManagerImpl beanManager, Collect
}
specializedBeans.add(abstractBean.getSpecializedBean());
}
if (Beans.isPassivationCapableBean(bean) && bean instanceof AbstractClassBean<?>)
if ((bean instanceof AbstractClassBean<?>) && bean.isPassivationCapableBean())
{
AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
if (classBean.hasDecorators())
Expand All @@ -154,22 +155,23 @@ private void validateRIBean(RIBean<?> bean, BeanManagerImpl beanManager, Collect
}
}

@SuppressWarnings("unchecked")
private void validateDirectlyDefinedInterceptorClasses(BeanManagerImpl beanManager, AbstractClassBean<?> classBean)
{
InterceptionModel<Class<?>, Class<?>> ejbInterceptorModel = beanManager.getClassDeclaredInterceptorsRegistry().getInterceptionModel(((AbstractClassBean<?>) classBean).getType());
InterceptionModel<Class<?>, Class<?>> ejbInterceptorModel = beanManager.getClassDeclaredInterceptorsRegistry().getInterceptionModel(classBean.getType());
if (ejbInterceptorModel != null)
{
Class<?>[] classDeclaredInterceptors = ejbInterceptorModel.getAllInterceptors().toArray(new Class<?>[ejbInterceptorModel.getAllInterceptors().size()]);
if (classDeclaredInterceptors != null)
{
for (Class<?> interceptorClass: classDeclaredInterceptors)
for (Class<?> interceptorClass : classDeclaredInterceptors)
{
if (!Reflections.isSerializable(interceptorClass))
{
throw new DeploymentException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, this, interceptorClass.getName());
}
InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) beanManager.createInjectionTarget(beanManager.createAnnotatedType(interceptorClass));
for (InjectionPoint injectionPoint: injectionTarget.getInjectionPoints())
for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints())
{
Bean<?> resolvedBean = beanManager.resolve(beanManager.getInjectableBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
Expand All @@ -181,33 +183,33 @@ private void validateDirectlyDefinedInterceptorClasses(BeanManagerImpl beanManag

private void validateCdiBoundInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean)
{
InterceptionModel<Class<?>, SerializableContextual<Interceptor<?>, ?>> cdiInterceptorModel = beanManager.getCdiInterceptorsRegistry().getInterceptionModel(((AbstractClassBean<?>) classBean).getType());
InterceptionModel<Class<?>, SerializableContextual<Interceptor<?>, ?>> cdiInterceptorModel = beanManager.getCdiInterceptorsRegistry().getInterceptionModel(classBean.getType());
if (cdiInterceptorModel != null)
{
Collection<SerializableContextual<Interceptor<?>, ?>> interceptors = cdiInterceptorModel.getAllInterceptors();
if (interceptors.size() > 0)
{
for (SerializableContextual<Interceptor<?>, ?> serializableContextual : interceptors)
{
Collection<SerializableContextual<Interceptor<?>, ?>> interceptors = cdiInterceptorModel.getAllInterceptors();
if (interceptors.size() > 0)
if (!((InterceptorImpl<?>)serializableContextual.get()).isSerializable())
{
for (SerializableContextual<Interceptor<?>, ?> serializableContextual : interceptors)
{
if (!Reflections.isSerializable(serializableContextual.get().getBeanClass()))
{
throw new DeploymentException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, this, serializableContextual.get());
}
for (InjectionPoint injectionPoint: serializableContextual.get().getInjectionPoints())
{
Bean<?> resolvedBean = beanManager.resolve(beanManager.getInjectableBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
}
}
throw new DeploymentException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, classBean, serializableContextual.get());
}
for (InjectionPoint injectionPoint : serializableContextual.get().getInjectionPoints())
{
Bean<?> resolvedBean = beanManager.resolve(beanManager.getInjectableBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
}
}
}
}
}

private void validateDecorators(BeanManagerImpl beanManager, AbstractClassBean<?> classBean)
{
for (Decorator<?> decorator : classBean.getDecorators())
{
if (!Reflections.isSerializable(decorator.getBeanClass()))
if (!((WeldDecorator<?>)decorator).getAnnotatedItem().isSerializable())
{
throw new UnserializableDependencyException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_DECORATOR, classBean, decorator);
}
Expand All @@ -223,7 +225,8 @@ private void validateDecorators(BeanManagerImpl beanManager, AbstractClassBean<?
* Validate an injection point
*
* @param ij the injection point to validate
* @param declaringBean the bean into which the injectionPoint has been injected, if null, certain validations aren't available
* @param declaringBean the bean into which the injectionPoint has been
* injected, if null, certain validations aren't available
* @param beanManager
*/
public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManager)
Expand All @@ -238,7 +241,7 @@ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManage
}
if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(ij.getBean().getScope()))
{
throw new DefinitionException(INJECTION_INTO_NON_DEPENDENT_BEAN, ij);
throw new DefinitionException(INJECTION_INTO_NON_DEPENDENT_BEAN, ij);
}
if (ij.getType() instanceof TypeVariable<?>)
{
Expand All @@ -255,7 +258,7 @@ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManage
}
if (resolvedBeans.size() > 1)
{
throw new DeploymentException(INJECTION_POINT_HAS_AMBIGUOUS_DEPENDENCIES, ij, Arrays.toString(bindings) +"; Possible dependencies: " + resolvedBeans);
throw new DeploymentException(INJECTION_POINT_HAS_AMBIGUOUS_DEPENDENCIES, ij, Arrays.toString(bindings) + "; Possible dependencies: " + resolvedBeans);
}
Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
if (beanManager.getServices().get(MetaAnnotationStore.class).getScopeModel(resolvedBean.getScope()).isNormal() && !Proxies.isTypeProxyable(ij.getType()))
Expand All @@ -271,12 +274,12 @@ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManage
validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
}
}

public void validateInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager)
{
if (!ij.isTransient() && !Beans.isPassivationCapableDependency(resolvedBean))
{
if (resolvedBean.getScope().equals(Dependent.class) && resolvedBean instanceof AbstractProducerBean<?, ?,?>)
if (resolvedBean.getScope().equals(Dependent.class) && resolvedBean instanceof AbstractProducerBean<?, ?, ?>)
{
throw new IllegalProductException(NON_SERIALIZABLE_BEAN_INJECTED_INTO_PASSIVATING_BEAN, ij.getBean(), resolvedBean);
}
Expand All @@ -294,7 +297,7 @@ public void validateDeployment(BeanManagerImpl manager, BeanDeployerEnvironment
validateDisposalMethods(environment);
validateBeanNames(manager);
}

public void validateBeans(Collection<? extends Bean<?>> beans, Collection<RIBean<?>> specializedBeans, BeanManagerImpl manager)
{
for (Bean<?> bean : beans)
Expand All @@ -309,17 +312,17 @@ public void validateBeans(Collection<? extends Bean<?>> beans, Collection<RIBean
}
}
}

public void validateBeanNames(BeanManagerImpl beanManager)
{
Multimap<String, Bean<?>> namedAccessibleBeans = Multimaps.newSetMultimap(new HashMap<String, Collection<Bean<?>>>(), new Supplier<Set<Bean<?>>>()
{

public Set<Bean<?>> get()
{
return new HashSet<Bean<?>>();
}

});
for (Bean<?> bean : beanManager.getAccessibleBeans())
{
Expand All @@ -328,19 +331,19 @@ public Set<Bean<?>> get()
namedAccessibleBeans.put(bean.getName(), bean);
}
}

List<String> accessibleNamespaces = new ArrayList<String>();
for (String namespace : beanManager.getAccessibleNamespaces())
{
accessibleNamespaces.add(namespace);
}

for (String name : namedAccessibleBeans.keySet())
{
Set<Bean<?>> resolvedBeans = beanManager.getBeanResolver().resolve(namedAccessibleBeans.get(name));
if (resolvedBeans.size() > 1)
{
throw new DeploymentException(AMBIGUOUS_EL_NAME, name, resolvedBeans );
throw new DeploymentException(AMBIGUOUS_EL_NAME, name, resolvedBeans);
}
if (accessibleNamespaces.contains(name))
{
Expand All @@ -356,10 +359,9 @@ private void validateEnabledInterceptorClasses(BeanManagerImpl beanManager)
{
interceptorBeanClasses.add(interceptor.getBeanClass());
}
for (Class<?> enabledInterceptorClass: beanManager.getEnabledInterceptorClasses())
for (Class<?> enabledInterceptorClass : beanManager.getEnabledInterceptorClasses())
{
if (beanManager.getEnabledInterceptorClasses().indexOf(enabledInterceptorClass)
< beanManager.getEnabledInterceptorClasses().lastIndexOf(enabledInterceptorClass))
if (beanManager.getEnabledInterceptorClasses().indexOf(enabledInterceptorClass) < beanManager.getEnabledInterceptorClasses().lastIndexOf(enabledInterceptorClass))
{
throw new DeploymentException(INTERCEPTOR_SPECIFIED_TWICE, enabledInterceptorClass + " specified twice");
}
Expand All @@ -369,7 +371,7 @@ private void validateEnabledInterceptorClasses(BeanManagerImpl beanManager)
}
}
}

private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager)
{
// TODO Move building this list to the boot or sth
Expand All @@ -391,7 +393,6 @@ private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager)
}
}


private void validateEnabledAlternatives(BeanManagerImpl beanManager)
{
List<Class<?>> seenAlternatives = new ArrayList<Class<?>>();
Expand Down Expand Up @@ -420,7 +421,7 @@ private void validateEnabledAlternatives(BeanManagerImpl beanManager)
seenAlternatives.add(clazz);
}
}

private void validateDisposalMethods(BeanDeployerEnvironment environment)
{
Set<DisposalMethod<?, ?>> beans = environment.getUnresolvedDisposalBeans();
Expand Down Expand Up @@ -451,10 +452,11 @@ private static void checkFacadeInjectionPoint(InjectionPoint injectionPoint, Cla
throw new DefinitionException(INJECTION_POINT_MUST_HAVE_TYPE_PARAMETER, type, injectionPoint);
}
}

}

}

public void cleanup() {}
public void cleanup()
{
}

}
21 changes: 0 additions & 21 deletions impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
Expand Up @@ -41,7 +41,6 @@
import javax.enterprise.inject.Specializes;
import javax.enterprise.inject.Stereotype;
import javax.enterprise.inject.Typed;
import javax.enterprise.inject.spi.Bean;
import javax.inject.Named;
import javax.inject.Qualifier;

Expand All @@ -51,8 +50,6 @@
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.injection.WeldInjectionPoint;
import org.jboss.weld.introspector.WeldAnnotated;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.literal.AnyLiteral;
import org.jboss.weld.literal.DefaultLiteral;
import org.jboss.weld.metadata.cache.MergedStereotypes;
Expand Down Expand Up @@ -301,24 +298,6 @@ protected void initPrimitive()
this.primitive = Reflections.isPrimitive(getType());
}

private boolean checkInjectionPointsAreSerializable()
{
boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(this.getScope()).isPassivating();
for (WeldInjectionPoint<?, ?> injectionPoint : getAnnotatedInjectionPoints())
{
Annotation[] bindings = injectionPoint.getMetaAnnotationsAsArray(Qualifier.class);
Bean<?> resolvedBean = manager.getBeans(injectionPoint.getJavaClass(), bindings).iterator().next();
if (passivating)
{
if (Dependent.class.equals(resolvedBean.getScope()) && !Reflections.isSerializable(resolvedBean.getBeanClass()) && (((injectionPoint instanceof WeldField<?, ?>) && !((WeldField<?, ?>) injectionPoint).isTransient()) || (injectionPoint instanceof WeldParameter<?, ?>)))
{
return false;
}
}
}
return true;
}

/**
* Initializes the scope type
*/
Expand Down
20 changes: 12 additions & 8 deletions impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
Expand Up @@ -81,34 +81,38 @@
* An abstract bean representation common for class-based beans
*
* @author Pete Muir
* @author David Allen
*
* @param <T>
* @param <E>
* @param <T> the type of class for the bean
*/
public abstract class AbstractClassBean<T> extends AbstractBean<T, Class<T>>
{
// Logger
private static final LocLogger log = loggerFactory().getLogger(BEAN);

// The item representation
protected WeldClass<T> annotatedItem;

// The injectable fields of each type in the type hierarchy, with the actual type at the bottom
private List<Set<FieldInjectionPoint<?, ?>>> injectableFields;

// The initializer methods of each type in the type hierarchy, with the actual type at the bottom
private List<Set<MethodInjectionPoint<?, ?>>> initializerMethods;

private List<Decorator<?>> decorators;

private Class<T> proxyClassForDecorators;

// Decorators
private List<Decorator<?>> decorators;
private Class<T> proxyClassForDecorators;
private final ThreadLocal<Integer> decoratorStackPosition;
private final ThreadLocal<T> decoratedActualInstance = new ThreadLocal<T>();

private final ThreadLocal<T> decoratedActualInstance = new ThreadLocal<T>();

// Interceptors
private boolean hasSerializationOrInvocationInterceptorMethods;

// Bean callback methods
private WeldMethod<?, ?> postConstruct;
private WeldMethod<?, ?> preDestroy;

// Injection target for the bean
private InjectionTarget<T> injectionTarget;

/**
Expand Down

0 comments on commit c840487

Please sign in to comment.