1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 1999, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Id: DOM_NamedNodeMap.hpp,v 1.3 2002/11/04 15:04:44 tng Exp $
|
---|
59 | */
|
---|
60 |
|
---|
61 | #ifndef DOM_NamedNodeMap_HEADER_GUARD_
|
---|
62 | #define DOM_NamedNodeMap_HEADER_GUARD_
|
---|
63 |
|
---|
64 | #include <xercesc/util/XercesDefs.hpp>
|
---|
65 |
|
---|
66 | #include "DOM_Node.hpp"
|
---|
67 |
|
---|
68 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
69 |
|
---|
70 |
|
---|
71 | class NamedNodeMapImpl;
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * <code>NamedNodeMap</code>s are used to
|
---|
75 | * represent collections of nodes that can be accessed by name.
|
---|
76 | *
|
---|
77 | * Note that <code>NamedNodeMap</code> does not inherit from <code>NodeList</code>;
|
---|
78 | * <code>NamedNodeMap</code>s are not maintained in any particular order.
|
---|
79 | * Nodes contained in a <code>NamedNodeMap</code> may
|
---|
80 | * also be accessed by an ordinal index, but this is simply to allow
|
---|
81 | * convenient enumeration of the contents, and
|
---|
82 | * does not imply that the DOM specifies an order to these Nodes.
|
---|
83 | */
|
---|
84 | class CDOM_EXPORT DOM_NamedNodeMap {
|
---|
85 | private:
|
---|
86 | void *fImpl;
|
---|
87 | short flagElem;
|
---|
88 |
|
---|
89 | static const unsigned short NNM_ELEMENT;
|
---|
90 | static const unsigned short NNM_OTHER;
|
---|
91 |
|
---|
92 | public:
|
---|
93 | /** @name Constructors and assignment operator */
|
---|
94 | //@{
|
---|
95 | /**
|
---|
96 | * Default constructor for DOM_NamedNodeMap. The resulting object does not
|
---|
97 | * refer to an actual DOM_NamedNodeMap node; it will compare == to 0, and is similar
|
---|
98 | * to a null object reference variable in Java. NamedNopes are instantiated
|
---|
99 | * by these methods: DOM_Node::getAttributes, DOM_DocumentType::getEntities
|
---|
100 | * andDOM_DocumentType::getNotations
|
---|
101 | *
|
---|
102 | */
|
---|
103 | DOM_NamedNodeMap();
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Copy constructor. Creates a new <code>DOM_NamedNodeMap</code> reference object
|
---|
107 | * that refers to the same underlying NamedNodeMap as the original.
|
---|
108 | *
|
---|
109 | * @param other The object to be copied.
|
---|
110 | */
|
---|
111 | DOM_NamedNodeMap(const DOM_NamedNodeMap &other);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Assignment operator.
|
---|
115 | *
|
---|
116 | * @param other The object to be copied.
|
---|
117 | */
|
---|
118 | DOM_NamedNodeMap & operator = (const DOM_NamedNodeMap &other);
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Assignment operator.
|
---|
122 | *
|
---|
123 | * @param other The object to be copied.
|
---|
124 | */
|
---|
125 | DOM_NamedNodeMap & operator = (const DOM_NullPtr *other);
|
---|
126 |
|
---|
127 | //@}
|
---|
128 | /** @name Destructor. */
|
---|
129 | //@{
|
---|
130 | /**
|
---|
131 | * Destructor for DOM_NamedNodeMap. The object being destroyed is the reference
|
---|
132 | * object, not the underlying NamedNodeMap itself.
|
---|
133 | *
|
---|
134 | * <p>Like most other DOM types in this implementation, memory management
|
---|
135 | * of named node maps is automatic. Instances of DOM_NamedNodeMap function
|
---|
136 | * as references to an underlying heap based implementation object,
|
---|
137 | * and should never be explicitly new-ed or deleted in application code, but
|
---|
138 | * should appear only as local variables or function parameters.
|
---|
139 | *
|
---|
140 | */
|
---|
141 | ~DOM_NamedNodeMap();
|
---|
142 |
|
---|
143 | //@}
|
---|
144 |
|
---|
145 | /** @Comparisons. */
|
---|
146 | //@{
|
---|
147 | /**
|
---|
148 | * Test whether this NamedNodeMap reference refers to the same underlying
|
---|
149 | * named node map as the other reference object. This does not
|
---|
150 | * compare the contents of two different objects.
|
---|
151 | *
|
---|
152 | * @param other The value to be compared
|
---|
153 | * @return Returns true if the underlying named node map is same
|
---|
154 | */
|
---|
155 | bool operator == (const DOM_NamedNodeMap &other) const;
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Test whether this NamedNodeMap reference refers to a different underlying
|
---|
159 | * named node map as the other reference object. This does not
|
---|
160 | * compare the contents of two different objects.
|
---|
161 | *
|
---|
162 | * @param other The value to be compared
|
---|
163 | * @return Returns true if the underlying named node map is different
|
---|
164 | */
|
---|
165 | bool operator != (const DOM_NamedNodeMap &other) const;
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Use this comparison operator to test whether a Named Node Map reference
|
---|
170 | * is null.
|
---|
171 | *
|
---|
172 | * @param p The value to be compared, which must be 0 or null.
|
---|
173 | * @return Returns true if the named node map is null
|
---|
174 | */
|
---|
175 | bool operator == (const DOM_NullPtr *p) const;
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Use this comparison operator to test whether a Named Node Map reference
|
---|
179 | * is not null.
|
---|
180 | *
|
---|
181 | * @param p The value to be compared, which must not be 0 or null.
|
---|
182 | * @return Returns true if the named node map is not null
|
---|
183 | */
|
---|
184 | bool operator != (const DOM_NullPtr *p) const;
|
---|
185 |
|
---|
186 | //@}
|
---|
187 |
|
---|
188 | /** @name Set functions. */
|
---|
189 | //@{
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Adds a node using its <code>nodeName</code> attribute.
|
---|
193 | *
|
---|
194 | * <br>As the <code>nodeName</code> attribute is used to derive the name
|
---|
195 | * which the node must be stored under, multiple nodes of certain types
|
---|
196 | * (those that have a "special" string value) cannot be stored as the names
|
---|
197 | * would clash. This is seen as preferable to allowing nodes to be aliased.
|
---|
198 | * @param arg A node to store in a named node map. The node will later be
|
---|
199 | * accessible using the value of the <code>nodeName</code> attribute of
|
---|
200 | * the node. If a node with that name is already present in the map, it
|
---|
201 | * is replaced by the new one.
|
---|
202 | * @return If the new <code>Node</code> replaces an existing node the
|
---|
203 | * replaced <code>Node</code> is returned,
|
---|
204 | * otherwise <code>null</code> is returned.
|
---|
205 | * @exception DOMException
|
---|
206 | * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a
|
---|
207 | * different document than the one that created the
|
---|
208 | * <code>NamedNodeMap</code>.
|
---|
209 | * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this
|
---|
210 | * <code>NamedNodeMap</code> is readonly.
|
---|
211 | * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an
|
---|
212 | * <code>Attr</code> that is already an attribute of another
|
---|
213 | * <code>Element</code> object. The DOM user must explicitly clone
|
---|
214 | * <code>Attr</code> nodes to re-use them in other elements.
|
---|
215 | */
|
---|
216 | DOM_Node setNamedItem(DOM_Node arg);
|
---|
217 |
|
---|
218 | //@}
|
---|
219 | /** @name Get functions. */
|
---|
220 | //@{
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Returns the <code>index</code>th item in the map.
|
---|
224 | *
|
---|
225 | * If <code>index</code>
|
---|
226 | * is greater than or equal to the number of nodes in the map, this returns
|
---|
227 | * <code>null</code>.
|
---|
228 | * @param index Index into the map.
|
---|
229 | * @return The node at the <code>index</code>th position in the
|
---|
230 | * <code>NamedNodeMap</code>, or <code>null</code> if that is not a valid
|
---|
231 | * index.
|
---|
232 | */
|
---|
233 | DOM_Node item(unsigned int index) const;
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Retrieves a node specified by name.
|
---|
237 | *
|
---|
238 | * @param name The <code>nodeName</code> of a node to retrieve.
|
---|
239 | * @return A <code>DOM_Node</code> (of any type) with the specified <code>nodeName</code>, or
|
---|
240 | * <code>null</code> if it does not identify any node in
|
---|
241 | * the map.
|
---|
242 | */
|
---|
243 | DOM_Node getNamedItem(const DOMString &name) const;
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * The number of nodes in the map.
|
---|
247 | *
|
---|
248 | * The range of valid child node indices is
|
---|
249 | * 0 to <code>length-1</code> inclusive.
|
---|
250 | */
|
---|
251 | unsigned int getLength() const;
|
---|
252 |
|
---|
253 | //@}
|
---|
254 | /** @name Functions to change the node collection. */
|
---|
255 | //@{
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Removes a node specified by name.
|
---|
259 | *
|
---|
260 | * If the removed node is an
|
---|
261 | * <code>Attr</code> with a default value it is immediately replaced.
|
---|
262 | * @param name The <code>nodeName</code> of a node to remove.
|
---|
263 | * @return The node removed from the map or <code>null</code> if no node
|
---|
264 | * with such a name exists.
|
---|
265 | * @exception DOMException
|
---|
266 | * NOT_FOUND_ERR: Raised if there is no node named <code>name</code> in
|
---|
267 | * the map.
|
---|
268 | * <br>
|
---|
269 | * NO_MODIFICATION_ALLOWED_ERR: Raised if this <code>NamedNodeMap</code>
|
---|
270 | * is readonly.
|
---|
271 | */
|
---|
272 | DOM_Node removeNamedItem(const DOMString &name);
|
---|
273 |
|
---|
274 | //@}
|
---|
275 | /** @name Functions introduced in DOM Level 2. */
|
---|
276 | //@{
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Retrieves a node specified by local name and namespace URI.
|
---|
280 | *
|
---|
281 | * @param namespaceURI The <em>namespace URI</em> of
|
---|
282 | * the node to retrieve.
|
---|
283 | * @param localName The <em>local name</em> of the node to retrieve.
|
---|
284 | * @return A <code>DOM_Node</code> (of any type) with the specified
|
---|
285 | * local name and namespace URI, or <code>null</code> if they do not
|
---|
286 | * identify any node in the map.
|
---|
287 | */
|
---|
288 | DOM_Node getNamedItemNS(const DOMString &namespaceURI,
|
---|
289 | const DOMString &localName);
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * Adds a node using its <CODE>namespaceURI</CODE> and <CODE>localName</CODE>.
|
---|
293 | *
|
---|
294 | * @param arg A node to store in a named node map. The node will later be
|
---|
295 | * accessible using the value of the <CODE>namespaceURI</CODE> and
|
---|
296 | * <CODE>localName</CODE> attribute of the node. If a node with those
|
---|
297 | * namespace URI and local name is already present in the map, it is
|
---|
298 | * replaced by the new one.
|
---|
299 | * @return If the new <code>DOM_Node</code> replaces an existing node the
|
---|
300 | * replaced <code>DOM_Node</code> is returned,
|
---|
301 | * otherwise <code>null</code> is returned.
|
---|
302 | * @exception DOMException
|
---|
303 | * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a
|
---|
304 | * different document than the one that created the
|
---|
305 | * <code>DOM_NamedNodeMap</code>.
|
---|
306 | * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this
|
---|
307 | * <code>vNamedNodeMap</code> is readonly.
|
---|
308 | * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an
|
---|
309 | * <code>DOM_Attr</code> that is already an attribute of another
|
---|
310 | * <code>DOM_Element</code> object. The DOM user must explicitly clone
|
---|
311 | * <code>DOM_Attr</code> nodes to re-use them in other elements.
|
---|
312 | */
|
---|
313 | DOM_Node setNamedItemNS(DOM_Node arg);
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Removes a node specified by local name and namespace URI.
|
---|
317 | *
|
---|
318 | * @param namespaceURI The <em>namespace URI</em> of
|
---|
319 | * the node to remove.
|
---|
320 | * @param localName The <em>local name</em> of the
|
---|
321 | * node to remove. When this <code>DOM_NamedNodeMap</code> contains the
|
---|
322 | * attributes attached to an element, as returned by the attributes
|
---|
323 | * attribute of the <code>DOM_Node</code> interface, if the removed
|
---|
324 | * attribute is known to have a default value, an attribute
|
---|
325 | * immediately appears containing the default value
|
---|
326 | * as well as the corresponding namespace URI, local name, and prefix.
|
---|
327 | * @return The node removed from the map if a node with such a local name
|
---|
328 | * and namespace URI exists.
|
---|
329 | * @exception DOMException
|
---|
330 | * NOT_FOUND_ERR: Raised if there is no node named <code>name</code> in
|
---|
331 | * the map.
|
---|
332 | * <br>
|
---|
333 | * NO_MODIFICATION_ALLOWED_ERR: Raised if this <code>DOM_NamedNodeMap</code>
|
---|
334 | * is readonly.
|
---|
335 | */
|
---|
336 | DOM_Node removeNamedItemNS(const DOMString &namespaceURI,
|
---|
337 | const DOMString &localName);
|
---|
338 |
|
---|
339 | //@}
|
---|
340 |
|
---|
341 | protected:
|
---|
342 |
|
---|
343 | DOM_NamedNodeMap(NamedNodeMapImpl *impl);
|
---|
344 | DOM_NamedNodeMap(NodeImpl *impl);
|
---|
345 |
|
---|
346 | friend class DOM_DocumentType;
|
---|
347 | friend class DOM_Node;
|
---|
348 |
|
---|
349 |
|
---|
350 | };
|
---|
351 |
|
---|
352 | XERCES_CPP_NAMESPACE_END
|
---|
353 |
|
---|
354 | #endif
|
---|
355 |
|
---|