1 /*****************************************************************************
5 * Creation date 02.10.2012
6 * @author Author: Maria KRUCHININA
8 *****************************************************************************/
10 package org.splat.exception;
12 import org.splat.i18n.I18nUtils;
15 * Superclass for all SIMAN application exceptions.
16 * @author Maria KRUCHININA
19 public class AbstractException extends Exception {
24 private static final long serialVersionUID = -96254753042743175L;
27 * message key to write to user interface.
29 private String _messageKey = null;
32 * message key to write to user interface.
34 private Object[] _context = new Object[0];
37 * default constructor.
39 public AbstractException() {
44 * constructor with one parameter :the original throwable.
47 * the original throwable
48 * @see java.lang.Exception#Exception(Throwable)
50 public AbstractException(final Throwable throwable) {
55 * constructor with two parameters : - the message - a throwable.
60 * the original throwable
61 * @see java.lang.Exception#Exception(String, Throwable)
63 public AbstractException(final String message, final Throwable throwable) {
64 super(I18nUtils.getMessageLocaleDefault(message), throwable);
65 this._messageKey = message;
69 * Build a ServiceException with message, user message key, and throwable.
70 * CAUTION: this only works with 1 log-messages.properties
73 * the User Interface Message Key
75 * the original exception
77 * the execution context
79 public AbstractException(final String messageKey,
80 final Throwable throwable, final Object... context) {
81 // read the CAUTION above
82 super(I18nUtils.getMessageLocaleDefault(messageKey, context), throwable);
83 this._messageKey = messageKey;
84 this._context = context.clone();
89 * Build a ServiceException with message, user message key and context.
90 * CAUTION: this only works with 1 log-messages.properties
93 * the User Interface Message Key
95 * the execution context
97 public AbstractException(final String messageKey, final Object... context) {
98 // read the CAUTION above
99 super(I18nUtils.getMessageLocaleDefault(messageKey, context));
100 this._messageKey = messageKey;
101 this._context = context.clone();
105 * get the exception message key.
107 * @return the messageKey
109 public String getMessageKey() {
114 * set the exception message key.
117 * the messageKey to set
119 public void setMessageKey(final String key) {
126 * @return the context
128 public Object[] getContext() {
129 return _context.clone();
133 * Converts the object context array into a string array.
134 * @return a string array
136 public String[] getContextAsStringArray() {
137 String[] result = null;
139 if (null != _context) {
141 new String[_context.length];
143 for (Object o : _context) {
147 result[i] = o.toString();
162 public void setContext(final Object[] context) {
163 this._context = context.clone();