001: /*
002: * $Id: ProgrammingException.java,v 1.18 2007/03/16 09:54:58 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.common;
008:
009: import org.xins.logdoc.ExceptionUtils;
010:
011: /**
012: * Exception thrown when a programming error is detected.
013: *
014: * @version $Revision: 1.18 $ $Date: 2007/03/16 09:54:58 $
015: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
016: *
017: * @since XINS 1.1.0
018: */
019: public final class ProgrammingException extends RuntimeException {
020:
021: /**
022: * The name of the class that detected the problem. Is <code>null</code> if
023: * unknown.
024: */
025: private final String _detectingClass;
026:
027: /**
028: * The name of the method where the problem was detected. Is
029: * <code>null</code> if unknown.
030: */
031: private final String _detectingMethod;
032:
033: /**
034: * The name of the class which exposes the programming error. Is
035: * <code>null</code> if unknown.
036: */
037: private final String _subjectClass;
038:
039: /**
040: * The name of the method which exposes the programming error, or
041: * <code>null</code> if unknown.
042: */
043: private final String _subjectMethod;
044:
045: /**
046: * The detail message. Can be <code>null</code>.
047: */
048: private final String _detail;
049:
050: /**
051: * Constructs a new <code>ProgrammingException</code> for the specified
052: * class and method, indicating which class and method detected the
053: * problem.
054: *
055: * @param detectingClass
056: * the name of the class that detected the problem, or
057: * <code>null</code> if unknown.
058: *
059: * @param detectingMethod
060: * the name of the method within the <code>detectingClass</code> that
061: * detected the problem, or <code>null</code> if unknown.
062: *
063: * @param subjectClass
064: * the name of the class which exposes the programming error, or
065: * <code>null</code> if unknown.
066: *
067: * @param subjectMethod
068: * the name of the method (within the <code>subjectClass</code>) which
069: * exposes the programming error, or <code>null</code> if unknown.
070: *
071: * @param detail
072: * the detail message, can be <code>null</code>.
073: *
074: * @param cause
075: * the cause exception, can be <code>null</code>.
076: */
077: public ProgrammingException(String detectingClass,
078: String detectingMethod, String subjectClass,
079: String subjectMethod, String detail, Throwable cause) {
080:
081: // Call superconstructor with a constructed message
082: super (createMessage(detectingClass, detectingMethod,
083: subjectClass, subjectMethod, detail, cause));
084:
085: // Register the cause for this exception
086: ExceptionUtils.setCause(this , cause);
087:
088: // Store all the information in fields
089: _detectingClass = detectingClass;
090: _detectingMethod = detectingMethod;
091: _subjectClass = subjectClass;
092: _subjectMethod = subjectMethod;
093: _detail = detail;
094: }
095:
096: /**
097: * Creates the exception message for the specified details.
098: *
099: * @param detectingClass
100: * the name of the class that detected the problem, or
101: * <code>null</code> if unknown.
102: *
103: * @param detectingMethod
104: * the name of the method within the <code>detectingClass</code> that
105: * detected the problem, or <code>null</code> if unknown.
106: *
107: * @param subjectClass
108: * the name of the class which exposes the programming error, or
109: * <code>null</code> if unknown.
110: *
111: * @param subjectMethod
112: * the name of the method (within the <code>subjectClass</code>) which
113: * exposes the programming error, or <code>null</code> if unknown.
114: *
115: * @param detail
116: * the detail message, can be <code>null</code>.
117: *
118: * @param cause
119: * the cause exception, can be <code>null</code>.
120: *
121: * @return
122: * the exception message, can be <code>null</code>.
123: */
124: private static String createMessage(String detectingClass,
125: String detectingMethod, String subjectClass,
126: String subjectMethod, String detail, Throwable cause) {
127:
128: String message = "Programming error suspected";
129:
130: if (subjectClass != null) {
131: message += " in class " + subjectClass;
132: if (subjectMethod != null) {
133: message += ", method " + subjectMethod;
134: }
135: }
136:
137: if (detectingClass != null) {
138: message += ". Detected by class " + detectingClass;
139: if (detectingMethod != null) {
140: message += ", method " + detectingMethod;
141: }
142: }
143:
144: if (detail != null) {
145: message += ". Detail: \"" + detail + "\"";
146: }
147:
148: message += ".";
149:
150: return message;
151: }
152:
153: /**
154: * Returns the name of the class that detected the problem.
155: *
156: * @return
157: * the name of the class that detected the problem, or <code>null</code>
158: * if unknown.
159: *
160: * @since XINS 1.3.0
161: */
162: public String getDetectingClass() {
163: return _detectingClass;
164: }
165:
166: /**
167: * Returns the name of the method where the problem was detected.
168: *
169: * @return
170: * the name of the method that detected the problem, or
171: * <code>null</code> if unknown.
172: *
173: * @since XINS 1.3.0
174: */
175: public String getDetectingMethod() {
176: return _detectingMethod;
177: }
178:
179: /**
180: * Returns the name of the class which exposes the programming error.
181: *
182: * @return
183: * the name of the class that exposed the problem, or
184: * <code>null</code> if unknown.
185: *
186: * @since XINS 1.3.0
187: */
188: public String getSubjectClass() {
189: return _subjectClass;
190: }
191:
192: /**
193: * Returns the name of the method which exposes the programming error.
194: *
195: * @return
196: * the name of the method that exposed the problem, or
197: * <code>null</code> if unknown.
198: *
199: * @since XINS 1.3.0
200: */
201: public String getSubjectMethod() {
202: return _subjectMethod;
203: }
204:
205: /**
206: * Returns the detail message.
207: *
208: * @return
209: * the detail message, can be <code>null</code>.
210: *
211: * @since XINS 1.3.0
212: */
213: public String getDetail() {
214: return _detail;
215: }
216: }
|