KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > tinytree > TinyNamespaceImpl


1 package com.icl.saxon.tinytree;
2 import com.icl.saxon.om.*;
3 import com.icl.saxon.output.Outputter;
4 import com.icl.saxon.Context;
5 import org.w3c.dom.Node JavaDoc;
6 import javax.xml.transform.TransformerException JavaDoc;
7 /**
8   * A node in the XML parse tree representing a Namespace. Note that this is
9   * generated only "on demand", when the namespace axis is expanded.<P>
10   * @author <A HREF="mailto:mhkay@iclway.co.uk>Michael H. Kay</A>
11   * @version 28 September 2000
12   */

13
14 final class TinyNamespaceImpl extends TinyNodeImpl {
15
16     private int parentNode; // an entry in the namespace array corresponds
17
// to a namespace declaration. This can result in one
18
// namespace node for each ancestor element. Therefore
19
// the namespace node needs to contain a reference to the
20
// actual parent element.
21
private int nameCode; // the name code of the name of the namespace node.
22
// The name of the namespace node is the prefix: the
23
// namecode is NOT the same as the namespace code, which
24
// identifies the prefix/uri pair
25

26     public TinyNamespaceImpl(TinyDocumentImpl doc, int nodeNr) {
27         document = doc;
28         this.nodeNr = nodeNr;
29         nameCode = document.getNamePool().allocate("", "", getLocalName());
30     }
31
32     /**
33     * Get the namespace code (a numeric representation of the prefix and URI)
34     */

35
36     public int getNamespaceCode() {
37         return document.namespaceCode[nodeNr];
38     }
39
40     /**
41     * Get the fingerprint
42     */

43
44     public int getFingerprint() {
45         return nameCode & 0xfffff;
46     }
47
48     /**
49     * Set the parent element for this namespace node
50     */

51
52     protected void setParentNode(int nodeNr) {
53         parentNode = nodeNr;
54     }
55
56     /**
57     * Get the nameCode, for name matching
58     */

59     
60     public int getNameCode() {
61         return nameCode;
62     }
63
64     /**
65     * Get the prefix part of the name of this node. This is the name before the ":" if any.
66     * @return the prefix part of the name. Always null.
67     */

68
69     public String JavaDoc getPrefix() {
70         return null;
71     }
72     
73     /**
74     * Get the display name of this node. For namespaces this is the namespace prefix.
75     * @return The display name of this node.
76     * For a node with no name, return an empty string.
77     */

78
79     public String JavaDoc getDisplayName() {
80         return getLocalName();
81     }
82
83     /**
84     * Get the local name of this node. For namespaces this is the namespace prefix.
85     * @return The local name of this node.
86     */

87
88     public String JavaDoc getLocalName() {
89         return document.getNamePool().getPrefixFromNamespaceCode(
90                         document.namespaceCode[nodeNr]);
91     }
92
93     /**
94     * Get the URI part of the name of this node.
95     * @return The URI of the namespace of this node. Always null.
96     */

97
98     public String JavaDoc getURI() {
99         return null;
100     }
101
102     /**
103     * Get the parent element of this namespace node
104     */

105
106     public NodeInfo getParent() {
107         return document.getNode(parentNode);
108     }
109
110     /**
111     * Determine whether this is the same node as another node
112     * @return true if this Node object and the supplied Node object represent the
113     * same node in the tree.
114     */

115
116     public final boolean isSameNode(NodeInfo other) {
117         if (!(other instanceof TinyNamespaceImpl)) return false;
118         if (this==other) return true;
119         TinyNamespaceImpl otherN = (TinyNamespaceImpl)other;
120         return (this.parentNode==((TinyNamespaceImpl)other).parentNode &&
121              this.document==otherN.document &&
122              this.nodeNr==((TinyNamespaceImpl)other).nodeNr);
123     }
124     
125     /**
126     * Return the type of node.
127     * @return NodeInfo.NAMESPACE
128     */

129
130     public final short getNodeType() {
131         return NAMESPACE;
132     }
133
134     /**
135     * Return the string value of the node.
136     * @return the namespace uri
137     */

138
139     public final String JavaDoc getStringValue() {
140         return document.getNamePool().getURIFromNamespaceCode(
141                         document.namespaceCode[nodeNr]);
142     }
143
144     /**
145     * Get unique identifier. Returns key of owning element with the namespace prefix as a suffix
146     */

147
148     public String JavaDoc generateId() {
149         return (getParent()).generateId() + "_xmlns_" + getLocalName();
150     }
151     
152     /**
153     * Copy this node to a given outputter
154     */

155
156     public void copy(Outputter out) throws TransformerException JavaDoc {
157         out.copyNamespaceNode(getNamespaceCode());
158     }
159
160     /**
161     * Get the node sequence number (in document order). Sequence numbers are monotonic but not
162     * consecutive. In the current implementation, parent nodes (elements and roots) have a zero
163     * least-significant word, while namespaces, attributes, text nodes, comments, and PIs have
164     * the top word the same as their owner and the bottom half reflecting their relative position.
165     */

166
167     protected long getSequenceNumber() {
168         return ((TinyNodeImpl)getParent()).getSequenceNumber() + nodeNr + 1;
169     }
170         
171 }
172
173 //
174
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
175
// you may not use this file except in compliance with the License. You may obtain a copy of the
176
// License at http://www.mozilla.org/MPL/
177
//
178
// Software distributed under the License is distributed on an "AS IS" basis,
179
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
180
// See the License for the specific language governing rights and limitations under the License.
181
//
182
// The Original Code is: all this file.
183
//
184
// The Initial Developer of the Original Code is
185
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
186
//
187
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
188
//
189
// Contributor(s): none.
190
//
191
Popular Tags