Author: dallen6
Date: 2010-04-29 16:01:54 -0400 (Thu, 29 Apr 2010)
New Revision: 6197
Added:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java
core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
Log:
WELD-504 Exception messages for lifecycle events now includes full stacktraces
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -17,6 +17,7 @@
package org.jboss.weld.context;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
/**
@@ -39,7 +40,7 @@
public <E extends Enum<?>> BusyConversationException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -17,6 +17,7 @@
package org.jboss.weld.context;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
/**
@@ -39,7 +40,7 @@
public <E extends Enum<?>> ContextNotActiveException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -17,6 +17,7 @@
package org.jboss.weld.context;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
/**
@@ -39,7 +40,7 @@
public <E extends Enum<?>> NonexistentConversationException(E key,
Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public AmbiguousResolutionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> AmbiguousResolutionException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -40,7 +40,7 @@
*/
public <E extends Enum<?>> CreationException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
/**
@@ -55,7 +55,7 @@
public <E extends Enum<?>> CreationException(E key, Throwable throwable,
Object... args)
{
super(throwable);
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -38,7 +38,7 @@
public ForbiddenArgumentException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -51,7 +51,7 @@
*/
public <E extends Enum<?>> ForbiddenArgumentException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -39,7 +39,7 @@
*/
public <E extends Enum<?>> ForbiddenStateException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
/**
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -40,7 +40,7 @@
*/
public <E extends Enum<?>> IllegalProductException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public InjectionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -51,7 +51,7 @@
public InjectionException(String message, Throwable throwable)
{
super(throwable);
- this.message = new WeldExceptionMessage(message);
+ this.message = new WeldExceptionStringMessage(message);
}
/**
@@ -64,7 +64,7 @@
*/
public <E extends Enum<?>> InjectionException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -41,7 +41,7 @@
public <E extends Enum<?>> InvalidObjectException(E key, Object... args)
{
super(null);
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> InvalidOperationException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public UnproxyableResolutionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> UnproxyableResolutionException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public UnsatisfiedResolutionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> UnsatisfiedResolutionException(E key, Object...
args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -38,7 +38,7 @@
public WeldException(Throwable throwable)
{
super(throwable);
- this.message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ this.message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -51,7 +51,7 @@
*/
public <E extends Enum<?>> WeldException(E key, Object... args)
{
- this.message = new WeldExceptionMessage(key, args);
+ this.message = new WeldExceptionKeyMessage(key, args);
}
/**
@@ -66,7 +66,7 @@
public <E extends Enum<?>> WeldException(E key, Throwable throwable,
Object... args)
{
super(throwable);
- this.message = new WeldExceptionMessage(key, args);
+ this.message = new WeldExceptionKeyMessage(key, args);
}
/**
@@ -79,19 +79,7 @@
public WeldException(List<Throwable> errors)
{
super();
- StringBuilder errorMessage = new StringBuilder();
- int i = 0;;
- for (Throwable throwable : errors)
- {
- if (i > 0)
- {
- errorMessage.append('\n');
- }
- errorMessage.append("Exception #").append(i).append(" :");
- errorMessage.append(throwable.getLocalizedMessage());
- i++;
- }
- this.message = new WeldExceptionMessage(errorMessage.toString());
+ this.message = new WeldExceptionListMessage(errors);
}
@Override
Added:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., 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.exceptions;
+
+import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
+
+import java.io.Serializable;
+
+/**
+ * Exception message based on an enumerated key and optional object arguments.
+ * This includes localization of the message based on the settings in the JVM
+ * when the {@link java.lang.Throwable#getMessage()} or
+ * {@link java.lang.Throwable#getLocalizedMessage()} methods are invoked on a
+ * Weld exception.
+ *
+ * @author David Allen
+ */
+public class WeldExceptionKeyMessage implements WeldExceptionMessage, Serializable
+{
+ private static final long serialVersionUID = 3474682221381024558L;
+ private Enum<?> messageKey;
+ private String messageArguments[];
+
+ /**
+ * <p>
+ * Creates a new exception message based on an enumerated message key. This
+ * message will not be localized until it is actually logged or other
+ * software invokes the {@link #getMessage()} method.
+ * </p>
+ *
+ * @param <E> the message key enumeration
+ * @param key the message key from the above enumeration
+ * @param args optional arguments for the message
+ */
+ public <E extends Enum<?>> WeldExceptionKeyMessage(E key, Object... args)
+ {
+ this.messageKey = key;
+ if ((args != null) && (args.length > 0))
+ {
+ this.messageArguments = new String[args.length];
+ int index = 0;
+ for (Object arg : args)
+ {
+ messageArguments[index++] = arg == null ? "null" : arg.toString();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.weld.exceptions.WeldExceptionMessage#getAsString()
+ */
+ public String getAsString()
+ {
+ String result = null;
+ try
+ {
+ result = loggerFactory().getMessageConveyor().getMessage(messageKey, (Object[])
messageArguments);
+ }
+ catch (Exception e)
+ {
+ // We want the using exception to be processed, but also include
+ // this one in its message
+ result = "Exception message for key " + messageKey + " not found
due to " + e.getLocalizedMessage();
+ }
+ if (result == null)
+ {
+ result = "Exception message for key " + messageKey + " not
found";
+ }
+ return result;
+ }
+
+}
Added:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., 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.exceptions;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.util.List;
+
+/**
+ * Exception message that produces a list of exceptions and their stack traces
+ * for logging. This is typically used in lifecycle events which accumulate
+ * exceptions across observers.
+ *
+ * @author David Allen
+ *
+ */
+public class WeldExceptionListMessage implements WeldExceptionMessage, Serializable
+{
+
+ private static final long serialVersionUID = 3445187707771082346L;
+
+ private List<Throwable> causes;
+ private String message;
+
+ public WeldExceptionListMessage(List<Throwable> throwables)
+ {
+ this.causes = throwables;
+ }
+
+ public String getAsString()
+ {
+ if (message == null)
+ {
+ generateMessage();
+ }
+ return message;
+ }
+
+ private void generateMessage()
+ {
+ PrintWriter messageBuffer = new PrintWriter(new StringWriter());
+ messageBuffer.print("Exception List with ");
+ messageBuffer.print(causes.size());
+ messageBuffer.print(" exceptions:\n");
+ int i = 0;
+ for (Throwable throwable : causes)
+ {
+ messageBuffer.print("Exception ");
+ messageBuffer.print(i);
+ messageBuffer.print(" :\n");
+ throwable.printStackTrace(messageBuffer);
+ }
+ }
+
+}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java 2010-04-29
19:24:23 UTC (rev 6196)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -17,101 +17,22 @@
package org.jboss.weld.exceptions;
-import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
-
-import java.io.Serializable;
-
/**
- * <p>
- * The message for exceptions generated by Weld. Each exception contains one
- * message object which will handle the generation of the string message at the
- * time the message is needed. This includes localization of the message based
- * on the settings in the JVM where the {@link java.lang.Throwable#getMessage()}
- * or {@link java.lang.Throwable#getLocalizedMessage()} methods are invoked.
- * </p>
+ * Interface for all exception messages in Weld. This replaces the simple
+ * String used by default in JVM exceptions and allows more complex forms
+ * of messages.
*
* @author David Allen
+ *
*/
-public class WeldExceptionMessage implements Serializable
+public interface WeldExceptionMessage
{
- private static final long serialVersionUID = 2L;
-
/**
- * The string version of the message. This is only used when the original
- * message from a wrapped exception is being used. Since it is already
- * localized, it will simply be stored here and used as the message.
- */
- private String message;
-
- private Enum<?> messageKey;
- private Object messageArguments[];
-
- /**
- * <p>
- * Creates a new exception message initialized to a static message. Use this
- * only for messages generated by third-party software, i.e., those which do
- * not use enumerated message keys.
- * </p>
- *
- * @param message the static message
- */
- public WeldExceptionMessage(String message)
- {
- // This will not be further localized
- this.message = message;
- }
-
- /**
- * <p>
- * Creates a new exception message based on an enumerated message key. This
- * message will not be localized until it is actually logged or other
- * software invokes the {@link #getMessage()} method.
- * </p>
- *
- * @param <E> the message key enumeration
- * @param key the message key from the above enumeration
- * @param args optional arguments for the message
- */
- public <E extends Enum<?>> WeldExceptionMessage(E key, Object... args)
- {
- this.messageKey = key;
- if ((args != null) && (args.length > 0))
- {
- this.messageArguments = new String[args.length];
- int index = 0;
- for (Object arg : args)
- {
- messageArguments[index++] = arg == null ? "null" : arg.toString();
- }
- }
- }
-
- /**
* Generates the localized message for the exception.
*
* @return exception message as a string
*/
- public String getAsString()
- {
- String result = message;
- if (result == null)
- {
- try
- {
- result = loggerFactory().getMessageConveyor().getMessage(messageKey,
messageArguments);
- }
- catch (Exception e)
- {
- // We want the using exception to be processed, but also include
- // this one in its message
- result = "Exception message for key " + messageKey + " not
found due to " + e.getLocalizedMessage();
- }
- if (result == null)
- {
- result = "Exception message for key " + messageKey + " not
found";
- }
- }
- return result;
- }
-}
+ public String getAsString();
+
+}
\ No newline at end of file
Copied:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java
(from rev 6162,
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java)
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java
(rev 0)
+++
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., 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.exceptions;
+
+import java.io.Serializable;
+
+/**
+ * Simple message object that just contains a String already formatted
+ * and localized.
+ *
+ * @author David Allen
+ */
+public class WeldExceptionStringMessage implements Serializable, WeldExceptionMessage
+{
+
+ private static final long serialVersionUID = 2L;
+
+ /**
+ * The string version of the message. This is only used when the original
+ * message from a wrapped exception is being used. Since it is already
+ * localized, it will simply be stored here and used as the message.
+ */
+ private String message;
+
+ /**
+ * <p>
+ * Creates a new exception message initialized to a static message. Use this
+ * only for messages generated by third-party software, i.e., those which do
+ * not use enumerated message keys.
+ * </p>
+ *
+ * @param message the static message
+ */
+ public WeldExceptionStringMessage(String message)
+ {
+ // This will not be further localized
+ this.message = message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.exceptions.WeldExceptionMessage#getAsString()
+ */
+ public String getAsString()
+ {
+ return message;
+ }
+}
Property changes on:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2010-04-29
19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2010-04-29
20:01:54 UTC (rev 6197)
@@ -19,7 +19,9 @@
import javax.enterprise.inject.InjectionException;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
+import org.jboss.weld.exceptions.WeldExceptionStringMessage;
/**
* Used for exceptions from the Weld XML parser and provides localization
@@ -37,12 +39,12 @@
public WeldXmlException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
public <E extends Enum<?>> WeldXmlException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override