KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > exception > BaseException


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.exception;
19
20
21 import org.sape.carbon.core.util.classify.SeverityEnum;
22
23 /**
24  * <P>This is an abstract, base exception class provided within the Carbon Core
25  * to support basic exception functionality. This includes the tracking of
26  * cause, severity and the source of an exception as well as a string message.
27  * </P>
28  *
29  * <P>Exceptions that subclass this one will attempt to log on creation when
30  * utilizing the default ExceptionDelegate. Other ExceptionDelegates may be
31  * configured by setting the </i>carbon.exceptiondelegate<i> system property.
32  * </P>
33  *
34  *
35  * Copyright 2002 Sapient
36  * @since carbon 1.0
37  * @author Greg Hinkle, January 2002
38  * @version $Revision: 1.12 $($Author: dvoet $ / $Date: 2003/05/05 21:21:21 $)
39  */

40 public abstract class BaseException extends Exception JavaDoc implements Exceptionable {
41
42
43     /**
44      * The implementing exception delegate that provides
45      * Carbon Core exceptions with their basic functionality.
46      */

47     protected ExceptionDelegate delegatedException;
48
49     /**
50      * Constructs an exception with the provided source and message
51      *
52      * @param sourceClass The source class of this exception
53      * @param message string information relating to this exception
54      */

55     public BaseException(Class JavaDoc sourceClass, String JavaDoc message) {
56
57         super(message);
58         this.delegatedException =
59             ExceptionDelegateFactory.getInstance().createDelegate(
60                 sourceClass, this.getSeverity(), this, message, null);
61         this.delegatedException.handleException();
62     }
63
64     /**
65      * Constructs an exception with the provided source, message and
66      * cause
67      *
68      * @param sourceClass The source class of this exception
69      * @param message string information relating to this exception
70      * @param cause a throwable that can be considered the cause
71      * of the current exception (used in levelizing exceptions)
72      */

73     public BaseException(Class JavaDoc sourceClass, String JavaDoc message,
74                          Throwable JavaDoc cause) {
75
76         super(message);
77
78         this.delegatedException =
79             ExceptionDelegateFactory.getInstance().createDelegate(
80                 sourceClass, this.getSeverity(), this, message, cause);
81         this.delegatedException.handleException();
82     }
83
84
85
86     /**
87      * This method must be overriden by subclasses so that
88      * they may declare their severity
89      * @return the severity of this exception
90      */

91     public abstract SeverityEnum getSeverity();
92
93
94     /**
95      * This method will normall return the supplied source
96      * of an exception, but may be overridden to always supply
97      * the class of the exception.
98      * @return the source of this exception
99      */

100     public Class JavaDoc getExceptionSource() {
101         return this.delegatedException.getExceptionSource();
102     }
103
104
105     /**
106      * calls getPreviousException on the delegated exception
107      * @return String - previousException from the delegated exception
108      */

109     public Throwable JavaDoc getCause() {
110         return this.delegatedException.getCause();
111     }
112
113
114     /**
115      * calls toString on the delegated exception
116      * @return String - toString from the delegated exception
117      */

118     public String JavaDoc toString() {
119         return this.delegatedException.toString();
120     }
121
122
123     /**
124      * calls getMessage on the delegated exception
125      * @return String - getMessage from the delegated exception
126      */

127     public String JavaDoc getMessage() {
128         return this.delegatedException.getMessage();
129     }
130
131     /*
132     public String getLocalizeMessage(Locale locale) {
133         return null;
134     }
135     */

136
137
138 }
Popular Tags