KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > EjenException


1 //
2
// Ejen (code generation system)
3
// Copyright (C) 2001, 2002 François Wolff (ejen@noos.fr).
4
//
5
// This file is part of Ejen.
6
//
7
// Ejen is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
11
//
12
// Ejen is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with Ejen; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//
21
package org.ejen;
22
23 /**
24  * Ejen exception class. May wrap another exception.
25  * @author F. Wolff
26  * @version 1.0
27  */

28 public class EjenException extends RuntimeException JavaDoc {
29     protected EjenChildNode _ejenChildNode = null;
30     protected String JavaDoc _message = "(no message)";
31     protected Throwable JavaDoc _embeddedThrowable = null;
32
33     /**
34      * Constructor.
35      * @param ejenChildNode the EjenChildNode that is throwing this EjenException.
36      * @param message the message associated with this EjenException.
37      */

38     public EjenException(EjenChildNode ejenChildNode, String JavaDoc message) {
39         this(ejenChildNode, message, null);
40     }
41
42     /**
43      * Constructor.
44      * @param ejenChildNode the EjenChildNode that is throwing this EjenException.
45      * @param message the message associated with this EjenException.
46      * @param t an embedded exception.
47      */

48     public EjenException(EjenChildNode ejenChildNode, String JavaDoc message, Throwable JavaDoc t) {
49         _ejenChildNode = ejenChildNode;
50         if (message != null) {
51             _message = message;
52         }
53         _embeddedThrowable = t;
54     }
55     
56     /**
57      * Returns a compound message: "<ecn> {<attrs>}: <msg> [<eemsg>]",
58      * where:
59      * <ul>
60      * <li>&lt;ecn&gt; is the name of the EjenChildNode that have thrown this
61      * EjenException.
62      * <li>&lt;attrs&gt; are all attributes of the EjenChildNode that have thrown this
63      * EjenException.
64      * <li>&lt;msg&gt; is the message associated with this EjenException.
65      * <li>&lt;eemsg&gt; is the message associated with the embedded exception.
66      * </ul>
67      * @return the compound message.
68      */

69     public String JavaDoc getMessage() {
70         String JavaDoc nodeInfo = "(unknown node)";
71         String JavaDoc embeddedThrowableString = "";
72
73         if (_ejenChildNode != null) {
74             nodeInfo = _ejenChildNode.toString();
75         }
76         if (_embeddedThrowable != null) {
77             embeddedThrowableString = " [" + _embeddedThrowable.toString() + "]";
78         }
79         return nodeInfo + ": " + _message + embeddedThrowableString;
80     }
81     
82     /**
83      * Returns the embedded exception.
84      * @return the embedded message (may be null).
85      */

86     public Throwable JavaDoc getEmbeddedThrowable() {
87         return _embeddedThrowable;
88     }
89     
90     /**
91      * Returns the EjenChildNode that have thrown this EjenException.
92      * @return the EjenChildNode.
93      */

94     public EjenChildNode getEjenChildNode() {
95         return _ejenChildNode;
96     }
97     
98     /**
99      * Returns the message associated with this EjenException.
100      * @return the message (may be null).
101      */

102     public String JavaDoc getRawMessage() {
103         return _message;
104     }
105 }
106
Popular Tags