001: /*
002: * Copyright (C) The DNA Group. All rights reserved.
003: *
004: * This software is published under the terms of the DNA
005: * Software License version 1.1, a copy of which has been included
006: * with this distribution in the LICENSE.txt file.
007: */
008: package org.codehaus.dna;
009:
010: /**
011: * The ConfigurationException is used to signal a problem
012: * with the configuration object. The configuration object
013: * may have malformed data (ie expected an integer but got
014: * a string), have missing data (ie no attribute with specified
015: * name) or may fail to be valid via some other mechanism.
016: *
017: * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
018: */
019: public class ConfigurationException extends Exception {
020: /**
021: * The exception that caused this exception if any.
022: */
023: private final Throwable m_cause;
024:
025: /**
026: * The xpath to the configuration element that
027: * caused the exception. This may be null or empty
028: * if not relevent or not known.
029: */
030: private final String m_path;
031:
032: /**
033: * A string describing the location of the configuration
034: * element that caused the exception. This may be null
035: * or empty if not relevent or not known. The location is
036: * usally formatted according to <tt>uri[:line number[:column number]]</tt>.
037: * Note that the line and column numbers may not be present.
038: */
039: private final String m_location;
040:
041: /**
042: * Create configuration exception with specified message,
043: * path and location.
044: *
045: * @param message the message
046: * @param path the path
047: * @param location the location
048: */
049: public ConfigurationException(final String message,
050: final String path, final String location) {
051: this (message, path, location, null);
052: }
053:
054: /**
055: * Create configuration exception with specified
056: * message and cause.
057: *
058: * @param message the message
059: * @param cause the cause
060: */
061: public ConfigurationException(final String message,
062: final Throwable cause) {
063: this (message, null, null, cause);
064: }
065:
066: /**
067: * Create configuration exception with specified message,
068: * path, location and cause.
069: *
070: * @param message the message
071: * @param path the path
072: * @param location the location
073: * @param cause the cause
074: */
075: public ConfigurationException(final String message,
076: final String path, final String location,
077: final Throwable cause) {
078: super (message);
079: m_cause = cause;
080: m_path = path;
081: m_location = location;
082: }
083:
084: /**
085: * The xpath to the configuration element that
086: * caused the exception. This may be null or empty
087: * if not relevent or not known.
088: *
089: * @return the xpath to element that caused exception
090: */
091: public String getPath() {
092: return m_path;
093: }
094:
095: /**
096: * Return a string describing the location of the configuration
097: * element that caused the exception. This may be null
098: * or empty if not relevent or not known. The location is usally
099: * formatted according to <tt>uri[:line number[:column number]]</tt>.
100: * Note that the line and column numbers may not be present.
101: *
102: * @return the location where exception occured
103: */
104: public String getLocation() {
105: return m_location;
106: }
107:
108: /**
109: * Return the exception that caused this exception if any.
110: *
111: * @return the exception that caused this exception if any.
112: */
113: public Throwable getCause() {
114: return m_cause;
115: }
116:
117: /**
118: * Return the string representation of exception.
119: *
120: * @return the string representation of exception.
121: */
122: public String toString() {
123: final StringBuffer sb = new StringBuffer();
124:
125: if (null != m_path && !"".equals(m_path)) {
126: sb.append(" - ");
127: sb.append(m_path);
128: }
129:
130: if (null != m_location && !"".equals(m_location)) {
131: sb.append(" @ ");
132: sb.append(m_location);
133: }
134:
135: if (0 != sb.length()) {
136: return super.toString() + sb;
137: } else {
138: return super.toString();
139: }
140: }
141: }
|