Author: marius.bogoevici
Date: 2010-02-19 01:36:14 -0500 (Fri, 19 Feb 2010)
New Revision: 5887
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ValidatorMessage.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties
Log:
WELD-419,WELD-424
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-02-18
21:41:01 UTC (rev 5886)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-02-19
06:36:14 UTC (rev 5887)
@@ -25,6 +25,12 @@
import static
org.jboss.weld.logging.messages.ValidatorMessage.BEAN_SPECIALIZED_TOO_MANY_TIMES;
import static
org.jboss.weld.logging.messages.ValidatorMessage.DECORATOR_CLASS_NOT_BEAN_CLASS_OF_DECORATOR;
import static
org.jboss.weld.logging.messages.ValidatorMessage.DECORATOR_SPECIFIED_TWICE;
+import static
org.jboss.weld.logging.messages.ValidatorMessage.DECORATORS_CANNOT_HAVE_DISPOSER_METHODS;
+import static
org.jboss.weld.logging.messages.ValidatorMessage.DECORATORS_CANNOT_HAVE_PRODUCER_FIELDS;
+import static
org.jboss.weld.logging.messages.ValidatorMessage.DECORATORS_CANNOT_HAVE_PRODUCER_METHODS;
+import static
org.jboss.weld.logging.messages.ValidatorMessage.INTERCEPTORS_CANNOT_HAVE_DISPOSER_METHODS;
+import static
org.jboss.weld.logging.messages.ValidatorMessage.INTERCEPTORS_CANNOT_HAVE_PRODUCER_FIELDS;
+import static
org.jboss.weld.logging.messages.ValidatorMessage.INTERCEPTORS_CANNOT_HAVE_PRODUCER_METHODS;
import static
org.jboss.weld.logging.messages.ValidatorMessage.DISPOSAL_METHODS_WITHOUT_PRODUCER;
import static org.jboss.weld.logging.messages.ValidatorMessage.INJECTION_INTO_NON_BEAN;
import static
org.jboss.weld.logging.messages.ValidatorMessage.INJECTION_INTO_NON_DEPENDENT_BEAN;
@@ -61,8 +67,10 @@
import javax.enterprise.context.Dependent;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.New;
+import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
@@ -304,7 +312,8 @@
public void validateDeployment(BeanManagerImpl manager, BeanDeployerEnvironment
environment)
{
- validateBeans(manager.getDecorators(), new ArrayList<RIBean<?>>(),
manager);
+ validateDecorators(manager.getDecorators(), new ArrayList<RIBean<?>>(),
manager);
+ validateInterceptors(manager.getInterceptors());
validateBeans(manager.getBeans(), new ArrayList<RIBean<?>>(),
manager);
validateEnabledDecoratorClasses(manager);
validateEnabledInterceptorClasses(manager);
@@ -328,6 +337,61 @@
}
}
+ public void validateInterceptors(Collection<? extends Interceptor<?>>
interceptors)
+ {
+ for (Interceptor<?> interceptor : interceptors)
+ {
+ // TODO: confirm that producer methods, fields and disposers can be only found
on Weld interceptors?
+ if (interceptor instanceof InterceptorImpl)
+ {
+ if (!((InterceptorImpl<?>)
interceptor).getWeldAnnotated().getWeldMethods(Produces.class).isEmpty())
+ {
+ throw new DefinitionException(INTERCEPTORS_CANNOT_HAVE_PRODUCER_METHODS,
interceptor);
+ }
+ if (!((InterceptorImpl<?>)
interceptor).getWeldAnnotated().getWeldFields(Produces.class).isEmpty())
+ {
+ throw new DefinitionException(INTERCEPTORS_CANNOT_HAVE_PRODUCER_FIELDS,
interceptor);
+ }
+ if (!((InterceptorImpl<?>)
interceptor).getWeldAnnotated().getDeclaredWeldMethodsWithAnnotatedParameters(Disposes.class).isEmpty())
+ {
+ throw new DefinitionException(INTERCEPTORS_CANNOT_HAVE_DISPOSER_METHODS,
interceptor);
+ }
+ }
+ }
+ }
+
+ public void validateDecorators(Collection<? extends Decorator<?>> beans,
Collection<RIBean<?>> specializedBeans, BeanManagerImpl manager)
+ {
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof RIBean<?>)
+ {
+ validateRIBean((RIBean<?>) bean, manager, specializedBeans);
+
+ if (bean instanceof WeldDecorator)
+ {
+ if (!((WeldDecorator)
bean).getWeldAnnotated().getWeldMethods(Produces.class).isEmpty())
+ {
+ throw new DefinitionException(DECORATORS_CANNOT_HAVE_PRODUCER_METHODS,
bean);
+ }
+ if (!((WeldDecorator)
bean).getWeldAnnotated().getWeldFields(Produces.class).isEmpty())
+ {
+ throw new DefinitionException(DECORATORS_CANNOT_HAVE_PRODUCER_FIELDS,
bean);
+ }
+ if (!((WeldDecorator)
bean).getWeldAnnotated().getDeclaredWeldMethodsWithAnnotatedParameters(Disposes.class).isEmpty())
+ {
+ throw new DefinitionException(DECORATORS_CANNOT_HAVE_DISPOSER_METHODS,
bean);
+ }
+ }
+
+ }
+ else
+ {
+ validateBean(bean, manager);
+ }
+ }
+ }
+
public void validateBeanNames(BeanManagerImpl beanManager)
{
SetMultimap<String, Bean<?>> namedAccessibleBeans =
Multimaps.newSetMultimap(new HashMap<String, Collection<Bean<?>>>(), new
Supplier<Set<Bean<?>>>()
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ValidatorMessage.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ValidatorMessage.java 2010-02-18
21:41:01 UTC (rev 5886)
+++
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ValidatorMessage.java 2010-02-19
06:36:14 UTC (rev 5887)
@@ -64,5 +64,12 @@
@MessageId("001424") DISPOSAL_METHODS_WITHOUT_PRODUCER,
@MessageId("001425") INJECTION_POINT_HAS_WILDCARD,
@MessageId("001426") INJECTION_POINT_MUST_HAVE_TYPE_PARAMETER,
- @MessageId("001427") NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED;
+ @MessageId("001427") NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED,
+ @MessageId("001428") DECORATORS_CANNOT_HAVE_PRODUCER_METHODS,
+ @MessageId("001429") DECORATORS_CANNOT_HAVE_PRODUCER_FIELDS,
+ @MessageId("001430")DECORATORS_CANNOT_HAVE_DISPOSER_METHODS,
+ @MessageId("001431") INTERCEPTORS_CANNOT_HAVE_PRODUCER_METHODS,
+ @MessageId("001432") INTERCEPTORS_CANNOT_HAVE_PRODUCER_FIELDS,
+ @MessageId("001433")INTERCEPTORS_CANNOT_HAVE_DISPOSER_METHODS;
+
}
Modified:
core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties
===================================================================
---
core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties 2010-02-18
21:41:01 UTC (rev 5886)
+++
core/trunk/impl/src/main/resources/org/jboss/weld/messages/validator_en.properties 2010-02-19
06:36:14 UTC (rev 5887)
@@ -26,3 +26,9 @@
INJECTION_POINT_HAS_WILDCARD=An injection point of type {0} cannot have a wildcard type
parameter: {0}
INJECTION_POINT_MUST_HAVE_TYPE_PARAMETER=An injection point of type {0} must have a type
parameter: {1}
NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED=Only field injection points can use the @Named
qualifier with no value. {0} is not a field injection point.
+DECORATORS_CANNOT_HAVE_PRODUCER_METHODS=A decorator cannot have producer methods, but at
least one was found on {0}.
+DECORATORS_CANNOT_HAVE_PRODUCER_FIELDS=A decorator cannot have producer fields, but at
least one was found on {0}.
+DECORATORS_CANNOT_HAVE_DISPOSER_METHODS=A decorator cannot have disposer methods, but at
least one was found on {0}.
+INTERCEPTORS_CANNOT_HAVE_PRODUCER_METHODS=An interceptor cannot have producer methods,
but at least one was found on {0}.
+INTERCEPTORS_CANNOT_HAVE_PRODUCER_FIELDS=An interceptor cannot have producer fields, but
at least one was found on {0}.
+INTERCEPTORS_CANNOT_HAVE_DISPOSER_METHODS=An interceptor cannot disposer methods, but at
least one was found on {0}.