001: /*
002: * Copyright 2004 Clinton Begin
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.ibatis.sqlmap.engine.scope;
017:
018: /**
019: * An error context to help us create meaningful error messages
020: */
021: public class ErrorContext {
022:
023: private String resource;
024: private String activity;
025: private String objectId;
026: private String moreInfo;
027: private Throwable cause;
028:
029: /**
030: * Getter for the resource causing the problem
031: *
032: * @return - the resource
033: */
034: public String getResource() {
035: return resource;
036: }
037:
038: /**
039: * Setter for the resource causing the problem
040: *
041: * @param resource - the resource
042: */
043: public void setResource(String resource) {
044: this .resource = resource;
045: }
046:
047: /**
048: * Getter for the activity that was happening when the error happened
049: *
050: * @return - the activity
051: */
052: public String getActivity() {
053: return activity;
054: }
055:
056: /**
057: * Getter for the activity that was happening when the error happened
058: *
059: * @param activity - the activity
060: */
061: public void setActivity(String activity) {
062: this .activity = activity;
063: }
064:
065: /**
066: * Getter for the object ID where the problem happened
067: *
068: * @return - the object id
069: */
070: public String getObjectId() {
071: return objectId;
072: }
073:
074: /**
075: * Setter for the object ID where the problem happened
076: *
077: * @param objectId - the object id
078: */
079: public void setObjectId(String objectId) {
080: this .objectId = objectId;
081: }
082:
083: /**
084: * Getter for more information about the error
085: *
086: * @return - more information
087: */
088: public String getMoreInfo() {
089: return moreInfo;
090: }
091:
092: /**
093: * Setter for more information about the error
094: *
095: * @param moreInfo - more information
096: */
097: public void setMoreInfo(String moreInfo) {
098: this .moreInfo = moreInfo;
099: }
100:
101: /**
102: * Getter for the cause of the error
103: *
104: * @return - the cause
105: */
106: public Throwable 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 cause) {
116: this .cause = cause;
117: }
118:
119: public String toString() {
120: StringBuffer message = new StringBuffer();
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: }
|