Author: pete.muir(a)jboss.org
Date: 2009-06-26 08:41:22 -0400 (Fri, 26 Jun 2009)
New Revision: 2900
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanValidator.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
Log:
Split BeanValidator up a bit
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-06-26
12:14:33 UTC (rev 2899)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-06-26
12:41:22 UTC (rev 2900)
@@ -78,7 +78,6 @@
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.EventObserver;
import org.jboss.webbeans.event.ObserverImpl;
-import org.jboss.webbeans.injection.NonContextualInjector;
import org.jboss.webbeans.injection.resolution.DecoratorResolver;
import org.jboss.webbeans.injection.resolution.ResolvableFactory;
import org.jboss.webbeans.injection.resolution.ResolvableWBClass;
@@ -192,7 +191,6 @@
private transient final EventManager eventManager;
private transient final Resolver resolver;
private transient final Resolver decoratorResolver;
- private final transient NonContextualInjector nonContextualInjector;
private final transient ELResolver webbeansELResolver;
/*
@@ -293,7 +291,6 @@
this.resolver = new Resolver(this, beans);
this.decoratorResolver = new DecoratorResolver(this, decorators);
this.eventManager = new EventManager(this);
- this.nonContextualInjector = new NonContextualInjector(this);
this.webbeansELResolver = new WebBeansELResolverImpl(this);
this.childActivities = new CopyOnWriteArraySet<BeanManagerImpl>();
this.currentInjectionPoint = new ThreadLocal<Stack<InjectionPoint>>()
@@ -337,6 +334,7 @@
*
* @see javax.enterprise.inject.spi.BeanManager#addBean(javax.inject.manager.Bean)
*/
+ @Deprecated
public void addBean(Bean<?> bean)
{
synchronized (bean)
@@ -375,6 +373,11 @@
return eventManager.getObservers(event, bindings);
}
+ public <T> Set<ObserverMethod<T, ?>> resolveObserverMethods(T event,
Annotation... bindings)
+ {
+ throw new UnsupportedOperationException();
+ }
+
private void checkEventType(Type eventType)
{
Type[] types;
@@ -420,6 +423,14 @@
{
return Collections.unmodifiableList(enabledDecoratorClasses);
}
+
+ /**
+ * @return the enabledInterceptorClasses
+ */
+ public List<Class<?>> getEnabledInterceptorClasses()
+ {
+ return Collections.unmodifiableList(enabledInterceptorClasses);
+ }
/**
* Set the enabled deployment types
@@ -573,11 +584,13 @@
*
* @see
javax.enterprise.inject.spi.BeanManager#addContext(javax.enterprise.context.spi.Context)
*/
+ @Deprecated
public void addContext(Context context)
{
contexts.put(context.getScopeType(), context);
}
+ @Deprecated
public void addObserver(Observer<?> observer, Annotation... bindings)
{
addObserver(observer, eventManager.getTypeOfObserver(observer), bindings);
@@ -589,6 +602,7 @@
* @param <T>
* @param observer
*/
+ @Deprecated
public <T> void addObserver(ObserverImpl<T> observer)
{
addObserver(observer, observer.getEventType(), observer.getBindingsAsArray());
@@ -602,6 +616,7 @@
* @param bindings
* @return
*/
+ @Deprecated
public void addObserver(Observer<?> observer, Type eventType, Annotation...
bindings)
{
checkEventType(eventType);
@@ -612,6 +627,7 @@
}
}
+ @Deprecated
public void removeObserver(Observer<?> observer)
{
eventManager.removeObserver(observer);
@@ -681,7 +697,7 @@
}
- public Object getInjectableReference(Bean<?> bean, CreationalContext<?>
creationalContext)
+ public Object getReference(Bean<?> bean, CreationalContext<?>
creationalContext)
{
bean = getMostSpecializedBean(bean);
if (creationalContext instanceof CreationalContextImpl)
@@ -705,14 +721,13 @@
}
}
- /*
- * TODO this is not correct, as the current implementation of getInstance
- * does not pay attention to what type the resulting instance needs to
- * implement
- */
public Object getReference(Bean<?> bean, Type beanType,
CreationalContext<?> creationalContext)
{
- return getInjectableReference(bean, creationalContext);
+ if (!bean.getTypes().contains(beanType))
+ {
+ throw new IllegalArgumentException("The given beanType is not a type "
+ beanType +" of the bean " + bean );
+ }
+ return getReference(bean, creationalContext);
}
@SuppressWarnings("unchecked")
@@ -740,12 +755,12 @@
}
else
{
- return getInjectableReference(resolvedBean, creationalContextImpl);
+ return getReference(resolvedBean, creationalContextImpl);
}
}
else
{
- return getInjectableReference(resolvedBean, creationalContext);
+ return getReference(resolvedBean, creationalContext);
}
}
finally
@@ -821,11 +836,6 @@
// TODO Fix this cast and make the resolver return a list
return new ArrayList(decoratorResolver.get(ResolvableFactory.of(types,
bindings)));
}
-
- public List<Decorator<?>> resolveDecorators(Contextual<?> bean)
- {
- throw new UnsupportedOperationException();
- }
/**
* Resolves a list of interceptors based on interception type and interceptor
@@ -1056,9 +1066,9 @@
return (Bean<X>) key;
}
- public void validate(InjectionPoint injectionPoint)
+ public void validate(InjectionPoint ij)
{
- throw new UnsupportedOperationException("Not yet implemented");
+ getServices().get(Validator.class).validateInjectionPoint(ij, this);
}
public Set<Annotation> getInterceptorBindingTypeDefinition(Class<? extends
Annotation> bindingType)
@@ -1104,6 +1114,26 @@
@Deprecated
public <X> Bean<? extends X> getHighestPrecedenceBean(Set<Bean<?
extends X>> beans)
{
+ return resolve(beans);
+ }
+
+ public ELResolver getELResolver()
+ {
+ return webbeansELResolver;
+ }
+
+ public <T> CreationalContextImpl<T>
createCreationalContext(Contextual<T> contextual)
+ {
+ return new CreationalContextImpl<T>(contextual);
+ }
+
+ public <T> AnnotatedType<T> createAnnotatedType(Class<T> type)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public <X> Bean<? extends X> resolve(Set<Bean<? extends X>>
beans)
+ {
if (beans.size() == 1)
{
return beans.iterator().next();
@@ -1133,39 +1163,5 @@
sortedBeans.addAll(beans);
return sortedBeans.last();
}
-
- public ELResolver getELResolver()
- {
- return webbeansELResolver;
- }
-
- public <T> CreationalContextImpl<T>
createCreationalContext(Contextual<T> contextual)
- {
- return new CreationalContextImpl<T>(contextual);
- }
- /* (non-Javadoc)
- * @see javax.enterprise.inject.spi.BeanManager#createAnnotatedType(java.lang.Class)
- */
- public <T> AnnotatedType<T> createAnnotatedType(Class<T> type)
- {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see javax.enterprise.inject.spi.BeanManager#resolve(java.util.Set)
- */
- public <X> Bean<? extends X> resolve(Set<Bean<? extends X>>
beans)
- {
- return getHighestPrecedenceBean(beans);
- }
-
- /* (non-Javadoc)
- * @see
javax.enterprise.inject.spi.BeanManager#resolveObserverMethods(java.lang.Object,
java.lang.annotation.Annotation[])
- */
- public <T> Set<ObserverMethod<T, ?>> resolveObserverMethods(T event,
Annotation... bindings)
- {
- throw new UnsupportedOperationException();
- }
-
}
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanValidator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanValidator.java 2009-06-26 12:14:33
UTC (rev 2899)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanValidator.java 2009-06-26 12:41:22
UTC (rev 2900)
@@ -1,218 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.webbeans;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.lang.reflect.WildcardType;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.AmbiguousResolutionException;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.New;
-import javax.enterprise.inject.UnproxyableResolutionException;
-import javax.enterprise.inject.UnsatisfiedResolutionException;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.Decorator;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-import org.jboss.webbeans.bean.AbstractClassBean;
-import org.jboss.webbeans.bean.DecoratorBean;
-import org.jboss.webbeans.bean.NewEnterpriseBean;
-import org.jboss.webbeans.bean.NewSimpleBean;
-import org.jboss.webbeans.bean.RIBean;
-import org.jboss.webbeans.injection.resolution.ResolvableWBClass;
-import org.jboss.webbeans.introspector.WBAnnotated;
-import org.jboss.webbeans.metadata.MetaDataCache;
-import org.jboss.webbeans.util.Beans;
-import org.jboss.webbeans.util.ListComparator;
-import org.jboss.webbeans.util.Names;
-import org.jboss.webbeans.util.Proxies;
-import org.jboss.webbeans.util.Reflections;
-
-/**
- * Checks a list of beans for DeploymentExceptions and their subclasses
- *
- * @author Nicklas Karlsson
- *
- */
-public class BeanValidator
-{
-
- private final BeanManagerImpl manager;
-
- public BeanValidator(BeanManagerImpl manager)
- {
- this.manager = manager;
- }
-
- /**
- * Validates the beans
- *
- * @param beans The beans to validate
- */
- public void validate()
- {
- final List<RIBean<?>> specializedBeans = new
ArrayList<RIBean<?>>();
- for (Bean<?> bean : manager.getBeans())
- {
- for (InjectionPoint injectionPoint : bean.getInjectionPoints())
- {
- if (injectionPoint.getAnnotated().getAnnotation(New.class) != null &&
injectionPoint.getBindings().size() > 1)
- {
- throw new DefinitionException("The injection point " +
injectionPoint + " is annotated with @New which cannot be combined with other binding
types");
- }
- if (injectionPoint.getType() instanceof ParameterizedType)
- {
- ParameterizedType parameterizedType = (ParameterizedType)
injectionPoint.getType();
- for (Type type : parameterizedType.getActualTypeArguments())
- {
- if (type instanceof TypeVariable)
- {
- throw new DefinitionException("Injection point cannot have a
type variable type parameter " + injectionPoint);
- }
- if (type instanceof WildcardType)
- {
- throw new DefinitionException("Injection point cannot have a
wildcard type parameter " + injectionPoint);
- }
- }
- }
- checkFacadeInjectionPoint(injectionPoint, Instance.class);
- checkFacadeInjectionPoint(injectionPoint, Event.class);
- Annotation[] bindings = injectionPoint.getBindings().toArray(new
Annotation[0]);
- WBAnnotated<?, ?> annotatedItem =
ResolvableWBClass.of(injectionPoint.getType(), bindings, manager);
- Set<?> resolvedBeans = manager.getInjectableBeans(injectionPoint);
- if (resolvedBeans.isEmpty())
- {
- throw new UnsatisfiedResolutionException("The injection point "
+ injectionPoint + " with binding types " +
Names.annotationsToString(injectionPoint.getBindings()) + " in " + bean + "
has unsatisfied dependencies with binding types ");
- }
- if (resolvedBeans.size() > 1)
- {
- throw new AmbiguousResolutionException("The injection point " +
injectionPoint + " with binding types " +
Names.annotationsToString(injectionPoint.getBindings()) + " in " + bean + "
has ambiguous dependencies");
- }
- Bean<?> resolvedBean = (Bean<?>)
resolvedBeans.iterator().next();
- if
(manager.getServices().get(MetaDataCache.class).getScopeModel(resolvedBean.getScopeType()).isNormal()
&& !Proxies.isTypeProxyable(injectionPoint.getType()))
- {
- throw new UnproxyableResolutionException("The injection point "
+ injectionPoint + " has non-proxyable dependencies");
- }
- if (Reflections.isPrimitive(annotatedItem.getJavaClass()) &&
resolvedBean.isNullable())
- {
- throw new NullableDependencyException("The injection point " +
injectionPoint + " has nullable dependencies");
- }
- if (Beans.isPassivatingBean(bean, manager) &&
!resolvedBean.isSerializable() &&
resolvedBean.getScopeType().equals(Dependent.class))
- {
- throw new UnserializableDependencyException("The bean " + bean +
" declares a passivating scope but has non-serializable dependency: " +
resolvedBean);
- }
- }
- if (bean instanceof RIBean && !(bean instanceof NewSimpleBean)
&& !(bean instanceof NewEnterpriseBean))
- {
- RIBean<?> abstractBean = (RIBean<?>) bean;
- if (abstractBean.isSpecializing())
- {
- if (!hasHigherPrecedence(bean.getDeploymentType(),
abstractBean.getSpecializedBean().getDeploymentType()))
- {
- throw new InconsistentSpecializationException("Specializing bean
must have a higher precedence deployment type than the specialized bean: " + bean);
- }
- if (specializedBeans.contains(abstractBean.getSpecializedBean()))
- {
- throw new InconsistentSpecializationException("Two beans cannot
specialize the same bean: " + bean);
- }
- specializedBeans.add(abstractBean.getSpecializedBean());
- }
- if (Beans.isPassivatingBean(bean, manager) && bean instanceof
AbstractClassBean)
- {
- AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
- if (classBean.hasDecorators())
- {
- for (Decorator<?> decorator : classBean.getDecorators())
- {
- if (!decorator.isSerializable())
- {
- throw new UnserializableDependencyException("The bean "
+ bean + " declares a passivating scope but has non-serializable decorator: " +
decorator);
- }
- }
- }
-
- }
- }
- boolean normalScoped =
manager.getServices().get(MetaDataCache.class).getScopeModel(bean.getScopeType()).isNormal();
- if (normalScoped && !Beans.isBeanProxyable(bean))
- {
- throw new UnproxyableResolutionException("Normal scoped bean " +
bean + " is not proxyable");
- }
- }
-
- validateEnabledDecoratorClasses();
-
- }
-
- private void validateEnabledDecoratorClasses()
- {
- // TODO Move building this list to the boot or sth
- Set<Class<?>> decoratorBeanClasses = new
HashSet<Class<?>>();
- for (DecoratorBean<?> bean : manager.getDecorators())
- {
- decoratorBeanClasses.add(bean.getType());
- }
- for (Class<?> clazz : manager.getEnabledDecoratorClasses())
- {
- if (!decoratorBeanClasses.contains(clazz))
- {
- throw new DeploymentException("Enabled decorator class " + clazz +
" is not the bean class of at least one decorator bean (detected decorator beans
" + decoratorBeanClasses + ")");
- }
- }
- }
-
- private boolean hasHigherPrecedence(Class<? extends Annotation> deploymentType,
Class<? extends Annotation> otherDeploymentType)
- {
- Comparator<Class<? extends Annotation>> comparator = new
ListComparator<Class<? extends
Annotation>>(manager.getEnabledDeploymentTypes());
- return comparator.compare(deploymentType, otherDeploymentType) > 0;
- }
-
- private void checkFacadeInjectionPoint(InjectionPoint injectionPoint, Class<?>
type)
- {
- if (injectionPoint.getAnnotated().getBaseType().equals(type))
- {
- if (injectionPoint.getType() instanceof ParameterizedType)
- {
- ParameterizedType parameterizedType = (ParameterizedType)
injectionPoint.getType();
- if (parameterizedType.getActualTypeArguments()[0] instanceof TypeVariable)
- {
- throw new DefinitionException("An injection point of type " +
type + " cannot have a type variable type parameter " + injectionPoint);
- }
- if (parameterizedType.getActualTypeArguments()[0] instanceof WildcardType)
- {
- throw new DefinitionException("An injection point of type " +
type + " cannot have a wildcard type parameter " + injectionPoint);
- }
- }
- else
- {
- throw new DefinitionException("An injection point of type " + type
+ " must have a type parameter " + injectionPoint);
- }
- }
-
- }
-
-}
Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java (from rev 2898,
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanValidator.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java 2009-06-26 12:41:22 UTC
(rev 2900)
@@ -0,0 +1,238 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.AmbiguousResolutionException;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.New;
+import javax.enterprise.inject.UnproxyableResolutionException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.DecoratorBean;
+import org.jboss.webbeans.bean.NewEnterpriseBean;
+import org.jboss.webbeans.bean.NewSimpleBean;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.injection.resolution.ResolvableWBClass;
+import org.jboss.webbeans.introspector.WBAnnotated;
+import org.jboss.webbeans.metadata.MetaDataCache;
+import org.jboss.webbeans.util.Beans;
+import org.jboss.webbeans.util.ListComparator;
+import org.jboss.webbeans.util.Names;
+import org.jboss.webbeans.util.Proxies;
+import org.jboss.webbeans.util.Reflections;
+
+/**
+ * Checks a list of beans for DeploymentExceptions and their subclasses
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class Validator implements Service
+{
+
+ private void validateBean(Bean<?> bean, BeanManagerImpl beanManager)
+ {
+ for (InjectionPoint ij : bean.getInjectionPoints())
+ {
+ validateInjectionPoint(ij, beanManager);
+ }
+ boolean normalScoped =
beanManager.getServices().get(MetaDataCache.class).getScopeModel(bean.getScopeType()).isNormal();
+ if (normalScoped && !Beans.isBeanProxyable(bean))
+ {
+ throw new UnproxyableResolutionException("Normal scoped bean " + bean
+ " is not proxyable");
+ }
+ }
+
+ /**
+ * Validate an RIBean.
+ *
+ * This includes validating whether two beans specialize the same bean
+ *
+ * @param bean the bean to validate
+ * @param beanManager the current manager
+ * @param specializedBeans the existing specialized beans
+ */
+ private void validateRIBean(RIBean<?> bean, BeanManagerImpl beanManager,
List<RIBean<?>> specializedBeans)
+ {
+ validateBean(bean, beanManager);
+ if (!(bean instanceof NewSimpleBean) && !(bean instanceof
NewEnterpriseBean))
+ {
+ RIBean<?> abstractBean = bean;
+ if (abstractBean.isSpecializing())
+ {
+ if (!hasHigherPrecedence(bean.getDeploymentType(),
abstractBean.getSpecializedBean().getDeploymentType(), beanManager))
+ {
+ throw new InconsistentSpecializationException("Specializing bean must
have a higher precedence deployment type than the specialized bean: " + bean);
+ }
+ if (specializedBeans.contains(abstractBean.getSpecializedBean()))
+ {
+ throw new InconsistentSpecializationException("Two beans cannot
specialize the same bean: " + bean);
+ }
+ specializedBeans.add(abstractBean.getSpecializedBean());
+ }
+ if (Beans.isPassivatingBean(bean, beanManager) && bean instanceof
AbstractClassBean)
+ {
+ AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
+ if (classBean.hasDecorators())
+ {
+ for (Decorator<?> decorator : classBean.getDecorators())
+ {
+ if (!decorator.isSerializable())
+ {
+ throw new UnserializableDependencyException("The bean " +
bean + " declares a passivating scope but has non-serializable decorator: " +
decorator);
+ }
+ }
+ }
+
+ }
+ }
+
+ }
+
+ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManager)
+ {
+ if (ij.getAnnotated().getAnnotation(New.class) != null &&
ij.getBindings().size() > 1)
+ {
+ throw new DefinitionException("The injection point " + ij + " is
annotated with @New which cannot be combined with other binding types");
+ }
+ if (ij.getType() instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) ij.getType();
+ for (Type type : parameterizedType.getActualTypeArguments())
+ {
+ if (type instanceof TypeVariable)
+ {
+ throw new DefinitionException("Injection point cannot have a type
variable type parameter " + ij);
+ }
+ if (type instanceof WildcardType)
+ {
+ throw new DefinitionException("Injection point cannot have a wildcard
type parameter " + ij);
+ }
+ }
+ }
+ checkFacadeInjectionPoint(ij, Instance.class);
+ checkFacadeInjectionPoint(ij, Event.class);
+ Annotation[] bindings = ij.getBindings().toArray(new Annotation[0]);
+ WBAnnotated<?, ?> annotatedItem = ResolvableWBClass.of(ij.getType(),
bindings, beanManager);
+ Set<?> resolvedBeans = beanManager.getInjectableBeans(ij);
+ if (resolvedBeans.isEmpty())
+ {
+ throw new UnsatisfiedResolutionException("The injection point " + ij +
" with binding types " + Names.annotationsToString(ij.getBindings()) + "
in " + ij.getBean() + " has unsatisfied dependencies with binding types
");
+ }
+ if (resolvedBeans.size() > 1)
+ {
+ throw new AmbiguousResolutionException("The injection point " + ij +
" with binding types " + Names.annotationsToString(ij.getBindings()) + " in
" + ij.getBean() + " has ambiguous dependencies");
+ }
+ Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
+ if
(beanManager.getServices().get(MetaDataCache.class).getScopeModel(resolvedBean.getScopeType()).isNormal()
&& !Proxies.isTypeProxyable(ij.getType()))
+ {
+ throw new UnproxyableResolutionException("The injection point " + ij +
" has non-proxyable dependencies");
+ }
+ if (Reflections.isPrimitive(annotatedItem.getJavaClass()) &&
resolvedBean.isNullable())
+ {
+ throw new NullableDependencyException("The injection point " + ij +
" has nullable dependencies");
+ }
+ if (Beans.isPassivatingBean(ij.getBean(), beanManager) &&
!resolvedBean.isSerializable() &&
resolvedBean.getScopeType().equals(Dependent.class))
+ {
+ throw new UnserializableDependencyException("The bean " + ij.getBean()
+ " declares a passivating scope but has non-serializable dependency: " +
resolvedBean);
+ }
+ }
+
+ public void validateDeployment(BeanManagerImpl manager)
+ {
+ List<RIBean<?>> specializedBeans = new
ArrayList<RIBean<?>>();
+ for (Bean<?> bean : manager.getBeans())
+ {
+ if (bean instanceof RIBean)
+ {
+ validateRIBean((RIBean<?>) bean, manager, specializedBeans);
+ }
+ else
+ {
+ validateBean(bean, manager);
+ }
+ }
+ validateEnabledDecoratorClasses(manager);
+
+ }
+
+ private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager)
+ {
+ // TODO Move building this list to the boot or sth
+ Set<Class<?>> decoratorBeanClasses = new
HashSet<Class<?>>();
+ for (DecoratorBean<?> bean : beanManager.getDecorators())
+ {
+ decoratorBeanClasses.add(bean.getType());
+ }
+ for (Class<?> clazz : beanManager.getEnabledDecoratorClasses())
+ {
+ if (!decoratorBeanClasses.contains(clazz))
+ {
+ throw new DeploymentException("Enabled decorator class " + clazz +
" is not the bean class of at least one decorator bean (detected decorator beans
" + decoratorBeanClasses + ")");
+ }
+ }
+ }
+
+ private static boolean hasHigherPrecedence(Class<? extends Annotation>
deploymentType, Class<? extends Annotation> otherDeploymentType, BeanManagerImpl
manager)
+ {
+ Comparator<Class<? extends Annotation>> comparator = new
ListComparator<Class<? extends
Annotation>>(manager.getEnabledDeploymentTypes());
+ return comparator.compare(deploymentType, otherDeploymentType) > 0;
+ }
+
+ private static void checkFacadeInjectionPoint(InjectionPoint injectionPoint,
Class<?> type)
+ {
+ if (injectionPoint.getAnnotated().getBaseType().equals(type))
+ {
+ if (injectionPoint.getType() instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType)
injectionPoint.getType();
+ if (parameterizedType.getActualTypeArguments()[0] instanceof TypeVariable)
+ {
+ throw new DefinitionException("An injection point of type " +
type + " cannot have a type variable type parameter " + injectionPoint);
+ }
+ if (parameterizedType.getActualTypeArguments()[0] instanceof WildcardType)
+ {
+ throw new DefinitionException("An injection point of type " +
type + " cannot have a wildcard type parameter " + injectionPoint);
+ }
+ }
+ else
+ {
+ throw new DefinitionException("An injection point of type " + type
+ " must have a type parameter " + injectionPoint);
+ }
+ }
+
+ }
+
+}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-06-26
12:14:33 UTC (rev 2899)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-06-26
12:41:22 UTC (rev 2900)
@@ -17,10 +17,10 @@
package org.jboss.webbeans.bootstrap;
import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.BeanValidator;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.DefinitionException;
import org.jboss.webbeans.DeploymentException;
+import org.jboss.webbeans.Validator;
import org.jboss.webbeans.bean.standard.EventBean;
import org.jboss.webbeans.bean.standard.InjectionPointBean;
import org.jboss.webbeans.bean.standard.InstanceBean;
@@ -132,6 +132,7 @@
// TODO expose AnnotatedClass on SPI and allow container to provide impl of this
via ResourceLoader
getServices().add(ClassTransformer.class, new ClassTransformer());
getServices().add(MetaDataCache.class, new
MetaDataCache(getServices().get(ClassTransformer.class)));
+ getServices().add(Validator.class, new Validator());
}
public BeanManagerImpl getManager()
@@ -207,7 +208,7 @@
registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses(),
ejbDescriptors);
fireAfterBeanDiscoveryEvent();
log.debug("Web Beans initialized. Validating beans.");
- new BeanValidator(manager).validate();
+ getServices().get(Validator.class).validateDeployment(manager);
// TODO I don't really think this is needed anymore, as we validate all
points
manager.getResolver().resolveInjectionPoints();
fireAfterDeploymentValidationEvent();
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolverImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolverImpl.java 2009-06-26
12:14:33 UTC (rev 2899)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolverImpl.java 2009-06-26
12:41:22 UTC (rev 2900)
@@ -137,7 +137,7 @@
CreationalContext<?> creationalContext =
manager.createCreationalContext(bean);
if (bean != null)
{
- holder.setValue(manager.getInjectableReference(bean, creationalContext));
+ holder.setValue(manager.getReference(bean, creationalContext));
}
creationalContext.release();
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-06-26
12:14:33 UTC (rev 2899)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-06-26
12:41:22 UTC (rev 2900)
@@ -176,7 +176,7 @@
{
creationalContext = manager.createCreationalContext(observerBean);
}
- instance = manager.getInjectableReference(observerBean, creationalContext);
+ instance = manager.getReference(observerBean, creationalContext);
if (instance == null)
{
return;
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java 2009-06-26
12:14:33 UTC (rev 2899)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java 2009-06-26
12:41:22 UTC (rev 2900)
@@ -40,7 +40,6 @@
@Test
public void testNoParameterizedCollectionInjection()
{
- assert getCurrentManager().getInstanceByType(Collection.class).size() == 3;
NoParameterizedCollectionInjection item =
getCurrentManager().getInstanceByType(NoParameterizedCollectionInjection.class);
assert item.getFieldInjection().size() == 3;