source: icXML/icXML-devel/src/xercesc/framework/psvi/XSWildcard.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.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: XSWildcard.cpp 674012 2008-07-04 11:18:21Z borisk $
20 */
21
22#include <xercesc/framework/psvi/XSWildcard.hpp>
23#include <xercesc/framework/psvi/XSModel.hpp>
24#include <xercesc/util/ValueVectorOf.hpp>
25#include <xercesc/util/StringPool.hpp>
26#include <xercesc/validators/common/ContentSpecNode.hpp>
27#include <xercesc/validators/schema/SchemaAttDef.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31// ---------------------------------------------------------------------------
32//  XSWildcard: Constructors and Destructor
33// ---------------------------------------------------------------------------
34XSWildcard::XSWildcard(SchemaAttDef* const  attWildCard,
35                       XSAnnotation* const  annot,
36                       XSModel* const       xsModel,
37                       MemoryManager* const manager)
38    : XSObject(XSConstants::WILDCARD, xsModel, manager)
39    , fConstraintType(NSCONSTRAINT_ANY)
40    , fProcessContents(PC_STRICT)
41    , fNsConstraintList(0)
42    , fAnnotation(annot)
43{
44    XMLAttDef::AttTypes attType = attWildCard->getType();
45    if (attType == XMLAttDef::Any_Other)
46    {
47        fConstraintType = NSCONSTRAINT_NOT;
48        fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(1, true, manager);
49        fNsConstraintList->addElement
50        (
51            XMLString::replicate(fXSModel->getURIStringPool()->getValueForId(
52                    attWildCard->getAttName()->getURI()), manager)
53        );
54    }
55    else if (attType == XMLAttDef::Any_List)
56    {
57        fConstraintType = NSCONSTRAINT_DERIVATION_LIST;
58        ValueVectorOf<unsigned int>* nsList = attWildCard->getNamespaceList();
59        if (nsList)
60        {
61            XMLSize_t nsListSize = nsList->size();
62            if (nsListSize)
63            {
64                fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(nsListSize, true, manager);
65                for (XMLSize_t i=0; i < nsListSize; i++)
66                {
67                    fNsConstraintList->addElement
68                    (
69                        XMLString::replicate
70                        (
71                            fXSModel->getURIStringPool()->getValueForId
72                            (
73                                nsList->elementAt(i)
74                            )
75                            , manager
76                        )
77                    );
78                }
79            }
80        }
81    }
82
83    XMLAttDef::DefAttTypes attDefType = attWildCard->getDefaultType();
84    if (attDefType == XMLAttDef::ProcessContents_Skip)
85        fProcessContents = PC_SKIP;
86    else if (attDefType == XMLAttDef::ProcessContents_Lax)
87        fProcessContents = PC_LAX;
88}
89
90XSWildcard::XSWildcard(const ContentSpecNode* const elmWildCard,
91                       XSAnnotation* const annot,
92                       XSModel* const xsModel,
93                       MemoryManager* const manager)
94    : XSObject(XSConstants::WILDCARD, xsModel, manager)
95    , fConstraintType(NSCONSTRAINT_ANY)
96    , fProcessContents(PC_STRICT)
97    , fNsConstraintList(0)
98    , fAnnotation(annot)
99{
100    ContentSpecNode::NodeTypes nodeType = elmWildCard->getType();
101    if ((nodeType & 0x0f) == ContentSpecNode::Any_Other)
102    {
103        fConstraintType = NSCONSTRAINT_NOT;
104        if (nodeType == ContentSpecNode::Any_Other_Lax)
105            fProcessContents = PC_LAX;
106        else if (nodeType == ContentSpecNode::Any_Other_Skip)
107            fProcessContents = PC_SKIP;
108    }
109    else if ((nodeType & 0x0f) == ContentSpecNode::Any_NS)
110    {
111        fConstraintType = NSCONSTRAINT_DERIVATION_LIST;
112        if (nodeType == ContentSpecNode::Any_NS_Lax)
113            fProcessContents = PC_LAX;
114        else if (nodeType == ContentSpecNode::Any_NS_Skip)
115            fProcessContents = PC_SKIP;
116    }
117    else if (nodeType == ContentSpecNode::Any_NS_Choice)
118    {
119        fConstraintType = NSCONSTRAINT_DERIVATION_LIST;
120        // inspect the second child, not the first one, as the first could hold another Any_NS_Choice wrapper
121        // if the choices are more than 2, while the second child is always a leaf node
122        ContentSpecNode::NodeTypes anyType = elmWildCard->getSecond()->getType();
123
124        if (anyType == ContentSpecNode::Any_NS_Lax)
125            fProcessContents = PC_LAX;
126        else if (anyType == ContentSpecNode::Any_NS_Skip)
127            fProcessContents = PC_SKIP;
128
129        fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(4, true, manager);
130        buildNamespaceList(elmWildCard);
131    }
132    // must be any
133    else
134    {
135        if (nodeType == ContentSpecNode::Any_Lax)
136            fProcessContents = PC_LAX;
137        else if (nodeType == ContentSpecNode::Any_Skip)
138            fProcessContents = PC_SKIP;
139    }
140
141    if (fConstraintType == NSCONSTRAINT_NOT
142        || (fConstraintType == NSCONSTRAINT_DERIVATION_LIST
143            && !fNsConstraintList))
144    {
145        fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(1, true, manager);
146        fNsConstraintList->addElement
147        (
148             XMLString::replicate(fXSModel->getURIStringPool()->getValueForId(
149                     elmWildCard->getElement()->getURI()), manager)
150        );
151    }
152}
153
154XSWildcard::~XSWildcard()
155{
156    if (fNsConstraintList)
157        delete fNsConstraintList;
158}
159
160// ---------------------------------------------------------------------------
161//  XSWildcard: helper methods
162// ---------------------------------------------------------------------------
163void XSWildcard::buildNamespaceList(const ContentSpecNode* const rootNode)
164{
165    ContentSpecNode::NodeTypes nodeType = rootNode->getType();
166    if (nodeType == ContentSpecNode::Any_NS_Choice)
167    {
168        buildNamespaceList(rootNode->getFirst());
169        buildNamespaceList(rootNode->getSecond());
170    }
171    else
172    {
173        fNsConstraintList->addElement
174        (
175            XMLString::replicate(fXSModel->getURIStringPool()->getValueForId(
176                    rootNode->getElement()->getURI()), fMemoryManager)
177        );
178    }
179}
180
181XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.