KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This exception should be used to support runtime exceptions.
28  * </P>
29  *
30  * <P>Exceptions that subclass this one will attempt to log on creation when
31  * utilizing the default ExceptionDelegate. Other ExceptionDelegates may be
32  * configured by setting the </i>carbon.exceptiondelegate<i> system property.
33  * </P>
34  *
35  *
36  * Copyright 2002 Sapient
37  * @since carbon 1.0
38  * @author Greg Hinkle, January 2002
39  * @version $Revision: 1.13 $($Author: dvoet $ / $Date: 2003/05/05 21:21:21 $)
40  */

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

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

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

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

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

101     public Class JavaDoc getExceptionSource() {
102         return this.delegatedException.getExceptionSource();
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      * calls toString on the delegated exception
115      * @return String - toString from the delegated exception
116      */

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

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

134
135 }
Popular Tags