KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > dom > DOMAttributeMap


1 package net.sf.saxon.dom;
2
3 import net.sf.saxon.om.Axis;
4 import net.sf.saxon.om.AxisIterator;
5 import net.sf.saxon.om.NodeInfo;
6 import org.w3c.dom.DOMException JavaDoc;
7 import org.w3c.dom.NamedNodeMap JavaDoc;
8 import org.w3c.dom.Node JavaDoc;
9
10 /**
11  * Implementation of DOM NamedNodeMap used to represent the attributes of an element, for use when
12  * Saxon element and attribute nodes are accessed using the DOM API.
13  */

14
15 class DOMAttributeMap implements NamedNodeMap JavaDoc {
16
17     private NodeInfo parent;
18
19     /**
20      * Construct an AttributeMap for a given element node
21      */

22
23     public DOMAttributeMap(NodeInfo parent) {
24         this.parent = parent;
25     }
26
27     /**
28     * Get named attribute (DOM NamedNodeMap method)
29     */

30
31     public Node JavaDoc getNamedItem(String JavaDoc name) {
32         AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
33         while (true) {
34             NodeInfo att = (NodeInfo)atts.next();
35             if (att == null) {
36                 return null;
37             }
38             if (name.equals(att.getDisplayName())) {
39                 return NodeOverNodeInfo.wrap(att);
40             }
41         }
42     }
43
44     /**
45     * Get n'th attribute (DOM NamedNodeMap method).
46     * Namespace declarations are not retrieved.
47     */

48
49     public Node JavaDoc item(int index) {
50         if (index<0) {
51             return null;
52         }
53         int length = 0;
54         AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
55         while (true) {
56             NodeInfo att = (NodeInfo)atts.next();
57             if (att == null) {
58                 return null;
59             }
60             if (length==index) {
61                 return NodeOverNodeInfo.wrap(att);
62             }
63             length++;
64         }
65     }
66
67     /**
68     * Get number of attributes (DOM NamedNodeMap method).
69     */

70
71     public int getLength() {
72         int length = 0;
73         AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
74         while (atts.next() != null) {
75             length++;
76         }
77         return length;
78     }
79
80     /**
81     * Get named attribute (DOM NamedNodeMap method)
82     */

83
84     public Node JavaDoc getNamedItemNS(String JavaDoc uri, String JavaDoc localName) {
85         if (uri==null) uri="";
86         AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
87         while (true) {
88             NodeInfo att = (NodeInfo)atts.next();
89             if (att == null) {
90                 return null;
91             }
92             if (uri.equals(att.getURI()) && localName.equals(att.getLocalPart())) {
93                 return NodeOverNodeInfo.wrap(att);
94             }
95         }
96     }
97
98     /**
99     * Set named attribute (DOM NamedNodeMap method: always fails)
100     */

101
102     public Node JavaDoc setNamedItem(Node JavaDoc arg) throws DOMException JavaDoc {
103         NodeOverNodeInfo.disallowUpdate();
104         return null;
105     }
106
107     /**
108     * Remove named attribute (DOM NamedNodeMap method: always fails)
109     */

110
111     public Node JavaDoc removeNamedItem(String JavaDoc name) throws DOMException JavaDoc {
112         NodeOverNodeInfo.disallowUpdate();
113         return null;
114     }
115
116     /**
117     * Set named attribute (DOM NamedNodeMap method: always fails)
118     */

119
120     public Node JavaDoc setNamedItemNS(Node JavaDoc arg) throws DOMException JavaDoc {
121         NodeOverNodeInfo.disallowUpdate();
122         return null;
123     }
124
125     /**
126     * Remove named attribute (DOM NamedNodeMap method: always fails)
127     */

128
129     public Node JavaDoc removeNamedItemNS(String JavaDoc uri, String JavaDoc localName) throws DOMException JavaDoc {
130         NodeOverNodeInfo.disallowUpdate();
131         return null;
132     }
133
134 }
135
136 //
137
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
138
// you may not use this file except in compliance with the License. You may obtain a copy of the
139
// License at http://www.mozilla.org/MPL/
140
//
141
// Software distributed under the License is distributed on an "AS IS" basis,
142
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
143
// See the License for the specific language governing rights and limitations under the License.
144
//
145
// The Original Code is: all this file.
146
//
147
// The Initial Developer of the Original Code is Michael H. Kay.
148
//
149
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
150
//
151
// Contributor(s): none.
152
//
153

154
Popular Tags