Skip to content

Commit

Permalink
Additional exception message conversion for localization
Browse files Browse the repository at this point in the history
  • Loading branch information
drallen committed Nov 23, 2009
1 parent fef030d commit 741259a
Show file tree
Hide file tree
Showing 30 changed files with 269 additions and 52 deletions.
5 changes: 5 additions & 0 deletions impl/src/main/java/org/jboss/weld/WeldException.java
Expand Up @@ -32,6 +32,11 @@ public class WeldException extends RuntimeException
// Exception messages
private static final IMessageConveyor messageConveyer = loggerFactory().getMessageConveyor();

public WeldException(Throwable throwable)
{
super(throwable);
}

public <E extends Enum<?>> WeldException(E key, Object... args)
{
super(messageConveyer.getMessage(key, args));
Expand Down
Expand Up @@ -17,8 +17,8 @@
package org.jboss.weld.injection;

import static org.jboss.weld.injection.Exceptions.rethrowException;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_REQUIRED;

import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
Expand All @@ -37,6 +37,7 @@
import javax.enterprise.inject.spi.Bean;

import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.InvalidObjectException;
import org.jboss.weld.introspector.ConstructorSignature;
import org.jboss.weld.introspector.ForwardingWeldConstructor;
import org.jboss.weld.introspector.WeldClass;
Expand Down Expand Up @@ -216,7 +217,7 @@ private Object writeReplace() throws ObjectStreamException

private void readObject(ObjectInputStream stream) throws InvalidObjectException
{
throw new InvalidObjectException("Proxy required");
throw new InvalidObjectException(PROXY_REQUIRED);
}

private static class SerializationProxy<T> extends WeldInjectionPointSerializationProxy<T, Constructor<T>>
Expand Down
6 changes: 4 additions & 2 deletions impl/src/main/java/org/jboss/weld/injection/Exceptions.java
Expand Up @@ -20,6 +20,8 @@

import javax.enterprise.inject.CreationException;

import org.jboss.weld.WeldException;

class Exceptions
{

Expand All @@ -38,11 +40,11 @@ private static void rethrowException(Throwable t, Class<? extends RuntimeExcepti
}
catch (InstantiationException e1)
{
throw new RuntimeException(e1);
throw new WeldException(e1);
}
catch (IllegalAccessException e1)
{
throw new RuntimeException(e1);
throw new WeldException(e1);
}
e.initCause(t);
throw e;
Expand Down
Expand Up @@ -17,8 +17,8 @@
package org.jboss.weld.injection;

import static org.jboss.weld.injection.Exceptions.rethrowException;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_REQUIRED;

import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
Expand All @@ -37,6 +37,7 @@

import org.jboss.interceptor.util.InterceptionUtils;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.InvalidObjectException;
import org.jboss.weld.introspector.ForwardingWeldField;
import org.jboss.weld.introspector.WeldField;

Expand Down Expand Up @@ -148,7 +149,7 @@ private Object writeReplace() throws ObjectStreamException

private void readObject(ObjectInputStream stream) throws InvalidObjectException
{
throw new InvalidObjectException("Proxy required");
throw new InvalidObjectException(PROXY_REQUIRED);
}

private static class SerializationProxy<T> extends WeldInjectionPointSerializationProxy<T, Field>
Expand Down
Expand Up @@ -17,8 +17,8 @@
package org.jboss.weld.injection;

import static org.jboss.weld.injection.Exceptions.rethrowException;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_REQUIRED;

import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.lang.annotation.Annotation;
Expand All @@ -36,6 +36,7 @@
import javax.enterprise.inject.spi.Bean;

import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.InvalidObjectException;
import org.jboss.weld.introspector.ForwardingWeldMethod;
import org.jboss.weld.introspector.MethodSignature;
import org.jboss.weld.introspector.WeldMethod;
Expand Down Expand Up @@ -307,7 +308,7 @@ private Object writeReplace() throws ObjectStreamException

private void readObject(ObjectInputStream stream) throws InvalidObjectException
{
throw new InvalidObjectException("Proxy required");
throw new InvalidObjectException(PROXY_REQUIRED);
}

private static class SerializationProxy<T> extends WeldInjectionPointSerializationProxy<T, Method>
Expand Down
Expand Up @@ -17,6 +17,8 @@
package org.jboss.weld.introspector;

import static org.jboss.weld.introspector.WeldAnnotated.MAPPED_METAANNOTATIONS;
import static org.jboss.weld.logging.messages.ReflectionMessage.ANNOTATION_MAP_NULL;
import static org.jboss.weld.logging.messages.ReflectionMessage.DECLARED_ANNOTATION_MAP_NULL;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
Expand All @@ -30,7 +32,9 @@

import javax.inject.Qualifier;

import org.jboss.weld.WeldException;
import org.jboss.weld.literal.DefaultLiteral;
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.metadata.TypeStore;

import com.google.common.base.Supplier;
Expand Down Expand Up @@ -155,7 +159,7 @@ protected AnnotationStore(Map<Class<? extends Annotation>, Annotation> annotatio
{
if (annotationMap == null)
{
throw new NullPointerException("annotationMap cannot be null");
throw new WeldException(ANNOTATION_MAP_NULL);
}
this.annotationMap = annotationMap;
this.annotationSet = new HashSet<Annotation>();
Expand All @@ -176,7 +180,7 @@ public Set<Annotation> get()

if (declaredAnnotationMap == null)
{
throw new NullPointerException("declaredAnnotationMap cannot be null");
throw new WeldException(DECLARED_ANNOTATION_MAP_NULL);
}
this.declaredAnnotationMap = declaredAnnotationMap;
this.declaredAnnotationSet = new HashSet<Annotation>();
Expand Down
Expand Up @@ -16,12 +16,15 @@
*/
package org.jboss.weld.introspector.jlr;

import static org.jboss.weld.logging.messages.ReflectionMessage.UNABLE_TO_GET_PARAMETER_NAME;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;

import javax.enterprise.inject.spi.AnnotatedCallable;

import org.jboss.weld.ForbiddenArgumentException;
import org.jboss.weld.introspector.AnnotationStore;
import org.jboss.weld.introspector.WeldCallable;
import org.jboss.weld.introspector.WeldParameter;
Expand Down Expand Up @@ -133,7 +136,7 @@ public Package getPackage()
*/
public String getName()
{
throw new IllegalArgumentException("Unable to determine name of parameter");
throw new ForbiddenArgumentException(UNABLE_TO_GET_PARAMETER_NAME);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion impl/src/main/java/org/jboss/weld/jsf/JsfHelper.java
Expand Up @@ -19,6 +19,7 @@
import static org.jboss.weld.logging.Category.JSF;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.JsfMessage.FOUND_CONVERSATION_FROM_REQUEST;
import static org.jboss.weld.logging.messages.JsfMessage.IMPROPER_ENVIRONMENT;
import static org.jboss.weld.logging.messages.JsfMessage.RESUMING_CONVERSATION;

import javax.enterprise.util.AnnotationLiteral;
Expand All @@ -28,6 +29,7 @@

import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.Container;
import org.jboss.weld.ForbiddenStateException;
import org.jboss.weld.conversation.ConversationIdName;
import org.jboss.weld.servlet.ServletHelper;
import org.jboss.weld.util.Reflections;
Expand Down Expand Up @@ -116,7 +118,7 @@ public static BeanManagerImpl getModuleBeanManager(FacesContext facesContext)
}
else
{
throw new IllegalStateException("Weld doesn not support using JSF in an non-servlet environment");
throw new ForbiddenStateException(IMPROPER_ENVIRONMENT);
}
}

Expand Down
@@ -0,0 +1,41 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.weld.logging.messages;

import org.jboss.weld.logging.MessageId;

import ch.qos.cal10n.BaseName;
import ch.qos.cal10n.Locale;
import ch.qos.cal10n.LocaleData;

@BaseName("org.jboss.weld.messages.beanmanager")
@LocaleData({
@Locale("en")
})
/**
* Log messages for bean manager and related support classes.
*
* Message IDs: 001300 - 001399
*
* @author David Allen
*
*/
public enum BeanManagerMessage
{
@MessageId("001300") CANNOT_LOCATE_BEAN_MANAGER
}
Expand Up @@ -22,6 +22,7 @@ public enum JsfMessage
@MessageId("000501") SKIPPING_CLEANING_UP_CONVERSATION,
@MessageId("000502") INITIATING_CONVERSATION,
@MessageId("000503") FOUND_CONVERSATION_FROM_REQUEST,
@MessageId("000504") RESUMING_CONVERSATION;
@MessageId("000504") RESUMING_CONVERSATION,
@MessageId("000505") IMPROPER_ENVIRONMENT;

}
@@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.weld.logging.messages;

import org.jboss.weld.logging.MessageId;

import ch.qos.cal10n.BaseName;
import ch.qos.cal10n.Locale;
import ch.qos.cal10n.LocaleData;

@BaseName("org.jboss.weld.messages.metadata")
@LocaleData({
@Locale("en")
})
/**
* Log messages for Meta Data.
*
* Message IDs: 001100 - 001199
*
* @author David Allen
*
*/
public enum MetadataMessage
{
@MessageId("001100") META_ANNOTATION_ON_WRONG_TYPE,
@MessageId("001101") NON_BINDING_MEMBER_TYPE,
@MessageId("001102") STEREOTYPE_NOT_REGISTERED,
@MessageId("001103") QUALIFIER_ON_STEREOTYPE,
@MessageId("001104") VALUE_ON_NAMED_STEREOTYPE,
@MessageId("001105") MULTIPLE_SCOPES;
}
Expand Up @@ -24,6 +24,9 @@ public enum ReflectionMessage
@MessageId("000602") MISSING_TARGET_TYPE_METHOD_OR_TARGET_TYPE,
@MessageId("000603") TARGET_TYPE_METHOD_INHERITS_FROM_TARGET_TYPE,
@MessageId("000604") MISSING_TARGET_METHOD_FIELD_TYPE,
@MessageId("000605") MISSING_TARGET_METHOD_FIELD_TYPE_PARAMETER_OR_TARGET_METHOD_TYPE_OR_TARGET_METHOD_OR_TARGET_TYPE_OR_TARGET_FIELD;
@MessageId("000605") MISSING_TARGET_METHOD_FIELD_TYPE_PARAMETER_OR_TARGET_METHOD_TYPE_OR_TARGET_METHOD_OR_TARGET_TYPE_OR_TARGET_FIELD,
@MessageId("000606") UNABLE_TO_GET_PARAMETER_NAME,
@MessageId("000607") ANNOTATION_MAP_NULL,
@MessageId("000608") DECLARED_ANNOTATION_MAP_NULL;

}
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.weld.logging.messages;

import org.jboss.weld.logging.MessageId;

import ch.qos.cal10n.BaseName;
import ch.qos.cal10n.Locale;
import ch.qos.cal10n.LocaleData;

@BaseName("org.jboss.weld.messages.resolution")
@LocaleData({
@Locale("en")
})
/**
* Log messages for resolution classes.
*
* Message IDs: 001200 - 001299
*
* @author David Allen
*
*/
public enum ResolutionMessage
{
@MessageId("001200") INVALID_MEMBER_TYPE,
@MessageId("001201") CANNOT_EXTRACT_RAW_TYPE,
@MessageId("001202") CANNOT_EXTRACT_TYPE_INFORMATION;
}
Expand Up @@ -18,6 +18,13 @@
public enum ServletMessage
{

@MessageId("000700") NOT_STARTING;
@MessageId("000700") NOT_STARTING,
@MessageId("000701") CONTEXT_NULL,
@MessageId("000702") BEAN_MANAGER_NOT_FOUND,
@MessageId("000703") REQUEST_SCOPE_BEAN_STORE_MISSING,
@MessageId("000704") BEAN_DEPLOYMENT_ARCHIVE_MISSING,
@MessageId("000705") BEAN_MANAGER_FOR_ARCHIVE_NOT_FOUND,
@MessageId("000706") ILLEGAL_USE_OF_WELD_LISTENER,
@MessageId("000707") ONLY_HTTP_SERVLET_LIFECYCLE_DEFINED;

}
Expand Up @@ -27,6 +27,7 @@

import org.jboss.weld.DefinitionException;
import org.jboss.weld.introspector.WeldAnnotation;
import org.jboss.weld.logging.messages.MetadataMessage;
import org.jboss.weld.resources.ClassTransformer;
import org.slf4j.cal10n.LocLogger;

Expand Down Expand Up @@ -71,7 +72,7 @@ protected void initType()
{
if (!Annotation.class.isAssignableFrom(getRawType()))
{
throw new DefinitionException(getMetaAnnotationTypes().toString() + " can only be applied to an annotation, it was applied to " + getRawType());
throw new DefinitionException(MetadataMessage.META_ANNOTATION_ON_WRONG_TYPE, getMetaAnnotationTypes(), getRawType());
}
}

Expand Down

0 comments on commit 741259a

Please sign in to comment.