net.sf.mmm.util.nls.api
Class AbstractNlsException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by net.sf.mmm.util.nls.api.AbstractNlsException
All Implemented Interfaces:
Serializable, NlsObject, NlsThrowable
Direct Known Subclasses:
NlsException

public abstract class AbstractNlsException
extends Exception
implements NlsThrowable

This is an abstract base implementation of a checked exception with real native language support (NLS).
ATTENTION:
Please prefer extending NlsException instead of this class.
INFORMATION:
Checked exceptions should be used for business errors and should only occur in unexpected situations.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
NlsThrowable, Serialized Form

Field Summary
private  NlsMessage nlsMessage
          the internationalized message
private static long serialVersionUID
          UID for serialization.
private  UUID uuid
           
 
Fields inherited from interface net.sf.mmm.util.nls.api.NlsObject
KEY_ANNOTATION, KEY_ARGUMENT, KEY_CAPACITY, KEY_DEFAULT, KEY_DIRECTORY, KEY_ERROR, KEY_FILE, KEY_FUNCTION, KEY_ID, KEY_KEY, KEY_LOCATION, KEY_MAX, KEY_MIN, KEY_MODE, KEY_NAME, KEY_OBJECT, KEY_OPERAND, KEY_OPERATION, KEY_OPTION, KEY_PATH, KEY_PROPERTY, KEY_QUERY, KEY_RESOURCE, KEY_SIZE, KEY_SOURCE, KEY_TARGET_TYPE, KEY_TITLE, KEY_TYPE, KEY_URI, KEY_VALUE
 
Constructor Summary
AbstractNlsException(NlsMessage message)
          The constructor.
AbstractNlsException(Throwable nested, NlsMessage message)
          The constructor.
 
Method Summary
protected  UUID createUuid()
          This method creates a new UUID.
 String getLocalizedMessage(Locale locale)
          This method gets the localized message as string.
 String getLocalizedMessage(Locale locale, NlsTemplateResolver resolver)
          This method gets the localized message as string.
 void getLocalizedMessage(Locale locale, NlsTemplateResolver resolver, Appendable buffer)
          This method writes the localized message to the given string buffer.
 String getMessage()
          
 NlsMessage getNlsMessage()
          This method gets the NlsMessage describing the problem.
 UUID getUuid()
          This method gets the UUID of this exception.
 void printStackTrace(Locale locale, Appendable buffer)
          This method prints the stack trace with localized exception message(s).
 void printStackTrace(Locale locale, NlsTemplateResolver resolver, Appendable buffer)
          This method prints the stack trace with localized exception message(s).
(package private) static void printStackTrace(NlsThrowable throwable, Locale locale, NlsTemplateResolver resolver, Appendable buffer)
           
 void printStackTrace(PrintStream s)
          
 void printStackTrace(PrintWriter s)
          
 NlsMessage toNlsMessage()
          This method is the equivalent to Object.toString() with native language support.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.nls.api.NlsThrowable
getCause, getStackTrace
 

Field Detail

serialVersionUID

private static final long serialVersionUID
UID for serialization.

See Also:
Constant Field Values

nlsMessage

private final NlsMessage nlsMessage
the internationalized message


uuid

private final UUID uuid
See Also:
getUuid()
Constructor Detail

AbstractNlsException

public AbstractNlsException(NlsMessage message)
The constructor.

Parameters:
message - the message describing the problem briefly.

AbstractNlsException

public AbstractNlsException(Throwable nested,
                            NlsMessage message)
The constructor.

Parameters:
nested - is the cause of this exception.
message - the message describing the problem briefly.
Method Detail

createUuid

protected UUID createUuid()
This method creates a new UUID.

Returns:
the new UUID or null to turn this feature off.

getUuid

public final UUID getUuid()
This method gets the UUID of this exception. The UUID is created when the exception is constructed or copied from the given cause if it is also a NlsThrowable.
The UUID will appear in the printed stacktrace but NOT in the message and should therefore be written to log-files if the NlsThrowable is logged. If you supply the UUID to the end-user in case of an unexpected error, he can easily find the stacktrace in the log-files.

Specified by:
getUuid in interface NlsThrowable
Returns:
the UUID of this exception. It may be null if this feature is turned of (it is turned on by default).

getNlsMessage

public final NlsMessage getNlsMessage()
This method gets the NlsMessage describing the problem.

Specified by:
getNlsMessage in interface NlsThrowable
Returns:
the NlsMessage.

printStackTrace

public void printStackTrace(PrintStream s)

Overrides:
printStackTrace in class Throwable

printStackTrace

public void printStackTrace(PrintWriter s)

Overrides:
printStackTrace in class Throwable

printStackTrace

public void printStackTrace(Locale locale,
                            Appendable buffer)
This method prints the stack trace with localized exception message(s).

Specified by:
printStackTrace in interface NlsThrowable
Parameters:
locale - is the locale to translate to.
buffer - is where to write the stack trace to.

printStackTrace

public void printStackTrace(Locale locale,
                            NlsTemplateResolver resolver,
                            Appendable buffer)
This method prints the stack trace with localized exception message(s).

Specified by:
printStackTrace in interface NlsThrowable
Parameters:
locale - is the locale to translate to.
resolver - translates the original message.
buffer - is where to write the stack trace to.

printStackTrace

static void printStackTrace(NlsThrowable throwable,
                            Locale locale,
                            NlsTemplateResolver resolver,
                            Appendable buffer)
Parameters:
throwable - is the throwable to print.
locale - is the locale to translate to.
resolver - translates the original message.
buffer - is where to write the stack trace to.
See Also:
NlsThrowable.printStackTrace(Locale, NlsTemplateResolver, Appendable)

getMessage

public String getMessage()

Specified by:
getMessage in interface NlsThrowable
Overrides:
getMessage in class Throwable
Returns:
the message.

getLocalizedMessage

public String getLocalizedMessage(Locale locale)
This method gets the localized message as string.

Specified by:
getLocalizedMessage in interface NlsThrowable
Parameters:
locale - is the locale to translate to.
Returns:
the localized message.
See Also:
NlsThrowable.getLocalizedMessage(Locale, NlsTemplateResolver, Appendable)

getLocalizedMessage

public String getLocalizedMessage(Locale locale,
                                  NlsTemplateResolver resolver)
This method gets the localized message as string.

Specified by:
getLocalizedMessage in interface NlsThrowable
Parameters:
locale - is the locale to translate to.
resolver - is used to resolve the template in order to translate the original i18n message.
Returns:
the localized message.
See Also:
NlsThrowable.getLocalizedMessage(Locale, NlsTemplateResolver, Appendable)

getLocalizedMessage

public void getLocalizedMessage(Locale locale,
                                NlsTemplateResolver resolver,
                                Appendable buffer)
This method writes the localized message to the given string buffer.

Specified by:
getLocalizedMessage in interface NlsThrowable
Parameters:
locale - is the locale to translate to.
resolver - is used to resolve the template required to translate the internationalized message.
buffer - is the buffer where to write the message to.
See Also:
NlsMessage.getLocalizedMessage(Locale, NlsTemplateResolver, Appendable)

toNlsMessage

public NlsMessage toNlsMessage()
This method is the equivalent to Object.toString() with native language support.

Specified by:
toNlsMessage in interface NlsObject
Returns:
an nls message representing this object.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.