KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > dna > ConfigurationException


1 /*
2  * Copyright (C) The DNA Group. All rights reserved.
3  *
4  * This software is published under the terms of the DNA
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.dna;
9
10 /**
11  * The ConfigurationException is used to signal a problem
12  * with the configuration object. The configuration object
13  * may have malformed data (ie expected an integer but got
14  * a string), have missing data (ie no attribute with specified
15  * name) or may fail to be valid via some other mechanism.
16  *
17  * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
18  */

19 public class ConfigurationException
20     extends Exception JavaDoc
21 {
22     /**
23      * The exception that caused this exception if any.
24      */

25     private final Throwable JavaDoc m_cause;
26
27     /**
28      * The xpath to the configuration element that
29      * caused the exception. This may be null or empty
30      * if not relevent or not known.
31      */

32     private final String JavaDoc m_path;
33
34     /**
35      * A string describing the location of the configuration
36      * element that caused the exception. This may be null
37      * or empty if not relevent or not known. The location is
38      * usally formatted according to <tt>uri[:line number[:column number]]</tt>.
39      * Note that the line and column numbers may not be present.
40      */

41     private final String JavaDoc m_location;
42
43     /**
44      * Create configuration exception with specified message,
45      * path and location.
46      *
47      * @param message the message
48      * @param path the path
49      * @param location the location
50      */

51     public ConfigurationException( final String JavaDoc message,
52                                    final String JavaDoc path,
53                                    final String JavaDoc location )
54     {
55         this( message, path, location, null );
56     }
57
58     /**
59      * Create configuration exception with specified
60      * message and cause.
61      *
62      * @param message the message
63      * @param cause the cause
64      */

65     public ConfigurationException( final String JavaDoc message,
66                                    final Throwable JavaDoc cause )
67     {
68         this( message, null, null, cause );
69     }
70
71     /**
72      * Create configuration exception with specified message,
73      * path, location and cause.
74      *
75      * @param message the message
76      * @param path the path
77      * @param location the location
78      * @param cause the cause
79      */

80     public ConfigurationException( final String JavaDoc message,
81                                    final String JavaDoc path,
82                                    final String JavaDoc location,
83                                    final Throwable JavaDoc cause )
84     {
85         super( message );
86         m_cause = cause;
87         m_path = path;
88         m_location = location;
89     }
90
91     /**
92      * The xpath to the configuration element that
93      * caused the exception. This may be null or empty
94      * if not relevent or not known.
95      *
96      * @return the xpath to element that caused exception
97      */

98     public String JavaDoc getPath()
99     {
100         return m_path;
101     }
102
103     /**
104      * Return a string describing the location of the configuration
105      * element that caused the exception. This may be null
106      * or empty if not relevent or not known. The location is usally
107      * formatted according to <tt>uri[:line number[:column number]]</tt>.
108      * Note that the line and column numbers may not be present.
109      *
110      * @return the location where exception occured
111      */

112     public String JavaDoc getLocation()
113     {
114         return m_location;
115     }
116
117     /**
118      * Return the exception that caused this exception if any.
119      *
120      * @return the exception that caused this exception if any.
121      */

122     public Throwable JavaDoc getCause()
123     {
124         return m_cause;
125     }
126
127     /**
128      * Return the string representation of exception.
129      *
130      * @return the string representation of exception.
131      */

132     public String JavaDoc toString()
133     {
134         final StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
135
136         if( null != m_path && !"".equals( m_path ) )
137         {
138             sb.append( " - " );
139             sb.append( m_path );
140         }
141
142         if( null != m_location && !"".equals( m_location ) )
143         {
144             sb.append( " @ " );
145             sb.append( m_location );
146         }
147
148         if( 0 != sb.length() )
149         {
150             return super.toString() + sb;
151         }
152         else
153         {
154             return super.toString();
155         }
156     }
157 }
158
Popular Tags