source: icXML/icXML-devel/src/xercesc/framework/psvi/XSSimpleTypeDefinition.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: 7.4 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: XSSimpleTypeDefinition.cpp 674012 2008-07-04 11:18:21Z borisk $
20 */
21
22#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
23#include <xercesc/framework/psvi/XSFacet.hpp>
24#include <xercesc/framework/psvi/XSMultiValueFacet.hpp>
25#include <xercesc/framework/psvi/XSAnnotation.hpp>
26#include <xercesc/framework/psvi/XSModel.hpp>
27#include <xercesc/validators/datatype/DatatypeValidator.hpp>
28#include <xercesc/validators/datatype/UnionDatatypeValidator.hpp>
29#include <xercesc/util/XMLStringTokenizer.hpp>
30#include <xercesc/util/XMLUniDefs.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34// ---------------------------------------------------------------------------
35//  Local, static functions
36// ---------------------------------------------------------------------------
37static bool XSSimpleTypeDefinitionTestFlag(int flag)
38{
39    if (flag)
40        return true;
41    return false;
42}
43
44
45// ---------------------------------------------------------------------------
46//  XSSimpleTypeDefinition: Constructors and Destructors
47// ---------------------------------------------------------------------------
48XSSimpleTypeDefinition::XSSimpleTypeDefinition
49(
50    DatatypeValidator* const            datatypeValidator
51    , VARIETY                           stVariety
52    , XSTypeDefinition* const           xsBaseType
53    , XSSimpleTypeDefinition* const     primitiveOrItemType
54    , XSSimpleTypeDefinitionList* const memberTypes
55    , XSAnnotation*                     headAnnot
56    , XSModel* const                    xsModel
57    , MemoryManager* const              manager
58)
59    : XSTypeDefinition(SIMPLE_TYPE, xsBaseType, xsModel, manager)
60    , fDefinedFacets(0)
61    , fFixedFacets(0)
62    , fVariety(stVariety)
63    , fDatatypeValidator(datatypeValidator)
64    , fXSFacetList(0)
65    , fXSMultiValueFacetList(0)
66    , fPatternList(0)
67    , fPrimitiveOrItemType(primitiveOrItemType)
68    , fMemberTypes(memberTypes)
69    , fXSAnnotationList(0)
70{
71    int finalset = fDatatypeValidator->getFinalSet();
72    if (finalset)
73    {
74        if (finalset & SchemaSymbols::XSD_EXTENSION)
75            fFinal |= XSConstants::DERIVATION_EXTENSION;
76
77        if (finalset & SchemaSymbols::XSD_RESTRICTION)
78            fFinal |= XSConstants::DERIVATION_RESTRICTION;
79
80        if (finalset & SchemaSymbols::XSD_LIST)
81            fFinal |= XSConstants::DERIVATION_LIST;
82
83        if (finalset & SchemaSymbols::XSD_UNION)
84            fFinal |= XSConstants::DERIVATION_UNION;
85    }
86
87    if (headAnnot)
88    {
89        XSAnnotation* annot = headAnnot;
90
91        fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(3, false, manager);
92        do
93        {
94            fXSAnnotationList->addElement(annot);
95            annot = annot->getNext();
96        } while (annot);
97    }
98}
99
100XSSimpleTypeDefinition::~XSSimpleTypeDefinition()
101{
102    if (fXSFacetList)
103        delete fXSFacetList;
104
105    if (fXSMultiValueFacetList)
106        delete fXSMultiValueFacetList;
107
108    if (fPatternList)
109        delete fPatternList;
110
111    // don't delete fPrimitiveOrItemType -> deleted by XSModel
112    if (fMemberTypes)
113        delete fMemberTypes;
114
115    if (fXSAnnotationList)
116        delete fXSAnnotationList;
117}
118
119
120// ---------------------------------------------------------------------------
121//  XSSimpleTypeDefinition: access methods
122// ---------------------------------------------------------------------------
123bool XSSimpleTypeDefinition::isDefinedFacet(FACET facetName)
124{
125    return XSSimpleTypeDefinitionTestFlag(fDefinedFacets & facetName);
126}
127
128bool XSSimpleTypeDefinition::isFixedFacet(FACET facetName)
129{
130    return XSSimpleTypeDefinitionTestFlag(fFixedFacets & facetName);
131}
132
133const XMLCh *XSSimpleTypeDefinition::getLexicalFacetValue(FACET facetName)
134{
135    XMLSize_t size = fXSFacetList->size();
136    for (XMLSize_t i=0; i<size; i++)
137    {
138        if (((fXSFacetList->elementAt(i))->getFacetKind()) == facetName)
139            return (fXSFacetList->elementAt(i))->getLexicalFacetValue();
140    }
141    return 0;
142}
143
144StringList *XSSimpleTypeDefinition::getLexicalEnumeration()
145{
146    return (RefArrayVectorOf<XMLCh>*) fDatatypeValidator->getEnumString();
147}
148
149XSSimpleTypeDefinition::ORDERING XSSimpleTypeDefinition::getOrdered() const
150{
151    return fDatatypeValidator->getOrdered();
152}
153
154bool XSSimpleTypeDefinition::getFinite() const
155{
156    return fDatatypeValidator->getFinite();
157}
158
159bool XSSimpleTypeDefinition::getBounded() const
160{
161    return fDatatypeValidator->getBounded();
162}
163
164bool XSSimpleTypeDefinition::getNumeric() const
165{
166    return fDatatypeValidator->getNumeric();
167}
168
169
170// ---------------------------------------------------------------------------
171//  XSSimpleTypeDefinition: virtual methods
172// ---------------------------------------------------------------------------
173const XMLCh *XSSimpleTypeDefinition::getName() const
174{
175    return fDatatypeValidator->getTypeLocalName();
176}
177
178const XMLCh *XSSimpleTypeDefinition::getNamespace()
179{
180    return fDatatypeValidator->getTypeUri();
181}
182
183XSNamespaceItem *XSSimpleTypeDefinition::getNamespaceItem()
184{
185    return fXSModel->getNamespaceItem(getNamespace());
186}
187
188bool XSSimpleTypeDefinition::getAnonymous() const
189{
190    return fDatatypeValidator->getAnonymous();
191}
192
193XSTypeDefinition *XSSimpleTypeDefinition::getBaseType()
194{
195    return fBaseType;
196}
197
198bool XSSimpleTypeDefinition::derivedFromType(const XSTypeDefinition * const ancestorType)
199{
200    if (!ancestorType)
201        return false;
202
203    XSTypeDefinition* type;
204
205    if (ancestorType->getTypeCategory() == XSTypeDefinition::COMPLEX_TYPE)
206    {
207        type = (XSTypeDefinition*) ancestorType;
208        if (ancestorType == type->getBaseType())
209        {
210            // ancestor is anytype
211            return true;
212        }
213        return false;
214    }
215
216    type = this;
217    XSTypeDefinition* lastType = 0;  // anysimple type has a base type of anytype
218                                     // anytype has a basetype of anytype so will have infinite loop...
219
220    while (type && (type != ancestorType) && (type != lastType))
221    {
222        lastType = type;
223        type = type->getBaseType();
224    }
225
226    return (type == ancestorType);
227}
228
229// ---------------------------------------------------------------------------
230//  XSSimpleTypeDefinition: helper methods
231// ---------------------------------------------------------------------------
232void XSSimpleTypeDefinition::setFacetInfo
233(
234    int                            definedFacets
235    , int                          fixedFacets
236    , XSFacetList* const           xsFacetList
237    , XSMultiValueFacetList* const xsMultiValueFacetList
238    , StringList* const            patternList
239)
240{
241    fDefinedFacets = definedFacets;
242    fFixedFacets = fixedFacets;
243    fXSFacetList = xsFacetList;
244    fXSMultiValueFacetList = xsMultiValueFacetList;
245    fPatternList = patternList;
246}
247
248
249XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.