Author: dallen6
Date: 2009-11-09 05:36:31 -0500 (Mon, 09 Nov 2009)
New Revision: 4849
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties
Log:
Additional exception conversion to localized messages
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java 2009-11-09
09:36:37 UTC (rev 4848)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java 2009-11-09
10:36:31 UTC (rev 4849)
@@ -16,6 +16,11 @@
*/
package org.jboss.weld.bean;
+import static org.jboss.weld.logging.messages.BeanMessage.DISPOSE_NOT_FIRST_PARAM;
+import static
org.jboss.weld.logging.messages.BeanMessage.INCONSISTENT_ANNOTATIONS_ON_METHOD;
+import static org.jboss.weld.logging.messages.BeanMessage.METHOD_NOT_BUSINESS_METHOD;
+import static org.jboss.weld.logging.messages.BeanMessage.MULTIPLE_DISPOSE_PARAMS;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -181,23 +186,23 @@
{
if
(!disposalMethodInjectionPoint.getWeldParameters().get(0).isAnnotationPresent(Disposes.class))
{
- throw new DefinitionException(disposalMethodInjectionPoint.toString() + "
doesn't have @Dispose as first parameter");
+ throw new DefinitionException(DISPOSE_NOT_FIRST_PARAM,
disposalMethodInjectionPoint);
}
if (disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).size() >
1)
{
- throw new DefinitionException(disposalMethodInjectionPoint.toString() + "
has more than one @Dispose parameters");
+ throw new DefinitionException(MULTIPLE_DISPOSE_PARAMS,
disposalMethodInjectionPoint);
}
if (disposalMethodInjectionPoint.getAnnotatedParameters(Observes.class).size() >
0)
{
- throw new DefinitionException("@Observes is not allowed on disposal method,
see " + disposalMethodInjectionPoint.toString());
+ throw new DefinitionException(INCONSISTENT_ANNOTATIONS_ON_METHOD,
"@Observes", "@Disposes", disposalMethodInjectionPoint);
}
if (disposalMethodInjectionPoint.getAnnotation(Inject.class) != null)
{
- throw new DefinitionException("@Intitializer is not allowed on a disposal
method, see " + disposalMethodInjectionPoint.toString());
+ throw new DefinitionException(INCONSISTENT_ANNOTATIONS_ON_METHOD,
"@Intitializer", "@Disposes", disposalMethodInjectionPoint);
}
if (disposalMethodInjectionPoint.getAnnotation(Produces.class) != null)
{
- throw new DefinitionException("@Produces is not allowed on a disposal
method, see " + disposalMethodInjectionPoint.toString());
+ throw new DefinitionException(INCONSISTENT_ANNOTATIONS_ON_METHOD,
"@Produces", "@Disposes", disposalMethodInjectionPoint);
}
if (getDeclaringBean() instanceof SessionBean<?>)
{
@@ -221,7 +226,7 @@
}
if (!methodDeclaredOnTypes)
{
- throw new DefinitionException("Producer method " + toString() +
" must be declared on a business interface of " + getDeclaringBean());
+ throw new DefinitionException(METHOD_NOT_BUSINESS_METHOD, this,
getDeclaringBean());
}
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java 2009-11-09
09:36:37 UTC (rev 4848)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java 2009-11-09
10:36:31 UTC (rev 4849)
@@ -17,6 +17,9 @@
package org.jboss.weld.bean;
+import static
org.jboss.weld.logging.messages.BeanMessage.CONFLICTING_INTERCEPTOR_BINDINGS;
+import static
org.jboss.weld.logging.messages.BeanMessage.MISSING_BINDING_ON_INTERCEPTOR;
+
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;
@@ -31,6 +34,7 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DeploymentException;
import org.jboss.weld.introspector.WeldClass;
+import org.jboss.weld.logging.messages.BeanMessage;
import org.jboss.weld.util.Beans;
/**
@@ -54,11 +58,11 @@
}
if (this.interceptorBindingTypes.size() == 0)
{
- throw new DeploymentException("An interceptor must have at least one
binding, but " + type.getName() + " has none");
+ throw new DeploymentException(MISSING_BINDING_ON_INTERCEPTOR, type.getName());
}
if (Beans.findInterceptorBindingConflicts(manager, interceptorBindingTypes))
{
- throw new DeploymentException("Conflicting interceptor bindings found on
" + getType());
+ throw new DeploymentException(CONFLICTING_INTERCEPTOR_BINDINGS, getType());
}
}
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 09:36:37
UTC (rev 4848)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2009-11-09 10:36:31
UTC (rev 4849)
@@ -18,8 +18,17 @@
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_DECORATED_BEAN_METHOD_NOT_ALLOWED;
+import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
+import static
org.jboss.weld.logging.messages.BeanMessage.PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR;
+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 java.util.ArrayList;
import java.util.List;
@@ -39,6 +48,7 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
import org.jboss.weld.DeploymentException;
+import org.jboss.weld.ForbiddenStateException;
import org.jboss.weld.bean.interceptor.CdiInterceptorHandlerFactory;
import org.jboss.weld.bean.interceptor.ClassInterceptionHandlerFactory;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
@@ -49,6 +59,7 @@
import org.jboss.weld.introspector.WeldConstructor;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.introspector.WeldMethod;
+import org.jboss.weld.logging.messages.BeanMessage;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Names;
@@ -57,8 +68,6 @@
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLogger.Level;
-import ch.qos.cal10n.IMessageConveyor;
-
/**
* Represents a simple bean
*
@@ -71,7 +80,6 @@
// Logger
private static final LocLogger log = loggerFactory().getLogger(BEAN);
private static final XLogger xLog = loggerFactory().getXLogger(BEAN);
- private static final IMessageConveyor messageConveyer =
loggerFactory().getMessageConveyor();
// The constructor
private ConstructorInjectionPoint<T> constructor;
@@ -144,7 +152,8 @@
Decorator<?> decorator = getDecorators().get(getDecorators().size() - 1);
InjectionPoint outerDelegateInjectionPoint =
Beans.getDelegateInjectionPoint(decorator);
if (outerDelegateInjectionPoint == null)
-{ throw new
IllegalStateException(messageConveyer.getMessage(DELEGATE_INJECTION_POINT_NOT_FOUND,
decorator));
+ {
+ throw new ForbiddenStateException(DELEGATE_INJECTION_POINT_NOT_FOUND,
decorator);
}
return
getManager().replaceOrPushCurrentInjectionPoint(outerDelegateInjectionPoint);
}
@@ -287,22 +296,22 @@
{
if (getAnnotatedItem().isAnonymousClass() || (getAnnotatedItem().isMemberClass()
&& !getAnnotatedItem().isStatic()))
{
- throw new DefinitionException("Simple bean " + type + " cannot be
a non-static inner class");
+ throw new DefinitionException(SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED,
type);
}
if (!isDependent() && getAnnotatedItem().isParameterizedType())
{
- throw new DefinitionException("Managed bean " + type + " must be
@Dependent");
+ throw new DefinitionException(BEAN_MUST_BE_DEPENDENT, type);
}
boolean passivating =
manager.getServices().get(MetaAnnotationStore.class).getScopeModel(scopeType).isPassivating();
if (passivating && !Reflections.isSerializable(getBeanClass()))
{
- throw new DefinitionException("Managed bean declaring a passivating scope
must have a serializable implementation class. Bean: " + toString());
+ throw new DefinitionException(PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL, this);
}
if (hasDecorators())
{
if (getAnnotatedItem().isFinal())
{
- throw new DefinitionException("Bean class which has decorators cannot be
declared final " + this);
+ throw new DefinitionException(FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED,
this);
}
for (Decorator<?> decorator : getDecorators())
{
@@ -314,13 +323,13 @@
WeldMethod<?, ?> method =
getAnnotatedItem().getWeldMethod(decoratorMethod.getSignature());
if (method != null && !method.isStatic() &&
!method.isPrivate() && method.isFinal())
{
- throw new DefinitionException("Decorated bean method " +
method + " (decorated by "+ decoratorMethod + ") cannot be declarted
final");
+ throw new
DefinitionException(FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED, method, decoratorMethod);
}
}
}
else
{
- throw new IllegalStateException("Can only operate on container
provided decorators " + decorator);
+ throw new ForbiddenStateException(NON_CONTAINER_DECORATOR, decorator);
}
}
}
@@ -336,7 +345,7 @@
{
if (field.isPublic() && !field.isStatic())
{
- throw new DefinitionException("Normal scoped Web Bean implementation
class has a public field " + getAnnotatedItem());
+ throw new
DefinitionException(PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED, getAnnotatedItem());
}
}
}
@@ -346,11 +355,11 @@
{
if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
{
- throw new DefinitionException("Managed bean constructor must not have a
parameter annotated @Disposes " + constructor);
+ throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR,
"@Disposes", constructor);
}
if (!constructor.getAnnotatedWBParameters(Observes.class).isEmpty())
{
- throw new DefinitionException("Managed bean constructor must not have a
parameter annotated @Observes " + constructor);
+ throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR,
"@Observes", constructor);
}
}
@@ -360,7 +369,7 @@
super.preSpecialize(environment);
if
(environment.getEjbDescriptors().contains(getAnnotatedItem().getWeldSuperclass().getJavaClass()))
{
- throw new DefinitionException("Simple bean must specialize a simple
bean");
+ throw new DefinitionException(SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN, this);
}
}
@@ -369,12 +378,12 @@
{
if (environment.getClassBean(getAnnotatedItem().getWeldSuperclass()) == null)
{
- throw new DefinitionException(toString() + " does not specialize a
bean");
+ throw new DefinitionException(SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN, this);
}
AbstractClassBean<?> specializedBean =
environment.getClassBean(getAnnotatedItem().getWeldSuperclass());
if (!(specializedBean instanceof ManagedBean))
{
- throw new DefinitionException(toString() + " doesn't have a simple bean
as a superclass " + specializedBean);
+ throw new DefinitionException(SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN, this);
} else
{
this.specializedBean = (ManagedBean<?>) specializedBean;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2009-11-09
09:36:37 UTC (rev 4848)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2009-11-09
10:36:31 UTC (rev 4849)
@@ -16,6 +16,11 @@
*/
package org.jboss.weld.bean;
+import static
org.jboss.weld.logging.messages.BeanMessage.INCONSISTENT_ANNOTATIONS_ON_METHOD;
+import static org.jboss.weld.logging.messages.BeanMessage.METHOD_NOT_BUSINESS_METHOD;
+import static org.jboss.weld.logging.messages.BeanMessage.MULTIPLE_DISPOSAL_METHODS;
+import static
org.jboss.weld.logging.messages.BeanMessage.PRODUCER_METHOD_NOT_SPECIALIZING;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -31,6 +36,7 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.DefinitionException;
+import org.jboss.weld.ForbiddenStateException;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.injection.ParameterInjectionPoint;
@@ -146,11 +152,11 @@
{
if (getAnnotatedItem().getAnnotatedWBParameters(Observes.class).size() > 0)
{
- throw new DefinitionException("Producer method cannot have parameter
annotated @Observes");
+ throw new DefinitionException(INCONSISTENT_ANNOTATIONS_ON_METHOD,
"@Produces", "@Observes");
}
else if (getAnnotatedItem().getAnnotatedWBParameters(Disposes.class).size() >
0)
{
- throw new DefinitionException("Producer method cannot have parameter
annotated @Disposes");
+ throw new DefinitionException(INCONSISTENT_ANNOTATIONS_ON_METHOD,
"@Produces", "@Disposes");
}
else if (getDeclaringBean() instanceof SessionBean<?>)
{
@@ -174,7 +180,7 @@
}
if (!methodDeclaredOnTypes)
{
- throw new DefinitionException("Producer method " + toString() +
" must be declared on a business interface of " + getDeclaringBean());
+ throw new DefinitionException(METHOD_NOT_BUSINESS_METHOD, this,
getDeclaringBean());
}
}
}
@@ -192,8 +198,7 @@
}
else if (disposalBeans.size() > 1)
{
- // TODO List out found disposal methods
- throw new DefinitionException("Cannot declare multiple disposal methods for
this producer method. Producer method: " + this + ". Disposal methods: " +
disposalBeans);
+ throw new DefinitionException(MULTIPLE_DISPOSAL_METHODS, this, disposalBeans);
}
}
@@ -277,7 +282,7 @@
{
if
(getDeclaringBean().getAnnotatedItem().getWeldSuperclass().getDeclaredWeldMethod(getAnnotatedItem().getAnnotatedMethod())
== null)
{
- throw new DefinitionException("Specialized producer method does not
override a method on the direct superclass");
+ throw new DefinitionException(PRODUCER_METHOD_NOT_SPECIALIZING, this);
}
}
@@ -287,7 +292,7 @@
WeldMethod<?, ?> superClassMethod =
getDeclaringBean().getAnnotatedItem().getWeldSuperclass().getWeldMethod(getAnnotatedItem().getAnnotatedMethod());
if (environment.getProducerMethod(superClassMethod) == null)
{
- throw new IllegalStateException(toString() + " does not specialize a
bean");
+ throw new ForbiddenStateException(PRODUCER_METHOD_NOT_SPECIALIZING, this);
}
this.specializedBean = environment.getProducerMethod(superClassMethod);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java 2009-11-09
09:36:37 UTC (rev 4848)
+++
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java 2009-11-09
10:36:31 UTC (rev 4849)
@@ -82,6 +82,20 @@
@MessageId("000061") DELEGATE_MUST_SUPPORT_EVERY_DECORATED_TYPE,
@MessageId("000062") DECORATED_TYPE_PARAMETERIZED_DELEGATE_NOT,
@MessageId("000063") DELEGATE_TYPE_PARAMETER_MISMATCH,
- @MessageId("000064") UNABLE_TO_PROCESS
+ @MessageId("000064") UNABLE_TO_PROCESS,
+ @MessageId("000065") DISPOSE_NOT_FIRST_PARAM,
+ @MessageId("000066") MULTIPLE_DISPOSE_PARAMS,
+ @MessageId("000067") INCONSISTENT_ANNOTATIONS_ON_METHOD,
+ @MessageId("000068") METHOD_NOT_BUSINESS_METHOD,
+ @MessageId("000069") MISSING_BINDING_ON_INTERCEPTOR,
+ @MessageId("000070") SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED,
+ @MessageId("000071") BEAN_MUST_BE_DEPENDENT,
+ @MessageId("000072") PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL,
+ @MessageId("000073") FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED,
+ @MessageId("000074") FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED,
+ @MessageId("000075") PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED,
+ @MessageId("000076") PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR,
+ @MessageId("000077") MULTIPLE_DISPOSAL_METHODS,
+ @MessageId("000078") PRODUCER_METHOD_NOT_SPECIALIZING
}
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
09:36:37 UTC (rev 4848)
+++
core/trunk/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties 2009-11-09
10:36:31 UTC (rev 4849)
@@ -22,6 +22,10 @@
ANNOTATION_NOT_BINDING=The annotation {0} is not a binding for {1}
DUPLICATE_BINDING=The annotation {0} is already present in the bindings list for {1}
TYPE_PARAMETER_MUST_BE_CONCRETE=Type parameter must be a concrete type\: {0}
+DISPOSE_NOT_FIRST_PARAM={0} does not have @Dispose as first parameter
+MULTIPLE_DISPOSE_PARAMS={0} has more than one @Dispose parameter
+INCONSISTENT_ANNOTATIONS_ON_METHOD={0} is not allowed on same method as {1}, see {2}
+METHOD_NOT_BUSINESS_METHOD=Method {0} must be declared on a business interface of {1}
BEAN_NOT_EE_RESOURCE_PRODUCER=The following bean is not an EE resource producer\: {0}
NULL_INSTANCE=Unable to obtain instance from {0}
VALIDATION_SERVICE_NOT_AVAILABLE=ValidationServices are not available
@@ -63,3 +67,13 @@
DECORATED_TYPE_PARAMETERIZED_DELEGATE_NOT=The decorated type is parameterized, but the
delegate type isn't. Delegate type {0} on {1}
DELEGATE_TYPE_PARAMETER_MISMATCH=The delegate type must have exactly the same type
parameters as the decorated type. Decorated type {0} on decorator {1}
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
have a serializable implementation class. 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}
+PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR=Managed bean constructor must not have a
parameter annotated {0}\: {1}
+MULTIPLE_DISPOSAL_METHODS=Cannot declare multiple disposal methods for this producer
method.\\n\\nProducer method\: {0}\\nDisposal methods\: {1}
+PRODUCER_METHOD_NOT_SPECIALIZING=Specialized producer method does not override a method
on the direct superclass\: {0}