KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > scope > ErrorContext


1 /*
2  * Copyright 2004 Clinton Begin
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 com.ibatis.sqlmap.engine.scope;
17
18 /**
19  * An error context to help us create meaningful error messages
20  */

21 public class ErrorContext {
22
23   private String JavaDoc resource;
24   private String JavaDoc activity;
25   private String JavaDoc objectId;
26   private String JavaDoc moreInfo;
27   private Throwable JavaDoc cause;
28
29   /**
30    * Getter for the resource causing the problem
31    *
32    * @return - the resource
33    */

34   public String JavaDoc getResource() {
35     return resource;
36   }
37
38   /**
39    * Setter for the resource causing the problem
40    *
41    * @param resource - the resource
42    */

43   public void setResource(String JavaDoc resource) {
44     this.resource = resource;
45   }
46
47   /**
48    * Getter for the activity that was happening when the error happened
49    *
50    * @return - the activity
51    */

52   public String JavaDoc getActivity() {
53     return activity;
54   }
55
56   /**
57    * Getter for the activity that was happening when the error happened
58    *
59    * @param activity - the activity
60    */

61   public void setActivity(String JavaDoc activity) {
62     this.activity = activity;
63   }
64
65   /**
66    * Getter for the object ID where the problem happened
67    *
68    * @return - the object id
69    */

70   public String JavaDoc getObjectId() {
71     return objectId;
72   }
73
74   /**
75    * Setter for the object ID where the problem happened
76    *
77    * @param objectId - the object id
78    */

79   public void setObjectId(String JavaDoc objectId) {
80     this.objectId = objectId;
81   }
82
83   /**
84    * Getter for more information about the error
85    *
86    * @return - more information
87    */

88   public String JavaDoc getMoreInfo() {
89     return moreInfo;
90   }
91
92   /**
93    * Setter for more information about the error
94    *
95    * @param moreInfo - more information
96    */

97   public void setMoreInfo(String JavaDoc moreInfo) {
98     this.moreInfo = moreInfo;
99   }
100
101   /**
102    * Getter for the cause of the error
103    *
104    * @return - the cause
105    */

106   public Throwable JavaDoc getCause() {
107     return cause;
108   }
109
110   /**
111    * Setter for the cause of the error
112    *
113    * @param cause - the cause
114    */

115   public void setCause(Throwable JavaDoc cause) {
116     this.cause = cause;
117   }
118
119   public String JavaDoc toString() {
120     StringBuffer JavaDoc message = new StringBuffer JavaDoc();
121
122     // resource
123
if (resource != null) {
124       message.append(" \n--- The error occurred in ");
125       message.append(resource);
126       message.append(".");
127     }
128
129     // activity
130
if (activity != null) {
131       message.append(" \n--- The error occurred while ");
132       message.append(activity);
133       message.append(".");
134     }
135
136     // object
137
if (objectId != null) {
138       message.append(" \n--- Check the ");
139       message.append(objectId);
140       message.append(".");
141     }
142
143     // more info
144
if (moreInfo != null) {
145       message.append(" \n--- ");
146       message.append(moreInfo);
147     }
148
149     // cause
150
if (cause != null) {
151       message.append(" \n--- Cause: ");
152       message.append(cause.toString());
153     }
154
155     return message.toString();
156   }
157
158   /**
159    * Clear the error context
160    */

161   public void reset() {
162     resource = null;
163     activity = null;
164     objectId = null;
165     moreInfo = null;
166     cause = null;
167   }
168
169
170 }
171
Popular Tags