1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xpath.domapi;
  58. import org.w3c.dom.xpath.XPathNamespace;
  59. import org.w3c.dom.Attr;
  60. import org.w3c.dom.DOMException;
  61. import org.w3c.dom.Document;
  62. import org.w3c.dom.Element;
  63. import org.w3c.dom.NamedNodeMap;
  64. import org.w3c.dom.Node;
  65. import org.w3c.dom.NodeList;
  66. /**
  67. *
  68. * <meta name="usage" content="experimental"/>
  69. *
  70. * The <code>XPathNamespace</code> interface is returned by
  71. * <code>XPathResult</code> interfaces to represent the XPath namespace node
  72. * type that DOM lacks. There is no public constructor for this node type.
  73. * Attempts to place it into a hierarchy or a NamedNodeMap result in a
  74. * <code>DOMException</code> with the code <code>HIERARCHY_REQUEST_ERR</code>
  75. * . This node is read only, so methods or setting of attributes that would
  76. * mutate the node result in a DOMException with the code
  77. * <code>NO_MODIFICATION_ALLOWED_ERR</code>.
  78. * <p>The core specification describes attributes of the <code>Node</code>
  79. * interface that are different for different node node types but does not
  80. * describe <code>XPATH_NAMESPACE_NODE</code>, so here is a description of
  81. * those attributes for this node type. All attributes of <code>Node</code>
  82. * not described in this section have a <code>null</code> or
  83. * <code>false</code> value.
  84. * <p><code>ownerDocument</code> matches the <code>ownerDocument</code> of the
  85. * <code>ownerElement</code> even if the element is later adopted.
  86. * <p><code>prefix</code> is the prefix of the namespace represented by the
  87. * node.
  88. * <p><code>nodeName</code> is the same as <code>prefix</code>.
  89. * <p><code>nodeType</code> is equal to <code>XPATH_NAMESPACE_NODE</code>.
  90. * <p><code>namespaceURI</code> is the namespace URI of the namespace
  91. * represented by the node.
  92. * <p><code>adoptNode</code>, <code>cloneNode</code>, and
  93. * <code>importNode</code> fail on this node type by raising a
  94. * <code>DOMException</code> with the code <code>NOT_SUPPORTED_ERR</code>.In
  95. * future versions of the XPath specification, the definition of a namespace
  96. * node may be changed incomatibly, in which case incompatible changes to
  97. * field values may be required to implement versions beyond XPath 1.0.
  98. * <p>See also the <a href='http://www.w3.org/2002/08/WD-DOM-Level-3-XPath-20020820'>Document Object Model (DOM) Level 3 XPath Specification</a>.
  99. *
  100. * This implementation wraps the DOM attribute node that contained the
  101. * namespace declaration.
  102. */
  103. public class XPathNamespaceImpl implements XPathNamespace {
  104. // Node that XPathNamespaceImpl wraps
  105. Node m_attributeNode = null;
  106. /**
  107. * Constructor for XPathNamespaceImpl.
  108. */
  109. public XPathNamespaceImpl(Node node) {
  110. m_attributeNode = node;
  111. }
  112. /**
  113. * @see org.apache.xalan.dom3.xpath.XPathNamespace#getOwnerElement()
  114. */
  115. public Element getOwnerElement() {
  116. return ((Attr)m_attributeNode).getOwnerElement();
  117. }
  118. /**
  119. * @see org.w3c.dom.Node#getNodeName()
  120. */
  121. public String getNodeName() {
  122. return m_attributeNode.getNodeName();
  123. }
  124. /**
  125. * @see org.w3c.dom.Node#getNodeValue()
  126. */
  127. public String getNodeValue() throws DOMException {
  128. return m_attributeNode.getNodeValue();
  129. }
  130. /**
  131. * @see org.w3c.dom.Node#setNodeValue(String)
  132. */
  133. public void setNodeValue(String arg0) throws DOMException {
  134. }
  135. /**
  136. * @see org.w3c.dom.Node#getNodeType()
  137. */
  138. public short getNodeType() {
  139. return XPathNamespace.XPATH_NAMESPACE_NODE;
  140. }
  141. /**
  142. * @see org.w3c.dom.Node#getParentNode()
  143. */
  144. public Node getParentNode() {
  145. return m_attributeNode.getParentNode();
  146. }
  147. /**
  148. * @see org.w3c.dom.Node#getChildNodes()
  149. */
  150. public NodeList getChildNodes() {
  151. return m_attributeNode.getChildNodes();
  152. }
  153. /**
  154. * @see org.w3c.dom.Node#getFirstChild()
  155. */
  156. public Node getFirstChild() {
  157. return m_attributeNode.getFirstChild();
  158. }
  159. /**
  160. * @see org.w3c.dom.Node#getLastChild()
  161. */
  162. public Node getLastChild() {
  163. return m_attributeNode.getLastChild();
  164. }
  165. /**
  166. * @see org.w3c.dom.Node#getPreviousSibling()
  167. */
  168. public Node getPreviousSibling() {
  169. return m_attributeNode.getPreviousSibling();
  170. }
  171. /**
  172. * @see org.w3c.dom.Node#getNextSibling()
  173. */
  174. public Node getNextSibling() {
  175. return m_attributeNode.getNextSibling();
  176. }
  177. /**
  178. * @see org.w3c.dom.Node#getAttributes()
  179. */
  180. public NamedNodeMap getAttributes() {
  181. return m_attributeNode.getAttributes();
  182. }
  183. /**
  184. * @see org.w3c.dom.Node#getOwnerDocument()
  185. */
  186. public Document getOwnerDocument() {
  187. return m_attributeNode.getOwnerDocument();
  188. }
  189. /**
  190. * @see org.w3c.dom.Node#insertBefore(Node, Node)
  191. */
  192. public Node insertBefore(Node arg0, Node arg1) throws DOMException {
  193. return null;
  194. }
  195. /**
  196. * @see org.w3c.dom.Node#replaceChild(Node, Node)
  197. */
  198. public Node replaceChild(Node arg0, Node arg1) throws DOMException {
  199. return null;
  200. }
  201. /**
  202. * @see org.w3c.dom.Node#removeChild(Node)
  203. */
  204. public Node removeChild(Node arg0) throws DOMException {
  205. return null;
  206. }
  207. /**
  208. * @see org.w3c.dom.Node#appendChild(Node)
  209. */
  210. public Node appendChild(Node arg0) throws DOMException {
  211. return null;
  212. }
  213. /**
  214. * @see org.w3c.dom.Node#hasChildNodes()
  215. */
  216. public boolean hasChildNodes() {
  217. return false;
  218. }
  219. /**
  220. * @see org.w3c.dom.Node#cloneNode(boolean)
  221. */
  222. public Node cloneNode(boolean arg0) {
  223. throw new DOMException(DOMException.NOT_SUPPORTED_ERR,null);
  224. }
  225. /**
  226. * @see org.w3c.dom.Node#normalize()
  227. */
  228. public void normalize() {
  229. m_attributeNode.normalize();
  230. }
  231. /**
  232. * @see org.w3c.dom.Node#isSupported(String, String)
  233. */
  234. public boolean isSupported(String arg0, String arg1) {
  235. return m_attributeNode.isSupported(arg0, arg1);
  236. }
  237. /**
  238. * @see org.w3c.dom.Node#getNamespaceURI()
  239. */
  240. public String getNamespaceURI() {
  241. return m_attributeNode.getNamespaceURI();
  242. }
  243. /**
  244. * @see org.w3c.dom.Node#getPrefix()
  245. */
  246. public String getPrefix() {
  247. return m_attributeNode.getPrefix();
  248. }
  249. /**
  250. * @see org.w3c.dom.Node#setPrefix(String)
  251. */
  252. public void setPrefix(String arg0) throws DOMException {
  253. }
  254. /**
  255. * @see org.w3c.dom.Node#getLocalName()
  256. */
  257. public String getLocalName() {
  258. return m_attributeNode.getLocalName();
  259. }
  260. /**
  261. * @see org.w3c.dom.Node#hasAttributes()
  262. */
  263. public boolean hasAttributes() {
  264. return m_attributeNode.hasAttributes();
  265. }
  266. }