xsobjectfactory.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,121 行 · 第 1/3 页

CPP
1,121
字号
/* * Copyright 2003,2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Log: XSObjectFactory.cpp,v $ * Revision 1.23  2004/09/08 13:56:14  peiyongz * Apache License Version 2.0 * * Revision 1.22  2004/07/06 14:58:15  cargilld * Rename VALUE_CONSTRAINT enumeration names to avoid naming conflict with AIX system header which already uses VC_DEFAULT as a macro.  Will need to document that this fix breaks source code compatibility. * * Revision 1.21  2004/03/05 16:28:21  knoaman * PSVI: prohibited attributes should not be part of attribute use. Patch by Mike Boos. * * Revision 1.20  2004/02/05 18:09:53  cargilld * Fix a seg fault with PSVI and set basetype of anysimpletype to be anytype. * * Revision 1.19  2004/01/07 02:33:56  knoaman * PSVI: inherit facets from base type * * Revision 1.18  2004/01/06 15:24:42  neilg * make sure locally-declared attributes have declarations in the PSVI * * Revision 1.17  2004/01/06 03:55:26  knoaman * Various PSVI fixes. * * Revision 1.16  2003/12/30 19:46:15  neilg * use a null-terminated string when tokenizing pattern facets * * Revision 1.15  2003/12/29 16:45:06  knoaman * PSVI: add whitespace facet if missing * * Revision 1.14  2003/12/29 16:15:41  knoaman * More PSVI updates * * Revision 1.13  2003/12/24 17:42:02  knoaman * Misc. PSVI updates * * Revision 1.12  2003/12/17 20:50:35  knoaman * PSVI: fix for annotation of attributes in attributeGroup/derived types * * Revision 1.11  2003/12/17 19:58:25  knoaman * Check for NULL when building XSParticle * * Revision 1.10  2003/12/17 00:18:34  cargilld * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. * * Revision 1.9  2003/12/10 05:14:00  neilg * fix seg fault caused when a complex type had simple content; we were not processing the complex type itself, only its base * * Revision 1.8  2003/12/01 20:41:25  neilg * fix for infinite loop between XSComplexTypeDefinitions and XSElementDeclarations; from David Cargill * * Revision 1.7  2003/11/27 16:42:00  neilg * fixes for segfaults and infinite loops in schema component model implementation; thanks to David Cargill * * Revision 1.6  2003/11/25 17:50:15  knoaman * Fix AIX linking error * * Revision 1.5  2003/11/24 15:45:36  knoaman * PSVI: finish construction of XSSimpleTypeDefinition * * Revision 1.4  2003/11/23 16:49:26  knoaman * PSVI: create local elements of groups * * Revision 1.3  2003/11/23 16:21:40  knoaman * PSVI: create local elements of complex types * * Revision 1.2  2003/11/21 22:34:46  neilg * More schema component model implementation, thanks to David Cargill. * In particular, this cleans up and completes the XSModel, XSNamespaceItem, * XSAttributeDeclaration and XSAttributeGroup implementations. * * Revision 1.1  2003/11/21 17:11:24  knoaman * Initial revision * */// ---------------------------------------------------------------------------//  Includes// ---------------------------------------------------------------------------#include <xercesc/internal/XSObjectFactory.hpp>#include <xercesc/framework/psvi/XSModel.hpp>#include <xercesc/framework/psvi/XSParticle.hpp>#include <xercesc/framework/psvi/XSModelGroup.hpp>#include <xercesc/framework/psvi/XSElementDeclaration.hpp>#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>#include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>#include <xercesc/framework/psvi/XSWildcard.hpp>#include <xercesc/framework/psvi/XSNamespaceItem.hpp>#include <xercesc/framework/psvi/XSIDCDefinition.hpp>#include <xercesc/framework/psvi/XSAttributeUse.hpp>#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>#include <xercesc/framework/psvi/XSNotationDeclaration.hpp>#include <xercesc/framework/psvi/XSFacet.hpp>#include <xercesc/framework/psvi/XSMultiValueFacet.hpp>#include <xercesc/validators/common/ContentSpecNode.hpp>#include <xercesc/validators/datatype/DatatypeValidator.hpp>#include <xercesc/validators/schema/SchemaAttDefList.hpp>#include <xercesc/validators/schema/SchemaGrammar.hpp>#include <xercesc/validators/schema/XercesGroupInfo.hpp>#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>#include <xercesc/validators/schema/identity/XercesXPath.hpp>#include <xercesc/util/HashPtr.hpp>#include <xercesc/util/XMLStringTokenizer.hpp>XERCES_CPP_NAMESPACE_BEGINstatic XMLCh regexSeparator[] = {chPipe, chNull};// ---------------------------------------------------------------------------//  XSObjectFactory: Constructors and Destructor// ---------------------------------------------------------------------------XSObjectFactory::XSObjectFactory(MemoryManager* const manager)    : fMemoryManager(manager)    , fXercesToXSMap(0)    , fDeleteVector(0){    fDeleteVector = new (manager) RefVectorOf<XSObject>(20, true, manager);    fXercesToXSMap = new (manager) RefHashTableOf<XSObject> (        109, false, new (manager) HashPtr(), manager);}XSObjectFactory::~XSObjectFactory(){    delete fXercesToXSMap;    delete fDeleteVector;}// ---------------------------------------------------------------------------//  XSObjectFactory: factory methods// ---------------------------------------------------------------------------XSParticle*XSObjectFactory::createModelGroupParticle(const ContentSpecNode* const rootNode,                                          XSModel* const xsModel){    if (rootNode == 0)        return 0;    ContentSpecNode::NodeTypes nodeType = rootNode->getType();    if (nodeType == ContentSpecNode::All        || nodeType == ContentSpecNode::ModelGroupChoice        || nodeType == ContentSpecNode::ModelGroupSequence)    {        XSParticleList* particleList = new (fMemoryManager) RefVectorOf<XSParticle> (4, true, fMemoryManager);        XSAnnotation* annot = getAnnotationFromModel(xsModel, rootNode);        XSModelGroup* modelGroup = 0;        if (nodeType == ContentSpecNode::All)        {            modelGroup = new (fMemoryManager) XSModelGroup(XSModelGroup::COMPOSITOR_ALL, particleList, annot, xsModel, fMemoryManager);            buildAllParticles(rootNode, particleList, xsModel);        }        else        {            if (nodeType == ContentSpecNode::ModelGroupChoice)                modelGroup = new (fMemoryManager) XSModelGroup(XSModelGroup::COMPOSITOR_CHOICE, particleList, annot, xsModel, fMemoryManager);            else                modelGroup = new (fMemoryManager) XSModelGroup(XSModelGroup::COMPOSITOR_SEQUENCE, particleList, annot, xsModel, fMemoryManager);            buildChoiceSequenceParticles(rootNode->getFirst(), particleList, xsModel);            buildChoiceSequenceParticles(rootNode->getSecond(), particleList, xsModel);        }        XSParticle* groupParticle = new (fMemoryManager) XSParticle        (            XSParticle::TERM_MODELGROUP            , xsModel            , modelGroup            , rootNode->getMinOccurs()            , rootNode->getMaxOccurs()            , fMemoryManager        );            return groupParticle;    }    else        return 0;}void XSObjectFactory::buildAllParticles(const ContentSpecNode* const rootNode,                                 XSParticleList* const particleList,                                 XSModel* const xsModel){    // Get the type of spec node our current node is    const ContentSpecNode::NodeTypes nodeType = rootNode->getType();    if (nodeType == ContentSpecNode::All)    {        const ContentSpecNode* rightNode = rootNode->getSecond();        buildAllParticles(rootNode->getFirst(), particleList, xsModel);        if (rightNode)            buildAllParticles(rightNode, particleList, xsModel);    }    else if (nodeType == ContentSpecNode::Leaf)    {        XSParticle* elemParticle = createElementParticle(rootNode, xsModel);        if (elemParticle)            particleList->addElement(elemParticle);    }}void XSObjectFactory::buildChoiceSequenceParticles(const ContentSpecNode* const rootNode,                                            XSParticleList* const particleList,                                            XSModel* const xsModel){    if (rootNode)    {        const ContentSpecNode::NodeTypes nodeType = rootNode->getType();        if (nodeType == ContentSpecNode::Sequence)        {            buildChoiceSequenceParticles(rootNode->getFirst(), particleList, xsModel);            buildChoiceSequenceParticles(rootNode->getSecond(), particleList, xsModel);        }        else if (nodeType == ContentSpecNode::Choice)        {            buildChoiceSequenceParticles(rootNode->getFirst(), particleList, xsModel);            buildChoiceSequenceParticles(rootNode->getSecond(), particleList, xsModel);        }        else if ((nodeType & 0x0f) == ContentSpecNode::Any                 || (nodeType & 0x0f) == ContentSpecNode::Any_Other                 || (nodeType & 0x0f) == ContentSpecNode::Any_NS                 || nodeType == ContentSpecNode::Any_NS_Choice)        {            XSParticle* wildcardParticle = createWildcardParticle(rootNode, xsModel);            if (wildcardParticle)                particleList->addElement(wildcardParticle);        }        else if (nodeType == ContentSpecNode::Leaf)        {            XSParticle* elemParticle = createElementParticle(rootNode, xsModel);            if (elemParticle)                particleList->addElement(elemParticle);        }        // must be a model group        else        {            XSParticle* xsParticle = createModelGroupParticle(rootNode, xsModel);            if (xsParticle)                particleList->addElement(xsParticle);        }    }}XSParticle*XSObjectFactory::createElementParticle(const ContentSpecNode* const rootNode,                                       XSModel* const xsModel){    if (rootNode->getElementDecl())    {        XSElementDeclaration* xsElemDecl = addOrFind(            (SchemaElementDecl*) rootNode->getElementDecl(), xsModel);        if (xsElemDecl)        {            XSParticle* particle = new (fMemoryManager) XSParticle            (                XSParticle::TERM_ELEMENT                , xsModel                , xsElemDecl                , rootNode->getMinOccurs()                , rootNode->getMaxOccurs()                , fMemoryManager            );            return particle;        }    }    return 0;}XSParticle*XSObjectFactory::createWildcardParticle(const ContentSpecNode* const rootNode,                                        XSModel* const xsModel){    XSWildcard* xsWildcard = createXSWildcard(rootNode, xsModel);    if (xsWildcard)    {        XSParticle* particle = new (fMemoryManager) XSParticle        (            XSParticle::TERM_WILDCARD            , xsModel            , xsWildcard            , rootNode->getMinOccurs()            , rootNode->getMaxOccurs()            , fMemoryManager        );        return particle;    }    return 0;}XSAttributeDeclaration*XSObjectFactory::addOrFind(SchemaAttDef* const attDef,                           XSModel* const xsModel,                           XSComplexTypeDefinition* const enclosingTypeDef){    XSAttributeDeclaration* xsObj = (XSAttributeDeclaration*) xsModel->getXSObject(attDef);    if (xsObj)    {        if (xsObj->getScope() == XSConstants::SCOPE_LOCAL            && xsObj->getEnclosingCTDefinition() == 0            && enclosingTypeDef)            xsObj->setEnclosingCTDefinition(enclosingTypeDef);    }    else    {        XSSimpleTypeDefinition* xsType = 0;        if (attDef->getDatatypeValidator())            xsType = addOrFind(attDef->getDatatypeValidator(), xsModel);        XSConstants::SCOPE scope = XSConstants::SCOPE_ABSENT;        XSComplexTypeDefinition* enclosingCTDefinition = 0;        if (attDef->getPSVIScope() == PSVIDefs::SCP_GLOBAL)            scope = XSConstants::SCOPE_GLOBAL;        else if (attDef->getPSVIScope() == PSVIDefs::SCP_LOCAL)        {            scope = XSConstants::SCOPE_LOCAL;            enclosingCTDefinition = enclosingTypeDef;        }        xsObj = new (fMemoryManager) XSAttributeDeclaration        (            attDef            , xsType            , getAnnotationFromModel(xsModel, attDef)            , xsModel            , scope            , enclosingCTDefinition            , fMemoryManager        );        putObjectInMap(attDef, xsObj);    }    return xsObj;}XSSimpleTypeDefinition*XSObjectFactory::addOrFind(DatatypeValidator* const validator,                           XSModel* const xsModel,                           bool isAnySimpleType){    XSSimpleTypeDefinition* xsObj = (XSSimpleTypeDefinition*) xsModel->getXSObject(validator);    if (!xsObj)    {        XSTypeDefinition* baseType = 0;        XSSimpleTypeDefinitionList* memberTypes = 0;        XSSimpleTypeDefinition* primitiveOrItemType = 0;        XSSimpleTypeDefinition::VARIETY typeVariety = XSSimpleTypeDefinition::VARIETY_ATOMIC;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?