XMLContentModel* ComplexTypeInfo::makeContentModel(const bool checkUPA, ContentSpecNode* const specNode) { if ((specNode || fContentSpec) && !fSpecNodesToDelete) { fSpecNodesToDelete = new (fMemoryManager) RefVectorOf<ContentSpecNode>(8, true, fMemoryManager); } // expand the content spec first ContentSpecNode* aSpecNode = specNode; XMLContentModel* retModel = 0; if (aSpecNode) { fContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate ( fContentSpecOrgURISize * sizeof(unsigned int) ); //new unsigned int[fContentSpecOrgURISize]; aSpecNode = convertContentSpecTree(aSpecNode, checkUPA); retModel = buildContentModel(aSpecNode); fSpecNodesToDelete->addElement(aSpecNode); } else { // building content model for the complex type aSpecNode = new (fMemoryManager) ContentSpecNode(*fContentSpec); aSpecNode = convertContentSpecTree(aSpecNode, checkUPA); retModel = buildContentModel(aSpecNode); delete aSpecNode; } return retModel; }
XMLContentModel* ComplexTypeInfo::makeContentModel(const bool checkUPA) { ContentSpecNode* aSpecNode = new (fMemoryManager) ContentSpecNode(*fContentSpec); XMLContentModel* retModel = 0; if (checkUPA) { fContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate ( fContentSpecOrgURISize * sizeof(unsigned int) ); //new unsigned int[fContentSpecOrgURISize]; } aSpecNode = convertContentSpecTree(aSpecNode, checkUPA); retModel = buildContentModel(aSpecNode); delete aSpecNode; return retModel; }
ContentSpecNode* ComplexTypeInfo::convertContentSpecTree(ContentSpecNode* const curNode, bool checkUPA, bool bAllowCompactSyntax) { if (!curNode) return 0; const ContentSpecNode::NodeTypes curType = curNode->getType(); // When checking Unique Particle Attribution, rename leaf elements if (checkUPA) { if (curNode->getElement()) { if (fUniqueURI == fContentSpecOrgURISize) { resizeContentSpecOrgURI(); } fContentSpecOrgURI[fUniqueURI] = curNode->getElement()->getURI(); curNode->getElement()->setURI(fUniqueURI); fUniqueURI++; } } // Get the spec type of the passed node int minOccurs = curNode->getMinOccurs(); int maxOccurs = curNode->getMaxOccurs(); ContentSpecNode* retNode = curNode; if ((curType & 0x0f) == ContentSpecNode::Any || (curType & 0x0f) == ContentSpecNode::Any_Other || (curType & 0x0f) == ContentSpecNode::Any_NS || curType == ContentSpecNode::Leaf) { retNode = expandContentModel(curNode, minOccurs, maxOccurs, bAllowCompactSyntax); } else if (((curType & 0x0f) == ContentSpecNode::Choice) || (curType == ContentSpecNode::All) || ((curType & 0x0f) == ContentSpecNode::Sequence)) { ContentSpecNode* childNode = curNode->getFirst(); ContentSpecNode* leftNode = convertContentSpecTree(childNode, checkUPA, bAllowCompactSyntax); ContentSpecNode* rightNode = curNode->getSecond(); if (!rightNode) { retNode = expandContentModel(leftNode, minOccurs, maxOccurs, bAllowCompactSyntax); curNode->setAdoptFirst(false); delete curNode; return retNode; } if (leftNode != childNode) { curNode->setAdoptFirst(false); curNode->setFirst(leftNode); curNode->setAdoptFirst(true); } childNode = rightNode; rightNode = convertContentSpecTree(childNode, checkUPA, bAllowCompactSyntax); if (rightNode != childNode) { curNode->setAdoptSecond(false); curNode->setSecond(rightNode); curNode->setAdoptSecond(true); } retNode = expandContentModel(curNode, minOccurs, maxOccurs, bAllowCompactSyntax); } return retNode; }
XMLContentModel* ComplexTypeInfo::makeContentModel(bool checkUPA) { ContentSpecNode* aSpecNode = new (fMemoryManager) ContentSpecNode(*fContentSpec); if (checkUPA) { fContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate ( fContentSpecOrgURISize * sizeof(unsigned int) ); //new unsigned int[fContentSpecOrgURISize]; } aSpecNode = convertContentSpecTree(aSpecNode, checkUPA, useRepeatingLeafNodes(aSpecNode)); Janitor<ContentSpecNode> janSpecNode(aSpecNode); XMLContentModel* cmRet = 0; if (fContentType == SchemaElementDecl::Simple || fContentType == SchemaElementDecl::ElementOnlyEmpty) { // just return nothing } else if (fContentType == SchemaElementDecl::Mixed_Simple) { // // Just create a mixel content model object. This type of // content model is optimized for mixed content validation. // cmRet = new (fMemoryManager) MixedContentModel(false, aSpecNode, false, fMemoryManager); } else if (fContentType == SchemaElementDecl::Mixed_Complex || fContentType == SchemaElementDecl::Children) { bool isMixed = (fContentType == SchemaElementDecl::Mixed_Complex); // // This method will create an optimal model for the complexity // of the element's defined model. If its simple, it will create // a SimpleContentModel object. If its a simple list, it will // create a SimpleListContentModel object. If its complex, it // will create a DFAContentModel object. // if(!aSpecNode) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, fMemoryManager); ContentSpecNode::NodeTypes specType = aSpecNode->getType(); // // Do a sanity check that the node is does not have a PCDATA id. Since, // if it was, it should have already gotten taken by the Mixed model. // if (aSpecNode->getElement() && aSpecNode->getElement()->getURI() == XMLElementDecl::fgPCDataElemId) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_NoPCDATAHere, fMemoryManager); // // According to the type of node, we will create the correct type of // content model. // if (((specType & 0x0f) == ContentSpecNode::Any) || ((specType & 0x0f) == ContentSpecNode::Any_Other) || ((specType & 0x0f) == ContentSpecNode::Any_NS) || specType == ContentSpecNode::Loop) { // let fall through to build a DFAContentModel } else if (isMixed) { if (specType == ContentSpecNode::All) { // All the nodes under an ALL must be additional ALL nodes and // ELEMENTs (or ELEMENTs under ZERO_OR_ONE nodes.) // We collapse the ELEMENTs into a single vector. cmRet = new (fMemoryManager) AllContentModel(aSpecNode, true, fMemoryManager); } else if (specType == ContentSpecNode::ZeroOrOne) { // An ALL node can appear under a ZERO_OR_ONE node. if (aSpecNode->getFirst()->getType() == ContentSpecNode::All) { cmRet = new (fMemoryManager) AllContentModel(aSpecNode->getFirst(), true, fMemoryManager); } } // otherwise, let fall through to build a DFAContentModel } else if (specType == ContentSpecNode::Leaf) { // Create a simple content model cmRet = new (fMemoryManager) SimpleContentModel ( false , aSpecNode->getElement() , 0 , ContentSpecNode::Leaf , fMemoryManager ); } else if (((specType & 0x0f) == ContentSpecNode::Choice) || ((specType & 0x0f) == ContentSpecNode::Sequence)) { // // Lets see if both of the children are leafs. If so, then it has to // be a simple content model // if ((aSpecNode->getFirst()->getType() == ContentSpecNode::Leaf) && (aSpecNode->getSecond()) && (aSpecNode->getSecond()->getType() == ContentSpecNode::Leaf)) { cmRet = new (fMemoryManager) SimpleContentModel ( false , aSpecNode->getFirst()->getElement() , aSpecNode->getSecond()->getElement() , specType , fMemoryManager ); } } else if ((specType == ContentSpecNode::OneOrMore) || (specType == ContentSpecNode::ZeroOrMore) || (specType == ContentSpecNode::ZeroOrOne)) { // // Its a repetition, so see if its one child is a leaf. If so its a // repetition of a single element, so we can do a simple content // model for that. // if (aSpecNode->getFirst()->getType() == ContentSpecNode::Leaf) { cmRet = new (fMemoryManager) SimpleContentModel ( false , aSpecNode->getFirst()->getElement() , 0 , specType , fMemoryManager ); } else if (aSpecNode->getFirst()->getType() == ContentSpecNode::All) cmRet = new (fMemoryManager) AllContentModel(aSpecNode->getFirst(), false, fMemoryManager); } else if (specType == ContentSpecNode::All) cmRet = new (fMemoryManager) AllContentModel(aSpecNode, false, fMemoryManager); else { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, fMemoryManager); } // Its not any simple type of content, so create a DFA based content model if(cmRet==0) cmRet = new (fMemoryManager) DFAContentModel(false, aSpecNode, isMixed, fMemoryManager); } else { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_MustBeMixedOrChildren, fMemoryManager); } return cmRet; }