3 //=============================================================================
5 * @file AttributesImpl.h
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
9 //=============================================================================
12 #ifndef ACEXML_ATTRIBUTESIMPL_H
13 #define ACEXML_ATTRIBUTESIMPL_H
15 #include /**/ "ace/pre.h"
16 #include "ACEXML/common/ACEXML_Export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ACEXML/common/Attributes.h"
23 #include "ace/Containers_T.h"
25 #if !defined ACEXML_AttributesImpl_Default_Size
26 #define ACEXML_AttributesImpl_Default_Size 20
27 #endif /* ACEXML_AttributesImpl_Default_Size */
29 class ACEXML_AttributesImpl
;
32 * @class ACEXML_Attribute
34 * @brief ACEXML_Attribute defines the data structure of an attribute
36 * @sa ACEXML_AttributesImpl
38 class ACEXML_Export ACEXML_Attribute
41 friend class ACEXML_AttributesImpl
;
43 /// Default constructor.
47 ACEXML_Attribute (const ACEXML_Attribute
&attr
);
49 /// Initialize all constructor.
50 ACEXML_Attribute (const ACEXML_Char
*uri
,
51 const ACEXML_Char
*localName
,
52 const ACEXML_Char
*qName
,
53 const ACEXML_Char
*type
,
54 const ACEXML_Char
*value
);
60 void setAttribute (const ACEXML_Char
*uri
,
61 const ACEXML_Char
*localName
,
62 const ACEXML_Char
*qName
,
63 const ACEXML_Char
*type
,
64 const ACEXML_Char
*value
);
67 const ACEXML_Char
*uri () const;
70 void uri (const ACEXML_Char
*uri
);
72 /// Get \a localName_.
73 const ACEXML_Char
*localName () const;
75 /// Set \a localName_.
76 void localName (const ACEXML_Char
*localName
);
79 const ACEXML_Char
*qName () const;
82 void qName (const ACEXML_Char
*qName
);
85 const ACEXML_Char
*type () const;
88 void type (const ACEXML_Char
*type
);
91 const ACEXML_Char
*value () const;
94 void value (const ACEXML_Char
*value
);
96 /// Assignment operator.
97 ACEXML_Attribute
&operator= (const ACEXML_Attribute
&rhs
);
99 /// Comparison operator.
100 bool operator!= (const ACEXML_Attribute
&rhs
) const;
103 /// Namespace URI of an attribute
106 ACEXML_Char
*localName_
;
113 * @typedef ACE_Array<ACEXML_Attribute> ACEXML_Attribute_Array
115 typedef ACE_Array
<ACEXML_Attribute
> ACEXML_Attribute_Array
;
118 * @class ACEXML_AttributesImpl AttributesImpl.h "ACEXML/common/AttributesImpl.h"
120 * @brief ACEXML_AttributesImpl provides the default implementation
121 * of interface ACEXML_Attributes.
123 * This class provides a default implementation of the SAX2 Attributes
124 * interface, with the addition of manipulators so that the list can
125 * be modified or reused.
127 * There are two typical uses of this class:
129 * - to take a persistent snapshot of an Attributes object in a
130 * startElement event; or
131 * - to construct or modify an Attributes object in a SAX2 driver or filter.
133 * This class replaces the now-deprecated SAX1 AttributeListImpl
134 * class; in addition to supporting the updated Attributes interface
135 * rather than the deprecated AttributeList interface, it also
136 * includes a much more efficient implementation using a single array
137 * rather than a set of Vectors.
139 * @sa ACEXML_Attributes
141 class ACEXML_Export ACEXML_AttributesImpl
142 : public ACEXML_Attributes
146 * Initialize an AttributesImpl that holds @a size attributes.
148 ACEXML_AttributesImpl (int size
= ACEXML_AttributesImpl_Default_Size
);
149 ACEXML_AttributesImpl (const ACEXML_AttributesImpl
&attrs
);
150 virtual ~ACEXML_AttributesImpl ();
153 * Add a new attribute using the argument(s) supplied.
154 * Return -1 if an attribute with the same name already exists.
156 virtual int addAttribute (const ACEXML_Char
*uri
,
157 const ACEXML_Char
*localName
,
158 const ACEXML_Char
*qName
,
159 const ACEXML_Char
*type
,
160 const ACEXML_Char
*value
);
161 virtual int addAttribute (const ACEXML_Attribute
&att
);
164 * Check for duplicate attributes.
166 virtual int isDuplicate (const ACEXML_Char
*uri
,
167 const ACEXML_Char
*localName
,
168 const ACEXML_Char
*qName
);
170 * Remove an attribute from the array. Notice that this
171 * operation can invalidate previously acquired @a index
172 * value. (It will repack the array.)
174 virtual int removeAttribute (size_t index
);
178 * Look up the index of an attribute by XML 1.0 qualified name.
179 * Return -1 if we fail to find a match.
181 virtual int getIndex (const ACEXML_Char
*qName
);
184 * Look up the index of an attribute by Namespace name.
185 * Return -1 if we fail to find a match.
187 virtual int getIndex (const ACEXML_Char
*uri
,
188 const ACEXML_Char
*localPart
);
191 * Return the number of attributes in the list.
193 virtual size_t getLength ();
196 * Look up an attribute's local name by index.
197 * Return 0 if index is out of range.
199 virtual const ACEXML_Char
*getLocalName (size_t index
);
202 * Look up an attribute's XML 1.0 qualified name by index.
203 * Return 0 if index is out of range.
205 virtual const ACEXML_Char
*getQName (size_t index
);
208 * Look up an attribute's type by index.
209 * Return 0 if index is out of range.
211 virtual const ACEXML_Char
*getType (size_t index
);
214 * Look up an attribute's type by XML 1.0 qualified name.
215 * Return 0 if we fail to find a match.
217 virtual const ACEXML_Char
*getType (const ACEXML_Char
*qName
);
220 * Look up an attribute's type by Namespace name.
221 * Return 0 if we fail to find a match.
223 virtual const ACEXML_Char
*getType (const ACEXML_Char
*uri
,
224 const ACEXML_Char
*localPart
);
227 * Look up an attribute's Namespace URI by index.
228 * Return 0 if index is out of range.
230 virtual const ACEXML_Char
*getURI (size_t index
);
233 * Look up an attribute's value by index.
234 * Return 0 if index is out of range.
236 virtual const ACEXML_Char
*getValue (size_t index
);
239 * Look up an attribute's value by XML 1.0 qualified name.
240 * Return 0 if we fail to find a match.
242 virtual const ACEXML_Char
*getValue (const ACEXML_Char
*qName
);
245 * Look up an attribute's value by Namespace name.
246 * Return 0 if we fail to find a match.
248 virtual const ACEXML_Char
*getValue (const ACEXML_Char
*uri
,
249 const ACEXML_Char
*localPart
);
252 * Set an attribute at index. Return -1 if index is out of
255 virtual int setAttribute (size_t index
,
256 const ACEXML_Char
*uri
,
257 const ACEXML_Char
*localName
,
258 const ACEXML_Char
*qName
,
259 const ACEXML_Char
*type
,
260 const ACEXML_Char
*value
);
263 * Set the localName of the attribute at @a index.
264 * return -1 if @a index is out of range.
266 virtual int setLocalName (size_t index
,
267 const ACEXML_Char
*localName
);
270 * Set the qName of the attribute at @a index.
271 * return -1 if @a index is out of range.
273 virtual int setQName (size_t index
,
274 const ACEXML_Char
*qName
);
277 * Set the URI of the attribute at @a index.
278 * return -1 if @a index is out of range.
280 virtual int setURI (size_t index
,
281 const ACEXML_Char
*uri
);
284 * Set the type of the attribute at @a index.
285 * return -1 if @a index is out of range.
287 virtual int setType (size_t index
,
288 const ACEXML_Char
*type
);
291 * Set the value of the attribute at @a index.
292 * return -1 if @a index is out of range.
294 virtual int setValue (size_t index
,
295 const ACEXML_Char
*value
);
297 /// Container for all attributes.
298 ACEXML_Attribute_Array attrs_
;
301 #if defined (__ACEXML_INLINE__)
302 # include "ACEXML/common/AttributesImpl.inl"
303 #endif /* __ACEXML_INLINE__ */
305 #include /**/ "ace/post.h"
307 #endif /* ACEXML_ATTRIBUTESIMPL_H */