Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jasig.portal.lang
Class ThrowableHelper

    java.lang.Object
      org.jasig.portal.lang.ThrowableHelper

    public final class ThrowableHelper

extends java.lang.Object

The `ThrowableHelper` class defines a set of utility methods for handling common error management operations in a fashion which takes advantage of the J2SDK 1.4 constructs while maintaining J2SDK 1.3 compatibility.

Version:
  "$Revision: 1.3.4.1 $"
Author:
  Jan Nielsen

Field Summary
`private static ThrowableHandler` | `DEFAULT_HANDLER` Default throwable handler.
`private static java.lang.String` | `I18N_TOKEN` Statically configured internationalization token.

Constructor Summary
`private` | `ThrowableHelper()` Private constructor.

Method Summary
`static java.lang.Throwable` | `create(java.lang.Class throwableClass, java.lang.Class client, java.lang.String propertyName, java.lang.String[] args, java.lang.Throwable cause)` Creates the specified `Throwable` object with the internationalized error code and arguments.
`private static java.lang.Throwable` | `createThrowable(java.lang.Class throwableClass, java.lang.Class[] clsArguments, java.lang.Object[] objArguments)` Creates a `Throwable` object of the specified type using a constructor matching the specified arguments.
`static ThrowableHandler` | `getDefaultHandler(java.lang.String className)` Returns a constructed instance of the default handler.
`static java.lang.String` | `getInternationalizedMessage(java.lang.Class client, java.lang.String error)` Returns an internationalized error message which can be reconstructed into a localized error message with the `getLocalizedMessage` method call.
`static java.lang.String` | `getInternationalizedMessage(java.lang.Class client, java.lang.String error, java.lang.String[] objects)` Returns an internationalized error message which can be reconstructed into a localized error message with the `getLocalizedMessage` method call.
`static java.lang.String` | `getLocalizedMessage(java.lang.String i18nMessage)` Returns the localized error message associated with the specified internationalized error message constructed with the `getInternationalizedMessage` method.
`static java.lang.String` | `getLocalizedMessage(java.lang.String i18nMessage, java.util.Locale locale)` Returns the localized error message associated with the specified internationalized error message constructed with the `getInternationalizedMessage` method.
`static java.lang.String` | `getLocalizedMessage(java.lang.Throwable throwable)` Returns the localized string associated with the argument.
`static java.lang.String` | `getLocalizedMessage(java.lang.Throwable throwable, java.util.Locale locale)` Returns the localized string associated with the argument in the specified locale, if possible.
`static void` | `handle(java.lang.Class client, java.lang.String message, java.lang.String[] objects, java.lang.Throwable cause)` Handles the throwable condition specified in the parameters.
`static void` | `handle(java.lang.Class client, java.lang.String message, java.lang.String[] objects, java.lang.Throwable cause, ThrowableHandler handler)` Handles the throwable condition specified in the parameters.
`static void` | `handle(java.lang.Throwable cause)` Handles the throwable condition specified in the parameter.
`static void` | `initCause(java.lang.Throwable throwable, java.lang.Throwable cause)` Initizlizes the chained cause of the throwable if possible using the J2SDK 1.4 constructs.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### I18N_TOKEN

    private static final java.lang.String I18N_TOKEN

  Statically configured internationalization token.

### DEFAULT_HANDLER

    private static final ThrowableHandler DEFAULT_HANDLER

  Default throwable handler.

Constructor Detail

### ThrowableHelper

    private ThrowableHelper()

  Private constructor.

Method Detail

### getDefaultHandler

    public static final ThrowableHandler getDefaultHandler(java.lang.String className)

  Returns a constructed instance of the default handler. The class name passed to the method must be an implementation of the `ThrowableHandler` interface and have an accessible default constructor.

  Parameters:
    `className` - name of the throwable handler class
  Returns:
    instance of the specified handler class, or the default error handler

### getInternationalizedMessage

    public static final java.lang.String getInternationalizedMessage(java.lang.Class client,
                                                                     java.lang.String error)

  Returns an internationalized error message which can be reconstructed into a localized error message with the `getLocalizedMessage` method call.

  Parameters:
    `client` - class of the client making this call
    `error` - error property name of the error condition
  Returns:
    internationalized error message

### getInternationalizedMessage

    public static final java.lang.String getInternationalizedMessage(java.lang.Class client,
                                                                     java.lang.String error,
                                                                     java.lang.String[] objects)

  Returns an internationalized error message which can be reconstructed into a localized error message with the `getLocalizedMessage` method call.

  Parameters:
    `client` - class of the client making this call
    `error` - error property name of the error condition
    `objects` - string objects which should be stored for the message
  Returns:
    internationalized error message
  Throws:
    `java.lang.NullPointerException` - if client, or error parameters are null

### getLocalizedMessage

    public static final java.lang.String getLocalizedMessage(java.lang.String i18nMessage)

  Returns the localized error message associated with the specified internationalized error message constructed with the `getInternationalizedMessage` method. The default locale is used.

  Parameters:
    `i18nMessage` - internationalized error message
  Returns:
    localized error message, or `null`

### getLocalizedMessage

    public static final java.lang.String getLocalizedMessage(java.lang.Throwable throwable)

  Returns the localized string associated with the argument.

  Parameters:
    `throwable` - object whose message is to be localized
  Returns:
    localized message associated with `Throwable`

### getLocalizedMessage

    public static final java.lang.String getLocalizedMessage(java.lang.Throwable throwable,
                                                             java.util.Locale locale)

  Returns the localized string associated with the argument in the specified locale, if possible. If the locale is not supported the default locale message will be returned.

  Parameters:
    `throwable` - object whose message is to be localized
    `locale` - locale to localized the message
  Returns:
    localized message associated with `Throwable`

### getLocalizedMessage

    public static final java.lang.String getLocalizedMessage(java.lang.String i18nMessage,
                                                             java.util.Locale locale)

  Returns the localized error message associated with the specified internationalized error message constructed with the `getInternationalizedMessage` method. The locale of for the translation is picked up from the current session.

  Parameters:
    `i18nMessage` - internationalized error message
    `locale` - locale to translate the message
  Returns:
    localized error message, or `null`

### initCause

    public static final void initCause(java.lang.Throwable throwable,
                                       java.lang.Throwable cause)

  Initizlizes the chained cause of the throwable if possible using the J2SDK 1.4 constructs. In a J2SDK pre-1.4 environment, this method does nothing.

  Parameters:
    `throwable` - throwable whose cause should be set
    `cause` - throwable which caused the throwable condition

### create

    public static final java.lang.Throwable create(java.lang.Class throwableClass,
                                                   java.lang.Class client,
                                                   java.lang.String propertyName,
                                                   java.lang.String[] args,
                                                   java.lang.Throwable cause)

  Creates the specified `Throwable` object with the internationalized error code and arguments. If the cause object is not null, the specified object's `initCause` method will be invoked reflectively to enable the standard chaining constructs. The specified error code is an internationalized error property value which must be defined in a resource bundle associated with the client, specificifically the code will perform a `ResourceBundle.getBundle( )` to resolve the resource. Invoking this method is equivalent to creating the `Throwable` with an internationalized message and then invoking `ThrowableHelper.initCause`, e.g.,: `

       Throwable someCause = ...

       String i18nMessage = ThrowableHelper.getInternationalizedMessage(
           MyApplication.class,
           "myapplication.some_error_code",
           new String[]{ "32", "1024" }
           );

       IllegalArgumentException iae = new IllegalArgumentException(
           i18nMessage
           );

       ThrowableHelper.initCause(
           iae,
           someCause
           );

  `

  Parameters:
    `throwableClass` - throwable object to be constructed
    `client` - class file of the client
    `propertyName` - internationalized error code property name defined in the client's resouce bundle
    `args` - arguments for the localized message
    `cause` - cause of the created exception, or `null`
  Returns:
    throwable object of the specified type

### createThrowable

    private static final java.lang.Throwable createThrowable(java.lang.Class throwableClass,
                                                             java.lang.Class[] clsArguments,
                                                             java.lang.Object[] objArguments)

  Creates a `Throwable` object of the specified type using a constructor matching the specified arguments. The constructed object is returned. It is considered a static programming error if the requested object cannot be constructed with the specified parameters, so checking for `null` in the return is inappropriate; instead, validate that the specified `Throwable` class can be constructed in the specified manner by, for example, building unit test code which performs the same construction..

  Parameters:
    `throwableClass` - class to construct
    `clsArguments` - constructor argument class types
    `objArguments` - constructor argument object values
  Returns:
    `Throwable` object of the specified type, or `null`

### handle

    public static final void handle(java.lang.Throwable cause)

  Handles the throwable condition specified in the parameter. The default handler is used to process this handler.

  Parameters:
    `cause` - throwable condition which should be handled

### handle

    public static final void handle(java.lang.Class client,
                                    java.lang.String message,
                                    java.lang.String[] objects,
                                    java.lang.Throwable cause)

  Handles the throwable condition specified in the parameters. The default handler is used to process this handler.

  Parameters:
    `client` - client performing the handling
    `cause` - throwable condition which should be handled
    `message` - associated with handling the error
    `objects` - associated with the error message

### handle

    public static final void handle(java.lang.Class client,
                                    java.lang.String message,
                                    java.lang.String[] objects,
                                    java.lang.Throwable cause,
                                    ThrowableHandler handler)

  Handles the throwable condition specified in the parameters. If the specified handler is `null` the default handler is used; otherwise, the specified handler is used to process this request.

  Parameters:
    `client` - client performing the handling
    `cause` - throwable condition which should be handled
    `message` - associated with handling the error
    `objects` - associated with the error message
    `handler` - which should be executed instead of the default handler

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD