001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 /*
019 * $Id: XPathNamespaceImpl.java 1225426 2011-12-29 04:13:08Z mrglavas $
020 */
021
022
023 package org.apache.xpath.domapi;
024
025 import org.w3c.dom.Attr;
026 import org.w3c.dom.DOMException;
027 import org.w3c.dom.Document;
028 import org.w3c.dom.Element;
029 import org.w3c.dom.NamedNodeMap;
030 import org.w3c.dom.Node;
031 import org.w3c.dom.NodeList;
032 import org.w3c.dom.xpath.XPathNamespace;
033
034 import org.w3c.dom.UserDataHandler;
035
036 /**
037 *
038 *
039 * The <code>XPathNamespace</code> interface is returned by
040 * <code>XPathResult</code> interfaces to represent the XPath namespace node
041 * type that DOM lacks. There is no public constructor for this node type.
042 * Attempts to place it into a hierarchy or a NamedNodeMap result in a
043 * <code>DOMException</code> with the code <code>HIERARCHY_REQUEST_ERR</code>
044 * . This node is read only, so methods or setting of attributes that would
045 * mutate the node result in a DOMException with the code
046 * <code>NO_MODIFICATION_ALLOWED_ERR</code>.
047 * <p>The core specification describes attributes of the <code>Node</code>
048 * interface that are different for different node node types but does not
049 * describe <code>XPATH_NAMESPACE_NODE</code>, so here is a description of
050 * those attributes for this node type. All attributes of <code>Node</code>
051 * not described in this section have a <code>null</code> or
052 * <code>false</code> value.
053 * <p><code>ownerDocument</code> matches the <code>ownerDocument</code> of the
054 * <code>ownerElement</code> even if the element is later adopted.
055 * <p><code>prefix</code> is the prefix of the namespace represented by the
056 * node.
057 * <p><code>nodeName</code> is the same as <code>prefix</code>.
058 * <p><code>nodeType</code> is equal to <code>XPATH_NAMESPACE_NODE</code>.
059 * <p><code>namespaceURI</code> is the namespace URI of the namespace
060 * represented by the node.
061 * <p><code>adoptNode</code>, <code>cloneNode</code>, and
062 * <code>importNode</code> fail on this node type by raising a
063 * <code>DOMException</code> with the code <code>NOT_SUPPORTED_ERR</code>.In
064 * future versions of the XPath specification, the definition of a namespace
065 * node may be changed incomatibly, in which case incompatible changes to
066 * field values may be required to implement versions beyond XPath 1.0.
067 * <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.
068 *
069 * This implementation wraps the DOM attribute node that contained the
070 * namespace declaration.
071 * @xsl.usage internal
072 */
073
074 class XPathNamespaceImpl implements XPathNamespace {
075
076 // Node that XPathNamespaceImpl wraps
077 final private Node m_attributeNode;
078
079 /**
080 * Constructor for XPathNamespaceImpl.
081 */
082 XPathNamespaceImpl(Node node) {
083 m_attributeNode = node;
084 }
085
086 /**
087 * @see org.apache.xalan.dom3.xpath.XPathNamespace#getOwnerElement()
088 */
089 public Element getOwnerElement() {
090 return ((Attr)m_attributeNode).getOwnerElement();
091 }
092
093 /**
094 * @see org.w3c.dom.Node#getNodeName()
095 */
096 public String getNodeName() {
097 return "#namespace";
098 }
099
100 /**
101 * @see org.w3c.dom.Node#getNodeValue()
102 */
103 public String getNodeValue() throws DOMException {
104 return m_attributeNode.getNodeValue();
105 }
106
107 /**
108 * @see org.w3c.dom.Node#setNodeValue(String)
109 */
110 public void setNodeValue(String arg0) throws DOMException {
111 }
112
113 /**
114 * @see org.w3c.dom.Node#getNodeType()
115 */
116 public short getNodeType() {
117 return XPathNamespace.XPATH_NAMESPACE_NODE;
118 }
119
120 /**
121 * @see org.w3c.dom.Node#getParentNode()
122 */
123 public Node getParentNode() {
124 return m_attributeNode.getParentNode();
125 }
126
127 /**
128 * @see org.w3c.dom.Node#getChildNodes()
129 */
130 public NodeList getChildNodes() {
131 return m_attributeNode.getChildNodes();
132 }
133
134 /**
135 * @see org.w3c.dom.Node#getFirstChild()
136 */
137 public Node getFirstChild() {
138 return m_attributeNode.getFirstChild();
139 }
140
141 /**
142 * @see org.w3c.dom.Node#getLastChild()
143 */
144 public Node getLastChild() {
145 return m_attributeNode.getLastChild();
146 }
147
148 /**
149 * @see org.w3c.dom.Node#getPreviousSibling()
150 */
151 public Node getPreviousSibling() {
152 return m_attributeNode.getPreviousSibling();
153 }
154
155 /**
156 * @see org.w3c.dom.Node#getNextSibling()
157 */
158 public Node getNextSibling() {
159 return m_attributeNode.getNextSibling();
160 }
161
162 /**
163 * @see org.w3c.dom.Node#getAttributes()
164 */
165 public NamedNodeMap getAttributes() {
166 return m_attributeNode.getAttributes();
167 }
168
169 /**
170 * @see org.w3c.dom.Node#getOwnerDocument()
171 */
172 public Document getOwnerDocument() {
173 return m_attributeNode.getOwnerDocument();
174 }
175
176 /**
177 * @see org.w3c.dom.Node#insertBefore(Node, Node)
178 */
179 public Node insertBefore(Node arg0, Node arg1) throws DOMException {
180 return null;
181 }
182
183 /**
184 * @see org.w3c.dom.Node#replaceChild(Node, Node)
185 */
186 public Node replaceChild(Node arg0, Node arg1) throws DOMException {
187 return null;
188 }
189
190 /**
191 * @see org.w3c.dom.Node#removeChild(Node)
192 */
193 public Node removeChild(Node arg0) throws DOMException {
194 return null;
195 }
196
197 /**
198 * @see org.w3c.dom.Node#appendChild(Node)
199 */
200 public Node appendChild(Node arg0) throws DOMException {
201 return null;
202 }
203
204 /**
205 * @see org.w3c.dom.Node#hasChildNodes()
206 */
207 public boolean hasChildNodes() {
208 return false;
209 }
210
211 /**
212 * @see org.w3c.dom.Node#cloneNode(boolean)
213 */
214 public Node cloneNode(boolean arg0) {
215 throw new DOMException(DOMException.NOT_SUPPORTED_ERR,null);
216 }
217
218 /**
219 * @see org.w3c.dom.Node#normalize()
220 */
221 public void normalize() {
222 m_attributeNode.normalize();
223 }
224
225 /**
226 * @see org.w3c.dom.Node#isSupported(String, String)
227 */
228 public boolean isSupported(String arg0, String arg1) {
229 return m_attributeNode.isSupported(arg0, arg1);
230 }
231
232 /**
233 * @see org.w3c.dom.Node#getNamespaceURI()
234 */
235 public String getNamespaceURI() {
236
237 // For namespace node, the namespaceURI is the namespace URI
238 // of the namespace represented by the node.
239 return m_attributeNode.getNodeValue();
240 }
241
242 /**
243 * @see org.w3c.dom.Node#getPrefix()
244 */
245 public String getPrefix() {
246 return m_attributeNode.getPrefix();
247 }
248
249 /**
250 * @see org.w3c.dom.Node#setPrefix(String)
251 */
252 public void setPrefix(String arg0) throws DOMException {
253 }
254
255 /**
256 * @see org.w3c.dom.Node#getLocalName()
257 */
258 public String getLocalName() {
259
260 // For namespace node, the local name is the same as the prefix
261 return m_attributeNode.getPrefix();
262 }
263
264 /**
265 * @see org.w3c.dom.Node#hasAttributes()
266 */
267 public boolean hasAttributes() {
268 return m_attributeNode.hasAttributes();
269 }
270
271 public String getBaseURI ( ) {
272 return null;
273 }
274
275 public short compareDocumentPosition(Node other) throws DOMException {
276 return 0;
277 }
278
279 private String textContent;
280
281 public String getTextContent() throws DOMException {
282 return textContent;
283 }
284
285 public void setTextContent(String textContent) throws DOMException {
286 this.textContent = textContent;
287 }
288
289 public boolean isSameNode(Node other) {
290 return false;
291 }
292
293 public String lookupPrefix(String namespaceURI) {
294 return ""; //PENDING
295 }
296
297 public boolean isDefaultNamespace(String namespaceURI) {
298 return false;
299 }
300
301 public String lookupNamespaceURI(String prefix) {
302 return null;
303 }
304
305 public boolean isEqualNode(Node arg) {
306 return false;
307 }
308
309 public Object getFeature(String feature, String version) {
310 return null; //PENDING
311 }
312
313 public Object setUserData(String key,
314 Object data,
315 UserDataHandler handler) {
316 return null; //PENDING
317 }
318
319 public Object getUserData(String key) {
320 return null;
321 }
322 }