/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.util;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
/**
* A static singleton that handles processing throwables that otherwise would
* be ignored or dumped to System.err.
*
* @version $Revision: 1.3 $
* @author Jason Dillon
*/
public final class ThrowableHandler
{
/**
* Container for throwable types.
*/
public static interface Type
{
/** Unknown throwable. */
int UNKNOWN = 0;
/** Error throwable. */
int ERROR = 1;
/** Warning throwable. */
int WARNING = 2;
}
/////////////////////////////////////////////////////////////////////////
// Listener Methods //
/////////////////////////////////////////////////////////////////////////
/** The list of listeners */
protected static List listeners = Collections.synchronizedList(new ArrayList());
/**
* Add a ThrowableListener to the listener list. Listener is added only
* if if it is not already in the list.
*
* @param listener ThrowableListener to add to the list.
*/
public static void addThrowableListener(ThrowableListener listener) {
// only add the listener if it isn't already in the list
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
/**
* Remove a ThrowableListener from the listener list.
*
* @param listener ThrowableListener to remove from the list.
*/
public static void removeThrowableListener(ThrowableListener listener) {
listeners.remove(listener);
}
/**
* Fire onThrowable to all registered listeners.
*
* @param type The type off the throwable.
* @param t Throwable
*/
protected static void fireOnThrowable(int type, Throwable t) {
Object[] list = listeners.toArray();
for (int i=0; i