KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > ConfigurationException


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
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
17 package org.apache.axis;
18
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.axis.utils.JavaUtils;
21 import org.apache.commons.logging.Log;
22
23 import java.io.IOException JavaDoc;
24
25 /**
26  * ConfigurationException is thrown when an error occurs trying to
27  * use an EngineConfiguration.
28  *
29  * @author Glyn Normington (glyn@apache.org)
30  */

31 public class ConfigurationException extends IOException JavaDoc {
32
33     /**
34      * The contained exception if present.
35      */

36     private Exception JavaDoc containedException=null;
37
38     private String JavaDoc stackTrace="";
39
40     /**
41      * Flag wether to copy the orginal exception by default.
42      */

43     protected static boolean copyStackByDefault= true;
44
45     /**
46      * The <code>Log</code> used by this class for logging all messages.
47      */

48     protected static Log log =
49         LogFactory.getLog(ConfigurationException.class.getName());
50
51     /**
52      * Construct a ConfigurationException from a String. The string is wrapped
53      * in an exception, enabling a stack traceback to be obtained.
54      * @param message String form of the error
55      */

56     public ConfigurationException(String JavaDoc message) {
57         super(message);
58         if(copyStackByDefault) {
59             stackTrace= JavaUtils.stackToString(this);
60         }
61         logException( this);
62     }
63
64     /**
65      * Construct a ConfigurationException from an Exception.
66      * @param exception original exception which was unexpected
67      */

68     public ConfigurationException(Exception JavaDoc exception) {
69         this(exception,copyStackByDefault);
70     }
71
72     /**
73      * Stringify, including stack trace.
74      *
75      * @return a <code>String</code> view of this object
76      */

77     public String JavaDoc toString() {
78         String JavaDoc stack;
79         if(stackTrace.length()== 0) {
80             stack = "";
81         } else {
82             stack="\n"+stackTrace;
83         }
84         return super.toString()+stack;
85     }
86
87     /**
88      * Construct a ConfigurationException from an Exception.
89      * @param exception original exception which was unexpected
90      * @param copyStack set to true to copy the orginal exception's stack
91      */

92     public ConfigurationException(Exception JavaDoc exception, final boolean copyStack) {
93         super(exception.toString() + (copyStack ? "\n"
94            + JavaUtils.stackToString(exception) : "" ));
95         containedException = exception;
96         if(copyStack) {
97             stackTrace = JavaUtils.stackToString(this);
98         }
99         // Log the exception the first time it appears.
100
if (!(exception instanceof ConfigurationException)) {
101             logException(exception);
102         }
103     }
104
105     /**
106      * single point for logging exceptions.
107      * @param exception
108      */

109     private void logException(Exception JavaDoc exception) {
110         log.debug("Exception: ", exception);
111     }
112
113     /**
114      * Get any contained exception.
115      *
116      * @return base exception or null
117      * @since axis1.1
118      */

119     public Exception JavaDoc getContainedException() {
120         return containedException;
121     }
122 }
123
Popular Tags