KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > tree > NamespaceEnumeration


1 package com.icl.saxon.tree;
2 import com.icl.saxon.om.NodeInfo;
3 import com.icl.saxon.om.Namespace;
4 import com.icl.saxon.pattern.NodeTest;
5 import java.util.Vector;
6
7 final class NamespaceEnumeration extends TreeEnumeration {
8     
9     private ElementImpl element;
10     private Vector nslist;
11     private int index;
12     private int length;
13
14     public NamespaceEnumeration(NodeImpl node, NodeTest nodeTest) {
15         super(node, nodeTest);
16         
17         if (node instanceof ElementImpl) {
18             element = (ElementImpl)node;
19             nslist = new Vector(10);
20             element.addNamespaceNodes(element, nslist, true);
21             index = -1;
22             length = nslist.size();
23             advance();
24         } else { // if it's not an element then there are no namespace nodes
25
next = null;
26         }
27
28     }
29
30     public void step() {
31         index++;
32         if (index<length) {
33             next = (NamespaceImpl)nslist.elementAt(index);
34         } else {
35             next = null;
36         }
37     }
38
39     /**
40     * Test whether a node conforms. Reject a node with prefix="", uri="" since
41     * this represents a namespace undeclaration and not a true namespace node.
42     */

43
44     protected boolean conforms(NodeInfo node) {
45         if (node==null) return true;
46         NamespaceImpl ns = (NamespaceImpl)node;
47         if (ns.getLocalName().equals("") && ns.getStringValue().equals("")) {
48             return false;
49         }
50         return nodeTest.matches(node);
51     }
52
53     public boolean isSorted() {
54         return false;
55     }
56
57     public boolean isPeer() {
58         return true;
59     }
60
61     /**
62     * Get the last position, that is the number of nodes in the enumeration
63     */

64
65     public int getLastPosition() {
66         if (last>=0) return last;
67         NamespaceEnumeration enum =
68             new NamespaceEnumeration(start, nodeTest);
69         return enum.count();
70     }
71 }
72
73
74
75 //
76
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
77
// you may not use this file except in compliance with the License. You may obtain a copy of the
78
// License at http://www.mozilla.org/MPL/
79
//
80
// Software distributed under the License is distributed on an "AS IS" basis,
81
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
82
// See the License for the specific language governing rights and limitations under the License.
83
//
84
// The Original Code is: all this file.
85
//
86
// The Initial Developer of the Original Code is
87
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
88
//
89
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
90
//
91
// Contributor(s): none.
92
//
93
Popular Tags