xsmodel.cpp

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

CPP
881
字号
/* * 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: XSModel.cpp,v $ * Revision 1.24  2004/09/08 13:56:08  peiyongz * Apache License Version 2.0 * * Revision 1.23  2004/06/09 17:01:48  gareth * Fixed null pointer bug. Patch by John Snelson. * * Revision 1.22  2004/05/04 19:12:42  cargilld * Enable IDs to work on all kinds of schema components * * Revision 1.21  2004/05/04 19:02:40  cargilld * Enable IDs to work on all kinds of schema components * * 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/29 11:46:30  cargilld * Code cleanup changes to get rid of various compiler diagnostic messages. * * Revision 1.18  2004/01/06 19:07:16  knoaman * Fix segfault when adding S4S * * Revision 1.17  2003/12/30 21:35:46  neilg * even if there are no grammars to add to an XSModel, the S4S grammar must be included * * Revision 1.16  2003/12/29 16:15:42  knoaman * More PSVI updates * * Revision 1.15  2003/12/24 17:42:02  knoaman * Misc. PSVI updates * * Revision 1.14  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.13  2003/12/15 17:23:48  cargilld * psvi updates; cleanup revisits and bug fixes * * Revision 1.12  2003/12/13 23:35:28  neilg * fix bug 25494; thanks to Han Ming * * Revision 1.11  2003/12/01 20:41:47  neilg * do not throw an exception if there is no user-defined registry * * Revision 1.10  2003/11/26 16:12:23  knoaman * Add a method to return the XSObject mapped to a schema grammar component * * Revision 1.9  2003/11/25 18:08:31  knoaman * Misc. PSVI updates. Thanks to David Cargill. * * Revision 1.8  2003/11/21 22:34:45  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.7  2003/11/21 17:25:09  knoaman * Use XSObjectFactory to create various components. * * Revision 1.6  2003/11/17 18:38:51  neilg * work around HP compiler bug * * Revision 1.5  2003/11/14 22:47:53  neilg * fix bogus log message from previous commit... * * Revision 1.4  2003/11/14 22:33:30  neilg * Second phase of schema component model implementation.   * Implement XSModel, XSNamespaceItem, and the plumbing necessary * to connect them to the other components. * Thanks to David Cargill. * * Revision 1.3  2003/11/06 15:30:04  neilg * first part of PSVI/schema component model implementation, thanks to David Cargill.  This covers setting the PSVIHandler on parser objects, as well as implementing XSNotation, XSSimpleTypeDefinition, XSIDCDefinition, and most of XSWildcard, XSComplexTypeDefinition, XSElementDeclaration, XSAttributeDeclaration and XSAttributeUse. * * Revision 1.2  2003/10/10 18:37:51  neilg * update XSModel and XSObject interface so that IDs can be used to query components in XSModels, and so that those IDs can be recovered from components * * Revision 1.1  2003/09/16 14:33:36  neilg * PSVI/schema component model classes, with Makefile/configuration changes necessary to build them * */#include <xercesc/framework/psvi/XSModel.hpp>#include <xercesc/framework/psvi/XSNamespaceItem.hpp>#include <xercesc/internal/XMLGrammarPoolImpl.hpp>#include <xercesc/validators/schema/SchemaGrammar.hpp>#include <xercesc/validators/common/GrammarResolver.hpp>#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>#include <xercesc/validators/schema/XercesGroupInfo.hpp>#include <xercesc/internal/XSObjectFactory.hpp>#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>#include <xercesc/framework/psvi/XSElementDeclaration.hpp>#include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>#include <xercesc/framework/psvi/XSNotationDeclaration.hpp>#include <xercesc/framework/psvi/XSAnnotation.hpp>#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------//  XSModel: Constructors and Destructor// ---------------------------------------------------------------------------XSModel::XSModel( XMLGrammarPool *grammarPool                , MemoryManager* const manager)    : fMemoryManager(manager)    , fNamespaceStringList(0)    , fXSNamespaceItemList(0)    , fURIStringPool(0)    , fXSAnnotationList(0)    , fHashNamespace(0)    , fObjFactory(0)    , fDeleteNamespace(0)    , fParent(0)    , fDeleteParent(false)    , fAddedS4SGrammar(false){    fURIStringPool = grammarPool->getURIStringPool();    fObjFactory = new (fMemoryManager) XSObjectFactory(manager);    // Populate XSNamedMaps by going through the components    for (unsigned int i=0; i<XSConstants::MULTIVALUE_FACET; i++)    {        switch (i+1)        {            case XSConstants::ATTRIBUTE_DECLARATION:            case XSConstants::ELEMENT_DECLARATION:            case XSConstants::TYPE_DEFINITION:            case XSConstants::ATTRIBUTE_GROUP_DEFINITION:            case XSConstants::MODEL_GROUP_DEFINITION:            case XSConstants::NOTATION_DECLARATION:                fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>                (                    20,     // size                    29,     // modulus                    fURIStringPool,                    false,  // adoptElems                    fMemoryManager                );                break;            default:                // ATTRIBUTE_USE                // MODEL_GROUP                // PARTICLE                // IDENTITY_CONSTRAINT                // WILDCARD                // ANNOTATION                // FACET                // MULTIVALUE                fComponentMap[i] = 0;                break;        }        fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager);    }    fNamespaceStringList        = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager);    fXSNamespaceItemList        = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager);    fXSAnnotationList           = new (manager) RefVectorOf <XSAnnotation> (10, false, manager);    fHashNamespace              = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager);    // Loop through all grammars in the grammar pool to create the XSNamespaceItem's    //  which will have access to Annotation Information which can be used later when    //  we create all the XS components.    XSNamespaceItem* namespaceItem = 0;    RefHashTableOfEnumerator<Grammar> grammarEnum = grammarPool->getGrammarEnumerator();    while (grammarEnum.hasMoreElements())    {        SchemaGrammar& sGrammar = (SchemaGrammar&) grammarEnum.nextElement();        if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType ||            XMLString::equals(sGrammar.getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA))            continue;        // NOTE: In the grammarpool, preprocessed grammars without targetnamespace        //       will use an empty string...        XMLCh* NameSpace = XMLString::replicate(sGrammar.getTargetNamespace(), manager);        fNamespaceStringList->addElement(NameSpace);        namespaceItem = new (manager) XSNamespaceItem(this, &sGrammar, manager);        fXSNamespaceItemList->addElement(namespaceItem);        fHashNamespace->put(NameSpace, namespaceItem);    }    // Now loop through all of the NamespaceItem's    // First, we add S4S namespace (irrespective of whether we have any grammars)    namespaceItem = new (manager) XSNamespaceItem    (        this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager    );    fNamespaceStringList->addElement    (        XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager)    );    fXSNamespaceItemList->addElement(namespaceItem);    fHashNamespace->put    (        (void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA        , namespaceItem    );    DatatypeValidatorFactory dvFactory(manager);    dvFactory.expandRegistryToFullSchemaSet();    addS4SToXSModel    (        namespaceItem        , dvFactory.getBuiltInRegistry()    );    // don't include  S4S (thus the -1)    unsigned int numberOfNamespaces = fXSNamespaceItemList->size() -1;    for (unsigned int j = 0; j < numberOfNamespaces; j++)        addGrammarToXSModel(fXSNamespaceItemList->elementAt(j));}XSModel::XSModel( XSModel *baseModel                , GrammarResolver *grammarResolver                , MemoryManager* const manager)    : fMemoryManager(manager)    , fNamespaceStringList(0)    , fXSNamespaceItemList(0)    , fURIStringPool(0)    , fXSAnnotationList(0)    , fHashNamespace(0)        , fObjFactory(0)    , fDeleteNamespace(0)    , fParent(baseModel)    , fDeleteParent(true)    , fAddedS4SGrammar(false){    fURIStringPool = grammarResolver->getStringPool();    fObjFactory = new (manager) XSObjectFactory(manager);    unsigned int i;    // Populate XSNamedMaps by going through the components    for (i=0; i<XSConstants::MULTIVALUE_FACET; i++)    {        switch (i+1)        {            case XSConstants::ATTRIBUTE_DECLARATION:            case XSConstants::ELEMENT_DECLARATION:            case XSConstants::TYPE_DEFINITION:            case XSConstants::ATTRIBUTE_GROUP_DEFINITION:            case XSConstants::MODEL_GROUP_DEFINITION:            case XSConstants::NOTATION_DECLARATION:                fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>                (                    20,     // size                    29,     // modulus                    fURIStringPool,                    false,  // adoptElems                    fMemoryManager                );                break;            default:                // ATTRIBUTE_USE                // MODEL_GROUP                // PARTICLE                // IDENTITY_CONSTRAINT                // WILDCARD                // ANNOTATION                // FACET                // MULTIVALUE                fComponentMap[i] = 0;                break;        }        fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager);    }    fNamespaceStringList        = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager);    fXSNamespaceItemList        = new (manager) RefVectorOf <XSNamespaceItem>(10, false, manager);    fDeleteNamespace            = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager);    fXSAnnotationList           = new (manager) RefVectorOf <XSAnnotation> (10, false, manager);     fHashNamespace              = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager);    if (fParent)    {        if (fParent->fAddedS4SGrammar)            fAddedS4SGrammar = true;        // Need to copy information from parent so it can be returned in this object...        for (i=0; i<fParent->fXSNamespaceItemList->size(); i++)

⌨️ 快捷键说明

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