source: icXML/icXML-devel/src/xercesc/validators/schema/XMLSchemaDescriptionImpl.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 6.3 KB
Line 
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: XMLSchemaDescriptionImpl.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
27#include <icxercesc/util/QName.hpp>
28
29#include <xercesc/internal/XTemplateSerializer.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  XMLSchemaDescriptionImpl: constructor and destructor
35// ---------------------------------------------------------------------------
36XMLSchemaDescriptionImpl::XMLSchemaDescriptionImpl(const XMLCh* const   targetNamespace
37                                                 , MemoryManager* const memMgr)
38:XMLSchemaDescription(memMgr)
39,fContextType(CONTEXT_UNKNOWN)
40,fNamespace(0)
41,fLocationHints(0)
42,fTriggeringComponent(0)
43,fEnclosingElementName(0)
44,fAttributes(0) 
45{
46    if (targetNamespace)
47        fNamespace = XMLString::replicate(targetNamespace, memMgr);
48
49
50    fLocationHints =  new (memMgr) RefArrayVectorOf<XMLCh>(4, true, memMgr);
51
52    /***
53        fAttributes
54    ***/
55}
56
57XMLSchemaDescriptionImpl::~XMLSchemaDescriptionImpl()
58{
59    if (fNamespace)
60        XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
61
62    if (fLocationHints)
63        delete fLocationHints;
64
65    if (fTriggeringComponent)
66        delete fTriggeringComponent;
67
68    if (fEnclosingElementName)
69        delete fEnclosingElementName;
70
71}
72
73const XMLCh* XMLSchemaDescriptionImpl::getGrammarKey() const
74{ 
75    return getTargetNamespace(); 
76}
77   
78XMLSchemaDescription::ContextType XMLSchemaDescriptionImpl::getContextType() const
79{
80    return fContextType; 
81}
82
83const XMLCh* XMLSchemaDescriptionImpl::getTargetNamespace() const
84{ 
85    return fNamespace; 
86}
87
88const RefArrayVectorOf<XMLCh>* XMLSchemaDescriptionImpl::getLocationHints() const
89{ 
90    return fLocationHints; 
91}
92
93const QName* XMLSchemaDescriptionImpl::getTriggeringComponent() const                     
94{ 
95    return fTriggeringComponent; 
96}
97
98const QName* XMLSchemaDescriptionImpl::getEnclosingElementName() const
99{ 
100    return fEnclosingElementName; 
101}
102
103const XMLAttDef* XMLSchemaDescriptionImpl::getAttributes() const                     
104{ 
105    return fAttributes; 
106}
107         
108void XMLSchemaDescriptionImpl::setContextType(ContextType type)
109{ 
110    fContextType = type; 
111}
112
113void XMLSchemaDescriptionImpl::setTargetNamespace(const XMLCh* const newNamespace)
114{ 
115    if (fNamespace) {
116        XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
117        fNamespace = 0;
118    }
119   
120    fNamespace = XMLString::replicate(newNamespace, XMLGrammarDescription::getMemoryManager()); 
121}
122
123void XMLSchemaDescriptionImpl::setLocationHints(const XMLCh* const hint)
124{   
125    fLocationHints->addElement(XMLString::replicate(hint, XMLGrammarDescription::getMemoryManager())); 
126}
127
128void XMLSchemaDescriptionImpl::setTriggeringComponent(QName* const trigComponent)
129{ 
130    if ( fTriggeringComponent) {
131        delete fTriggeringComponent;
132        fTriggeringComponent = 0;
133    }
134   
135    fTriggeringComponent = new (trigComponent->getMemoryManager()) QName(*trigComponent); 
136
137}
138
139void XMLSchemaDescriptionImpl::setEnclosingElementName(QName* const encElement)
140{ 
141    if (fEnclosingElementName) {
142        delete fEnclosingElementName;
143        fEnclosingElementName = 0; 
144    }
145
146    fEnclosingElementName = new (encElement->getMemoryManager()) QName(*encElement); 
147
148}
149
150void XMLSchemaDescriptionImpl::setAttributes(XMLAttDef* const attDefs)
151{ 
152    // XMLAttDef is part of the grammar that this description refers to
153    // so we reference to it instead of adopting/owning/cloning.
154    fAttributes = attDefs; 
155}
156
157/***
158 * Support for Serialization/De-serialization
159 ***/
160
161IMPL_XSERIALIZABLE_TOCREATE(XMLSchemaDescriptionImpl)
162
163void XMLSchemaDescriptionImpl::serialize(XSerializeEngine& serEng)
164{
165    XMLSchemaDescription::serialize(serEng);
166
167    if (serEng.isStoring())
168    {
169        serEng<<(int)fContextType;       
170        serEng.writeString(fNamespace);
171
172        /***
173         *
174         * Serialize RefArrayVectorOf<XMLCh>*               fLocationHints;
175         *
176         ***/
177        XTemplateSerializer::storeObject(fLocationHints, serEng);
178
179        QName* tempQName = (QName*)fTriggeringComponent;
180        serEng<<tempQName;
181        tempQName = (QName*)fEnclosingElementName;
182        serEng<<tempQName;
183
184        XMLAttDef* tempAttDef = (XMLAttDef*)fAttributes;
185        serEng<<tempAttDef;
186    }
187
188    else
189    {
190        int i;
191        serEng>>i;
192
193        fContextType = (ContextType)i;       
194
195        //the original fNamespace which came from the ctor needs deallocated
196        if (fNamespace)
197        {
198            XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
199        }
200        serEng.readString((XMLCh*&)fNamespace);
201
202        /***
203         *
204         *  Deserialize RefArrayVectorOf<XMLCh>    fLocationHints     
205         *
206         ***/
207        XTemplateSerializer::loadObject(&fLocationHints, 4, true, serEng);
208
209        QName* tempQName;
210        serEng>>tempQName;
211        fTriggeringComponent = tempQName;
212
213        serEng>>tempQName;
214        fEnclosingElementName = tempQName;
215
216        XMLAttDef* tempAttDef;
217        serEng>>tempAttDef;
218        fAttributes=tempAttDef;
219
220    }
221
222}
223
224XMLSchemaDescriptionImpl::XMLSchemaDescriptionImpl(MemoryManager* const memMgr)
225:XMLSchemaDescription(memMgr)
226,fContextType(CONTEXT_UNKNOWN)
227,fNamespace(0)
228,fLocationHints(0)
229,fTriggeringComponent(0)
230,fEnclosingElementName(0)
231,fAttributes(0) 
232{
233}
234
235XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.