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