source: icXML/icXML-devel/src/xercesc/framework/psvi/XSComplexTypeDefinition.cpp @ 2736

Last change on this file since 2736 was 2736, checked in by cameron, 7 years ago

icxml versions of SchemaValidator?.cpp, ComplexTypeInfo?.hpp

File size: 6.5 KB
RevLine 
[2722]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: XSComplexTypeDefinition.cpp 594002 2007-11-12 01:05:09Z cargilld $
20 */
21
22#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
23#include <xercesc/framework/psvi/XSWildcard.hpp>
24#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
25#include <xercesc/framework/psvi/XSAttributeUse.hpp>
26#include <xercesc/framework/psvi/XSModel.hpp>
27#include <xercesc/framework/psvi/XSAnnotation.hpp>
28#include <xercesc/framework/psvi/XSParticle.hpp>
[2736]29#include <icxercesc/validators/schema/ComplexTypeInfo.hpp>
[2722]30#include <xercesc/validators/schema/SchemaElementDecl.hpp>
31#include <xercesc/validators/schema/SchemaAttDefList.hpp>
32
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36// ---------------------------------------------------------------------------
37//  XSComplexTypeDefinition: Constructors and Destructor
38// ---------------------------------------------------------------------------
39XSComplexTypeDefinition::XSComplexTypeDefinition
40(
41    ComplexTypeInfo* const          complexTypeInfo
42    , XSWildcard* const             xsWildcard
43    , XSSimpleTypeDefinition* const xsSimpleType
44    , XSAttributeUseList* const     xsAttList
45    , XSTypeDefinition* const       xsBaseType
46    , XSParticle* const             xsParticle
47    , XSAnnotation* const           headAnnot
48    , XSModel* const                xsModel
49    , MemoryManager* const          manager
50)
51    : XSTypeDefinition(COMPLEX_TYPE, xsBaseType, xsModel, manager)
52    , fComplexTypeInfo(complexTypeInfo)
53    , fXSWildcard(xsWildcard)
54    , fXSAttributeUseList(xsAttList)
55    , fXSSimpleTypeDefinition(xsSimpleType)
56    , fXSAnnotationList(0)
57    , fParticle(xsParticle)
58    , fProhibitedSubstitution(0)
59{
60    int blockset = fComplexTypeInfo->getBlockSet();
61    if (blockset)
62    {
63        if (blockset & SchemaSymbols::XSD_EXTENSION)
64            fProhibitedSubstitution |= XSConstants::DERIVATION_EXTENSION;
65
66        if (blockset & SchemaSymbols::XSD_RESTRICTION)
67            fProhibitedSubstitution |= XSConstants::DERIVATION_RESTRICTION;
68    }
69
70    int finalSet = fComplexTypeInfo->getFinalSet();
71    if (finalSet)
72    {
73        if (finalSet & SchemaSymbols::XSD_EXTENSION)
74            fFinal |= XSConstants::DERIVATION_EXTENSION;
75
76        if (finalSet & SchemaSymbols::XSD_RESTRICTION)
77            fFinal |= XSConstants::DERIVATION_RESTRICTION;
78    }
79
80    if (headAnnot)
81    {
82        fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(1, false, manager);
83        XSAnnotation* annot = headAnnot;
84
85        do
86        {
87            fXSAnnotationList->addElement(annot);
88            annot = annot->getNext();       
89        } while (annot);
90    }
91}
92
93XSComplexTypeDefinition::~XSComplexTypeDefinition() 
94{
95    // don't delete fXSWildcard - deleted by XSModel
96    // don't delete fXSSimpleTypeDefinition - deleted by XSModel
97    if (fXSAttributeUseList)
98        delete fXSAttributeUseList;
99
100    if (fXSAnnotationList)
101        delete fXSAnnotationList;
102
103    if (fParticle)
104        delete fParticle;
105}
106
107// ---------------------------------------------------------------------------
108//  XSComplexTypeDefinition: access methods
109// ---------------------------------------------------------------------------
110XSConstants::DERIVATION_TYPE XSComplexTypeDefinition::getDerivationMethod() const
111{
112    if(fComplexTypeInfo->getDerivedBy() == SchemaSymbols::XSD_EXTENSION)
113        return XSConstants::DERIVATION_EXTENSION;   
114    return XSConstants::DERIVATION_RESTRICTION;
115}
116
117bool XSComplexTypeDefinition::getAbstract() const
118{
119    return fComplexTypeInfo->getAbstract();
120}
121
122
123XSComplexTypeDefinition::CONTENT_TYPE XSComplexTypeDefinition::getContentType() const
124{
125    switch(fComplexTypeInfo->getContentType()) {
126        case SchemaElementDecl::Simple:
127            return CONTENTTYPE_SIMPLE;
128        case SchemaElementDecl::Empty:
129        case SchemaElementDecl::ElementOnlyEmpty:
130            return CONTENTTYPE_EMPTY;
131        case SchemaElementDecl::Children:       
132            return CONTENTTYPE_ELEMENT;
133        default:
134            //case SchemaElementDecl::Mixed_Complex:
135            //case SchemaElementDecl::Mixed_Simple:
136            //case SchemaElementDecl::Any:
137            return CONTENTTYPE_MIXED;
138    }
139}
140
141bool XSComplexTypeDefinition::isProhibitedSubstitution(XSConstants::DERIVATION_TYPE toTest)                                                     
142{
143    if (fProhibitedSubstitution & toTest)
144        return true;
145
146    return false;
147}
148
149XSAnnotationList *XSComplexTypeDefinition::getAnnotations()
150{   
151    return fXSAnnotationList;
152}
153
154// ---------------------------------------------------------------------------
155//  XSComplexTypeDefinition: virtual methods
156// ---------------------------------------------------------------------------
157const XMLCh *XSComplexTypeDefinition::getName() const
158{
159    return fComplexTypeInfo->getTypeLocalName();
160}
161
162const XMLCh *XSComplexTypeDefinition::getNamespace() 
163{
164    return fComplexTypeInfo->getTypeUri();
165}
166
167XSNamespaceItem *XSComplexTypeDefinition::getNamespaceItem() 
168{
169    return fXSModel->getNamespaceItem(getNamespace());
170}
171
172bool XSComplexTypeDefinition::getAnonymous() const
173{
174    return fComplexTypeInfo->getAnonymous(); 
175}
176
177XSTypeDefinition *XSComplexTypeDefinition::getBaseType() 
178{
179    return fBaseType;
180}
181
182bool XSComplexTypeDefinition::derivedFromType(const XSTypeDefinition * const ancestorType)
183{
184    if (!ancestorType)
185        return false;
186
187    XSTypeDefinition* type = (XSTypeDefinition*) ancestorType;
188
189    if (ancestorType == type->getBaseType())
190    {
191        // ancestor is anytype
192        return true;
193    }
194
195    type = this;
196    XSTypeDefinition* lastType = 0;  // anytype has a basetype of anytype so will have infinite loop...
197
198    while (type && (type != ancestorType) && (type != lastType))
199    {
200        lastType = type;
201        type = type->getBaseType();
202    }
203
204    return (type == ancestorType);
205}
206
207XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.