001 /*
002 * $Id: IncidentInfo.java,v 1.6 2006/03/18 22:52:11 rbair Exp $
003 *
004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020 */
021
022 /**
023 * This is a simple class that incapsulates all the information needed
024 * to report a problem to the automated report/processing system.
025 *
026 * @author Alexander Zuev
027 * @version 1.4
028 */
029 package org.jdesktop.swingx;
030
031 import java.util.logging.Level;
032
033 public class IncidentInfo {
034 /**
035 * Short string that will be used as a error header
036 */
037 private String header;
038 /**
039 * Basic message that describes incident
040 */
041 private String basicErrorMessage;
042 /**
043 * Message that will fully describe the incident with all the
044 * available details
045 */
046 private String detailedErrorMessage;
047 /**
048 * Optional Throwable that will be used as a possible source for
049 * additional information
050 */
051 private Throwable errorException;
052 /**
053 * Used to specify how bad this error was.
054 */
055 private Level errorLevel;
056
057 /**
058 * Main constructor that adds all the information to <code>IncidentInfo</code>
059 * @param header Header that will be used as the quick reference for the
060 * incident (e.g. title for a dialog or subject for the incident message)
061 * @param basicErrorMessage Short description of the given problem
062 * @param detailedErrorMessage Full description of the problem
063 * @param errorException <code>Throwable</code> that can be used as a source for
064 * additional information such as call stack, thread name, etc.
065 */
066 public IncidentInfo(String header, String basicErrorMessage,
067 String detailedErrorMessage, Throwable errorException) {
068 this.header = header;
069 if(basicErrorMessage != null) {
070 this.basicErrorMessage = basicErrorMessage;
071 } else {
072 if(errorException != null) {
073 this.basicErrorMessage = errorException.getLocalizedMessage();
074 if (this.basicErrorMessage == null) {
075 this.basicErrorMessage = errorException.toString();
076 }
077 } else {
078 this.basicErrorMessage = "";
079 }
080 }
081 this.detailedErrorMessage = detailedErrorMessage;
082 this.errorException = errorException;
083 this.errorLevel = Level.SEVERE;
084 }
085
086 /**
087 * Constructor that creates <code>IncidentInfo</code> with all the provided descriptions
088 * @param header Header that will be used as the quick reference for the
089 * incident (e.g. title for a dialog or subject for the incident message)
090 * @param basicErrorMessage Short description of the given problem
091 * @param detailedErrorMessage Full description og the problem
092 */
093 public IncidentInfo(String header, String basicErrorMessage, String detailedErrorMessage) {
094 this(header, basicErrorMessage, detailedErrorMessage, null);
095 }
096
097 /**
098 * Constructor that creates <code>IncidentInfo</code> retreiving all the
099 * information from the provided <code>Throwable</code>
100 * @param header Header that will be used as the quick reference for the
101 * incident (e.g. title for a dialog or subject for the incident message)
102 * @param errorException <code>Throwable</code> that can be used as a main source of
103 * information about the incident
104 */
105 public IncidentInfo(String header, Throwable errorException) {
106 this(header, null, null, errorException);
107 }
108
109 /**
110 * Get the current header string
111 *
112 * @return header string
113 */
114 public String getHeader() {
115 return header;
116 }
117
118 /**
119 * Set the current header string
120 *
121 * @param header
122 */
123 public void setHeader(String header) {
124 this.header = header;
125 }
126
127 /**
128 * Get the basic error description
129 *
130 * @return basic error description
131 */
132 public String getBasicErrorMessage() {
133 return basicErrorMessage;
134 }
135
136 /**
137 * Set the current basic error description
138 *
139 * @param basicErrorMessage new basic error description
140 */
141 public void setBasicErrorMessage(String basicErrorMessage) {
142 this.basicErrorMessage = basicErrorMessage;
143 }
144
145 /**
146 * Get the detailed error description
147 *
148 * @return detailed description
149 */
150 public String getDetailedErrorMessage() {
151 return detailedErrorMessage;
152 }
153
154 /**
155 * Set the detailed description for this error
156 *
157 * @param detailedErrorMessage new detailed description
158 */
159 public void setDetailedErrorMessage(String detailedErrorMessage) {
160 this.detailedErrorMessage = detailedErrorMessage;
161 }
162
163 /**
164 * Get an exception that contains some additional information about the
165 * error if provided.
166 *
167 * @return exception or null if no exception provided
168 */
169 public Throwable getErrorException() {
170 return errorException;
171 }
172
173 /**
174 * Set the exception that may contain additional information about the
175 * error.
176 *
177 * @param errorException new <code>Throwable</code> or <code>null</code>
178 * if there is no <code>Throwable</code> related to this error
179 */
180 public void setErrorException(Throwable errorException) {
181 this.errorException = errorException;
182 }
183
184 /**
185 * Returns the severity of the Error. This defaults to Level.SEVERE, but
186 * may be specified via setErrorLevel
187 *
188 * @return the Level. This will never be null
189 */
190 public Level getErrorLevel() {
191 return errorLevel;
192 }
193
194 /**
195 * Sets the error level for this IncidentInfo
196 *
197 * @param errorLevel any Level (Level.SEVERE, Level.WARNING, etc). If null,
198 * then the level will be set to SEVERE.
199 */
200 public void setErrorLevel(Level errorLevel) {
201 this.errorLevel = errorLevel == null ? Level.SEVERE : errorLevel;
202 }
203 }