traverseschema.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,791 行 · 第 1/5 页
CPP
1,791 行
return typeNameIndex;}/** * Traverse Group Declaration. * * <group * id = ID * maxOccurs = string * minOccurs = nonNegativeInteger * name = NCName * ref = QName> * Content: (annotation? , (all | choice | sequence)?) * <group/> * */XercesGroupInfo*TraverseSchema::traverseGroupDecl(const DOMElement* const elem, const bool topLevel) { const XMLCh* name = getElementAttValue(elem, SchemaSymbols::fgATT_NAME); const XMLCh* ref = getElementAttValue(elem, SchemaSymbols::fgATT_REF); bool nameEmpty = (!name || !*name); bool refEmpty = (!ref || !*ref); if (nameEmpty && topLevel) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoNameGlobalElement, SchemaSymbols::fgELT_GROUP); return 0; } if (nameEmpty && refEmpty) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoNameRefGroup); return 0; } // ------------------------------------------------------------------ // Check attributes // ------------------------------------------------------------------ unsigned short scope = (topLevel) ? GeneralAttributeCheck::E_GroupGlobal : GeneralAttributeCheck::E_GroupRef; fAttributeCheck.checkAttributes(elem, scope, this, topLevel, fNonXSAttList); // ------------------------------------------------------------------ // Handle "ref=" // ------------------------------------------------------------------ if (!topLevel) { if (refEmpty) { return 0; } return processGroupRef(elem, ref); } // name must be a valid NCName if (!XMLString::isValidNCName(name)) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidDeclarationName, SchemaSymbols::fgELT_GROUP, name); return 0; } fBuffer.set(fTargetNSURIString); fBuffer.append(chComma); fBuffer.append(name); unsigned int nameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer()); const XMLCh* fullName = fStringPool->getValueForId(nameIndex); XercesGroupInfo* groupInfo = fGroupRegistry->get(fullName); if (groupInfo) { return groupInfo; } // ------------------------------------------------------------------ // Check for annotations // ------------------------------------------------------------------ DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); if (fScanner->getGenerateSyntheticAnnotations() && !fAnnotation && fNonXSAttList->size()) { fAnnotation = generateSyntheticAnnotation(elem, fNonXSAttList); } Janitor<XSAnnotation> janAnnot(fAnnotation); // ------------------------------------------------------------------ // Process contents of global groups // ------------------------------------------------------------------ int saveScope = fCurrentScope; ContentSpecNode* specNode = 0; XercesGroupInfo* saveGroupInfo = fCurrentGroupInfo; groupInfo = new (fGrammarPoolMemoryManager) XercesGroupInfo( fStringPool->addOrFind(name), fTargetNSURI, fGrammarPoolMemoryManager); fCurrentGroupStack->addElement(nameIndex); fCurrentGroupInfo = groupInfo; fCurrentScope = fScopeCount++; fCurrentGroupInfo->setScope(fCurrentScope); if (content == 0) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::GroupContentError, name); } else { if (content->getAttributeNode(SchemaSymbols::fgATT_MINOCCURS) != 0 || content->getAttributeNode(SchemaSymbols::fgATT_MAXOCCURS) != 0) { reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::MinMaxOnGroupChild); } bool illegalChild = false; const XMLCh* childName = content->getLocalName(); if (XMLString::equals(childName, SchemaSymbols::fgELT_SEQUENCE)) { specNode = traverseChoiceSequence(content, ContentSpecNode::Sequence); } else if (XMLString::equals(childName, SchemaSymbols::fgELT_CHOICE)) { specNode = traverseChoiceSequence(content, ContentSpecNode::Choice); } else if (XMLString::equals(childName, SchemaSymbols::fgELT_ALL)) { specNode = traverseAll(content); } else { illegalChild = true; } if (illegalChild || XUtil::getNextSiblingElement(content) != 0) { reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::GroupContentError, name); } // copy local elements to complex type if it exists if (fCurrentComplexType) processElements(elem, fCurrentGroupInfo, fCurrentComplexType); } // ------------------------------------------------------------------ // Set groupInfo and pop group name from stack // ------------------------------------------------------------------ unsigned int stackSize = fCurrentGroupStack->size(); if (stackSize != 0) { fCurrentGroupStack->removeElementAt(stackSize - 1); } fCurrentGroupInfo->setContentSpec(specNode); fGroupRegistry->put((void*) fullName, fCurrentGroupInfo); fCurrentGroupInfo = saveGroupInfo; fCurrentScope = saveScope; // Store Annotation if (!janAnnot.isDataNull()) fSchemaGrammar->putAnnotation(groupInfo, janAnnot.release()); if (fFullConstraintChecking) { XSDLocator* aLocator = new (fGrammarPoolMemoryManager) XSDLocator(); groupInfo->setLocator(aLocator); aLocator->setValues(fStringPool->getValueForId(fStringPool->addOrFind(fSchemaInfo->getCurrentSchemaURL())), 0, ((XSDElementNSImpl*) elem)->getLineNo(), ((XSDElementNSImpl*) elem)->getColumnNo()); if (fRedefineComponents && fRedefineComponents->get(SchemaSymbols::fgELT_GROUP, nameIndex)) { fBuffer.set(fullName); fBuffer.append(SchemaSymbols::fgRedefIdentifier); unsigned int rdfNameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer()); if (fCurrentGroupStack->containsElement(rdfNameIndex)) { reportSchemaError(aLocator, XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, name); } else { XercesGroupInfo* baseGroup = fGroupRegistry->get(fBuffer.getRawBuffer()); if (baseGroup) { groupInfo->setBaseGroup(baseGroup); } else { fBuffer.set(name); fBuffer.append(SchemaSymbols::fgRedefIdentifier); SchemaInfo* saveInfo = fSchemaInfo; DOMElement* groupElem = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_Group, SchemaSymbols::fgELT_GROUP, fBuffer.getRawBuffer(), &fSchemaInfo); if (groupElem != 0) { baseGroup = traverseGroupDecl(groupElem); groupInfo->setBaseGroup(baseGroup); fSchemaInfo = saveInfo; } else { reportSchemaError(aLocator, XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound, SchemaSymbols::fgELT_GROUP, fTargetNSURIString, fBuffer.getRawBuffer()); } } } } } return groupInfo;}/** * Traverse attributeGroup Declaration. * * <attributeGroup * id = ID * name = NCName * ref = QName> * Content: (annotation? , (attribute|attributeGroup)*, anyAttribute?) * <attributeGroup/> * */XercesAttGroupInfo*TraverseSchema::traverseAttributeGroupDecl(const DOMElement* const elem, ComplexTypeInfo* const typeInfo, const bool topLevel) { const XMLCh* name = getElementAttValue(elem, SchemaSymbols::fgATT_NAME); const XMLCh* ref = getElementAttValue(elem, SchemaSymbols::fgATT_REF); bool nameEmpty = (!name || !*name) ? true : false; bool refEmpty = (!ref || !*ref) ? true : false; if (nameEmpty && topLevel) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoNameGlobalElement, SchemaSymbols::fgELT_ATTRIBUTEGROUP); return 0; } if (nameEmpty && refEmpty) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoNameRefAttGroup); return 0; } // ------------------------------------------------------------------ // Check attributes // ------------------------------------------------------------------ unsigned short scope = (topLevel) ? GeneralAttributeCheck::E_AttributeGroupGlobal : GeneralAttributeCheck::E_AttributeGroupRef; fAttributeCheck.checkAttributes(elem, scope, this, topLevel, fNonXSAttList); // ------------------------------------------------------------------ // Handle "ref=" // ------------------------------------------------------------------ XercesAttGroupInfo* attGroupInfo = 0; if (!topLevel) { if (refEmpty) { return 0; } attGroupInfo = processAttributeGroupRef(elem, ref, typeInfo); } else { // name must be a valid NCName if (!XMLString::isValidNCName(name)) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidDeclarationName, SchemaSymbols::fgELT_ATTRIBUTEGROUP, name); return 0; } // Check for annotations DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); if (fScanner->getGenerateSyntheticAnnotations() && !fAnnotation && fNonXSAttList->size()) { fAnnotation = generateSyntheticAnnotation(elem, fNonXSAttList); } Janitor<XSAnnotation> janAnnot(fAnnotation); // Process contents of global attributeGroups XercesAttGroupInfo* saveAttGroupInfo = fCurrentAttGroupInfo; attGroupInfo = new (fGrammarPoolMemoryManager) XercesAttGroupInfo( fStringPool->addOrFind(name), fTargetNSURI, fGrammarPoolMemoryManager); fDeclStack->addElement(elem); fCurrentAttGroupInfo = attGroupInfo; for (; content !=0; content = XUtil::getNextSiblingElement(content)) { if (XMLString::equals(content->getLocalName(), SchemaSymbols::fgELT_ATTRIBUTE)) { traverseAttributeDecl(content, typeInfo); } else if (XMLString::equals(content->getLocalName(), SchemaSymbols::fgELT_ATTRIBUTEGROUP)) { traverseAttributeGroupDecl(content, typeInfo); } else { break; } } if (content != 0) { if (XMLString::equals(content->getLocalName(), SchemaSymbols::fgELT_ANYATTRIBUTE)) { SchemaAttDef* anyAtt = traverseAnyAttribute(content); if (anyAtt) { fCurrentAttGroupInfo->addAnyAttDef(anyAtt); } if (XUtil::getNextSiblingElement(content) != 0) { reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::AttGroupContentError, name); } } else { reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::AttGroupContentError, name); } } // Pop declaration fDeclStack->removeElementAt(fDeclStack->size() - 1); // Restore old attGroupInfo fAttGroupRegistry->put((void*) fStringPool->getValueForId(fStringPool->addOrFind(name)), attGroupInfo); fCurrentAttGroupInfo = saveAttGroupInfo; // Check Attribute Derivation Restriction OK fBuffer.set(fTargetNSURIString); fBuffer.append(chComma); fBuffer.append(name); unsigned int nameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer()); if (fRedefineComponents && fRedefineComponents->get(SchemaSymbols::fgELT_ATTRIBUTEGROUP, nameIndex)) { fBuffer.set(name); fBuffer.append(SchemaSymbols::fgRedefIdentifier); XercesAttGroupInfo* baseAttGroupInfo = fAttGroupRegistry->get(fBuffer.getRawBuffer()); if (baseAttGroupInfo) checkAttDerivationOK(elem, baseAttGroupInfo, attGroupInfo); } // Store annotation if (!janAnnot.isDataNull()) fSchemaGrammar->putAnnotation(attGroupInfo, janAnnot.release()); } // calculate complete wildcard if necessary if (attGroupInfo) { unsigned int anyAttCount = attGroupInfo->anyAttributeCount(); if (anyAttCount && !attGroupInfo->getCompleteWildCard()) { SchemaAttDef* attGroupWildCard = new (fGrammarPoolMemoryManager) SchemaAttDef(attGroupInfo->anyAttributeAt(0)); for (unsigned int k= 1; k < anyAttCount; k++) attWildCardIntersection(attGroupWildCard, attGroupInfo->anyAttributeAt(k)); attGroupInfo
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?