📄 exceptioncontainerformbean.java
字号:
/* @LICENSE_COPYRIGHT@ */
package net.sf.irunninglog.servlet.formbean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.irunninglog.util.IdGenerator;
/**
* Form bean useful for storing an exception, along with any exception(s) that
* caused it. When a bean is created, the root exception is unwrapped, and
* any exceptions are stored in an internal list. The list of exceptions
* is accessible via the <code>getExceptions</code> method.
*
* @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a>
* @version $Revision: 1.1 $ $Date: 2005/06/30 02:01:05 $
* @since iRunningLog 1.0
*/
public final class ExceptionContainerFormBean extends FormBean {
/** Log instance for this class. */
private static final Log LOG =
LogFactory.getLog(ExceptionContainerFormBean.class);
/** List of exceptions contained in this container. */
private List mExceptions;
/**
* Create a new exception container.
*/
public ExceptionContainerFormBean() {
super();
mExceptions = new ArrayList();
}
/**
* Create a new exception container to hold a given exception.
*
* @param ex The exception for this container
*/
public ExceptionContainerFormBean(Exception ex) {
this();
setException(ex);
}
/**
* Set the exception that this container represents. This will clear
* out any previous exception and unwrap the parameter exception, storing
* the exception and any nested exceptions.
*
* @param ex The exception to store in this container
*/
public void setException(Exception ex) {
mExceptions.clear();
Throwable exception = ex;
while (exception != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding an exception with this class to the container"
+ exception.getClass());
}
mExceptions.add(exception);
exception = exception.getCause();
}
}
/**
* Get the list of exceptions contained in this container.
*
* @return The list of exceptions, with the root exception in the first
* position in the list
*/
public List getExceptions() {
return Collections.unmodifiableList(mExceptions);
}
/**
* Get the string that identifies this container. Constructed using the
* bean's hash code along with a value from <code>IdGenerator</code>.
*
* @return The exception container's identifier
* @see IdGenerator
*/
public String getId() {
return String.valueOf(hashCode()) + IdGenerator.generateId();
}
/**
* Get the list of exceptions contained in this container.
*
* @return The list of exceptions, with the root exception in the first
* position in the list
*/
public String toString() {
StringBuffer buff = new StringBuffer();
buff.append("ExceptionContainer[");
buff.append("exceptions={");
for (Iterator i = mExceptions.iterator(); i.hasNext();) {
buff.append(i.next().getClass().getName());
if (i.hasNext()) {
buff.append(", ");
}
}
buff.append("}");
buff.append("]");
return buff.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -