dfacontentmodel.cpp

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

CPP
1,381
字号
/* * Copyright 1999-2001,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: DFAContentModel.cpp,v $ * Revision 1.13  2004/09/16 13:32:03  amassari * Updated error message for UPA to also state the complex type that is failing the test * * Revision 1.12  2004/09/08 13:56:51  peiyongz * Apache License Version 2.0 * * Revision 1.11  2004/01/29 11:51:21  cargilld * Code cleanup changes to get rid of various compiler diagnostic messages. * * Revision 1.10  2003/12/17 00:18:38  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/11/20 18:12:20  knoaman * Use a bitwise operation to check the node type. * * Revision 1.8  2003/11/07 17:08:11  knoaman * For PSVI support, distinguish wildcard elements with namespace lists. * * Revision 1.7  2003/05/18 14:02:06  knoaman * Memory manager implementation: pass per instance manager. * * Revision 1.6  2003/05/16 21:43:20  knoaman * Memory manager implementation: Modify constructors to pass in the memory manager. * * Revision 1.5  2003/05/15 18:48:27  knoaman * Partial implementation of the configurable memory manager. * * Revision 1.4  2002/11/04 14:54:58  tng * C++ Namespace Support. * * Revision 1.3  2002/09/24 19:48:39  tng * Performance: use XMLString::equals instead of XMLString::compareString * * Revision 1.2  2002/02/25 21:18:53  tng * Schema Fix: Ensure no invalid uri index for UPA checking. * * Revision 1.1.1.1  2002/02/01 22:22:38  peiyongz * sane_include * * Revision 1.29  2001/12/10 21:42:55  peiyongz * Memory Leak: fLeafNameTypeVector * * Revision 1.28  2001/12/06 17:52:17  tng * Performance Enhancement.  The QName that was passed to the CMLeaf * constructor was always being copied, even though the CMLeaf objects * only existed during construction of a DFA.  In most cases the original * QName that was passed into the CMLeaf constructor continued to exist long * after the CMLeaf was destroyed; in some cases the QName was constructed * specifically to be passed to the CMLeaf constructor.  Added a second CMLeaf constructor that indicated the QName passed in was to be adopted; otherwise the CMLeaf constructor just sets a reference to the QName passed in. * By Henry Zongaro. * * Revision 1.27  2001/11/21 14:30:13  knoaman * Fix for UPA checking. * * Revision 1.26  2001/11/07 21:10:46  tng * Performance: move getRawName() to outer loop so that it is called only once per outer loop. * * Revision 1.25  2001/10/04 15:08:55  knoaman * Add support for circular import. * * Revision 1.24  2001/09/14 14:50:22  tng * Schema: Fix some wildcard bugs, and some retrieving qualified/unqualified element decl problems. * * Revision 1.23  2001/08/24 12:48:48  tng * Schema: AllContentModel * * Revision 1.22  2001/08/22 16:58:55  tng * typo: should issue the name of second element. * * Revision 1.21  2001/08/21 16:50:23  tng * Schema: Unique Particle Attribution Constraint Checking. * * Revision 1.20  2001/08/21 16:06:11  tng * Schema: Unique Particle Attribution Constraint Checking. * * Revision 1.19  2001/08/17 16:12:51  peiyongz * Fix to memory leak in buildDFA(),  patch from Nick Chiang (nchiang@ss8.com) * * Revision 1.18  2001/08/16 21:52:40  peiyongz * stateTable created to optimize the identification of new state created. * * Revision 1.17  2001/07/31 17:45:25  peiyongz * Fix: memory leak in postTreeBuildInit() * * Revision 1.16  2001/07/24 20:00:33  peiyongz * Memory Leak fix: Bugzilla #2707 reported by Francois Rioux * * + |                              DESCRIPTION                                   | * + There are some memory leaks in the buildDFA method : * +    the first QName allocated object * +    the nodeOrgContent * +    fHeadNode * * Revision 1.15  2001/07/09 15:22:36  knoaman * complete <any> declaration. * * Revision 1.14  2001/06/13 20:50:56  peiyongz * fIsMixed: to handle mixed Content Model * * Revision 1.13  2001/06/12 19:07:14  peiyongz * Memory leak: fixed by Erik Rydgren * * Revision 1.12  2001/06/12 17:30:49  knoaman * Fix Typo * * Revision 1.11  2001/06/07 21:08:20  tng * Fix unsigned/signed warning from Linux.  By Pei Yong Zhang. * * Revision 1.10  2001/05/28 20:52:44  tng * Schema: move static data gInvalidTrans, gEOCFakeId, gEpsilonFakeId to XMLContentModel for others to access * * Revision 1.9  2001/05/11 13:27:18  tng * Copyright update. * * Revision 1.8  2001/05/03 21:02:29  tng * Schema: Add SubstitutionGroupComparator and update exception messages.  By Pei Yong Zhang. * * Revision 1.7  2001/04/19 18:17:30  tng * Schema: SchemaValidator update, and use QName in Content Model * * Revision 1.6  2001/03/21 21:56:27  tng * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar. * * Revision 1.5  2001/03/21 19:29:51  tng * Schema: Content Model Updates, by Pei Yong Zhang. * * Revision 1.4  2001/02/27 18:32:31  tng * Schema: Use XMLElementDecl instead of DTDElementDecl in Content Model. * * Revision 1.3  2001/02/27 14:48:51  tng * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang * * Revision 1.2  2001/02/16 14:58:57  tng * Schema: Update Makefile, configure files, project files, and include path in * certain cpp files because of the move of the common Content Model files.  By Pei Yong Zhang. * * Revision 1.1  2001/02/16 14:17:29  tng * Schema: Move the common Content Model files that are shared by DTD * and schema from 'DTD' folder to 'common' folder.  By Pei Yong Zhang. * * Revision 1.5  2000/03/28 19:43:25  roddey * Fixes for signed/unsigned warnings. New work for two way transcoding * stuff. * * Revision 1.4  2000/03/08 23:52:34  roddey * Got rid of the use of -1 to represent an invalid transition state, * and just created a const value that is unsigned. This should make * some compilers happier. * * Revision 1.3  2000/03/02 19:55:38  roddey * This checkin includes many changes done while waiting for the * 1.1.0 code to be finished. I can't list them all here, but a list is * available elsewhere. * * Revision 1.2  2000/02/09 21:42:37  abagchi * Copyright swatswat * * Revision 1.1.1.1  1999/11/09 01:03:17  twl * Initial checkin * * Revision 1.2  1999/11/08 20:45:38  rahul * Swat for adding in Product name and CVS comment log variable. * */// ---------------------------------------------------------------------------//  Includes// ---------------------------------------------------------------------------#include <xercesc/util/RuntimeException.hpp>#include <xercesc/framework/XMLBuffer.hpp>#include <xercesc/framework/XMLElementDecl.hpp>#include <xercesc/framework/XMLValidator.hpp>#include <xercesc/validators/common/CMAny.hpp>#include <xercesc/validators/common/CMBinaryOp.hpp>#include <xercesc/validators/common/CMLeaf.hpp>#include <xercesc/validators/common/CMUnaryOp.hpp>#include <xercesc/validators/common/DFAContentModel.hpp>#include <xercesc/validators/common/ContentSpecNode.hpp>#include <xercesc/validators/common/Grammar.hpp>#include <xercesc/validators/schema/SchemaSymbols.hpp>#include <xercesc/validators/schema/SubstitutionGroupComparator.hpp>#include <xercesc/validators/schema/XercesElementWildcard.hpp>#include <xercesc/util/RefHashTableOf.hpp>#include <xercesc/util/HashCMStateSet.hpp>#include <xercesc/util/XMLInteger.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------//  DFAContentModel: Constructors and Destructor// ---------------------------------------------------------------------------DFAContentModel::DFAContentModel( const bool             dtd                                , ContentSpecNode* const elemContentSpec                                , MemoryManager* const   manager) :    fElemMap(0)    , fElemMapType(0)    , fElemMapSize(0)    , fEmptyOk(false)    , fEOCPos(0)    , fFinalStateFlags(0)    , fFollowList(0)    , fHeadNode(0)    , fLeafCount(0)    , fLeafList(0)    , fLeafListType(0)    , fTransTable(0)    , fTransTableSize(0)    , fDTD(dtd)    , fIsMixed(false)    , fLeafNameTypeVector(0)    , fMemoryManager(manager){    // And build the DFA data structures    buildDFA(elemContentSpec);}DFAContentModel::DFAContentModel( const bool             dtd                                , ContentSpecNode* const elemContentSpec                                , const bool             isMixed                                , MemoryManager* const   manager):    fElemMap(0)    , fElemMapType(0)    , fElemMapSize(0)    , fEmptyOk(false)    , fEOCPos(0)    , fFinalStateFlags(0)    , fFollowList(0)    , fHeadNode(0)    , fLeafCount(0)    , fLeafList(0)    , fLeafListType(0)    , fTransTable(0)    , fTransTableSize(0)    , fDTD(dtd)    , fIsMixed(isMixed)    , fLeafNameTypeVector(0)    , fMemoryManager(manager){    // And build the DFA data structures    buildDFA(elemContentSpec);}DFAContentModel::~DFAContentModel(){    //    //  Clean up all the stuff that is not just temporary representation    //  data that was cleaned up after building the DFA.    //    fMemoryManager->deallocate(fFinalStateFlags); //delete [] fFinalStateFlags;    unsigned index;    for (index = 0; index < fTransTableSize; index++)        fMemoryManager->deallocate(fTransTable[index]); //delete [] fTransTable[index];    fMemoryManager->deallocate(fTransTable); //delete [] fTransTable;    for (index = 0; index < fLeafCount; index++)        delete fElemMap[index];    fMemoryManager->deallocate(fElemMap); //delete [] fElemMap;    fMemoryManager->deallocate(fElemMapType); //delete [] fElemMapType;    fMemoryManager->deallocate(fLeafListType); //delete [] fLeafListType;	delete fLeafNameTypeVector;}// ---------------------------------------------------------------------------//  DFAContentModel: Implementation of the ContentModel virtual interface// ---------------------------------------------------------------------------intDFAContentModel::validateContent( QName** const        children                                , const unsigned int   childCount                                , const unsigned int) const{    //    //  If there are no children, then either we fail on the 0th element    //  or we return success. It depends upon whether this content model    //  accepts empty content, which we determined earlier.    //    if (!childCount)    {        // success -1        return fEmptyOk ? -1 : 0;    }    //    //  Lets loop through the children in the array and move our way    //  through the states. Note that we use the fElemMap array to map    //  an element index to a state index.    //    unsigned int curState = 0;    unsigned int nextState = 0;    unsigned int childIndex = 0;    for (; childIndex < childCount; childIndex++)    {        // Get the current element index out        const QName* curElem = children[childIndex];        const XMLCh* curElemRawName = 0;        if (fDTD)            curElemRawName = curElem->getRawName();        // If this is text in a Schema mixed content model, skip it.        if ( fIsMixed &&            ( curElem->getURI() == XMLElementDecl::fgPCDataElemId))            continue;        // Look up this child in our element map        unsigned int elemIndex = 0;        for (; elemIndex < fElemMapSize; elemIndex++)        {            const QName* inElem  = fElemMap[elemIndex];            if (fDTD) {                if (XMLString::equals(inElem->getRawName(), curElemRawName)) {                    nextState = fTransTable[curState][elemIndex];                    if (nextState != XMLContentModel::gInvalidTrans)                        break;                }            }            else {                ContentSpecNode::NodeTypes type = fElemMapType[elemIndex];                if (type == ContentSpecNode::Leaf)                {                    if ((inElem->getURI() == curElem->getURI()) &&                    (XMLString::equals(inElem->getLocalPart(), curElem->getLocalPart()))) {

⌨️ 快捷键说明

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