KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > utility > NoUnitException


1 package net.firstpartners.nounit.utility;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

26
27  /**
28   * System Wide Exception (containing original Exception & user friendly message)
29   * thrown whenever invalid values are found.
30   */

31 public class NoUnitException extends Exception JavaDoc {
32
33
34   //User Friendly Error Message , initialised to empty string
35
private String JavaDoc userErrorMessage;
36   private Exception JavaDoc internalException;
37
38
39   /**
40    * Constructor , repackages other Exceptions to add (User Friendly) information
41    * @param inException to hold
42    * @param userFriendlyMessage to display to user
43    */

44   public NoUnitException(Exception JavaDoc inException, String JavaDoc userFriendlyMessage) {
45
46     //Call the super constructor
47
super(inException.toString());
48
49     //Set the Internal Error
50
internalException = inException;
51
52     //Set the user Friendly Error Message
53
userErrorMessage=userFriendlyMessage;
54
55   }
56
57
58   /**
59    * Constructor , calls exception with value pair information
60    * @param inValidValueName - the name the value was stored under
61    * @param inValidValue - the value that was rejected
62    */

63   public NoUnitException(String JavaDoc inValidValueName , String JavaDoc inValidValue) {
64     super ("Invalid value submitted ("+inValidValue+") under keyname "+inValidValueName);
65
66     //Set the internal error message
67
userErrorMessage=this.toString();
68
69     //Set the InternalException
70
internalException = this;
71
72   }
73
74    /**
75    * Constructor , calls exception with value pair information , plus reason
76    * @param inValidValueName - the name the value was stored under
77    * @param inValidValue - the value that was rejected
78    * @param reason - the reason why the value was rejected
79    */

80   public NoUnitException(String JavaDoc inValidValueName , String JavaDoc inValidValue ,String JavaDoc reason) {
81     super ("Invalid value submitted ("+inValidValue+") under keyname "+inValidValueName
82       + " reason: "+reason);
83
84     //Set the InternalException
85
internalException = this;
86
87     //Set the internal error message
88
userErrorMessage=this.toString();
89   }
90
91   /**
92    * Constructor , calls exception with value pair information , plus reason
93    * @param inUserErrorMessage that will be displayed to the user
94    */

95   public NoUnitException(String JavaDoc inUserErrorMessage) {
96     super (inUserErrorMessage);
97
98     //Set the InternalException
99
internalException = this;
100
101     //Set the internal error message
102
userErrorMessage=inUserErrorMessage;
103   }
104
105   /**
106    * Returns the userFriendly Error Message
107    * @return userErrorMessage
108    */

109   public String JavaDoc getUserErrorMessage() {
110     return userErrorMessage;
111   }
112
113
114    /**
115     * Over-rides the toString method to provide more information.
116     * @return infoString containing concatanated original error (if any) , plus
117     * any user friendly messages.
118     */

119    public String JavaDoc toString(){
120
121     //Give as much information as possible about this exception in string format
122
StringBuffer JavaDoc infoString = new StringBuffer JavaDoc("Exception:");
123     infoString.append(super.toString());
124     infoString.append("\n");
125     infoString.append("UserMessage:");
126     infoString.append(getUserErrorMessage());
127     infoString.append("\n");
128
129     //Give Info if internal exception has anything useful...
130
if ((internalException!=null)&&(!(internalException instanceof NoUnitException))) {
131       infoString.append("Original Exception:");
132       infoString.append(internalException.toString());
133       infoString.append("\n");
134     }
135
136     return infoString.toString();
137
138    }
139
140   /**
141    * return the internal / original Exception , if any
142    * @return internalException that is stored when this was created
143    */

144    public Exception JavaDoc getOriginalException() {
145
146     return this.internalException;
147
148    }
149
150 }
Popular Tags