traverseschema.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,791 行 · 第 1/5 页
CPP
1,791 行
/* * Copyright 2001-2002,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. *//* * $Id: TraverseSchema.cpp,v 1.122 2004/09/30 13:14:28 amassari Exp $ */// ---------------------------------------------------------------------------// Includes// ---------------------------------------------------------------------------#include <xercesc/validators/schema/TraverseSchema.hpp>#include <xercesc/framework/XMLEntityHandler.hpp>#include <xercesc/framework/XMLValidityCodes.hpp>#include <xercesc/validators/schema/identity/IC_Key.hpp>#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>#include <xercesc/validators/schema/identity/IC_Unique.hpp>#include <xercesc/validators/schema/identity/IC_Field.hpp>#include <xercesc/validators/schema/identity/IC_Selector.hpp>#include <xercesc/validators/schema/identity/XercesXPath.hpp>#include <xercesc/util/XMLStringTokenizer.hpp>#include <xercesc/validators/schema/XUtil.hpp>#include <xercesc/validators/common/GrammarResolver.hpp>#include <xercesc/internal/XMLReader.hpp>#include <xercesc/validators/schema/ComplexTypeInfo.hpp>#include <xercesc/validators/schema/NamespaceScope.hpp>#include <xercesc/validators/schema/SchemaAttDefList.hpp>#include <xercesc/internal/XMLScanner.hpp>#include <xercesc/framework/LocalFileInputSource.hpp>#include <xercesc/framework/URLInputSource.hpp>#include <xercesc/framework/XMLGrammarPool.hpp>#include <xercesc/framework/XMLSchemaDescription.hpp>#include <xercesc/validators/schema/identity/XPathException.hpp>#include <xercesc/validators/schema/GeneralAttributeCheck.hpp>#include <xercesc/validators/schema/XercesGroupInfo.hpp>#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>#include <xercesc/validators/schema/XSDLocator.hpp>#include <xercesc/validators/schema/XSDDOMParser.hpp>#include <xercesc/util/HashPtr.hpp>#include <xercesc/dom/DOMNamedNodeMap.hpp>#include <xercesc/dom/DOMText.hpp>#include <xercesc/dom/impl/XSDElementNSImpl.hpp>#include <xercesc/util/OutOfMemoryException.hpp>#include <xercesc/util/XMLEntityResolver.hpp>#include <xercesc/util/XMLUri.hpp>#include <xercesc/framework/psvi/XSAnnotation.hpp>#include <xercesc/framework/MemBufInputSource.hpp>#include <xercesc/internal/XSAXMLScanner.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------// TraverseSchema: Local declaration// ---------------------------------------------------------------------------typedef RefVectorOf<DatatypeValidator> DVRefVector;// ---------------------------------------------------------------------------// TraverseSchema: Static member data// ---------------------------------------------------------------------------// ---------------------------------------------------------------------------// TraverseSchema: Local const data// ---------------------------------------------------------------------------const XMLCh fgAnonSNamePrefix[] ={ chLatin_S, chNull};const XMLCh fgAnonCNamePrefix[] ={ chLatin_C, chNull};const XMLCh fgUnbounded[] ={ chLatin_u, chLatin_n, chLatin_b, chLatin_o, chLatin_u, chLatin_n, chLatin_d, chLatin_e, chLatin_d, chNull};const XMLCh fgSkip[] ={ chLatin_s, chLatin_k, chLatin_i, chLatin_p, chNull};const XMLCh fgLax[] ={ chLatin_l, chLatin_a, chLatin_x, chNull};const XMLCh fgStrict[] ={ chLatin_s, chLatin_t, chLatin_r, chLatin_i, chLatin_c, chLatin_t, chNull};const XMLCh fgValueOne[] ={ chDigit_1, chNull};const XMLCh fgValueZero[] ={ chDigit_0, chNull};const XMLCh fgForwardSlash[] ={ chForwardSlash, chNull};const XMLCh fgDot[] ={ chPeriod, chNull};const XMLCh fgDotForwardSlash[] ={ chPeriod, chForwardSlash, chNull};const XMLCh* fgIdentityConstraints[] ={ SchemaSymbols::fgELT_UNIQUE, SchemaSymbols::fgELT_KEY, SchemaSymbols::fgELT_KEYREF};const XMLCh fgSynthetic_Annotation[] ={ chLatin_S, chLatin_y, chLatin_n, chLatin_t, chLatin_h, chLatin_e, chLatin_t , chLatin_i, chLatin_c, chUnderscore , chLatin_A, chLatin_n, chLatin_n, chLatin_o, chLatin_t, chLatin_a, chLatin_t , chLatin_i, chLatin_o, chLatin_n, chNull};// Flags for global declarationenum { ENUM_ELT_SIMPLETYPE, ENUM_ELT_COMPLEXTYPE, ENUM_ELT_ELEMENT, ENUM_ELT_ATTRIBUTE, ENUM_ELT_ATTRIBUTEGROUP, ENUM_ELT_GROUP, ENUM_ELT_SIZE};// ---------------------------------------------------------------------------// TraverseSchema: Constructors and Destructor// ---------------------------------------------------------------------------TraverseSchema::TraverseSchema( DOMElement* const schemaRoot , XMLStringPool* const uriStringPool , SchemaGrammar* const schemaGrammar , GrammarResolver* const grammarResolver , XMLScanner* const xmlScanner , const XMLCh* const schemaURL , XMLEntityHandler* const entityHandler , XMLErrorReporter* const errorReporter , MemoryManager* const manager) : fFullConstraintChecking(false) , fTargetNSURI(-1) , fEmptyNamespaceURI(-1) , fCurrentScope(Grammar::TOP_LEVEL_SCOPE) , fScopeCount(0) , fAnonXSTypeCount(0) , fCircularCheckIndex(0) , fTargetNSURIString(0) , fDatatypeRegistry(0) , fGrammarResolver(grammarResolver) , fSchemaGrammar(schemaGrammar) , fEntityHandler(entityHandler) , fErrorReporter(errorReporter) , fURIStringPool(uriStringPool) , fStringPool(0) , fBuffer(1023, manager) , fScanner(xmlScanner) , fNamespaceScope(0) , fAttributeDeclRegistry(0) , fComplexTypeRegistry(0) , fGroupRegistry(0) , fAttGroupRegistry(0) , fIC_ElementsNS(0) , fPreprocessedNodes(0) , fSchemaInfo(0) , fCurrentGroupInfo(0) , fCurrentAttGroupInfo(0) , fCurrentComplexType(0) , fCurrentTypeNameStack(0) , fCurrentGroupStack(0) , fIC_NamespaceDepth(0) , fIC_Elements(0) , fDeclStack(0) , fGlobalDeclarations(0) , fNonXSAttList(0) , fIC_NodeListNS(0) , fIC_NamespaceDepthNS(0) , fNotationRegistry(0) , fRedefineComponents(0) , fIdentityConstraintNames(0) , fValidSubstitutionGroups(0) , fSchemaInfoList(0) , fParser(0) , fLocator(0) , fMemoryManager(manager) , fGrammarPoolMemoryManager(fGrammarResolver->getGrammarPoolMemoryManager()) , fAnnotation(0) , fAttributeCheck(manager){ try { if (fGrammarResolver && schemaRoot && fURIStringPool) { init(); preprocessSchema(schemaRoot, schemaURL); doTraverseSchema(schemaRoot); } } catch(const OutOfMemoryException&) { throw; } catch(...) { cleanUp(); throw; }}TraverseSchema::~TraverseSchema(){ cleanUp();}// ---------------------------------------------------------------------------// TraverseSchema: Traversal methods// ---------------------------------------------------------------------------void TraverseSchema::doTraverseSchema(const DOMElement* const schemaRoot) { // process children nodes processChildren(schemaRoot); // Handle identity constraints - keyref if (fIC_ElementsNS && fIC_ElementsNS->containsKey(fTargetNSURIString)) { fIC_Elements = fIC_ElementsNS->get(fTargetNSURIString); fIC_NamespaceDepth = fIC_NamespaceDepthNS->get(fTargetNSURIString); unsigned int icListSize = fIC_Elements->size(); for (unsigned int i=0; i < icListSize; i++) { SchemaElementDecl* curElem = fIC_Elements->elementAt(i); ValueVectorOf<DOMElement*>* icNodes = fIC_NodeListNS->get(curElem); unsigned int icNodesSize = icNodes->size(); unsigned int scopeDepth = fIC_NamespaceDepth->elementAt(i); for (unsigned int j = 0; j < icNodesSize; j++) { traverseKeyRef(icNodes->elementAt(j), curElem, scopeDepth); } } } if (fScanner->getValidateAnnotations() && !fSchemaGrammar->getAnnotations()->isEmpty()) { validateAnnotations(); } fSchemaInfo->setProcessed();}void TraverseSchema::preprocessSchema(DOMElement* const schemaRoot, const XMLCh* const schemaURL) { // Make sure namespace binding is defaulted const XMLCh* rootPrefix = schemaRoot->getPrefix(); if (rootPrefix == 0 || !*rootPrefix) { const XMLCh* xmlnsStr = schemaRoot->getAttribute(XMLUni::fgXMLNSString); if (!xmlnsStr || !*xmlnsStr) { schemaRoot->setAttribute(XMLUni::fgXMLNSString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); } } // Set schemaGrammar data and add it to GrammarResolver // For complex type registry, attribute decl registry , group/attGroup // and namespace mapping, needs to check whether the passed in // Grammar was a newly instantiated one. fComplexTypeRegistry = fSchemaGrammar->getComplexTypeRegistry(); if (fComplexTypeRegistry == 0 ) { fComplexTypeRegistry = new (fGrammarPoolMemoryManager) RefHashTableOf<ComplexTypeInfo>(29, fGrammarPoolMemoryManager); fSchemaGrammar->setComplexTypeRegistry(fComplexTypeRegistry); } fGroupRegistry = fSchemaGrammar->getGroupInfoRegistry(); if (fGroupRegistry == 0 ) { fGroupRegistry = new (fGrammarPoolMemoryManager) RefHashTableOf<XercesGroupInfo>(13, fGrammarPoolMemoryManager); fSchemaGrammar->setGroupInfoRegistry(fGroupRegistry); } fAttGroupRegistry = fSchemaGrammar->getAttGroupInfoRegistry(); if (fAttGroupRegistry == 0 ) { fAttGroupRegistry = new (fGrammarPoolMemoryManager) RefHashTableOf<XercesAttGroupInfo>(13, fGrammarPoolMemoryManager); fSchemaGrammar->setAttGroupInfoRegistry(fAttGroupRegistry); } fAttributeDeclRegistry = fSchemaGrammar->getAttributeDeclRegistry(); if (fAttributeDeclRegistry == 0) { fAttributeDeclRegistry = new (fGrammarPoolMemoryManager) RefHashTableOf<XMLAttDef>(29, fGrammarPoolMemoryManager); fSchemaGrammar->setAttributeDeclRegistry(fAttributeDeclRegistry); } fNamespaceScope = fSchemaGrammar->getNamespaceScope(); if (fNamespaceScope == 0) { fNamespaceScope = new (fGrammarPoolMemoryManager) NamespaceScope(fGrammarPoolMemoryManager); fNamespaceScope->reset(fEmptyNamespaceURI); fSchemaGrammar->setNamespaceScope(fNamespaceScope); } fValidSubstitutionGroups = fSchemaGrammar->getValidSubstitutionGroups(); if (!fValidSubstitutionGroups) { fValidSubstitutionGroups = new (fGrammarPoolMemoryManager) RefHash2KeysTableOf<ElemVector>(29, fGrammarPoolMemoryManager); fSchemaGrammar->setValidSubstitutionGroups(fValidSubstitutionGroups); } //Retrieve the targetnamespace URI information const XMLCh* targetNSURIStr = schemaRoot->getAttribute(SchemaSymbols::fgATT_TARGETNAMESPACE); fSchemaGrammar->setTargetNamespace(targetNSURIStr); fScopeCount = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?