1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: SchemaAttDefList.hpp 673679 2008-07-03 13:50:10Z borisk $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(XERCESC_INCLUDE_GUARD_SCHEMAATTDEFLIST_HPP) |
---|
23 | #define XERCESC_INCLUDE_GUARD_SCHEMAATTDEFLIST_HPP |
---|
24 | |
---|
25 | #include <xercesc/util/RefHash2KeysTableOf.hpp> |
---|
26 | // #include <icxercesc/validators/schema/SchemaElementDecl.hpp> |
---|
27 | #include <xercesc/framework/XMLAttDefList.hpp> |
---|
28 | #include <icxercesc/validators/schema/SchemaAttDef.hpp> |
---|
29 | #include <icxercesc/util/QName.hpp> |
---|
30 | #include <icxmlc/XMLConfig.hpp> |
---|
31 | |
---|
32 | XERCES_CPP_NAMESPACE_BEGIN |
---|
33 | |
---|
34 | // |
---|
35 | // This is a derivative of the framework abstract class which defines the |
---|
36 | // interface to a list of attribute defs that belong to a particular |
---|
37 | // element. The scanner needs to be able to get a list of the attributes |
---|
38 | // that an element supports, for use during the validation process and for |
---|
39 | // fixed/default attribute processing. |
---|
40 | // |
---|
41 | // For us, we just wrap the RefHash2KeysTableOf collection that the SchemaElementDecl |
---|
42 | // class uses to store the attributes that belong to it. |
---|
43 | // |
---|
44 | // This class does not adopt the hash table, it just references it. The |
---|
45 | // hash table is owned by the element decl it is a member of. |
---|
46 | // |
---|
47 | class VALIDATORS_EXPORT SchemaAttDefList : public XMLAttDefList |
---|
48 | { |
---|
49 | public : |
---|
50 | // ----------------------------------------------------------------------- |
---|
51 | // Constructors and Destructor |
---|
52 | // ----------------------------------------------------------------------- |
---|
53 | SchemaAttDefList |
---|
54 | ( |
---|
55 | RefHash2KeysTableOf<SchemaAttDef>* const listToUse, |
---|
56 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
57 | ); |
---|
58 | |
---|
59 | ~SchemaAttDefList(); |
---|
60 | |
---|
61 | |
---|
62 | // ----------------------------------------------------------------------- |
---|
63 | // Implementation of the virtual interface |
---|
64 | // ----------------------------------------------------------------------- |
---|
65 | |
---|
66 | virtual bool isEmpty() const; |
---|
67 | virtual XMLAttDef* findAttDef |
---|
68 | ( |
---|
69 | const unsigned int uriID |
---|
70 | , const XMLCh* const attName |
---|
71 | ); |
---|
72 | virtual const XMLAttDef* findAttDef |
---|
73 | ( |
---|
74 | const unsigned int uriID |
---|
75 | , const XMLCh* const attName |
---|
76 | ) const; |
---|
77 | virtual XMLAttDef* findAttDef |
---|
78 | ( |
---|
79 | const XMLCh* const attURI |
---|
80 | , const XMLCh* const attName |
---|
81 | ); |
---|
82 | virtual const XMLAttDef* findAttDef |
---|
83 | ( |
---|
84 | const XMLCh* const attURI |
---|
85 | , const XMLCh* const attName |
---|
86 | ) const; |
---|
87 | |
---|
88 | XMLAttDef* findAttDefLocalPart |
---|
89 | ( |
---|
90 | const unsigned int uriID |
---|
91 | , const XMLCh* const attLocalPart |
---|
92 | ); |
---|
93 | |
---|
94 | const XMLAttDef* findAttDefLocalPart |
---|
95 | ( |
---|
96 | const unsigned int uriID |
---|
97 | , const XMLCh* const attLocalPart |
---|
98 | ) const; |
---|
99 | |
---|
100 | /** |
---|
101 | * return total number of attributes in this list |
---|
102 | */ |
---|
103 | virtual XMLSize_t getAttDefCount() const ; |
---|
104 | |
---|
105 | /** |
---|
106 | * return attribute at the index-th position in the list. |
---|
107 | */ |
---|
108 | virtual XMLAttDef &getAttDef(XMLSize_t index) ; |
---|
109 | |
---|
110 | /** |
---|
111 | * return attribute at the index-th position in the list. |
---|
112 | */ |
---|
113 | virtual const XMLAttDef &getAttDef(XMLSize_t index) const ; |
---|
114 | |
---|
115 | /*** |
---|
116 | * Support for Serialization/De-serialization |
---|
117 | ***/ |
---|
118 | DECL_XSERIALIZABLE(SchemaAttDefList) |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | SchemaAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
124 | |
---|
125 | private : |
---|
126 | // ----------------------------------------------------------------------- |
---|
127 | // Unimplemented constructors and operators |
---|
128 | // ----------------------------------------------------------------------- |
---|
129 | SchemaAttDefList(const SchemaAttDefList&); |
---|
130 | SchemaAttDefList& operator=(const SchemaAttDefList&); |
---|
131 | |
---|
132 | void addAttDef(SchemaAttDef *toAdd); |
---|
133 | |
---|
134 | // ----------------------------------------------------------------------- |
---|
135 | // Private data members |
---|
136 | // |
---|
137 | // fEnum |
---|
138 | // This is an enumerator for the list that we use to do the enumerator |
---|
139 | // type methods of this class. |
---|
140 | // |
---|
141 | // fList |
---|
142 | // The list of SchemaAttDef objects that represent the attributes that |
---|
143 | // a particular element supports. |
---|
144 | // fArray |
---|
145 | // vector of pointers to the DTDAttDef objects contained in this list |
---|
146 | // fSize |
---|
147 | // size of fArray |
---|
148 | // fCount |
---|
149 | // number of DTDAttDef objects currently stored in this list |
---|
150 | // ----------------------------------------------------------------------- |
---|
151 | // RefHash2KeysTableOfEnumerator<SchemaAttDef>* fEnum; |
---|
152 | // RefHash2KeysTableOf<SchemaAttDef>* fList; |
---|
153 | SchemaAttDef** fArray; |
---|
154 | XMLSize_t fSize; |
---|
155 | XMLSize_t fCount; |
---|
156 | |
---|
157 | friend class ComplexTypeInfo; |
---|
158 | }; |
---|
159 | |
---|
160 | inline void SchemaAttDefList::addAttDef(SchemaAttDef *toAdd) |
---|
161 | { |
---|
162 | if (unlikely(fCount == fSize)) |
---|
163 | { |
---|
164 | fSize <<= 1; |
---|
165 | |
---|
166 | SchemaAttDef** newArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize )); |
---|
167 | memcpy(newArray, fArray, fCount * sizeof(SchemaAttDef *)); |
---|
168 | getMemoryManager()->deallocate(fArray); |
---|
169 | fArray = newArray; |
---|
170 | } |
---|
171 | |
---|
172 | fArray[fCount] = toAdd; |
---|
173 | fCount++; |
---|
174 | } |
---|
175 | |
---|
176 | inline XMLAttDef* SchemaAttDefList::findAttDefLocalPart(const unsigned int uriID, const XMLCh* const attLocalPart) |
---|
177 | { |
---|
178 | for (XMLSize_t i = 0; i < fCount; i++) |
---|
179 | { |
---|
180 | SchemaAttDef * attDef = fArray[i]; |
---|
181 | const QName * attName = attDef->getAttName(); |
---|
182 | if (attName->getURI() == uriID) |
---|
183 | { |
---|
184 | if (XMLString::equals(attName->getLocalPart(), attLocalPart)) |
---|
185 | { |
---|
186 | return attDef; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | } |
---|
191 | return 0; |
---|
192 | } |
---|
193 | |
---|
194 | inline const XMLAttDef* SchemaAttDefList::findAttDefLocalPart(const unsigned int uriID, const XMLCh* const attLocalPart) const |
---|
195 | { |
---|
196 | for (XMLSize_t i = 0; i < fCount; i++) |
---|
197 | { |
---|
198 | const SchemaAttDef * attDef = fArray[i]; |
---|
199 | const QName * attName = attDef->getAttName(); |
---|
200 | if (attName->getURI() == uriID) |
---|
201 | { |
---|
202 | if (XMLString::equals(attName->getLocalPart(), attLocalPart)) |
---|
203 | { |
---|
204 | return attDef; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | return 0; |
---|
209 | } |
---|
210 | |
---|
211 | #ifdef PRINT_DEBUG_MESSAGE |
---|
212 | static std::ostream & operator << (std::ostream & out, const SchemaAttDefList & list) |
---|
213 | { |
---|
214 | out << '{'; |
---|
215 | for (size_t i = 0; i < list.getAttDefCount(); i++) |
---|
216 | { |
---|
217 | out << (const SchemaAttDef&)list.getAttDef(i); |
---|
218 | } |
---|
219 | out << '}'; |
---|
220 | return out; |
---|
221 | } |
---|
222 | |
---|
223 | static std::ostream & operator << (std::ostream & out, const SchemaAttDefList * list) |
---|
224 | { |
---|
225 | if (list) |
---|
226 | { |
---|
227 | out << *list; |
---|
228 | } |
---|
229 | return out; |
---|
230 | } |
---|
231 | #endif |
---|
232 | |
---|
233 | XERCES_CPP_NAMESPACE_END |
---|
234 | |
---|
235 | #endif |
---|