1 /*
2 * Copyright 2007 Sebastien Brunot (sbrunot@gmail.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sourceforge.buildmonitor;
17
18 import java.net.URI;
19
20 /**
21 * Exception that signal an error that occurs during the monitoring of a build
22 * @author sbrunot
23 *
24 */
25 public class MonitoringException extends Exception
26 {
27 /////////////////////////////
28 // Constants
29 /////////////////////////////
30
31 private static final long serialVersionUID = 1875572548525646573L;
32
33 /////////////////////////////
34 // Instance attributes
35 /////////////////////////////
36
37 /**
38 * Signal that the exception might be related to a bad option (parameter) of the monitor
39 */
40 private boolean optionsRelated = false;
41
42 /**
43 * An URI that might be opened in the web browser by the end user in order to solve the problem
44 */
45 private URI customRelatedURI = null;
46
47 /////////////////////////////
48 // Constructors
49 /////////////////////////////
50
51 /**
52 * Create a new instance of the exception not related to a bad option (user parameter) of the monitor.
53 *
54 * @param theMessage the message that explains the exception
55 * @param theCause the cause of the exception
56 * @param theRelatedURI an URI that could be opened in a browser by the end user to resolve the problem.
57 */
58 public MonitoringException(String theMessage, Throwable theCause, URI theRelatedURI)
59 {
60 super(theMessage, theCause);
61 this.customRelatedURI = theRelatedURI;
62 }
63
64 /**
65 * Create a new instance of the exception not related to a bad option (user parameter) of the monitor.
66 *
67 * @param theMessage the message that explains the exception
68 * @param theRelatedURI an URI that could be opened in a browser by the end user to resolve the problem.
69 */
70 public MonitoringException(String theMessage, URI theRelatedURI)
71 {
72 super(theMessage);
73 this.customRelatedURI = theRelatedURI;
74 }
75
76 /**
77 * Create a new instance of the exception not related to a bad option (user parameter) of the monitor.
78 *
79 * @param theCause the cause of the exception
80 * @param theRelatedURI an URI that could be opened in a browser by the end user to resolve the problem.
81 */
82 public MonitoringException(Throwable theCause, URI theRelatedURI)
83 {
84 super(theCause);
85 this.customRelatedURI = theRelatedURI;
86 }
87
88 /**
89 * Create a new instance of the exception.
90 *
91 * @param theMessage the message that explains the exception
92 * @param theCause the cause of the exception
93 * @param isOptionsRelated a boolean that signal if the error is related to a bad
94 * option of the monitor
95 * @param theRelatedURI if isOptionsRelated is false, an URI that could be opened
96 * in a browser by the end user to resolve the problem.
97 */
98 public MonitoringException(String theMessage, Throwable theCause, boolean isOptionsRelated, URI theRelatedURI)
99 {
100 super(theMessage, theCause);
101 this.optionsRelated = isOptionsRelated;
102 this.customRelatedURI = theRelatedURI;
103 }
104
105 /**
106 * Create a new instance of the exception.
107 *
108 * @param theMessage the message that explains the exception
109 * @param isOptionsRelated a boolean that signal if the error is related to a bad
110 * @param theRelatedURI if isOptionsRelated is false, an URI that could be opened
111 * in a browser by the end user to resolve the problem.
112 */
113 public MonitoringException(String theMessage, boolean isOptionsRelated, URI theRelatedURI)
114 {
115 super(theMessage);
116 this.optionsRelated = isOptionsRelated;
117 this.customRelatedURI = theRelatedURI;
118 }
119
120 /**
121 * Create a new instance of the exception.
122 *
123 * @param theCause the cause of the exception
124 * @param isOptionsRelated a boolean that signal if the error is related to a bad
125 * @param theRelatedURI if isOptionsRelated is false, an URI that could be opened
126 * in a browser by the end user to resolve the problem.
127 */
128 public MonitoringException(Throwable theCause, boolean isOptionsRelated, URI theRelatedURI)
129 {
130 super(theCause);
131 this.optionsRelated = isOptionsRelated;
132 this.customRelatedURI = theRelatedURI;
133 }
134
135 /////////////////////////////////////
136 // Getters
137 /////////////////////////////////////
138
139 /**
140 * {@inheritDoc}
141 */
142 public String getMessage()
143 {
144 // If the monitoring exception contains another monitoring exception, return the message of
145 // the contained monitoring exception
146 if (getCause() != null && getCause() instanceof MonitoringException)
147 {
148 return getCause().getMessage();
149 }
150 else
151 {
152 return super.getMessage();
153 }
154 }
155
156 /**
157 * Is this error related to a bad option (user parameter) of the monitor ?
158 * @return true if the error is related to a bad option, false otherwise
159 */
160 public boolean isOptionsRelated()
161 {
162 return this.optionsRelated;
163 }
164
165 /**
166 * Get an URI that can be openend by the end user to resolve the problem (null if
167 * not available)
168 * @return an URI that can be openend by the end user to resolve the problem, or null
169 */
170 public URI getRelatedURI()
171 {
172 return this.customRelatedURI;
173 }
174 }