1 | #ifndef AttrImpl_HEADER_GUARD_
|
---|
2 | #define AttrImpl_HEADER_GUARD_
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * The Apache Software License, Version 1.1
|
---|
6 | *
|
---|
7 | * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
|
---|
8 | * reserved.
|
---|
9 | *
|
---|
10 | * Redistribution and use in source and binary forms, with or without
|
---|
11 | * modification, are permitted provided that the following conditions
|
---|
12 | * are met:
|
---|
13 | *
|
---|
14 | * 1. Redistributions of source code must retain the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer.
|
---|
16 | *
|
---|
17 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
18 | * notice, this list of conditions and the following disclaimer in
|
---|
19 | * the documentation and/or other materials provided with the
|
---|
20 | * distribution.
|
---|
21 | *
|
---|
22 | * 3. The end-user documentation included with the redistribution,
|
---|
23 | * if any, must include the following acknowledgment:
|
---|
24 | * "This product includes software developed by the
|
---|
25 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
26 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
27 | * if and wherever such third-party acknowledgments normally appear.
|
---|
28 | *
|
---|
29 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
30 | * not be used to endorse or promote products derived from this
|
---|
31 | * software without prior written permission. For written
|
---|
32 | * permission, please contact apache\@apache.org.
|
---|
33 | *
|
---|
34 | * 5. Products derived from this software may not be called "Apache",
|
---|
35 | * nor may "Apache" appear in their name, without prior written
|
---|
36 | * permission of the Apache Software Foundation.
|
---|
37 | *
|
---|
38 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
39 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
40 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
41 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
44 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
45 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
46 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
48 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
49 | * SUCH DAMAGE.
|
---|
50 | * ====================================================================
|
---|
51 | *
|
---|
52 | * This software consists of voluntary contributions made by many
|
---|
53 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
54 | * originally based on software copyright (c) 1999, International
|
---|
55 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
56 | * on the Apache Software Foundation, please see
|
---|
57 | * <http://www.apache.org/>.
|
---|
58 | */
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Attribute represents an XML-style attribute of an
|
---|
62 | * Element. Typically, the allowable values are controlled by its
|
---|
63 | * declaration in the Document Type Definition (DTD) governing this
|
---|
64 | * kind of document.
|
---|
65 | * <P>
|
---|
66 | * If the attribute has not been explicitly assigned a value, but has
|
---|
67 | * been declared in the DTD, it will exist and have that default. Only
|
---|
68 | * if neither the document nor the DTD specifies a value will the
|
---|
69 | * Attribute really be considered absent and have no value; in that
|
---|
70 | * case, querying the attribute will return null.
|
---|
71 | * <P>
|
---|
72 | * Attributes may have multiple children that contain their data. (XML
|
---|
73 | * allows attributes to contain entity references, and tokenized
|
---|
74 | * attribute types such as NMTOKENS may have a child for each token.)
|
---|
75 | * For convenience, the Attribute object's getValue() method returns
|
---|
76 | * the string version of the attribute's value.
|
---|
77 | * <P>
|
---|
78 | * Attributes are not children of the Elements they belong to, in the
|
---|
79 | * usual sense, and have no valid Parent reference. However, the spec
|
---|
80 | * says they _do_ belong to a specific Element, and an INUSE exception
|
---|
81 | * is to be thrown if the user attempts to explicitly share them
|
---|
82 | * between elements.
|
---|
83 | * <P>
|
---|
84 | * Note that Elements do not permit attributes to appear to be shared
|
---|
85 | * (see the INUSE exception), so this object's mutability is
|
---|
86 | * officially not an issue.
|
---|
87 | * <p>
|
---|
88 | * Note: The ownerNode attribute is used to store the Element the Attr
|
---|
89 | * node is associated with. Attr nodes do not have parent nodes.
|
---|
90 | * Besides, the getOwnerElement() method can be used to get the element node
|
---|
91 | * this attribute is associated with.
|
---|
92 | * <P>
|
---|
93 | * AttrImpl does not support Namespaces. AttrNSImpl, which inherits from
|
---|
94 | * it, does.
|
---|
95 | *
|
---|
96 | * <p>AttrImpl used to inherit from ParentNode. It now directly inherits from
|
---|
97 | * NodeImpl and provide its own implementation of the ParentNode's behavior.
|
---|
98 | * The reason is that we now try and avoid to always creating a Text node to
|
---|
99 | * hold the value of an attribute. The DOM spec requires it, so we still have
|
---|
100 | * to do it in case getFirstChild() is called for instance. The reason
|
---|
101 | * attribute values are stored as a list of nodes is so that they can carry
|
---|
102 | * more than a simple string. They can also contain EntityReference nodes.
|
---|
103 | * However, most of the times people only have a single string that they only
|
---|
104 | * set and get through Element.set/getAttribute or Attr.set/getValue. In this
|
---|
105 | * new version, the Attr node has a value pointer which can either be the
|
---|
106 | * String directly or a pointer to the first ChildNode. A flag tells which one
|
---|
107 | * it currently is. Note that while we try to stick with the direct String as
|
---|
108 | * much as possible once we've switched to a node there is no going back. This
|
---|
109 | * is because we have no way to know whether the application keeps referring to
|
---|
110 | * the node we once returned.
|
---|
111 | * <p> The gain in memory varies on the density of attributes in the document.
|
---|
112 | * But in the tests I've run I've seen up to 12% of memory gain. And the good
|
---|
113 | * thing is that it also leads to a slight gain in speed because we allocate
|
---|
114 | * fewer objects! I mean, that's until we have to actually create the node...
|
---|
115 | * <p>
|
---|
116 | * To avoid too much duplicated code, I got rid of ParentNode and renamed
|
---|
117 | * ChildAndParentNode, which I never really liked, to ParentNode for
|
---|
118 | * simplicity, this doesn't make much of a difference in memory usage because
|
---|
119 | * there are only very objects that are only a Parent. This is only true now
|
---|
120 | * because AttrImpl now inherits directly from NodeImpl and has its own
|
---|
121 | * implementation of the ParentNode's node behavior. So there is still some
|
---|
122 | * duplicated code there.
|
---|
123 | *
|
---|
124 | * <p><b>WARNING</b>: Some of the code here is partially duplicated in
|
---|
125 | * ParentNode, be careful to keep these two classes in sync!
|
---|
126 | *
|
---|
127 | * $Id: AttrImpl.hpp,v 1.4 2003/05/24 23:56:35 neilg Exp $
|
---|
128 | */
|
---|
129 |
|
---|
130 | //
|
---|
131 | // This file is part of the internal implementation of the C++ XML DOM.
|
---|
132 | // It should NOT be included or used directly by application programs.
|
---|
133 | //
|
---|
134 | // Applications should include the file <xercesc/dom/deprecated/DOM.hpp> for the entire
|
---|
135 | // DOM API, or DOM_*.hpp for individual DOM classes, where the class
|
---|
136 | // name is substituded for the *.
|
---|
137 | //
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 | #include <xercesc/util/XercesDefs.hpp>
|
---|
142 | #include "ChildNode.hpp"
|
---|
143 | #include "DOM_Node.hpp"
|
---|
144 |
|
---|
145 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
146 |
|
---|
147 |
|
---|
148 | class ElementImpl;
|
---|
149 |
|
---|
150 | class CDOM_EXPORT AttrImpl: public NodeImpl {
|
---|
151 |
|
---|
152 | public:
|
---|
153 | DOMString name;
|
---|
154 |
|
---|
155 | /** This can either be a DOMString or the first child node (ChildNode*). */
|
---|
156 | union {
|
---|
157 | ChildNode *child;
|
---|
158 | DOMString *str;
|
---|
159 | } value;
|
---|
160 |
|
---|
161 | public:
|
---|
162 | AttrImpl(DocumentImpl *ownerDocument, const DOMString &aName);
|
---|
163 | AttrImpl(const AttrImpl &other, bool deep=false);
|
---|
164 | virtual ~AttrImpl();
|
---|
165 | virtual NodeImpl *cloneNode(bool deep=false);
|
---|
166 | virtual DOMString getNodeName();
|
---|
167 | virtual short getNodeType();
|
---|
168 | virtual DOMString getName();
|
---|
169 | virtual DOMString getNodeValue();
|
---|
170 | virtual bool getSpecified();
|
---|
171 | virtual DOMString getValue();
|
---|
172 | virtual bool isAttrImpl();
|
---|
173 | virtual void setNodeValue(const DOMString &value);
|
---|
174 | virtual void setSpecified(bool arg);
|
---|
175 | virtual void setValue(const DOMString &value);
|
---|
176 | virtual DOMString toString();
|
---|
177 |
|
---|
178 | //Introduced in DOM Level 2
|
---|
179 | ElementImpl *getOwnerElement();
|
---|
180 | void setOwnerElement(ElementImpl *ownerElem); //internal use only
|
---|
181 |
|
---|
182 |
|
---|
183 | // ParentNode stuff
|
---|
184 | virtual NodeListImpl *getChildNodes();
|
---|
185 | virtual NodeImpl * getFirstChild();
|
---|
186 | virtual NodeImpl * getLastChild();
|
---|
187 | virtual unsigned int getLength();
|
---|
188 | virtual bool hasChildNodes();
|
---|
189 | virtual NodeImpl *insertBefore(NodeImpl *newChild, NodeImpl *refChild);
|
---|
190 | virtual NodeImpl *item(unsigned int index);
|
---|
191 | virtual NodeImpl *removeChild(NodeImpl *oldChild);
|
---|
192 | virtual NodeImpl *replaceChild(NodeImpl *newChild, NodeImpl *oldChild);
|
---|
193 | virtual void setReadOnly(bool isReadOnly, bool deep);
|
---|
194 |
|
---|
195 | //Introduced in DOM Level 2
|
---|
196 | virtual void normalize();
|
---|
197 |
|
---|
198 | protected:
|
---|
199 | void makeChildNode();
|
---|
200 | void cloneChildren(const NodeImpl &other);
|
---|
201 | ChildNode * lastChild();
|
---|
202 | void lastChild(ChildNode *);
|
---|
203 | inline DOMString* valueToDOMString();
|
---|
204 |
|
---|
205 | };
|
---|
206 |
|
---|
207 | XERCES_CPP_NAMESPACE_END
|
---|
208 |
|
---|
209 | #endif
|
---|