source: icXML/icXML-devel/src/xercesc/framework/psvi/XSElementDeclaration.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: 5.6 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: XSElementDeclaration.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
23#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
24#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
25#include <xercesc/framework/psvi/XSIDCDefinition.hpp>
26#include <xercesc/framework/psvi/XSModel.hpp>
27#include <xercesc/validators/schema/SchemaElementDecl.hpp>
28#include <xercesc/util/StringPool.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31   
32// ---------------------------------------------------------------------------
33//  XSElementDeclaration: Constructors and Destructor
34// ---------------------------------------------------------------------------
35XSElementDeclaration::XSElementDeclaration
36(
37    SchemaElementDecl* const             schemaElementDecl
38    , XSTypeDefinition* const            typeDefinition
39    , XSElementDeclaration* const        substitutionGroupAffiliation
40    , XSAnnotation* const                annot
41    , XSNamedMap<XSIDCDefinition>* const identityConstraints
42    , XSModel* const                     xsModel
43    , XSConstants::SCOPE                 elemScope
44    , XSComplexTypeDefinition* const     enclosingTypeDefinition
45    , MemoryManager* const               manager
46)
47    : XSObject(XSConstants::ELEMENT_DECLARATION, xsModel, manager)
48    , fDisallowedSubstitutions(0)
49    , fSubstitutionGroupExclusions(0)
50    , fScope(elemScope)
51    , fSchemaElementDecl(schemaElementDecl)
52    , fTypeDefinition(typeDefinition)
53    , fEnclosingTypeDefinition(enclosingTypeDefinition)
54    , fSubstitutionGroupAffiliation(substitutionGroupAffiliation)
55    , fAnnotation(annot)
56    , fIdentityConstraints(identityConstraints)
57{
58    // set block and final information
59    // NOTE: rest of setup will be taken care of in construct()
60    int blockFinalSet = fSchemaElementDecl->getBlockSet();
61    if (blockFinalSet) 
62    {
63        if (blockFinalSet & SchemaSymbols::XSD_EXTENSION)
64            fDisallowedSubstitutions |= XSConstants::DERIVATION_EXTENSION;
65
66        if (blockFinalSet & SchemaSymbols::XSD_RESTRICTION)
67            fDisallowedSubstitutions |= XSConstants::DERIVATION_RESTRICTION;
68
69        if (blockFinalSet & SchemaSymbols::XSD_SUBSTITUTION)
70            fDisallowedSubstitutions |= XSConstants::DERIVATION_SUBSTITUTION;
71    }
72   
73    if (0 != (blockFinalSet = fSchemaElementDecl->getFinalSet()))
74    {
75        if (blockFinalSet & SchemaSymbols::XSD_EXTENSION)
76            fSubstitutionGroupExclusions |= XSConstants::DERIVATION_EXTENSION;
77
78        if (blockFinalSet & SchemaSymbols::XSD_RESTRICTION)
79            fSubstitutionGroupExclusions |= XSConstants::DERIVATION_RESTRICTION;
80    }
81}
82
83XSElementDeclaration::~XSElementDeclaration() 
84{
85    // don't delete fTypeDefinition - deleted by XSModel
86    // don't delete fSubstitutionGroupAffiliation - deleted by XSModel
87    if (fIdentityConstraints)
88        delete fIdentityConstraints;
89}
90
91// ---------------------------------------------------------------------------
92//  XSElementDeclaration: XSObject virtual methods
93// ---------------------------------------------------------------------------
94const XMLCh *XSElementDeclaration::getName() const
95{
96    return fSchemaElementDecl->getElementName()->getLocalPart();
97}
98
99const XMLCh *XSElementDeclaration::getNamespace() 
100{
101    return fXSModel->getURIStringPool()->getValueForId(fSchemaElementDecl->getURI());
102}
103
104XSNamespaceItem *XSElementDeclaration::getNamespaceItem() 
105{
106    return fXSModel->getNamespaceItem(getNamespace());
107}
108
109
110// ---------------------------------------------------------------------------
111//  XSElementDeclaration: access methods
112// ---------------------------------------------------------------------------
113XSConstants::VALUE_CONSTRAINT XSElementDeclaration::getConstraintType() const
114{
115    if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_FIXED)
116        return XSConstants::VALUE_CONSTRAINT_FIXED;
117
118    if (fSchemaElementDecl->getDefaultValue())
119        return XSConstants::VALUE_CONSTRAINT_DEFAULT;
120
121    return XSConstants::VALUE_CONSTRAINT_NONE;
122}
123
124const XMLCh *XSElementDeclaration::getConstraintValue()
125{
126    return fSchemaElementDecl->getDefaultValue();
127}
128
129bool XSElementDeclaration::getNillable() const
130{
131    if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_NILLABLE)
132        return true;
133
134    return false;
135}
136
137bool XSElementDeclaration::isSubstitutionGroupExclusion(XSConstants::DERIVATION_TYPE exclusion)
138{
139    if (fSubstitutionGroupExclusions & exclusion)
140        return true;
141
142    return false;
143}
144
145
146bool XSElementDeclaration::isDisallowedSubstitution(XSConstants::DERIVATION_TYPE disallowed)
147{
148    if (fDisallowedSubstitutions & disallowed)
149        return true;
150
151    return false;
152}
153
154
155bool XSElementDeclaration::getAbstract() const
156{
157    if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_ABSTRACT)
158        return true;
159
160    return false;
161}
162
163XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.