DomDOMException.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* DomDOMException.java --
  2. Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.xml.dom;
  32. import org.w3c.dom.DOMException;
  33. import org.w3c.dom.Node;
  34. /**
  35. * <p> DOMException implementation. The version that
  36. * is provided by the W3C is abstract, so it can't be instantiated.
  37. *
  38. * <p> This also provides a bit more information about the error
  39. * that is being reported, in terms of the relevant DOM structures
  40. * and data.
  41. *
  42. * @author David Brownell
  43. */
  44. public class DomDOMException
  45. extends DOMException
  46. {
  47. /** @serial Data that caused an error to be reported */
  48. private String data;
  49. /** @serial Node associated with the error. */
  50. private Node node;
  51. /** @serial Data associated with the error. */
  52. private int value;
  53. /**
  54. * Constructs an exception, with the diagnostic message
  55. * corresponding to the specified code.
  56. */
  57. public DomDOMException(short code)
  58. {
  59. super(code, diagnostic(code));
  60. }
  61. /**
  62. * Constructs an exception, with the diagnostic message
  63. * corresponding to the specified code and additional
  64. * information as provided.
  65. */
  66. public DomDOMException(short code, String data, Node node, int value)
  67. {
  68. super(code, diagnostic(code));
  69. this.data = data;
  70. this.node = node;
  71. this.value = value;
  72. }
  73. /** Returns the node to which the diagnotic applies, or null. */
  74. final public Node getNode()
  75. {
  76. return node;
  77. }
  78. /** Returns data to which the diagnotic applies, or null. */
  79. final public String getData()
  80. {
  81. return data;
  82. }
  83. /** Returns data to which the diagnotic applies, or null. */
  84. final public int getValue()
  85. {
  86. return value;
  87. }
  88. /**
  89. * Returns a diagnostic message that may be slightly more useful
  90. * than the generic one, where possible.
  91. */
  92. public String getMessage()
  93. {
  94. String retval = super.getMessage();
  95. if (data != null)
  96. {
  97. retval += "\nMore Information: " + data;
  98. }
  99. if (value != 0)
  100. {
  101. retval += "\nNumber: " + value;
  102. }
  103. if (node != null)
  104. {
  105. retval += "\nNode Name: " + node.getNodeName();
  106. }
  107. return retval;
  108. }
  109. // these strings should be localizable.
  110. private static String diagnostic(short code)
  111. {
  112. switch (code)
  113. {
  114. // DOM L1:
  115. case INDEX_SIZE_ERR:
  116. return "An index or size is out of range.";
  117. case DOMSTRING_SIZE_ERR:
  118. return "A string is too big.";
  119. case HIERARCHY_REQUEST_ERR:
  120. return "The node doesn't belong here.";
  121. case WRONG_DOCUMENT_ERR:
  122. return "The node belongs in another document.";
  123. case INVALID_CHARACTER_ERR:
  124. return "That character is not permitted.";
  125. case NO_DATA_ALLOWED_ERR:
  126. return "This node does not permit data.";
  127. case NO_MODIFICATION_ALLOWED_ERR:
  128. return "No changes are allowed.";
  129. case NOT_FOUND_ERR:
  130. return "The node was not found in that context.";
  131. case NOT_SUPPORTED_ERR:
  132. return "That object is not supported.";
  133. case INUSE_ATTRIBUTE_ERR:
  134. return "The attribute belongs to a different element.";
  135. // DOM L2:
  136. case INVALID_STATE_ERR:
  137. return "The object is not usable.";
  138. case SYNTAX_ERR:
  139. return "An illegal string was provided.";
  140. case INVALID_MODIFICATION_ERR:
  141. return "An object's type may not be changed.";
  142. case NAMESPACE_ERR:
  143. return "The operation violates XML Namespaces.";
  144. case INVALID_ACCESS_ERR:
  145. return "Parameter or operation isn't supported by this node.";
  146. case TYPE_MISMATCH_ERR:
  147. return "The type of the argument is incompatible with the expected type.";
  148. }
  149. return "Reserved exception number: " + code;
  150. }
  151. }