001: /***
002: * jwma Java WebMail
003: * Copyright (c) 2000-2003 jwma team
004: *
005: * jwma is free software; you can distribute and use this source
006: * under the terms of the BSD-style license received along with
007: * the distribution.
008: ***/package dtw.webmail.model;
009:
010: import java.io.*;
011: import java.util.*;
012:
013: import dtw.webmail.JwmaKernel;
014:
015: /**
016: * Class implementing the JwmaError model.
017: * It can contain an embedded exception and allows
018: * access to it and it's corresponding stack trace.
019: *
020: * @author Dieter Wimberger
021: * @version 0.9.7 07/02/2003
022: */
023: public class JwmaException extends Exception implements JwmaError {
024:
025: //instance attributes
026: private boolean inline;
027: private boolean displayed = false;
028: private Set m_Descriptions = new HashSet(5);
029: private Exception m_Exception;
030:
031: /**
032: * Constructs a new <tt>JwmaException</tt> instance
033: * with a given description.
034: *
035: * @param msg the description of the Exception as <tt>String</tt>.
036: */
037: public JwmaException(String msg) {
038: super (msg);
039: addDescription(msg);
040: inline = false;
041: }//constructor
042:
043: /**
044: * Constructs a new <tt>JwmaException</tt> instance.
045: * with a given description and possibly as inline error.
046: *
047: * @param msg the description of the Exception as <tt>String</tt>.
048: * @param inlined true when inline error, false otherwise.
049: */
050: public JwmaException(String msg, boolean inlined) {
051: super (msg);
052: addDescription(msg);
053: inline = inlined;
054: }//constructor
055:
056: /**
057: * Sets the flag that controls if the Exception represents
058: * an inline error.
059: * <p>
060: * An inline error should be displayed within the same view
061: * and not on the error view.
062: *
063: * @param true if the overriding is to be allowed, false otherwise.
064: * @return reference to this exception.
065: */
066: public JwmaException setInlineError(boolean b) {
067: inline = b;
068: return this ;
069: }//setInlineError
070:
071: public boolean isInlineError() {
072: return inline;
073: }//isInlineError
074:
075: public void addDescription(String description) {
076: m_Descriptions.add(description);
077: }//addDescription
078:
079: public String[] getDescriptions() {
080: String[] desc = new String[m_Descriptions.size()];
081: return (String[]) m_Descriptions.toArray(desc);
082: }//getDescriptions
083:
084: public Iterator iterator() {
085: return m_Descriptions.iterator();
086: }//iterator
087:
088: /**
089: * Resolves the description for the error in the
090: * given language.
091: *
092: * @param language the string denoting the language.
093: *
094: public void resolveDescription(String language) {
095: if(!isResolved()) {
096: m_Description= JwmaKernel.getReference()
097: .getErrorMessage(super.getMessage(),language);
098: setResolved(true);
099: }
100: }//resolveDescription
101:
102: /**
103: * Tests if the error has been resolved to
104: * an i18n description.
105: *
106: * @return true if it was resolved, false otherwise.
107: *
108: public boolean isResolved() {
109: return m_Resolved;
110: }//isResolved
111:
112: /**
113: * Sets the flag that controls if this error has already
114: * i18n resolved the description.
115: *
116: * @param true if resolved, false otherwise.
117: * @return reference to this exception.
118: *
119: public JwmaException setResolved(boolean b) {
120: m_Resolved=true;
121: return this;
122: }//setResolved
123: */
124:
125: /**
126: * Sets the flag that controls if this error was already
127: * displayed.
128: *
129: * @param true if the overriding is to be allowed, false otherwise.
130: */
131: public void setDisplayed(boolean b) {
132: displayed = b;
133: }//setDisplayed
134:
135: public boolean isDisplayed() {
136: return displayed;
137: }//isDisplayed
138:
139: /**
140: * Sets an embedded exception.
141: *
142: * @param ex the exception to be embedded.
143: * @return reference to this exception.
144: */
145: public JwmaException setException(Exception ex) {
146: m_Exception = ex;
147: return this ;
148: }//setException
149:
150: public boolean hasException() {
151: return (m_Exception != null);
152: }//hasException
153:
154: public String getExceptionTrace() {
155: if (hasException()) {
156: StringWriter trace = new StringWriter();
157: m_Exception.printStackTrace(new PrintWriter(trace));
158: return trace.toString();
159: } else {
160: return "";
161: }
162: }//getExceptionTrace
163:
164: /**
165: * Returns the embedded exception.
166: *
167: * @return the embedded exception.
168: */
169: public Exception getException() {
170: return m_Exception;
171: }//getException
172:
173: }//JwmaException
|