KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > dtm > ref > dom2dtm > DOM2DTMdefaultNamespaceDeclarationNode


1 /*
2  * Copyright 1999-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: DOM2DTMdefaultNamespaceDeclarationNode.java,v 1.5 2004/02/16 23:06:53 minchau Exp $
18  */

19
20 package org.apache.xml.dtm.ref.dom2dtm;
21
22 import org.apache.xml.dtm.DTMException;
23
24 import org.w3c.dom.Attr 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
31 /** This is a kluge to let us shove a declaration for xml: into the
32  * DOM2DTM model. Basically, it creates a proxy node in DOM space to
33  * carry the additional information. This is _NOT_ a full DOM
34  * implementation, and shouldn't be one since it sits alongside the
35  * DOM rather than becoming part of the DOM model.
36  *
37  * (This used to be an internal class within DOM2DTM. Moved out because
38  * I need to perform an instanceof operation on it to support a temporary
39  * workaround in DTMManagerDefault.)
40  *
41  * %REVIEW% What if the DOM2DTM was built around a DocumentFragment and
42  * there isn't a single root element? I think this fails that case...
43  *
44  * %REVIEW% An alternative solution would be to create the node _only_
45  * in DTM space, but given how DOM2DTM is currently written I think
46  * this is simplest.
47  * */

48 public class DOM2DTMdefaultNamespaceDeclarationNode implements Attr JavaDoc
49 {
50   final String JavaDoc NOT_SUPPORTED_ERR="Unsupported operation on pseudonode";
51   
52   Element JavaDoc pseudoparent;
53   String JavaDoc prefix,uri,nodename;
54   int handle;
55   DOM2DTMdefaultNamespaceDeclarationNode(Element JavaDoc pseudoparent,String JavaDoc prefix,String JavaDoc uri,int handle)
56   {
57     this.pseudoparent=pseudoparent;
58     this.prefix=prefix;
59     this.uri=uri;
60     this.handle=handle;
61     this.nodename="xmlns:"+prefix;
62   }
63   public String JavaDoc getNodeName() {return nodename;}
64   public String JavaDoc getName() {return nodename;}
65   public String JavaDoc getNamespaceURI() {return "http://www.w3.org/2000/xmlns/";}
66   public String JavaDoc getPrefix() {return prefix;}
67   public String JavaDoc getLocalName() {return prefix;}
68   public String JavaDoc getNodeValue() {return uri;}
69   public String JavaDoc getValue() {return uri;}
70   public Element JavaDoc getOwnerElement() {return pseudoparent;}
71   
72   public boolean isSupported(String JavaDoc feature, String JavaDoc version) {return false;}
73   public boolean hasChildNodes() {return false;}
74   public boolean hasAttributes() {return false;}
75   public Node JavaDoc getParentNode() {return null;}
76   public Node JavaDoc getFirstChild() {return null;}
77   public Node JavaDoc getLastChild() {return null;}
78   public Node JavaDoc getPreviousSibling() {return null;}
79   public Node JavaDoc getNextSibling() {return null;}
80   public boolean getSpecified() {return false;}
81   public void normalize() {return;}
82   public NodeList JavaDoc getChildNodes() {return null;}
83   public NamedNodeMap JavaDoc getAttributes() {return null;}
84   public short getNodeType() {return Node.ATTRIBUTE_NODE;}
85   public void setNodeValue(String JavaDoc value) {throw new DTMException(NOT_SUPPORTED_ERR);}
86   public void setValue(String JavaDoc value) {throw new DTMException(NOT_SUPPORTED_ERR);}
87   public void setPrefix(String JavaDoc value) {throw new DTMException(NOT_SUPPORTED_ERR);}
88   public Node JavaDoc insertBefore(Node JavaDoc a, Node JavaDoc b) {throw new DTMException(NOT_SUPPORTED_ERR);}
89   public Node JavaDoc replaceChild(Node JavaDoc a, Node JavaDoc b) {throw new DTMException(NOT_SUPPORTED_ERR);}
90   public Node JavaDoc appendChild(Node JavaDoc a) {throw new DTMException(NOT_SUPPORTED_ERR);}
91   public Node JavaDoc removeChild(Node JavaDoc a) {throw new DTMException(NOT_SUPPORTED_ERR);}
92   public Document JavaDoc getOwnerDocument() {return pseudoparent.getOwnerDocument();}
93   public Node JavaDoc cloneNode(boolean deep) {throw new DTMException(NOT_SUPPORTED_ERR);}
94     
95     /** Non-DOM method, part of the temporary kluge
96      * %REVIEW% This would be a pruning problem, but since it will always be
97      * added to the root element and we prune on elements, we shouldn't have
98      * to worry.
99      */

100     public int getHandleOfNode()
101     {
102         return handle;
103     }
104 }
105
106
Popular Tags