Package org.apache.uima.internal.util
Class I18nx_impl
- java.lang.Object
-
- org.apache.uima.internal.util.I18nx_impl
-
public class I18nx_impl extends java.lang.Object
Common implementation of InternationalizedException and InternationalizedRuntimeException
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Locale
default_locale
private java.util.ResourceBundle
default_localized_resourceBundle
private java.lang.Object[]
mArguments
The arguments to this exception's message, if any.private java.lang.Throwable
mCause
The exception that caused this exception to occur.private java.lang.String
mMessageKey
An identifier that maps to the message for this exception.private java.lang.String
mResourceBundleName
The base name of the resource bundle in which the message for this exception is located.private java.lang.ClassLoader
originalContextClassLoader
the thread local class loader at creation time, see UIMA-4793 Transient to allow exceptions to be serialized.private java.util.ResourceBundle
user_specified_resourceBundle
-
Constructor Summary
Constructors Constructor Description I18nx_impl(java.lang.String aResourceBundleName, java.lang.String aMessageKey, java.lang.Object[] aArguments, java.lang.Throwable aCause)
Creates a newInternationalizedException
with the specified message and cause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object[]
getArguments()
Gets the arguments to this exception's message.java.lang.Throwable
getCause()
Gets the cause of this Exception.java.lang.String
getLocalizedMessage()
Gets the localized detail message for this exception.java.lang.String
getLocalizedMessage(java.util.Locale aLocale)
Gets the localized detail message for this exception using the specifiedLocale
.java.lang.String
getMessage()
Gets the English detail message for this exception.java.lang.String
getMessageKey()
Gets the identifier for this exception's message.java.lang.String
getResourceBundleName()
Gets the base name of the resource bundle in which the message for this exception is located.boolean
hasMessageKey(java.lang.String messageKey)
Checks if this exception, or any of its root causes, has a particular UIMA message key.void
setCause(java.lang.Throwable cause)
void
setResourceBundle(java.util.Locale aLocale)
For the case where the default locale is not being used for getting messages, and the lookup path in the classpath for the resource bundle needs to be set at a specific point, call this method to set the resource bundle at that point in the call stack.
-
-
-
Field Detail
-
mResourceBundleName
private java.lang.String mResourceBundleName
The base name of the resource bundle in which the message for this exception is located.
-
mMessageKey
private java.lang.String mMessageKey
An identifier that maps to the message for this exception.
-
mArguments
private java.lang.Object[] mArguments
The arguments to this exception's message, if any. This allows anInternationalizedException
to have a compound message, made up of multiple parts that are concatenated in a language-neutral way.
-
mCause
private java.lang.Throwable mCause
The exception that caused this exception to occur.
-
originalContextClassLoader
private final transient java.lang.ClassLoader originalContextClassLoader
the thread local class loader at creation time, see UIMA-4793 Transient to allow exceptions to be serialized. Deserialized versions have null as their value, which is handled by the users
-
default_localized_resourceBundle
private final transient java.util.ResourceBundle default_localized_resourceBundle
-
default_locale
private final transient java.util.Locale default_locale
-
user_specified_resourceBundle
private transient java.util.ResourceBundle user_specified_resourceBundle
-
-
Constructor Detail
-
I18nx_impl
public I18nx_impl(java.lang.String aResourceBundleName, java.lang.String aMessageKey, java.lang.Object[] aArguments, java.lang.Throwable aCause)
Creates a newInternationalizedException
with the specified message and cause.- Parameters:
aResourceBundleName
- the base name of the resource bundle in which the message for this exception is located.aMessageKey
- an identifier that maps to the message for this exception. The message may contain placeholders for arguments as defined by theMessageFormat
class.aArguments
- The arguments to the message.null
may be used if the message has no arguments.aCause
- the original exception that caused this exception to be thrown, if any
-
-
Method Detail
-
getResourceBundleName
public java.lang.String getResourceBundleName()
Gets the base name of the resource bundle in which the message for this exception is located.- Returns:
- the resource bundle base name. May return
null
if this exception has no message.
-
getMessageKey
public java.lang.String getMessageKey()
Gets the identifier for this exception's message. This identifier can be looked up in this exception'sResourceBundle
to get the locale-specific message for this exception.- Returns:
- the resource identifier for this exception's message. May return
null
if this exception has no message.
-
getArguments
public java.lang.Object[] getArguments()
Gets the arguments to this exception's message. Arguments allow aInternationalizedException
to have a compound message, made up of multiple parts that are concatenated in a language-neutral way.- Returns:
- the arguments to this exception's message.
-
getMessage
public java.lang.String getMessage()
Gets the English detail message for this exception. For the localized message usegetLocalizedMessage()
.- Returns:
- the English detail message for this exception.
-
getLocalizedMessage
public java.lang.String getLocalizedMessage()
Gets the localized detail message for this exception. This uses the default Locale for this JVM. A Locale may be specified usinggetLocalizedMessage(Locale)
.- Returns:
- this exception's detail message, localized for the default Locale.
-
getLocalizedMessage
public java.lang.String getLocalizedMessage(java.util.Locale aLocale)
Gets the localized detail message for this exception using the specifiedLocale
.- Parameters:
aLocale
- the locale to use for localizing the message- Returns:
- this exception's detail message, localized for the specified
Locale
.
-
getCause
public java.lang.Throwable getCause()
Gets the cause of this Exception.- Returns:
- the Throwable that caused this Exception to occur, if any. Returns
null
if there is no such cause.
-
setCause
public void setCause(java.lang.Throwable cause)
-
hasMessageKey
public boolean hasMessageKey(java.lang.String messageKey)
Checks if this exception, or any of its root causes, has a particular UIMA message key. This allows checking for particular error condition- Parameters:
messageKey
- to search for in the exception chain- Returns:
- true if this exception or any of its root causes has a particular UIMA message key.
-
setResourceBundle
public void setResourceBundle(java.util.Locale aLocale)
For the case where the default locale is not being used for getting messages, and the lookup path in the classpath for the resource bundle needs to be set at a specific point, call this method to set the resource bundle at that point in the call stack. Example: If in a Pear, and you are throwing an exception, which is defined in a bundle in the Pear context, but the catcher of the throw is up the stack above where the pear context exists (and therefore, is no longer present at "catch" time), and you don't want to use the default-locale for getting the message out of the message bundle, then do something like this Exception e = new AnalysisEngineProcessException(MESSAGE_BUNDLE, "TEST_KEY", objects); e.setResourceBundle(my_locale); // call this method, pass in the needed locale object throw e; // or whatever should be done with it- Parameters:
aLocale
- the locale to use when getting the message from the message bundle at a later time
-
-