001: /*
002: Copyright (c) 2003 eInnovation Inc. All rights reserved
003:
004: This library is free software; you can redistribute it and/or modify it under the terms
005: of the GNU Lesser General Public License as published by the Free Software Foundation;
006: either version 2.1 of the License, or (at your option) any later version.
007:
008: This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
009: without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: See the GNU Lesser General Public License for more details.
011: */
012:
013: package com.openedit;
014:
015: import java.io.PrintWriter;
016: import java.io.Serializable;
017: import java.io.StringWriter;
018:
019: import org.apache.commons.logging.Log;
020: import org.apache.commons.logging.LogFactory;
021:
022: /**
023: * This is the superclass of all non-runtime exceptions thrown from Open Edit.
024: *
025: * @author Eric Galluzzo
026: */
027: public class OpenEditException extends Exception implements
028: Serializable {
029: private static final long serialVersionUID = 1630227379714618008L;
030:
031: private static final Log log = LogFactory
032: .getLog(OpenEditException.class);
033: protected String fieldPathWithError;
034:
035: public OpenEditException() {
036: this ("No Error Entered");
037: }
038:
039: public OpenEditException(String inMsg) {
040: this (inMsg, (Throwable) null);
041: }
042:
043: public OpenEditException(String inMsg, String inPath) {
044: this (inMsg, null, inPath);
045: }
046:
047: public OpenEditException(String inMsg, Throwable inRootCause,
048: String inPath) {
049: super (inMsg, inRootCause);
050:
051: if (inRootCause instanceof OpenEditException) {
052: log
053: .error("Should not wrap an exception of type OpenEditException ");
054: }
055: setPathWithError(inPath);
056: }
057:
058: public OpenEditException(String inMsg, Throwable inRootCause) {
059: this (inMsg, inRootCause, null);
060: }
061:
062: public OpenEditException(Throwable inRootCause, String inPath) {
063: this (null, inRootCause, inPath);
064: }
065:
066: public OpenEditException(Throwable inRootCause) {
067: this (inRootCause.getMessage(), inRootCause);
068: }
069:
070: /**
071: * DOCME
072: *
073: * @return DOCME
074: */
075: public String getMessage() {
076: String message = super .getMessage();
077:
078: if ((message == null) || (message.length() == 0)) {
079: if (getCause() != null) {
080: return getCause().getMessage();
081: } else {
082: return "No error message";
083: }
084: } else {
085: return message;
086: }
087: }
088:
089: /**
090: * Sets the fieldPathWithError.
091: *
092: * @param fieldPathWithError The fieldPathWithError to set
093: */
094: public void setPathWithError(String fieldPathWithError) {
095: this .fieldPathWithError = fieldPathWithError;
096: }
097:
098: /**
099: * DOCUMENT ME!
100: *
101: * @return String
102: */
103: public String getPathWithError() {
104: return fieldPathWithError;
105: }
106:
107: /**
108: * DOCUMENT ME!
109: *
110: * @return
111: */
112: public String toStackTrace() {
113: StringWriter out = new StringWriter();
114:
115: if (getCause() != null) {
116: getCause().printStackTrace(new PrintWriter(out));
117: } else {
118: printStackTrace(new PrintWriter(out));
119: }
120:
121: return out.toString();
122: }
123: }
|