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: SchemaAttDef.cpp 679359 2008-07-24 11:15:19Z borisk $
20 */
21
22
23 // ---------------------------------------------------------------------------
24 // Includes
25 // ---------------------------------------------------------------------------
26 #include <xercesc/framework/XMLElementDecl.hpp>
27 #include <xercesc/validators/schema/SchemaAttDef.hpp>
28
29 #include <xercesc/internal/XTemplateSerializer.hpp>
30
31 XERCES_CPP_NAMESPACE_BEGIN
32
33 // ---------------------------------------------------------------------------
34 // SchemaAttDef: Implementation of the XMLAttDef interface
35 // ---------------------------------------------------------------------------
getFullName() const36 const XMLCh* SchemaAttDef::getFullName() const
37 {
38 return fAttName->getRawName();
39 }
40
41 // ---------------------------------------------------------------------------
42 // SchemaAttDef: Constructors and Destructor
43 // ---------------------------------------------------------------------------
SchemaAttDef(MemoryManager * const manager)44 SchemaAttDef::SchemaAttDef(MemoryManager* const manager) :
45 XMLAttDef(XMLAttDef::CData, XMLAttDef::Implied, manager)
46 , fElemId(XMLElementDecl::fgInvalidElemId)
47 , fPSVIScope(PSVIDefs::SCP_ABSENT)
48 , fAttName(0)
49 , fDatatypeValidator(0)
50 , fNamespaceList(0)
51 , fBaseAttDecl(0)
52 {
53 }
54
SchemaAttDef(const XMLCh * const prefix,const XMLCh * const localPart,const int uriId,const XMLAttDef::AttTypes type,const XMLAttDef::DefAttTypes defType,MemoryManager * const manager)55 SchemaAttDef::SchemaAttDef( const XMLCh* const prefix
56 , const XMLCh* const localPart
57 , const int uriId
58 , const XMLAttDef::AttTypes type
59 , const XMLAttDef::DefAttTypes defType
60 , MemoryManager* const manager) :
61 XMLAttDef(type, defType, manager)
62 , fElemId(XMLElementDecl::fgInvalidElemId)
63 , fPSVIScope(PSVIDefs::SCP_ABSENT)
64 , fDatatypeValidator(0)
65 , fNamespaceList(0)
66 , fBaseAttDecl(0)
67 {
68 fAttName = new (manager) QName(prefix, localPart, uriId, manager);
69 }
70
SchemaAttDef(const XMLCh * const prefix,const XMLCh * const localPart,const int uriId,const XMLCh * const attValue,const XMLAttDef::AttTypes type,const XMLAttDef::DefAttTypes defType,const XMLCh * const enumValues,MemoryManager * const manager)71 SchemaAttDef::SchemaAttDef( const XMLCh* const prefix
72 , const XMLCh* const localPart
73 , const int uriId
74 , const XMLCh* const attValue
75 , const XMLAttDef::AttTypes type
76 , const XMLAttDef::DefAttTypes defType
77 , const XMLCh* const enumValues
78 , MemoryManager* const manager) :
79
80 XMLAttDef(attValue, type, defType, enumValues, manager)
81 , fElemId(XMLElementDecl::fgInvalidElemId)
82 , fPSVIScope(PSVIDefs::SCP_ABSENT)
83 , fDatatypeValidator(0)
84 , fNamespaceList(0)
85 , fBaseAttDecl(0)
86 {
87 fAttName = new (manager) QName(prefix, localPart, uriId, manager);
88 }
89
SchemaAttDef(const SchemaAttDef * other)90 SchemaAttDef::SchemaAttDef(const SchemaAttDef* other) :
91
92 XMLAttDef(other->getValue(), other->getType(),
93 other->getDefaultType(), other->getEnumeration(),
94 other->getMemoryManager())
95 , fElemId(XMLElementDecl::fgInvalidElemId)
96 , fPSVIScope(other->fPSVIScope)
97 , fAttName(0)
98 , fDatatypeValidator(other->fDatatypeValidator)
99 , fNamespaceList(0)
100 , fBaseAttDecl(other->fBaseAttDecl)
101 {
102 QName* otherName = other->getAttName();
103 fAttName = new (getMemoryManager()) QName(otherName->getPrefix(),
104 otherName->getLocalPart(), otherName->getURI(),
105 getMemoryManager());
106
107 if (other->fNamespaceList && other->fNamespaceList->size()) {
108 fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*(other->fNamespaceList));
109 }
110 }
111
~SchemaAttDef()112 SchemaAttDef::~SchemaAttDef()
113 {
114 delete fAttName;
115 delete fNamespaceList;
116 }
117
118
119 // ---------------------------------------------------------------------------
120 // SchemaAttDef: Setter methods
121 // ---------------------------------------------------------------------------
setAttName(const XMLCh * const prefix,const XMLCh * const localPart,const int uriId)122 void SchemaAttDef::setAttName(const XMLCh* const prefix
123 , const XMLCh* const localPart
124 , const int uriId )
125 {
126 fAttName->setName(prefix, localPart, uriId);
127 }
128
129 /***
130 * Support for Serialization/De-serialization
131 ***/
132
IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDef)133 IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDef)
134
135 void SchemaAttDef::serialize(XSerializeEngine& serEng)
136 {
137
138 XMLAttDef::serialize(serEng);
139
140 if (serEng.isStoring())
141 {
142 serEng.writeSize (fElemId);
143 serEng<<(int)fPSVIScope;
144
145 serEng<<fAttName;
146
147 DatatypeValidator::storeDV(serEng, fDatatypeValidator);
148
149 /***
150 * Serialize ValueVectorOf<unsigned int>
151 ***/
152 XTemplateSerializer::storeObject(fNamespaceList, serEng);
153
154 serEng<<fBaseAttDecl;
155 }
156 else
157 {
158
159 serEng.readSize (fElemId);
160 int i;
161 serEng>>i;
162 fPSVIScope = (PSVIDefs::PSVIScope)i;
163
164 serEng>>fAttName;
165
166 fDatatypeValidator = DatatypeValidator::loadDV(serEng);
167
168 /***
169 * Deserialize ValueVectorOf<unsigned int>
170 ***/
171 XTemplateSerializer::loadObject(&fNamespaceList, 8, false, serEng);
172
173 serEng>>fBaseAttDecl;
174 }
175 }
176
177
178 XERCES_CPP_NAMESPACE_END
179