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: XercesAttGroupInfo.cpp 676911 2008-07-15 13:27:32Z amassari $
20 */
21
22 // ---------------------------------------------------------------------------
23 // Includes
24 // ---------------------------------------------------------------------------
25 #include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
26 #include <xercesc/util/QName.hpp>
27
28 #include <xercesc/internal/XTemplateSerializer.hpp>
29
30 XERCES_CPP_NAMESPACE_BEGIN
31
32 // ---------------------------------------------------------------------------
33 // XercesAttGroupInfo: Constructors and Destructor
34 // ---------------------------------------------------------------------------
XercesAttGroupInfo(MemoryManager * const manager)35 XercesAttGroupInfo::XercesAttGroupInfo(MemoryManager* const manager)
36 : fTypeWithId(false)
37 , fNameId(0)
38 , fNamespaceId(0)
39 , fAttributes(0)
40 , fAnyAttributes(0)
41 , fCompleteWildCard(0)
42 , fMemoryManager(manager)
43 {
44
45 }
46
XercesAttGroupInfo(unsigned int attGroupNameId,unsigned int attGroupNamespaceId,MemoryManager * const manager)47 XercesAttGroupInfo::XercesAttGroupInfo(unsigned int attGroupNameId,
48 unsigned int attGroupNamespaceId,
49 MemoryManager* const manager)
50 : fTypeWithId(false)
51 , fNameId(attGroupNameId)
52 , fNamespaceId(attGroupNamespaceId)
53 , fAttributes(0)
54 , fAnyAttributes(0)
55 , fCompleteWildCard(0)
56 , fMemoryManager(manager)
57 {
58
59 }
60
~XercesAttGroupInfo()61 XercesAttGroupInfo::~XercesAttGroupInfo()
62 {
63 delete fAttributes;
64 delete fAnyAttributes;
65 delete fCompleteWildCard;
66 }
67
containsAttribute(const XMLCh * const name,const unsigned int uri)68 bool XercesAttGroupInfo::containsAttribute(const XMLCh* const name,
69 const unsigned int uri) {
70
71 if (fAttributes) {
72
73 XMLSize_t attCount = fAttributes->size();
74
75 if (attCount) {
76
77 for (XMLSize_t i=0; i < attCount; i++) {
78
79 QName* attName = fAttributes->elementAt(i)->getAttName();
80
81 if (attName->getURI() == uri &&
82 XMLString::equals(attName->getLocalPart(),name)) {
83 return true;
84 }
85 }
86 }
87 }
88
89 return false;
90 }
91
92 // ---------------------------------------------------------------------------
93 // XercesAttGroupInfo: Getter methods
94 // ---------------------------------------------------------------------------
getAttDef(const XMLCh * const baseName,const int uriId) const95 const SchemaAttDef* XercesAttGroupInfo::getAttDef(const XMLCh* const baseName,
96 const int uriId) const {
97
98 // If no list, then return a null
99 if (!fAttributes)
100 return 0;
101
102 XMLSize_t attSize = fAttributes->size();
103
104 for (XMLSize_t i=0; i<attSize; i++) {
105
106 const SchemaAttDef* attDef = fAttributes->elementAt(i);
107 QName* attName = attDef->getAttName();
108
109 if (uriId == (int) attName->getURI() &&
110 XMLString::equals(baseName, attName->getLocalPart())) {
111
112 return attDef;
113 }
114 }
115
116 return 0;
117 }
118
119 /***
120 * Support for Serialization/De-serialization
121 ***/
122
IMPL_XSERIALIZABLE_TOCREATE(XercesAttGroupInfo)123 IMPL_XSERIALIZABLE_TOCREATE(XercesAttGroupInfo)
124
125 void XercesAttGroupInfo::serialize(XSerializeEngine& serEng)
126 {
127
128 if (serEng.isStoring())
129 {
130 serEng<<fTypeWithId;
131 serEng<<fNameId;
132 serEng<<fNamespaceId;
133
134 /***
135 *
136 * Serialize RefVectorOf<SchemaAttDef>* fAttributes;
137 *
138 ***/
139 XTemplateSerializer::storeObject(fAttributes, serEng);
140
141 /***
142 *
143 * Serialize RefVectorOf<SchemaAttDef>* fAnyAttributes;
144 *
145 ***/
146 XTemplateSerializer::storeObject(fAnyAttributes, serEng);
147
148 serEng<<fCompleteWildCard;
149 }
150 else
151 {
152 serEng>>fTypeWithId;
153 serEng>>fNameId;
154 serEng>>fNamespaceId;
155
156 /***
157 *
158 * Deserialize RefVectorOf<SchemaAttDef>* fAttributes;
159 *
160 ***/
161 XTemplateSerializer::loadObject(&fAttributes, 4, true, serEng);
162
163 /***
164 *
165 * Deserialize RefVectorOf<SchemaAttDef>* fAnyAttributes;
166 *
167 ***/
168
169 XTemplateSerializer::loadObject(&fAnyAttributes, 2, true, serEng);
170
171 serEng>>fCompleteWildCard;
172 }
173
174 }
175
176 XERCES_CPP_NAMESPACE_END
177
178 /**
179 * End of file XercesAttGroupInfo.cpp
180 */
181
182
183