1 /* DomDOMException.java --
2 Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 import org.w3c.dom.DOMException;
41 import org.w3c.dom.Node;
44 * <p> DOMException implementation. The version that
45 * is provided by the W3C is abstract, so it can't be instantiated.
47 * <p> This also provides a bit more information about the error
48 * that is being reported, in terms of the relevant DOM structures
51 * @author David Brownell
53 public class DomDOMException
57 /** @serial Data that caused an error to be reported */
60 /** @serial Node associated with the error. */
63 /** @serial Data associated with the error. */
67 * Constructs an exception, with the diagnostic message
68 * corresponding to the specified code.
70 public DomDOMException(short code)
72 super(code, diagnostic(code));
76 * Constructs an exception, with the diagnostic message
77 * corresponding to the specified code and additional
78 * information as provided.
80 public DomDOMException(short code, String data, Node node, int value)
82 super(code, diagnostic(code));
88 /** Returns the node to which the diagnotic applies, or null. */
89 final public Node getNode()
94 /** Returns data to which the diagnotic applies, or null. */
95 final public String getData()
100 /** Returns data to which the diagnotic applies, or null. */
101 final public int getValue()
107 * Returns a diagnostic message that may be slightly more useful
108 * than the generic one, where possible.
110 public String getMessage()
112 String retval = super.getMessage();
116 retval += "\nMore Information: " + data;
120 retval += "\nNumber: " + value;
124 retval += "\nNode Name: " + node.getNodeName();
129 // these strings should be localizable.
131 private static String diagnostic(short code)
137 return "An index or size is out of range.";
138 case DOMSTRING_SIZE_ERR:
139 return "A string is too big.";
140 case HIERARCHY_REQUEST_ERR:
141 return "The node doesn't belong here.";
142 case WRONG_DOCUMENT_ERR:
143 return "The node belongs in another document.";
144 case INVALID_CHARACTER_ERR:
145 return "That character is not permitted.";
146 case NO_DATA_ALLOWED_ERR:
147 return "This node does not permit data.";
148 case NO_MODIFICATION_ALLOWED_ERR:
149 return "No changes are allowed.";
151 return "The node was not found in that context.";
152 case NOT_SUPPORTED_ERR:
153 return "That object is not supported.";
154 case INUSE_ATTRIBUTE_ERR:
155 return "The attribute belongs to a different element.";
158 case INVALID_STATE_ERR:
159 return "The object is not usable.";
161 return "An illegal string was provided.";
162 case INVALID_MODIFICATION_ERR:
163 return "An object's type may not be changed.";
165 return "The operation violates XML Namespaces.";
166 case INVALID_ACCESS_ERR:
167 return "Parameter or operation isn't supported by this node.";
168 case TYPE_MISMATCH_ERR:
169 return "The type of the argument is incompatible with the expected type.";
171 return "Reserved exception number: " + code;