KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > bridge > BridgeException


1 /*
2
3    Copyright 2000-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.bridge;
19
20 import org.apache.batik.gvt.GraphicsNode;
21 import org.w3c.dom.Element JavaDoc;
22 import org.w3c.dom.svg.SVGDocument;
23
24 /**
25  * Thrown when the bridge has detected an error.
26  *
27  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
28  * @version $Id: BridgeException.java,v 1.8 2004/08/18 07:12:30 vhardy Exp $
29  */

30 public class BridgeException extends RuntimeException JavaDoc {
31
32     /** The element on which the error occured. */
33     protected Element JavaDoc e;
34
35     /** The error code. */
36     protected String JavaDoc code;
37
38     /** The paramters to use for the error message. */
39     protected Object JavaDoc [] params;
40
41     /** The line number on which the error occured. */
42     protected int line;
43
44     /** The graphics node that represents the current state of the GVT tree. */
45     protected GraphicsNode node;
46
47     /**
48      * Constructs a new <tt>BridgeException</tt> with the specified parameters.
49      *
50      * @param e the element on which the error occured
51      * @param code the error code
52      * @param params the parameters to use for the error message
53      */

54     public BridgeException(Element JavaDoc e, String JavaDoc code, Object JavaDoc [] params) {
55         this.e = e;
56         this.code = code;
57         this.params = params;
58     }
59
60     /**
61      * Returns the element on which the error occurred.
62      */

63     public Element JavaDoc getElement() {
64         return e;
65     }
66
67     /**
68      * Returns the line number on which the error occurred.
69      */

70     public void setLineNumber(int line) {
71         this.line = line;
72     }
73
74     /**
75      * Sets the graphics node that represents the current GVT tree built.
76      *
77      * @param node the graphics node
78      */

79     public void setGraphicsNode(GraphicsNode node) {
80         this.node = node;
81     }
82
83     /**
84      * Returns the graphics node that represents the current GVT tree built.
85      */

86     public GraphicsNode getGraphicsNode() {
87         return node;
88     }
89
90     /**
91      * Returns the error message according to the error code and parameters.
92      */

93     public String JavaDoc getMessage() {
94         String JavaDoc uri;
95         String JavaDoc lname = "<Unknown Element>";
96         SVGDocument doc = null;
97         if (e != null) {
98             doc = (SVGDocument)e.getOwnerDocument();
99             lname = e.getLocalName();
100         }
101         if (doc == null) uri = "<Unknown Document>";
102         else uri = doc.getURL();
103         Object JavaDoc [] fullparams = new Object JavaDoc[params.length+3];
104         fullparams[0] = uri;
105         fullparams[1] = new Integer JavaDoc(line);
106         fullparams[2] = lname;
107         for (int i=0; i < params.length; ++i) {
108             fullparams[i+3] = params[i];
109         }
110         return Messages.formatMessage(code, fullparams);
111     }
112
113     /**
114      * Returns the exception's error code
115      */

116     public String JavaDoc getCode() {
117         return code;
118     }
119 }
120
Popular Tags