KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > domapi > XPathNamespaceImpl


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id$
18  */

19
20
21 package org.apache.xpath.domapi;
22
23 import org.w3c.dom.Attr JavaDoc;
24 import org.w3c.dom.DOMException JavaDoc;
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.NamedNodeMap JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.NodeList JavaDoc;
30 import org.w3c.dom.xpath.XPathNamespace;
31
32 /**
33  *
34  *
35  * The <code>XPathNamespace</code> interface is returned by
36  * <code>XPathResult</code> interfaces to represent the XPath namespace node
37  * type that DOM lacks. There is no public constructor for this node type.
38  * Attempts to place it into a hierarchy or a NamedNodeMap result in a
39  * <code>DOMException</code> with the code <code>HIERARCHY_REQUEST_ERR</code>
40  * . This node is read only, so methods or setting of attributes that would
41  * mutate the node result in a DOMException with the code
42  * <code>NO_MODIFICATION_ALLOWED_ERR</code>.
43  * <p>The core specification describes attributes of the <code>Node</code>
44  * interface that are different for different node node types but does not
45  * describe <code>XPATH_NAMESPACE_NODE</code>, so here is a description of
46  * those attributes for this node type. All attributes of <code>Node</code>
47  * not described in this section have a <code>null</code> or
48  * <code>false</code> value.
49  * <p><code>ownerDocument</code> matches the <code>ownerDocument</code> of the
50  * <code>ownerElement</code> even if the element is later adopted.
51  * <p><code>prefix</code> is the prefix of the namespace represented by the
52  * node.
53  * <p><code>nodeName</code> is the same as <code>prefix</code>.
54  * <p><code>nodeType</code> is equal to <code>XPATH_NAMESPACE_NODE</code>.
55  * <p><code>namespaceURI</code> is the namespace URI of the namespace
56  * represented by the node.
57  * <p><code>adoptNode</code>, <code>cloneNode</code>, and
58  * <code>importNode</code> fail on this node type by raising a
59  * <code>DOMException</code> with the code <code>NOT_SUPPORTED_ERR</code>.In
60  * future versions of the XPath specification, the definition of a namespace
61  * node may be changed incomatibly, in which case incompatible changes to
62  * field values may be required to implement versions beyond XPath 1.0.
63  * <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>.
64  *
65  * This implementation wraps the DOM attribute node that contained the
66  * namespace declaration.
67  * @xsl.usage experimental
68  */

69
70 public class XPathNamespaceImpl implements XPathNamespace {
71
72     // Node that XPathNamespaceImpl wraps
73
Node JavaDoc m_attributeNode = null;
74     
75     /**
76      * Constructor for XPathNamespaceImpl.
77      */

78     public XPathNamespaceImpl(Node JavaDoc node) {
79         m_attributeNode = node;
80     }
81
82     /**
83      * @see org.apache.xalan.dom3.xpath.XPathNamespace#getOwnerElement()
84      */

85     public Element JavaDoc getOwnerElement() {
86         return ((Attr JavaDoc)m_attributeNode).getOwnerElement();
87     }
88
89     /**
90      * @see org.w3c.dom.Node#getNodeName()
91      */

92     public String JavaDoc getNodeName() {
93         return "#namespace";
94     }
95
96     /**
97      * @see org.w3c.dom.Node#getNodeValue()
98      */

99     public String JavaDoc getNodeValue() throws DOMException JavaDoc {
100         return m_attributeNode.getNodeValue();
101     }
102
103     /**
104      * @see org.w3c.dom.Node#setNodeValue(String)
105      */

106     public void setNodeValue(String JavaDoc arg0) throws DOMException JavaDoc {
107     }
108
109     /**
110      * @see org.w3c.dom.Node#getNodeType()
111      */

112     public short getNodeType() {
113         return XPathNamespace.XPATH_NAMESPACE_NODE;
114     }
115
116     /**
117      * @see org.w3c.dom.Node#getParentNode()
118      */

119     public Node JavaDoc getParentNode() {
120         return m_attributeNode.getParentNode();
121     }
122
123     /**
124      * @see org.w3c.dom.Node#getChildNodes()
125      */

126     public NodeList JavaDoc getChildNodes() {
127         return m_attributeNode.getChildNodes();
128     }
129
130     /**
131      * @see org.w3c.dom.Node#getFirstChild()
132      */

133     public Node JavaDoc getFirstChild() {
134         return m_attributeNode.getFirstChild();
135     }
136
137     /**
138      * @see org.w3c.dom.Node#getLastChild()
139      */

140     public Node JavaDoc getLastChild() {
141         return m_attributeNode.getLastChild();
142     }
143
144     /**
145      * @see org.w3c.dom.Node#getPreviousSibling()
146      */

147     public Node JavaDoc getPreviousSibling() {
148         return m_attributeNode.getPreviousSibling();
149     }
150
151     /**
152      * @see org.w3c.dom.Node#getNextSibling()
153      */

154     public Node JavaDoc getNextSibling() {
155         return m_attributeNode.getNextSibling();
156     }
157
158     /**
159      * @see org.w3c.dom.Node#getAttributes()
160      */

161     public NamedNodeMap JavaDoc getAttributes() {
162         return m_attributeNode.getAttributes();
163     }
164
165     /**
166      * @see org.w3c.dom.Node#getOwnerDocument()
167      */

168     public Document JavaDoc getOwnerDocument() {
169         return m_attributeNode.getOwnerDocument();
170     }
171
172     /**
173      * @see org.w3c.dom.Node#insertBefore(Node, Node)
174      */

175     public Node JavaDoc insertBefore(Node JavaDoc arg0, Node JavaDoc arg1) throws DOMException JavaDoc {
176         return null;
177     }
178
179     /**
180      * @see org.w3c.dom.Node#replaceChild(Node, Node)
181      */

182     public Node JavaDoc replaceChild(Node JavaDoc arg0, Node JavaDoc arg1) throws DOMException JavaDoc {
183         return null;
184     }
185
186     /**
187      * @see org.w3c.dom.Node#removeChild(Node)
188      */

189     public Node JavaDoc removeChild(Node JavaDoc arg0) throws DOMException JavaDoc {
190         return null;
191     }
192
193     /**
194      * @see org.w3c.dom.Node#appendChild(Node)
195      */

196     public Node JavaDoc appendChild(Node JavaDoc arg0) throws DOMException JavaDoc {
197         return null;
198     }
199
200     /**
201      * @see org.w3c.dom.Node#hasChildNodes()
202      */

203     public boolean hasChildNodes() {
204         return false;
205     }
206
207     /**
208      * @see org.w3c.dom.Node#cloneNode(boolean)
209      */

210     public Node JavaDoc cloneNode(boolean arg0) {
211         throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR,null);
212     }
213
214     /**
215      * @see org.w3c.dom.Node#normalize()
216      */

217     public void normalize() {
218         m_attributeNode.normalize();
219     }
220
221     /**
222      * @see org.w3c.dom.Node#isSupported(String, String)
223      */

224     public boolean isSupported(String JavaDoc arg0, String JavaDoc arg1) {
225         return m_attributeNode.isSupported(arg0, arg1);
226     }
227
228     /**
229      * @see org.w3c.dom.Node#getNamespaceURI()
230      */

231     public String JavaDoc getNamespaceURI() {
232         
233         // For namespace node, the namespaceURI is the namespace URI
234
// of the namespace represented by the node.
235
return m_attributeNode.getNodeValue();
236     }
237
238     /**
239      * @see org.w3c.dom.Node#getPrefix()
240      */

241     public String JavaDoc getPrefix() {
242         return m_attributeNode.getPrefix();
243     }
244
245     /**
246      * @see org.w3c.dom.Node#setPrefix(String)
247      */

248     public void setPrefix(String JavaDoc arg0) throws DOMException JavaDoc {
249     }
250
251     /**
252      * @see org.w3c.dom.Node#getLocalName()
253      */

254     public String JavaDoc getLocalName() {
255         
256         // For namespace node, the local name is the same as the prefix
257
return m_attributeNode.getPrefix();
258     }
259
260     /**
261      * @see org.w3c.dom.Node#hasAttributes()
262      */

263     public boolean hasAttributes() {
264         return m_attributeNode.hasAttributes();
265     }
266
267 }
268
Popular Tags