TraverseSchema.cpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:302k
- if (!dv) {
- DOMElement* typeElem = fSchemaInfo->getTopLevelComponent
- (
- SchemaInfo::C_SimpleType
- , SchemaSymbols::fgELT_SIMPLETYPE
- , localPart
- , &fSchemaInfo
- );
- if (typeElem)
- dv = traverseSimpleTypeDecl(typeElem);
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- }
- return dv;
- }
- ComplexTypeInfo*
- TraverseSchema::getElementComplexTypeInfo(const DOMElement* const elem,
- const XMLCh* const typeStr,
- bool& noErrorDetected,
- const XMLCh* const otherSchemaURI)
- {
- const XMLCh* localPart = getLocalPart(typeStr);
- const XMLCh* prefix = getPrefix(typeStr);
- const XMLCh* typeURI = (otherSchemaURI) ? otherSchemaURI : resolvePrefixToURI(elem, prefix);
- ComplexTypeInfo* typeInfo = 0;
- SchemaInfo* saveInfo = fSchemaInfo;
- SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
- int saveScope = fCurrentScope;
- fBuffer.set(typeURI);
- fBuffer.append(chComma);
- fBuffer.append(localPart);
- if (otherSchemaURI != 0) {
- // Make sure that we have an explicit import statement.
- // Clause 4 of Schema Representation Constraint:
- // http://www.w3.org/TR/xmlschema-1/#src-resolve
- unsigned int uriId = fURIStringPool->addOrFind(typeURI);
- if (!fSchemaInfo->isImportingNS(uriId))
- return 0;
- Grammar* aGrammar = fGrammarResolver->getGrammar(typeURI);
- if (!aGrammar || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
- return 0;
- }
- typeInfo = ((SchemaGrammar*)aGrammar)->getComplexTypeRegistry()->get(fBuffer.getRawBuffer());
- if (typeInfo) {
- return typeInfo;
- }
- SchemaInfo* impInfo = fSchemaInfo->getImportInfo(uriId);
- if (!impInfo || impInfo->getProcessed()) {
- return 0;
- }
- infoType = SchemaInfo::IMPORT;
- restoreSchemaInfo(impInfo, infoType);
- }
- else {
- typeInfo = fComplexTypeRegistry->get(fBuffer.getRawBuffer());
- }
- if (!typeInfo) {
- if (!XMLString::equals(typeURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) ||
- XMLString::equals(fTargetNSURIString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) {
- DOMElement* typeNode = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_ComplexType,
- SchemaSymbols::fgELT_COMPLEXTYPE, localPart, &fSchemaInfo);
- if (typeNode) {
- int typeIndex = traverseComplexTypeDecl(typeNode);
- typeInfo = fComplexTypeRegistry->get(fStringPool->getValueForId(typeIndex));
- }
- }
- }
- // restore schema information
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- return typeInfo;
- }
- SchemaElementDecl*
- TraverseSchema::getSubstituteGroupElemDecl(const DOMElement* const elem,
- const XMLCh* const name,
- bool& noErrorDetected) {
- const XMLCh* nameURI = resolvePrefixToURI(elem, getPrefix(name));
- const XMLCh* localPart = getLocalPart(name);
- SchemaElementDecl* elemDecl = 0;
- SchemaInfo* saveInfo = fSchemaInfo;
- SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
- int saveScope = fCurrentScope;
- unsigned int uriId = fURIStringPool->addOrFind(nameURI);
- bool wasAdded = false;
- if (!XMLString::equals(nameURI, fTargetNSURIString)) {
- // Make sure that we have an explicit import statement.
- // Clause 4 of Schema Representation Constraint:
- // http://www.w3.org/TR/xmlschema-1/#src-resolve
- if (!fSchemaInfo->isImportingNS(uriId)) {
- noErrorDetected = false;
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidNSReference, nameURI);
- return (SchemaElementDecl*) fSchemaGrammar->findOrAddElemDecl(uriId, localPart, XMLUni::fgZeroLenString,
- 0, Grammar::TOP_LEVEL_SCOPE, wasAdded);
- }
- Grammar* grammar = fGrammarResolver->getGrammar(nameURI);
- if (grammar && grammar->getGrammarType() == Grammar::SchemaGrammarType) {
- elemDecl = (SchemaElementDecl*)
- grammar->getElemDecl(uriId, localPart, 0, Grammar::TOP_LEVEL_SCOPE);
- }
- else {
- noErrorDetected = false;
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, nameURI);
- return (SchemaElementDecl*) fSchemaGrammar->findOrAddElemDecl(uriId, localPart, XMLUni::fgZeroLenString,
- 0, Grammar::TOP_LEVEL_SCOPE, wasAdded);
- }
- if (!elemDecl) {
- SchemaInfo* impInfo = fSchemaInfo->getImportInfo(uriId);
- if (!impInfo || impInfo->getProcessed()) {
- noErrorDetected = false;
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, nameURI, localPart);
- return (SchemaElementDecl*) grammar->findOrAddElemDecl(uriId, localPart, XMLUni::fgZeroLenString,
- 0, Grammar::TOP_LEVEL_SCOPE, wasAdded);
- }
- infoType = SchemaInfo::IMPORT;
- restoreSchemaInfo(impInfo, infoType);
- }
- }
- else {
- elemDecl = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(fTargetNSURI, localPart, 0, Grammar::TOP_LEVEL_SCOPE);
- }
- if (!elemDecl) {
- DOMElement* subsGroupElem = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_Element,
- SchemaSymbols::fgELT_ELEMENT,localPart, &fSchemaInfo);
- if (subsGroupElem != 0) {
- QName* subsGroupQName = traverseElementDecl(subsGroupElem, true);
- Janitor<QName> janQName(subsGroupQName);
- if (subsGroupQName) {
- elemDecl = (SchemaElementDecl*) fSchemaGrammar->getElemDecl(fTargetNSURI, localPart,0, Grammar::TOP_LEVEL_SCOPE);
- }
- }
- if (!elemDecl) {
- noErrorDetected = false;
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, nameURI, localPart);
- elemDecl = (SchemaElementDecl*) fSchemaGrammar->findOrAddElemDecl(uriId, localPart, XMLUni::fgZeroLenString,
- 0, Grammar::TOP_LEVEL_SCOPE, wasAdded);
- }
- }
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- return elemDecl;
- }
- bool
- TraverseSchema::isSubstitutionGroupValid(const DOMElement* const elem,
- const SchemaElementDecl* const subsElemDecl,
- const ComplexTypeInfo* const typeInfo,
- const DatatypeValidator* const validator,
- const XMLCh* const elemName,
- const bool toEmit) {
- // here we must do two things:
- // 1. Make sure there actually *is* a relation between the types of
- // the element being nominated and the element doing the nominating;
- // (see PR 3.3.6 point #3 in the first tableau, for instance; this
- // and the corresponding tableaux from 3.4.6 and 3.14.6 rule out the nominated
- // element having an anonymous type declaration.
- // 2. Make sure the nominated element allows itself to be nominated by
- // an element with the given type-relation.
- // Note: we assume that (complex|simple)Type processing checks
- // whether the type in question allows itself to
- // be modified as this element desires.
- // if substitution element has any as content model type, return true
- bool subsRestricted = false;
- if (subsElemDecl->getModelType() == SchemaElementDecl::Any) {
- if ((subsElemDecl->getFinalSet() & SchemaSymbols::XSD_RESTRICTION) == 0
- || (typeInfo == 0 && validator == 0))
- return true;
- else
- subsRestricted = true;
- }
- // Check for type relationship;
- // that is, make sure that the type we're deriving has some relatoinship
- // to substitutionGroupElt's type.
- else if (typeInfo) { // do complexType case ...need testing
- int derivationMethod = typeInfo->getDerivedBy();
- if (typeInfo->getContentType() == SchemaElementDecl::Simple) { // take care of complexType based on simpleType case...
- DatatypeValidator* elemDV = typeInfo->getDatatypeValidator();
- DatatypeValidator* subsValidator = subsElemDecl->getDatatypeValidator();
- if (elemDV == subsValidator) {
- return true;
- }
- else if (subsValidator && subsValidator->isSubstitutableBy(elemDV)) {
- if ((subsElemDecl->getFinalSet() & derivationMethod) == 0) {
- return true;
- }
- else {
- subsRestricted = true;
- }
- }
- }
- else { // complex content
- ComplexTypeInfo* subsTypeInfo = subsElemDecl->getComplexTypeInfo();
- if (subsTypeInfo == typeInfo)
- return true;
- const ComplexTypeInfo* elemTypeInfo = typeInfo;
- for (; elemTypeInfo && elemTypeInfo != subsTypeInfo;
- elemTypeInfo = elemTypeInfo->getBaseComplexTypeInfo()) {
- }
- if (elemTypeInfo) {
- if ((subsElemDecl->getFinalSet() & derivationMethod) == 0) {
- return true;
- }
- else {
- subsRestricted = true;
- }
- }
- }
- }
- else if (validator) { // do simpleType case...
- // first, check for type relation.
- DatatypeValidator* subsValidator = subsElemDecl->getDatatypeValidator();
- if (subsValidator == validator) {
- return true;
- }
- else if (subsValidator && subsValidator->isSubstitutableBy(validator)
- && ((subsElemDecl->getFinalSet() & SchemaSymbols::XSD_RESTRICTION) == 0)) {
- return true;
- }
- }
- if (toEmit) {
- if (subsRestricted) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidSubstitutionGroupElement,
- elemName, subsElemDecl->getBaseName());
- }
- else {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::SubstitutionGroupTypeMismatch, elemName);
- }
- }
- return false;
- }
- SchemaElementDecl*
- TraverseSchema::createSchemaElementDecl(const DOMElement* const elem,
- const bool topLevel,
- const unsigned short elemType,
- bool& isDuplicate,
- const bool isFixedVal)
- {
- const XMLCh* name = getElementAttValue(elem, SchemaSymbols::fgATT_NAME);
- const XMLCh* elemForm = getElementAttValue(elem, SchemaSymbols::fgATT_FORM);
- int enclosingScope = fCurrentScope;
- int uriIndex = fEmptyNamespaceURI;
- //refer to 4.3.2 in "XML Schema Part 1: Structures"
- if (topLevel) {
- uriIndex = fTargetNSURI;
- enclosingScope = Grammar::TOP_LEVEL_SCOPE;
- }
- else if (((!elemForm || !*elemForm) &&
- (fSchemaInfo->getElemAttrDefaultQualified() & Elem_Def_Qualified))
- || XMLString::equals(elemForm,SchemaSymbols::fgATTVAL_QUALIFIED)) {
- uriIndex = fTargetNSURI;
- }
- // Check for duplicate elements
- SchemaElementDecl* other = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(uriIndex, name, 0, enclosingScope);
- if (other != 0) {
- isDuplicate = true;
- return other;
- }
- int blockSet = parseBlockSet(elem, ES_Block);
- int finalSet = parseFinalSet(elem, EC_Final);
- int elementMiscFlags = 0;
- const XMLCh* nillable = getElementAttValue(elem, SchemaSymbols::fgATT_NILLABLE);
- const XMLCh* abstract = getElementAttValue(elem, SchemaSymbols::fgATT_ABSTRACT);
- if (nillable && *nillable) {
- if (XMLString::equals(nillable, SchemaSymbols::fgATTVAL_TRUE)
- || XMLString::equals(nillable, fgValueOne)) {
- elementMiscFlags += SchemaSymbols::XSD_NILLABLE;
- }
- }
- if (abstract && *abstract) {
- if (XMLString::equals(abstract, SchemaSymbols::fgATTVAL_TRUE)
- || XMLString::equals(abstract, fgValueOne)) {
- elementMiscFlags += SchemaSymbols::XSD_ABSTRACT;
- }
- }
- if (isFixedVal) {
- elementMiscFlags += SchemaSymbols::XSD_FIXED;
- }
- const XMLCh* prefix = getPrefix(name);
- SchemaElementDecl* elemDecl = new (fMemoryManager) SchemaElementDecl
- (
- prefix
- , name
- , uriIndex
- , (SchemaElementDecl::ModelTypes) elemType
- , enclosingScope
- , fMemoryManager
- );
- elemDecl->setFinalSet(finalSet);
- elemDecl->setBlockSet(blockSet);
- elemDecl->setMiscFlags(elementMiscFlags);
- elemDecl->setCreateReason(XMLElementDecl::Declared);
- return elemDecl;
- }
- void TraverseSchema::processAttributeDeclRef(const DOMElement* const elem,
- ComplexTypeInfo* const typeInfo,
- const XMLCh* const refName,
- const XMLCh* const useAttr,
- const XMLCh* const defaultVal,
- const XMLCh* const fixedVal) {
- if (!typeInfo && !fCurrentAttGroupInfo) {
- return;
- }
- const XMLCh* prefix = getPrefix(refName);
- const XMLCh* localPart = getLocalPart(refName);
- const XMLCh* uriStr = resolvePrefixToURI(elem, prefix);
- unsigned int attURI = fURIStringPool->addOrFind(uriStr);
- // Check for duplicate references
- if (typeInfo && typeInfo->getAttDef(localPart, attURI)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateRefAttribute, uriStr, localPart);
- return;
- }
- else if (fCurrentAttGroupInfo && fCurrentAttGroupInfo->containsAttribute(localPart, attURI)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateRefAttribute, uriStr, localPart);
- return;
- }
- // check for different namespace
- SchemaInfo* saveInfo = fSchemaInfo;
- SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
- SchemaAttDef* refAttDef = 0;
- int saveScope = fCurrentScope;
- if (!XMLString::equals(uriStr, fTargetNSURIString)) {
- // Make sure that we have an explicit import statement.
- // Clause 4 of Schema Representation Constraint:
- // http://www.w3.org/TR/xmlschema-1/#src-resolve
- unsigned int uriId = fURIStringPool->addOrFind(uriStr);
- if (!fSchemaInfo->isImportingNS(uriId)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidNSReference, uriStr);
- return;
- }
- Grammar* grammar = fGrammarResolver->getGrammar(uriStr);
- if (grammar == 0 || grammar->getGrammarType() != Grammar::SchemaGrammarType) {
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, uriStr);
- return;
- }
- refAttDef = (SchemaAttDef*) ((SchemaGrammar*) grammar)->getAttributeDeclRegistry()->get(localPart);
- if (!refAttDef) {
- SchemaInfo* impInfo = fSchemaInfo->getImportInfo(attURI);
- if (!impInfo || impInfo->getProcessed()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::TopLevelAttributeNotFound, refName);
- return;
- }
- infoType = SchemaInfo::IMPORT;
- restoreSchemaInfo(impInfo, infoType);
- }
- }
- // if Global attribute registry does not contain the ref attribute, get
- // the referred attribute declaration and traverse it.
- if (!refAttDef) {
-
- if (fAttributeDeclRegistry->containsKey(localPart) == false) {
- DOMElement* referredAttribute = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_Attribute,
- SchemaSymbols::fgELT_ATTRIBUTE, localPart, &fSchemaInfo);
- if (referredAttribute != 0) {
- traverseAttributeDecl(referredAttribute, 0, true);
- }
- }
- refAttDef = (SchemaAttDef*) fAttributeDeclRegistry->get(localPart);
- }
- // restore schema information, if necessary
- if (fSchemaInfo != saveInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- if (!refAttDef) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::TopLevelAttributeNotFound, refName);
- return;
- }
- XMLAttDef::DefAttTypes refAttDefType = refAttDef->getDefaultType();
- const XMLCh* refAttValue = refAttDef->getValue();
- bool invalidAttUse = false;
- if (refAttDefType == XMLAttDef::Fixed &&
- (defaultVal || (fixedVal && !XMLString::equals(fixedVal, refAttValue)))) {
- invalidAttUse = true;
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttUseCorrect, refName);
- }
- DatatypeValidator* attDV = refAttDef->getDatatypeValidator();
- //check for multiple attributes with type derived from ID
- if (attDV && attDV->getType() == DatatypeValidator::ID) {
- if (fCurrentAttGroupInfo) {
- if (fCurrentAttGroupInfo->containsTypeWithId()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttGrpPropCorrect3, refName);
- return;
- }
- fCurrentAttGroupInfo->setTypeWithId(true);
- }
- else {
- if (typeInfo->containsAttWithTypeId()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttDeclPropCorrect5, refName);
- return;
- }
- typeInfo->setAttWithTypeId(true);
- }
- }
- bool required = XMLString::equals(useAttr,SchemaSymbols::fgATTVAL_REQUIRED);
- bool prohibited = XMLString::equals(useAttr,SchemaSymbols::fgATTVAL_PROHIBITED);
- QName* attQName = refAttDef->getAttName();
- SchemaAttDef* attDef = new (fMemoryManager) SchemaAttDef(attQName->getPrefix(),
- attQName->getLocalPart(),
- attQName->getURI(),
- refAttValue,
- refAttDef->getType(),
- refAttDefType,
- 0, fMemoryManager);
- if (refAttDefType == XMLAttDef::Fixed) {
- if (required && !invalidAttUse) {
- attDef->setDefaultType(XMLAttDef::Required_And_Fixed);
- }
- }
- else {
- if (prohibited) {
- attDef->setDefaultType(XMLAttDef::Prohibited);
- }
- else {
- const XMLCh* valueConstraint = defaultVal;
- if (required){
- if (fixedVal) {
- attDef->setDefaultType(XMLAttDef::Required_And_Fixed);
- valueConstraint = fixedVal;
- }
- else {
- attDef->setDefaultType(XMLAttDef::Required);
- }
- }
- if (valueConstraint) {
- // validate content of value constraint
- if (attDV) {
- if (attDV->getType() == DatatypeValidator::ID) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttDeclPropCorrect3,
- SchemaSymbols::fgATT_REF, refName);
- }
- else {
- try {
- attDV->validate(valueConstraint);
- }
- catch(const XMLException& excep) {
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::DisplayErrorMessage, excep.getMessage());
- }
- catch (...) {
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::DatatypeValidationFailure, valueConstraint);
- }
- }
- }
- attDef->setValue(valueConstraint);
- }
- }
- }
- attDef->setDatatypeValidator(attDV);
- bool toClone = false;
- if (typeInfo) {
- toClone = true;
- typeInfo->addAttDef(attDef);
- }
- if (fCurrentAttGroupInfo) {
- fCurrentAttGroupInfo->addAttDef(attDef, toClone);
- }
- }
- void TraverseSchema::checkMinMax(ContentSpecNode* const specNode,
- const DOMElement* const elem,
- const int allContextFlag) {
- int minOccurs = 1;
- int maxOccurs = 1;
- const XMLCh* minOccursStr = getElementAttValue(elem, SchemaSymbols::fgATT_MINOCCURS, true);
- const XMLCh* maxOccursStr = getElementAttValue(elem, SchemaSymbols::fgATT_MAXOCCURS, true);
- if (!minOccursStr || !*minOccursStr) {
- if (specNode)
- minOccurs = specNode->getMinOccurs();
- }
- else {
- try {
- minOccurs = XMLString::parseInt(minOccursStr);
- }
- catch (...) {
- minOccurs = 1;
- }
- if (specNode)
- specNode->setMinOccurs(minOccurs);
- }
- bool isMaxUnbounded = XMLString::equals(maxOccursStr, fgUnbounded);
- if (isMaxUnbounded) {
- maxOccurs = SchemaSymbols::XSD_UNBOUNDED;
- if (specNode)
- specNode->setMaxOccurs(maxOccurs);
- }
- else {
- if (!maxOccursStr || !*maxOccursStr) {
- if (specNode)
- maxOccurs = specNode->getMaxOccurs();
- }
- else {
- try {
- maxOccurs = XMLString::parseInt(maxOccursStr);
- }
- catch(...) {
- maxOccurs = minOccurs;
- }
- if (specNode)
- specNode->setMaxOccurs(maxOccurs);
- }
- }
- // Constraint checking for min/max value
- if (!isMaxUnbounded) {
- XMLCh tmpMinStr[128];
- XMLCh tmpMaxStr[128];
- XMLString::binToText(minOccurs, tmpMinStr, 127, 10);
- XMLString::binToText(maxOccurs, tmpMaxStr, 127, 10);
- if (maxOccurs < 1) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidAttValue,
- tmpMaxStr, SchemaSymbols::fgATT_MAXOCCURS);
- if (specNode)
- specNode->setMaxOccurs(minOccurs);
- }
- else if (maxOccurs < minOccurs) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidMin2MaxOccurs,
- tmpMinStr, tmpMaxStr);
- if (specNode)
- specNode->setMaxOccurs(minOccurs);
- }
- }
- if (minOccurs == 0 && maxOccurs == 0){
- return;
- }
- // Constraint checking for 'all' content
- bool isAllElement = (allContextFlag == All_Element);
- bool isAllGroup = (allContextFlag == All_Group);
- bool isGroupRefAll = (allContextFlag == Group_Ref_With_All);
- if (isAllElement || isAllGroup || isGroupRefAll) {
- if (maxOccurs != 1) {
- // set back correct value in order to carry on
- if (specNode) {
- specNode->setMaxOccurs(1);
- if (minOccurs > 1)
- specNode->setMinOccurs(1);
- }
- if (isAllElement) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadMinMaxAllElem);
- }
- else {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadMinMaxAllCT);
- }
- }
- }
- }
- void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
- const XMLCh* const typeName,
- const DOMElement* const childElem,
- ComplexTypeInfo* const typeInfo,
- const XMLCh* const baseRawName,
- const XMLCh* const baseLocalPart,
- const XMLCh* const baseURI,
- const bool isMixed,
- const bool isBaseAnyType) {
- ContentSpecNode* specNode = 0;
- const DOMElement* attrNode = 0;
- int typeDerivedBy = typeInfo->getDerivedBy();
- ComplexTypeInfo* baseTypeInfo = typeInfo->getBaseComplexTypeInfo();
- int baseContentType = (baseTypeInfo) ? baseTypeInfo->getContentType() : SchemaElementDecl::Empty;
- if (baseTypeInfo) {
- if (typeDerivedBy == SchemaSymbols::XSD_RESTRICTION) {
- // check to see if the baseType permits derivation by restriction
- if((baseTypeInfo->getFinalSet() & typeDerivedBy) != 0) {
- reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::ForbiddenDerivationByRestriction,
- baseLocalPart);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- }
- else {
- // check to see if the baseType permits derivation by extension
- if((baseTypeInfo->getFinalSet() & typeDerivedBy) != 0) {
- reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::ForbiddenDerivationByExtension, baseLocalPart);
- throw TraverseSchema::InvalidComplexTypeInfo; // REVISIT - should we continue
- }
- processElements(ctElem, baseTypeInfo, typeInfo);
- }
- }
- if (childElem != 0) {
- fCircularCheckIndex = fCurrentTypeNameStack->size();
- // --------------------------------------------------------------------
- // GROUP, ALL, SEQUENCE or CHOICE, followed by attributes, if specified.
- // Note that it's possible that only attributes are specified.
- // --------------------------------------------------------------------
- const XMLCh* childName = childElem->getLocalName();
- if (XMLString::equals(childName, SchemaSymbols::fgELT_GROUP)) {
- XercesGroupInfo* grpInfo = traverseGroupDecl(childElem, false);
- if (grpInfo) {
- specNode = grpInfo->getContentSpec();
- if (specNode) {
- int contentContext = specNode->hasAllContent() ? Group_Ref_With_All : Not_All_Context;
- specNode = new (fMemoryManager) ContentSpecNode(*specNode);
- checkMinMax(specNode, childElem, contentContext);
- }
- }
- attrNode = XUtil::getNextSiblingElement(childElem);
- }
- else if (XMLString::equals(childName, SchemaSymbols::fgELT_SEQUENCE)) {
- specNode = traverseChoiceSequence(childElem, ContentSpecNode::Sequence);
- checkMinMax(specNode, childElem);
- attrNode = XUtil::getNextSiblingElement(childElem);
- }
- else if (XMLString::equals(childName, SchemaSymbols::fgELT_CHOICE)) {
- specNode = traverseChoiceSequence(childElem, ContentSpecNode::Choice);
- checkMinMax(specNode, childElem);
- attrNode = XUtil::getNextSiblingElement(childElem);
- }
- else if (XMLString::equals(childName, SchemaSymbols::fgELT_ALL)) {
- specNode = traverseAll(childElem);
- checkMinMax(specNode, childElem, All_Group);
- attrNode = XUtil::getNextSiblingElement(childElem);
- }
- else if (isAttrOrAttrGroup(childElem)) {
- // reset the contentType
- typeInfo->setContentType(SchemaElementDecl::Any);
- attrNode = childElem;
- }
- else {
- reportSchemaError(childElem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidChildInComplexType, childName);
- }
- }
- typeInfo->setContentSpec(specNode);
- typeInfo->setAdoptContentSpec(true);
- // -----------------------------------------------------------------------
- // Merge in information from base, if it exists
- // -----------------------------------------------------------------------
- if (baseTypeInfo) {
- ContentSpecNode* baseSpecNode = baseTypeInfo->getContentSpec();
- if (typeDerivedBy == SchemaSymbols::XSD_RESTRICTION) {
- //check derivation valid - content type is empty (5.2)
- if (!typeInfo->getContentSpec()) {
- if (baseContentType != SchemaElementDecl::Empty
- && !emptiableParticle(baseSpecNode)) {
- reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::EmptyComplexRestrictionDerivation);
- }
- }
- // Delay particle constraint checking (5.3) until we have processed
- // the whole schema.
- }
- else {
- // Compose the final content model by concatenating the base and
- // the current in sequence
- if (!specNode) {
- if (baseSpecNode) {
- specNode = new (fMemoryManager) ContentSpecNode(*baseSpecNode);
- typeInfo->setContentSpec(specNode);
- typeInfo->setAdoptContentSpec(true);
- }
- }
- else if (baseSpecNode) {
- if (specNode->hasAllContent() || baseSpecNode->hasAllContent()) {
- reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::NotAllContent);
- throw TraverseSchema::InvalidComplexTypeInfo; // REVISIT - should we continue
- }
- // Check for derivation valid (extension) - 1.4.3.2.2.1
- if ((isMixed && baseContentType == SchemaElementDecl::Children)
- || (!isMixed && baseContentType != SchemaElementDecl::Children)) {
- reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::MixedOrElementOnly, baseLocalPart, typeName);
- throw TraverseSchema::InvalidComplexTypeInfo; //REVISIT - should we continue
- }
- typeInfo->setAdoptContentSpec(false);
- typeInfo->setContentSpec
- (
- new (fMemoryManager) ContentSpecNode
- (
- ContentSpecNode::Sequence
- , new (fMemoryManager) ContentSpecNode(*baseSpecNode)
- , specNode
- , true
- , true
- , fMemoryManager
- )
- );
- typeInfo->setAdoptContentSpec(true);
- }
- }
- }
- else {
- typeInfo->setDerivedBy(0);
- }
- // -------------------------------------------------------------
- // Set the content type
- // -------------------------------------------------------------
- if (isBaseAnyType && typeDerivedBy == SchemaSymbols::XSD_EXTENSION) {
- ContentSpecNode* anySpecNode = new (fMemoryManager) ContentSpecNode
- (
- new (fMemoryManager) QName
- (
- XMLUni::fgZeroLenString
- , XMLUni::fgZeroLenString
- , fEmptyNamespaceURI, fMemoryManager
- )
- , false
- , fMemoryManager
- );
- anySpecNode->setType(ContentSpecNode::Any_Lax);
- anySpecNode->setMinOccurs(0);
- anySpecNode->setMaxOccurs(SchemaSymbols::XSD_UNBOUNDED);
- if (!specNode) {
- typeInfo->setContentSpec(anySpecNode);
- typeInfo->setDerivedBy(typeDerivedBy);
- }
- else {
- typeInfo->setAdoptContentSpec(false);
- typeInfo->setContentSpec
- (
- new (fMemoryManager) ContentSpecNode
- (
- ContentSpecNode::Sequence
- , anySpecNode
- , specNode
- , true
- , true
- , fMemoryManager
- )
- );
- typeInfo->setAdoptContentSpec(true);
- if (!isMixed) {
- reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::MixedOrElementOnly, baseLocalPart, typeName);
- throw TraverseSchema::InvalidComplexTypeInfo; //REVISIT - should we continue
- }
- }
- typeInfo->setContentType(SchemaElementDecl::Mixed_Complex);
- }
- else if (isMixed) {
- if (specNode != 0) {
- typeInfo->setContentType(SchemaElementDecl::Mixed_Complex);
- }
- else {
- // add #PCDATA leaf and set its minOccurs to 0
- ContentSpecNode* pcdataNode = new (fMemoryManager) ContentSpecNode
- (
- new (fMemoryManager) QName
- (
- XMLUni::fgZeroLenString
- , XMLUni::fgZeroLenString
- , XMLElementDecl::fgPCDataElemId
- , fMemoryManager
- )
- , false
- , fMemoryManager
- );
- pcdataNode->setMinOccurs(0);
- typeInfo->setContentSpec(pcdataNode);
- typeInfo->setAdoptContentSpec(true);
- typeInfo->setContentType(SchemaElementDecl::Mixed_Simple);
- }
- }
- else if (typeInfo->getContentSpec() == 0) {
- typeInfo->setContentType(SchemaElementDecl::Empty);
- }
- else {
- typeInfo->setContentType(SchemaElementDecl::Children);
- }
- // -------------------------------------------------------------
- // Now, check attributes and handle
- // -------------------------------------------------------------
- if (attrNode != 0) {
- if (!isAttrOrAttrGroup(attrNode)) {
- reportSchemaError(attrNode, XMLUni::fgXMLErrDomain, XMLErrs::InvalidChildInComplexType,
- attrNode->getLocalName());
- }
- else {
- processAttributes(ctElem, attrNode, baseRawName, baseLocalPart, baseURI, typeInfo, isBaseAnyType);
- }
- }
- else if (baseTypeInfo != 0 || isBaseAnyType) {
- processAttributes(ctElem, 0, baseRawName, baseLocalPart, baseURI, typeInfo, isBaseAnyType);
- }
- }
- void TraverseSchema::processBaseTypeInfo(const DOMElement* const elem,
- const XMLCh* const baseName,
- const XMLCh* const localPart,
- const XMLCh* const uriStr,
- ComplexTypeInfo* const typeInfo) {
- SchemaInfo* saveInfo = fSchemaInfo;
- ComplexTypeInfo* baseComplexTypeInfo = 0;
- DatatypeValidator* baseDTValidator = 0;
- SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
- int saveScope = fCurrentScope;
- // check if the base type is from another schema
- if (!XMLString::equals(uriStr, fTargetNSURIString)) {
- // check for datatype validator if it's schema for schema URI
- if (XMLString::equals(uriStr, SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) {
- baseDTValidator = getDatatypeValidator(uriStr, localPart);
- if (!baseDTValidator) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidNSReference, uriStr);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- }
- else {
-
- // Make sure that we have an explicit import statement.
- // Clause 4 of Schema Representation Constraint:
- // http://www.w3.org/TR/xmlschema-1/#src-resolve
- unsigned int uriId = fURIStringPool->addOrFind(uriStr);
- if (!fSchemaInfo->isImportingNS(uriId)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidNSReference, uriStr);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- baseComplexTypeInfo = getTypeInfoFromNS(elem, uriStr, localPart);
- if (!baseComplexTypeInfo) {
- SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(uriStr));
- if (!impInfo || impInfo->getProcessed()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BaseTypeNotFound, baseName);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- infoType = SchemaInfo::IMPORT;
- restoreSchemaInfo(impInfo, infoType);
- }
- }
- }
- else {
- fBuffer.set(uriStr);
- fBuffer.append(chComma);
- fBuffer.append(localPart);
- // assume the base is a complexType and try to locate the base type first
- const XMLCh* fullBaseName = fBuffer.getRawBuffer();
- baseComplexTypeInfo = fComplexTypeRegistry->get(fullBaseName);
- // Circular check
- if (baseComplexTypeInfo) {
- if (fCurrentTypeNameStack->containsElement(fStringPool->addOrFind(fullBaseName), fCircularCheckIndex)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, fullBaseName);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- else if (fCurrentTypeNameStack->containsElement(fStringPool->addOrFind(fullBaseName))) {
- typeInfo->setBaseComplexTypeInfo(baseComplexTypeInfo);
- throw TraverseSchema::RecursingElement;
- }
- else if (baseComplexTypeInfo->getPreprocessed()) {
- baseComplexTypeInfo = 0;
- }
- }
- }
- // if not found, 2 possibilities:
- // 1: ComplexType in question has not been compiled yet;
- // 2: base is SimpleType;
- if (!baseComplexTypeInfo && !baseDTValidator) {
- baseDTValidator = getDatatypeValidator(uriStr, localPart);
- if (baseDTValidator == 0) {
- DOMElement* baseTypeNode = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_ComplexType,
- SchemaSymbols::fgELT_COMPLEXTYPE, localPart, &fSchemaInfo);
- if (baseTypeNode != 0) {
- int baseTypeSymbol = traverseComplexTypeDecl(baseTypeNode);
- baseComplexTypeInfo = fComplexTypeRegistry->get(fStringPool->getValueForId(baseTypeSymbol));
- }
- else {
- baseTypeNode = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_SimpleType,
- SchemaSymbols::fgELT_SIMPLETYPE, localPart, &fSchemaInfo);
- if (baseTypeNode != 0) {
- baseDTValidator = traverseSimpleTypeDecl(baseTypeNode);
- if (baseDTValidator == 0) {
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, uriStr, localPart, uriStr);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- }
- else {
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BaseTypeNotFound, baseName);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- }
- }
- } // end if
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- typeInfo->setBaseComplexTypeInfo(baseComplexTypeInfo);
- typeInfo->setBaseDatatypeValidator(baseDTValidator);
- }
- ComplexTypeInfo* TraverseSchema::getTypeInfoFromNS(const DOMElement* const elem,
- const XMLCh* const uriStr,
- const XMLCh* const localPart)
- {
- Grammar* grammar = fGrammarResolver->getGrammar(uriStr);
- if (grammar != 0 && grammar->getGrammarType() == Grammar::SchemaGrammarType) {
- fBuffer.set(uriStr);
- fBuffer.append(chComma);
- fBuffer.append(localPart);
- ComplexTypeInfo* typeInfo =
- ((SchemaGrammar*)grammar)->getComplexTypeRegistry()->get(fBuffer.getRawBuffer());
- return typeInfo;
- }
- else {
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, uriStr);
- }
- return 0;
- }
- void TraverseSchema::processAttributes(const DOMElement* const elem,
- const DOMElement* const attElem,
- const XMLCh* const baseRawName,
- const XMLCh* const baseLocalPart,
- const XMLCh* const baseURI,
- ComplexTypeInfo* const typeInfo,
- const bool isBaseAnyType) {
- // If we do not have a complexTypeInfo, then what is the point of
- // processing.
- if (typeInfo == 0) {
- return;
- }
- const DOMElement* child = attElem;
- SchemaAttDef* attWildCard = 0;
- Janitor<SchemaAttDef> janAttWildCard(0);
- XercesAttGroupInfo* attGroupInfo = 0;
- ValueVectorOf<XercesAttGroupInfo*> attGroupList(4, fMemoryManager);
- for (; child != 0; child = XUtil::getNextSiblingElement(child)) {
- const XMLCh* childName = child->getLocalName();
- if (XMLString::equals(childName, SchemaSymbols::fgELT_ATTRIBUTE)) {
- traverseAttributeDecl(child, typeInfo);
- }
- else if (XMLString::equals(childName, SchemaSymbols::fgELT_ATTRIBUTEGROUP)) {
- attGroupInfo = traverseAttributeGroupDecl(child, typeInfo);
- if (attGroupInfo && !attGroupList.containsElement(attGroupInfo)) {
- attGroupList.addElement(attGroupInfo);
- }
- }
- else if (XMLString::equals(childName, SchemaSymbols::fgELT_ANYATTRIBUTE) ) {
- attWildCard = traverseAnyAttribute(child);
- janAttWildCard.reset(attWildCard);
- }
- else {
- reportSchemaError(child, XMLUni::fgXMLErrDomain, XMLErrs::InvalidChildInComplexType, childName);
- }
- }
- // -------------------------------------------------------------
- // Handle wild card/any attribute
- // -------------------------------------------------------------
- ComplexTypeInfo* baseTypeInfo = typeInfo->getBaseComplexTypeInfo();
- int derivedBy = typeInfo->getDerivedBy();
- unsigned int attGroupListSize = attGroupList.size();
- if (attGroupListSize) {
- SchemaAttDef* completeWildCard = 0;
- Janitor<SchemaAttDef> janCompleteWildCard(0);
- XMLAttDef::DefAttTypes defAttType;
- bool defAttTypeSet = false;
- for (unsigned int i=0; i < attGroupListSize; i++) {
- attGroupInfo = attGroupList.elementAt(i);
- unsigned int anyAttCount = attGroupInfo->anyAttributeCount();
- if (anyAttCount) {
- if (!defAttTypeSet) {
- defAttType = (attWildCard) ? attWildCard->getDefaultType()
- : attGroupInfo->anyAttributeAt(0)->getDefaultType();
- defAttTypeSet = true;
- }
- SchemaAttDef* attGroupWildCard = attGroupInfo->getCompleteWildCard();
- if (!attGroupWildCard) {
- attGroupWildCard = new (fMemoryManager) SchemaAttDef(attGroupInfo->anyAttributeAt(0));
- for (unsigned int i= 1; i < anyAttCount; i++) {
- attWildCardIntersection(attGroupWildCard, attGroupInfo->anyAttributeAt(i));
- }
- attGroupInfo->setCompleteWildCard(attGroupWildCard);
- }
- if (completeWildCard) {
- attWildCardIntersection(completeWildCard, attGroupWildCard);
- }
- else {
- completeWildCard = new (fMemoryManager) SchemaAttDef(attGroupWildCard);
- janCompleteWildCard.reset(completeWildCard);
- }
- }
- }
- if (completeWildCard) {
- if (attWildCard) {
- attWildCardIntersection(attWildCard, completeWildCard);
- }
- else {
- attWildCard = completeWildCard;
- janCompleteWildCard.orphan();
- janAttWildCard.reset(attWildCard);
- }
- attWildCard->setDefaultType(defAttType);
- }
- }
- SchemaAttDef* baseAttWildCard = (baseTypeInfo) ? baseTypeInfo->getAttWildCard() : 0;
- Janitor<SchemaAttDef> janBaseAttWildCard(0);
- if (derivedBy == SchemaSymbols::XSD_EXTENSION) {
- if (isBaseAnyType) {
- baseAttWildCard = new (fMemoryManager) SchemaAttDef(XMLUni::fgZeroLenString,
- XMLUni::fgZeroLenString,
- fEmptyNamespaceURI, XMLAttDef::Any_Any,
- XMLAttDef::ProcessContents_Lax,
- fMemoryManager);
- janBaseAttWildCard.reset(baseAttWildCard);
- }
-
- if (baseAttWildCard && attWildCard) {
- XMLAttDef::DefAttTypes saveDefType = attWildCard->getDefaultType();
- attWildCardUnion(attWildCard, baseAttWildCard);
- attWildCard->setDefaultType(saveDefType);
- }
- }
- // -------------------------------------------------------------
- // insert wildcard attribute
- // -------------------------------------------------------------
- if (attWildCard) {
- typeInfo->setAttWildCard(attWildCard);
- janAttWildCard.orphan();
- if (attWildCard->getType() == XMLAttDef::AttTypes_Unknown) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NotExpressibleWildCardIntersection);
- }
- }
- else if (baseAttWildCard && derivedBy == SchemaSymbols::XSD_EXTENSION) {
- if (isBaseAnyType) {
- typeInfo->setAttWildCard(baseAttWildCard);
- janBaseAttWildCard.orphan();
- }
- else {
- SchemaAttDef* newWildCard = new (fMemoryManager) SchemaAttDef(baseAttWildCard);
- typeInfo->setAttWildCard(newWildCard);
- }
- }
- // -------------------------------------------------------------
- // Check attributes derivation OK
- // -------------------------------------------------------------
- bool baseWithAttributes = (baseTypeInfo && baseTypeInfo->hasAttDefs());
- bool childWithAttributes = (typeInfo->hasAttDefs() || typeInfo->getAttWildCard());
- if (derivedBy == SchemaSymbols::XSD_RESTRICTION && childWithAttributes) {
- if (!baseWithAttributes && !baseAttWildCard) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_1);
- }
- else {
- checkAttDerivationOK(elem, baseTypeInfo, typeInfo);
- }
- }
- // -------------------------------------------------------------
- // merge in base type's attribute decls
- // -------------------------------------------------------------
- if (baseTypeInfo && baseTypeInfo->hasAttDefs()) {
- SchemaAttDefList& baseAttList = (SchemaAttDefList&)
- baseTypeInfo->getAttDefList();
- while (baseAttList.hasMoreElements()) {
- SchemaAttDef& attDef = (SchemaAttDef&) baseAttList.nextElement();
- QName* attName = attDef.getAttName();
- const XMLCh* localPart = attName->getLocalPart();
- // if found a duplicate, then skip the one from the base type
- if (typeInfo->getAttDef(localPart, attName->getURI()) != 0) {
- if (derivedBy == SchemaSymbols::XSD_EXTENSION) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateAttInDerivation, localPart);
- }
- continue;
- }
- if (attDef.getDefaultType() != XMLAttDef::Prohibited) {
- SchemaAttDef* newAttDef = new (fMemoryManager) SchemaAttDef(attName->getPrefix(),
- attName->getLocalPart(),
- attName->getURI(),
- attDef.getValue(),
- attDef.getType(),
- attDef.getDefaultType(),
- attDef.getEnumeration(),
- fMemoryManager);
- newAttDef->setDatatypeValidator(attDef.getDatatypeValidator());
- typeInfo->addAttDef(newAttDef);
- }
- }
- }
- }
- void TraverseSchema::defaultComplexTypeInfo(ComplexTypeInfo* const typeInfo) {
- if (typeInfo) {
- typeInfo->setDerivedBy(0);
- typeInfo->setContentType(SchemaElementDecl::Any);
- typeInfo->setDatatypeValidator(0);
- typeInfo->setContentSpec(0);
- typeInfo->setBaseComplexTypeInfo(0);
- typeInfo->setBaseDatatypeValidator(0);
- }
- }
- InputSource* TraverseSchema::resolveSchemaLocation(const XMLCh* const loc) {
- // ------------------------------------------------------------------
- // Create an input source
- // ------------------------------------------------------------------
- InputSource* srcToFill = 0;
- normalizeURI(loc, fBuffer);
- const XMLCh* normalizedURI = fBuffer.getRawBuffer();
- if (fEntityHandler){
- srcToFill = fEntityHandler->resolveEntity(XMLUni::fgZeroLenString, normalizedURI);
- }
- // If they didn't create a source via the entity resolver, then we
- // have to create one on our own.
- if (!srcToFill) {
- try {
- XMLURL urlTmp(fSchemaInfo->getCurrentSchemaURL(), normalizedURI);
- if (urlTmp.isRelative()) {
- ThrowXML(MalformedURLException,
- XMLExcepts::URL_NoProtocolPresent);
- }
- else {
- if (fScanner->getStandardUriConformant() && urlTmp.hasInvalidChar())
- ThrowXML(MalformedURLException, XMLExcepts::URL_MalformedURL);
- srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager);
- }
- }
- catch(const MalformedURLException& e) {
- // Its not a URL, so lets assume its a local file name if non-standard URI is allowed
- if (!fScanner->getStandardUriConformant())
- srcToFill = new (fMemoryManager) LocalFileInputSource(fSchemaInfo->getCurrentSchemaURL(),normalizedURI, fMemoryManager);
- else
- throw e;
- }
- }
- return srcToFill;
- }
- void TraverseSchema::restoreSchemaInfo(SchemaInfo* const toRestore,
- SchemaInfo::ListType const aListType,
- const int saveScope) {
- if (aListType == SchemaInfo::IMPORT) { // restore grammar info
- fSchemaInfo->setScopeCount(fScopeCount);
- int targetNSURI = toRestore->getTargetNSURI();
- fSchemaGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(toRestore->getTargetNSURIString());
- if (!fSchemaGrammar) {
- return;
- }
- fTargetNSURI = targetNSURI;
- fCurrentScope = saveScope;
- fScopeCount = toRestore->getScopeCount();
- fDatatypeRegistry = fSchemaGrammar->getDatatypeRegistry();
- fTargetNSURIString = fSchemaGrammar->getTargetNamespace();
- fGroupRegistry = fSchemaGrammar->getGroupInfoRegistry();
- fAttGroupRegistry = fSchemaGrammar->getAttGroupInfoRegistry();
- fAttributeDeclRegistry = fSchemaGrammar->getAttributeDeclRegistry();
- fComplexTypeRegistry = fSchemaGrammar->getComplexTypeRegistry();
- fValidSubstitutionGroups = fSchemaGrammar->getValidSubstitutionGroups();
- fNamespaceScope = fSchemaGrammar->getNamespaceScope();
- fAttributeCheck.setIDRefList(fSchemaGrammar->getIDRefList());
- }
- fSchemaInfo = toRestore;
- }
- bool
- TraverseSchema::emptiableParticle(const ContentSpecNode* const specNode) {
- if (!fFullConstraintChecking || (specNode->getMinTotalRange() == 0)) {
- return true;
- }
- return false;
- }
- void TraverseSchema::checkFixedFacet(const DOMElement* const elem,
- const XMLCh* const facetName,
- const DatatypeValidator* const baseDV,
- unsigned int& flags)
- {
- const XMLCh* fixedFacet = getElementAttValue(elem, SchemaSymbols::fgATT_FIXED);
- if ((fixedFacet && *fixedFacet) &&
- (XMLString::equals(fixedFacet, SchemaSymbols::fgATTVAL_TRUE)
- || XMLString::equals(fixedFacet, fgValueOne))) {
- if (XMLString::equals(SchemaSymbols::fgELT_MINLENGTH, facetName)) {
- flags |= DatatypeValidator::FACET_MINLENGTH;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_MAXLENGTH, facetName)) {
- flags |= DatatypeValidator::FACET_MAXLENGTH;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_MAXEXCLUSIVE, facetName)) {
- flags |= DatatypeValidator::FACET_MAXEXCLUSIVE;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_MAXINCLUSIVE, facetName)) {
- flags |= DatatypeValidator::FACET_MAXINCLUSIVE;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_MINEXCLUSIVE, facetName)) {
- flags |= DatatypeValidator::FACET_MINEXCLUSIVE;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_MININCLUSIVE, facetName)) {
- flags |= DatatypeValidator::FACET_MININCLUSIVE;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_TOTALDIGITS, facetName)) {
- flags |= DatatypeValidator::FACET_TOTALDIGITS;
- }
- else if (XMLString::equals(SchemaSymbols::fgELT_FRACTIONDIGITS, facetName)) {
- flags |= DatatypeValidator::FACET_FRACTIONDIGITS;
- }
- else if ((XMLString::equals(SchemaSymbols::fgELT_WHITESPACE, facetName)) &&
- baseDV->getType() == DatatypeValidator::String) {
- flags |= DatatypeValidator::FACET_WHITESPACE;
- }
- }
- }
- void
- TraverseSchema::buildValidSubstitutionListB(const DOMElement* const elem,
- SchemaElementDecl* const elemDecl,
- SchemaElementDecl* const subsElemDecl) {
- SchemaElementDecl* chainElemDecl = subsElemDecl->getSubstitutionGroupElem();
- while (chainElemDecl) {
- int chainElemURI = chainElemDecl->getURI();
- XMLCh* chainElemName = chainElemDecl->getBaseName();
- ValueVectorOf<SchemaElementDecl*>* validSubsElements =
- fValidSubstitutionGroups->get(chainElemName, chainElemURI);
- if (!validSubsElements) {
- if (fTargetNSURI == chainElemURI) {
- break; // an error must have occured
- }
- SchemaGrammar* aGrammar = (SchemaGrammar*)
- fGrammarResolver->getGrammar(fURIStringPool->getValueForId(chainElemURI));
- if (!aGrammar)
- break;
- validSubsElements = aGrammar->getValidSubstitutionGroups()->get(chainElemName, chainElemURI);
- if (!validSubsElements) {
- break;
- }
-
- validSubsElements = new (fMemoryManager) ValueVectorOf<SchemaElementDecl*>(*validSubsElements);
- fValidSubstitutionGroups->put((void*) chainElemName, chainElemURI, validSubsElements);
- }
- if (validSubsElements->containsElement(elemDecl) ||
- !isSubstitutionGroupValid(elem, chainElemDecl, elemDecl->getComplexTypeInfo(),
- elemDecl->getDatatypeValidator(), 0, false)) {
- break;
- }
- validSubsElements->addElement(elemDecl);
- // update related subs. info in case of circular import
- BaseRefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator();
- while (importingEnum.hasMoreElements()) {
- const SchemaInfo& curRef = importingEnum.nextElement();
- SchemaGrammar* aGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(curRef.getTargetNSURIString());
- ValueVectorOf<SchemaElementDecl*>* subsElemList =
- aGrammar->getValidSubstitutionGroups()->get(chainElemName, chainElemURI);
- if (subsElemList && !subsElemList->containsElement(elemDecl)) {
- subsElemList->addElement(elemDecl);
- }
- }
- chainElemDecl = chainElemDecl->getSubstitutionGroupElem();
- }
- }
- void
- TraverseSchema::buildValidSubstitutionListF(const DOMElement* const elem,
- SchemaElementDecl* const elemDecl,
- SchemaElementDecl* const subsElemDecl) {
- int elemURI = elemDecl->getURI();
- XMLCh* elemName = elemDecl->getBaseName();
- ValueVectorOf<SchemaElementDecl*>* validSubsElements =fValidSubstitutionGroups->get(elemName, elemURI);
- if (validSubsElements) {
- int subsElemURI = subsElemDecl->getURI();
- XMLCh* subsElemName = subsElemDecl->getBaseName();
- ValueVectorOf<SchemaElementDecl*>* validSubs = fValidSubstitutionGroups->get(subsElemName, subsElemURI);
- if (!validSubs) {
- if (fTargetNSURI == subsElemURI) {
- return; // an error must have occured
- }
- SchemaGrammar* aGrammar = (SchemaGrammar*)
- fGrammarResolver->getGrammar(fURIStringPool->getValueForId(subsElemURI));
- if (!aGrammar)
- return;
- validSubs = aGrammar->getValidSubstitutionGroups()->get(subsElemName, subsElemURI);
- if (!validSubs) {
- return;
- }
-
- validSubs = new (fMemoryManager) ValueVectorOf<SchemaElementDecl*>(*validSubs);
- fValidSubstitutionGroups->put((void*) subsElemName, subsElemURI, validSubs);
- }
- unsigned int elemSize = validSubsElements->size();
- for (unsigned int i=0; i<elemSize; i++) {
- SchemaElementDecl* chainElem = validSubsElements->elementAt(i);
- if (validSubs->containsElement(chainElem)) {
- continue;
- }
- if (isSubstitutionGroupValid(elem, subsElemDecl, chainElem->getComplexTypeInfo(),
- chainElem->getDatatypeValidator(), 0, false)) {
- validSubs->addElement(chainElem);
- buildValidSubstitutionListB(elem, chainElem, subsElemDecl);
- }
- }
- }
- }
- void TraverseSchema::checkEnumerationRequiredNotation(const DOMElement* const elem,
- const XMLCh* const name,
- const XMLCh* const type) {
- const XMLCh* localPart = getLocalPart(type);
- if (XMLString::equals(localPart, SchemaSymbols::fgELT_NOTATION)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoNotationType, name);
- }
- }
- XercesGroupInfo* TraverseSchema::processGroupRef(const DOMElement* const elem,
- const XMLCh* const refName) {
- if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) {
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::NoContentForRef, SchemaSymbols::fgELT_GROUP);
- }
- const XMLCh* prefix = getPrefix(refName);
- const XMLCh* localPart = getLocalPart(refName);
- const XMLCh* uriStr = resolvePrefixToURI(elem, prefix);
- fBuffer.set(uriStr);
- fBuffer.append(chComma);
- fBuffer.append(localPart);
- unsigned int nameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer());
-
- if (fCurrentGroupStack->containsElement(nameIndex)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, localPart);
- return 0;
- }
- XercesGroupInfo* groupInfo = 0;
- SchemaInfo* saveInfo = fSchemaInfo;
- SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
- int saveScope = fCurrentScope;
- //if from another target namespace
- if (!XMLString::equals(uriStr, fTargetNSURIString)) {
- // Make sure that we have an explicit import statement.
- // Clause 4 of Schema Representation Constraint:
- // http://www.w3.org/TR/xmlschema-1/#src-resolve
- unsigned int uriId = fURIStringPool->addOrFind(uriStr);
- if (!fSchemaInfo->isImportingNS(uriId)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidNSReference, uriStr);
- return 0;
- }
- Grammar* aGrammar = fGrammarResolver->getGrammar(uriStr);
- if (!aGrammar || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
- reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, uriStr);
- return 0;
- }
- groupInfo = ((SchemaGrammar*)aGrammar)->getGroupInfoRegistry()->get(fStringPool->getValueForId(nameIndex));
- if (!groupInfo) {
- SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(uriStr));
- if (!impInfo || impInfo->getProcessed()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_GROUP, uriStr, localPart);
- return 0;
- }
- infoType = SchemaInfo::IMPORT;
- restoreSchemaInfo(impInfo, infoType);
- }
- }
- else {
- groupInfo = fGroupRegistry->get(fStringPool->getValueForId(nameIndex));
- }
- if (!groupInfo) {
- DOMElement* groupElem = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_Group,
- SchemaSymbols::fgELT_GROUP, localPart, &fSchemaInfo);
- if (groupElem != 0) {
- groupInfo = traverseGroupDecl(groupElem);
- // restore schema information
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- if (groupInfo && (fCurrentGroupInfo || infoType == SchemaInfo::IMPORT)) {
- copyGroupElements(elem, groupInfo, fCurrentGroupInfo,
- (infoType == SchemaInfo::IMPORT) ? fCurrentComplexType : 0);
- }
- return groupInfo;
- }
- else {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_GROUP, uriStr, localPart);
- }
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- }
- else {
- copyGroupElements(elem, groupInfo, fCurrentGroupInfo, fCurrentComplexType);
- }
- return groupInfo;
- }
- XercesAttGroupInfo*
- TraverseSchema::processAttributeGroupRef(const DOMElement* const elem,
- const XMLCh* const refName,
- ComplexTypeInfo* const typeInfo) {
- if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) {
- reportSchemaError(elem ,XMLUni::fgValidityDomain, XMLValid::NoContentForRef, SchemaSymbols::fgELT_ATTRIBUTEGROUP);
- }
- const XMLCh* prefix = getPrefix(refName);
- const XMLCh* localPart = getLocalPart(refName);
- const XMLCh* uriStr = resolvePrefixToURI(elem, prefix);
- XercesAttGroupInfo* attGroupInfo = 0;
- SchemaInfo* saveInfo = fSchemaInfo;
- SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
- int saveScope = fCurrentScope;
- if (!XMLString::equals(uriStr, fTargetNSURIString)) {
- // Make sure that we have an explicit import statement.
- // Clause 4 of Schema Representation Constraint:
- // http://www.w3.org/TR/xmlschema-1/#src-resolve
- unsigned int uriId = fURIStringPool->addOrFind(uriStr);
- if (!fSchemaInfo->isImportingNS(uriId)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidNSReference, uriStr);
- return 0;
- }
- attGroupInfo = traverseAttributeGroupDeclNS(elem, uriStr, localPart);
- if (!attGroupInfo) {
- SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(uriStr));
- if (!impInfo || impInfo->getProcessed()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_ATTRIBUTEGROUP, uriStr, localPart);
- return 0;
- }
- infoType = SchemaInfo::IMPORT;
- restoreSchemaInfo(impInfo, infoType);
- }
- }
- else {
- attGroupInfo = fAttGroupRegistry->get(localPart);
- }
- if (!attGroupInfo) {
- // traverse top level attributeGroup - if found
- DOMElement* attGroupElem = fSchemaInfo->getTopLevelComponent(SchemaInfo::C_AttributeGroup,
- SchemaSymbols::fgELT_ATTRIBUTEGROUP, localPart, &fSchemaInfo);
- if (attGroupElem != 0) {
- // circular attribute check
- if (fDeclStack->containsElement(attGroupElem)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, refName);
- return 0;
- }
- attGroupInfo = traverseAttributeGroupDecl(attGroupElem, typeInfo, true);
- if (attGroupInfo && fCurrentAttGroupInfo) {
- copyAttGroupAttributes(elem, attGroupInfo, fCurrentAttGroupInfo, 0);
- }
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType, saveScope);
- }
- return attGroupInfo;
- }
- else {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_ATTRIBUTEGROUP, uriStr, localPart);
- }
- }
- if (attGroupInfo) {
- copyAttGroupAttributes(elem, attGroupInfo, fCurrentAttGroupInfo, typeInfo);
- }
- // restore schema information, if necessary
- if (saveInfo != fSchemaInfo) {
- restoreSchemaInfo(saveInfo, infoType);
- }
- return attGroupInfo;
- }
- void TraverseSchema::processElements(const DOMElement* const elem,
- ComplexTypeInfo* const baseTypeInfo,
- ComplexTypeInfo* const newTypeInfo) {
- unsigned int elemCount = baseTypeInfo->elementCount();
- if (elemCount) {
- int newTypeScope = newTypeInfo->getScopeDefined();
- int schemaURI = fURIStringPool->addOrFind(SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
- for (unsigned int i=0; i < elemCount; i++) {
- SchemaGrammar* aGrammar = fSchemaGrammar;
- SchemaElementDecl* elemDecl = baseTypeInfo->elementAt(i);
- int elemURI = elemDecl->getURI();
- int elemScope = elemDecl->getEnclosingScope();
- if (elemScope != Grammar::TOP_LEVEL_SCOPE) {
- if (elemURI != fTargetNSURI && elemURI != schemaURI && elemURI != fEmptyNamespaceURI) {
- Grammar* aGrammar =
- fGrammarResolver->getGrammar(fURIStringPool->getValueForId(elemURI));
- if (!aGrammar || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
- continue; // REVISIT - error message
- }
- }
- const XMLCh* localPart = elemDecl->getBaseName();
- const SchemaElementDecl* other = (SchemaElementDecl*)
- aGrammar->getElemDecl(elemURI, localPart, 0, newTypeScope);
- if (other) {
- if (elemDecl->getComplexTypeInfo() != other->getComplexTypeInfo()
- || elemDecl->getDatatypeValidator() != other->getDatatypeValidator()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateElementDeclaration, localPart);
- }
- continue;
- }
- elemDecl->setEnclosingScope(newTypeScope);
- ((SchemaGrammar*) aGrammar)->putGroupElemDecl(elemDecl);
- elemDecl->setEnclosingScope(elemScope);
- }
- newTypeInfo->addElement(elemDecl);
- }
- }
- }
- void TraverseSchema::copyGroupElements(const DOMElement* const elem,
- XercesGroupInfo* const fromGroup,
- XercesGroupInfo* const toGroup,
- ComplexTypeInfo* const typeInfo) {
- unsigned int elemCount = fromGroup->elementCount();
- int newScope = (typeInfo) ? typeInfo->getScopeDefined() : 0;
- if (typeInfo)
- fromGroup->setCheckElementConsistency(false);
- for (unsigned int i = 0; i < elemCount; i++) {
- SchemaElementDecl* elemDecl = fromGroup->elementAt(i);
- if (typeInfo) {
- int elemScope = elemDecl->getEnclosingScope();
- if (elemScope != Grammar::TOP_LEVEL_SCOPE) {
- int elemURI = elemDecl->getURI();
- const XMLCh* localPart = elemDecl->getBaseName();
- const SchemaElementDecl* other = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(elemURI, localPart, 0, fCurrentScope);
- if (other) {
- if (elemDecl->getComplexTypeInfo() != other->getComplexTypeInfo()
- || elemDecl->getDatatypeValidator() != other->getDatatypeValidator()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateElementDeclaration, localPart);
- }
- continue;
- }
- elemDecl->setEnclosingScope(newScope);
- fSchemaGrammar->putGroupElemDecl(elemDecl);
- elemDecl->setEnclosingScope(elemScope);
- }
- typeInfo->addElement(elemDecl);
- }
- if (toGroup) {
- toGroup->addElement(elemDecl);
- }
- }
- }
- void TraverseSchema::copyAttGroupAttributes(const DOMElement* const elem,
- XercesAttGroupInfo* const fromAttGroup,
- XercesAttGroupInfo* const toAttGroup,
- ComplexTypeInfo* const typeInfo) {
- unsigned int attCount = fromAttGroup->attributeCount();
- for (unsigned int i=0; i < attCount; i++) {
- SchemaAttDef* attDef = fromAttGroup->attributeAt(i);
- QName* attName = attDef->getAttName();
- const XMLCh* localPart = attName->getLocalPart();
- DatatypeValidator* attDV = attDef->getDatatypeValidator();
- if (typeInfo) {
- if (typeInfo->getAttDef(localPart, attName->getURI())) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateAttribute, localPart);
- continue;
- }
- if (attDV && attDV->getType() == DatatypeValidator::ID) {
- if (typeInfo->containsAttWithTypeId()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttDeclPropCorrect5, localPart);
- continue;
- }
- typeInfo->setAttWithTypeId(true);
- }
- typeInfo->addAttDef(new (fMemoryManager) SchemaAttDef(attDef));
- if (toAttGroup) {
- toAttGroup->addAttDef(attDef, true);
- }
- }
- else {
- if (toAttGroup->containsAttribute(localPart, attName->getURI())) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateAttribute, localPart);
- continue;
- }
- if (attDV && attDV->getType() == DatatypeValidator::ID) {
- if (toAttGroup->containsTypeWithId()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttGrpPropCorrect3, localPart);
- continue;
- }
- toAttGroup->setTypeWithId(true);
- }
- toAttGroup->addAttDef(attDef, true);
- }
- }
- if (toAttGroup) {
- unsigned int anyAttCount = fromAttGroup->anyAttributeCount();
- for (unsigned int j=0; j < anyAttCount; j++) {
- toAttGroup->addAnyAttDef(fromAttGroup->anyAttributeAt(j), true);
- }
- }
- }
- void
- TraverseSchema::attWildCardIntersection(SchemaAttDef* const resultWildCard,
- const SchemaAttDef* const compareWildCard) {
- XMLAttDef::AttTypes typeR = resultWildCard->getType();
- XMLAttDef::AttTypes typeC = compareWildCard->getType();
- //If either O1 or O2 is any, then the other must be the value.
- if (typeC == XMLAttDef::Any_Any ||
- typeR == XMLAttDef::AttTypes_Unknown) {
- return;
- }
- if (typeR == XMLAttDef::Any_Any ||
- typeC == XMLAttDef::AttTypes_Unknown) {
- resultWildCard->resetNamespaceList();
- copyWildCardData(compareWildCard, resultWildCard);
- return;
- }
- // If either O1 or O2 is a pair of not and a namespace name and the other
- // is a set, then that set, minus the negated namespace name if it was in
- // is the value
- if ((typeC == XMLAttDef::Any_Other && typeR == XMLAttDef::Any_List) ||
- (typeR == XMLAttDef::Any_Other && typeC == XMLAttDef::Any_List)) {
- unsigned int compareURI = 0;
- ValueVectorOf<unsigned int>* nameURIList = 0;
- if (typeC == XMLAttDef::Any_List) {
- nameURIList = compareWildCard->getNamespaceList();
- compareURI = resultWildCard->getAttName()->getURI();
- }
- else {
- nameURIList = resultWildCard->getNamespaceList();
- compareURI = compareWildCard->getAttName()->getURI();
- }
- unsigned int listSize = (nameURIList) ? nameURIList->size() : 0;
- if (listSize) {
- bool found = false;
- ValueVectorOf<unsigned int> tmpURIList(listSize, fMemoryManager);
- for (unsigned int i=0; i < listSize; i++) {
- unsigned int nameURI = nameURIList->elementAt(i);
- if (nameURI != compareURI &&
- nameURI != (unsigned int) fEmptyNamespaceURI) {
- tmpURIList.addElement(nameURI);
- }
- else {
- found = true;
- }
- }
- if (found || typeC == XMLAttDef::Any_List) {
- resultWildCard->setNamespaceList(&tmpURIList);
- }
- }
- if (typeC == XMLAttDef::Any_List) {
- copyWildCardData(compareWildCard, resultWildCard);
- }
- return;
- }
- // If both O1 and O2 are sets, then the intersection of those sets must be
- // the value.
- if (typeR == XMLAttDef::Any_List && typeC == XMLAttDef::Any_List) {
-
- ValueVectorOf<unsigned int>* uriListR = resultWildCard->getNamespaceList();
- ValueVectorOf<unsigned int>* uriListC = compareWildCard->getNamespaceList();
- unsigned int listSize = (uriListC) ? uriListC->size() : 0;
- if (listSize) {
- ValueVectorOf<unsigned int> tmpURIList(listSize, fMemoryManager);
- for (unsigned int i=0; i < listSize; i++) {
- unsigned int uriName = uriListC->elementAt(i);
- if (uriListR && uriListR->containsElement(uriName)) {
- tmpURIList.addElement(uriName);
- }
- }
- resultWildCard->setNamespaceList(&tmpURIList);
- }
- else {
- resultWildCard->resetNamespaceList();
- }
- return;
- }
- // If the two are negations of different namespace names, then:
- // if one is a negation of absent, then result is negation of namespace
- // else intersection is not expressible.
- if (typeR == XMLAttDef::Any_Other && typeC == XMLAttDef::Any_Other) {
- QName* qnameR = resultWildCard->getAttName();
- if (qnameR->getURI() != compareWildCard->getAttName()->getURI()) {
- if (qnameR->getURI() == (unsigned int)fEmptyNamespaceURI) {
- qnameR->setURI(compareWildCard->getAttName()->getURI());
- }
- else if (compareWildCard->getAttName()->getURI() != (unsigned int)fEmptyNamespaceURI) {
- qnameR->setURI(fEmptyNamespaceURI);
- resultWildCard->setType(XMLAttDef::AttTypes_Unknown);
- }
- }
- }
- }
- void
- TraverseSchema::attWildCardUnion(SchemaAttDef* const resultWildCard,
- const SchemaAttDef* const compareWildCard) {
- XMLAttDef::AttTypes typeR = resultWildCard->getType();
- XMLAttDef::AttTypes typeC = compareWildCard->getType();
- //If either O1 or O2 is any, then the other must be the value.
- if (typeR == XMLAttDef::Any_Any ||
- typeR == XMLAttDef::AttTypes_Unknown) {
- return;
- }
- if (typeC == XMLAttDef::Any_Any ||
- typeC == XMLAttDef::AttTypes_Unknown) {
- resultWildCard->resetNamespaceList();
- copyWildCardData(compareWildCard, resultWildCard);
- return;
- }
- // If both O1 and O2 are sets, then the union of those sets must be
- // the value.
- if (typeR == XMLAttDef::Any_List && typeC == XMLAttDef::Any_List) {
- ValueVectorOf<unsigned int>* uriListR = resultWildCard->getNamespaceList();
- ValueVectorOf<unsigned int>* uriListC = compareWildCard->getNamespaceList();
- unsigned int listSizeC = (uriListC) ? uriListC->size() : 0;
- if (listSizeC) {
- if (!uriListR || !uriListR->size()) {
- resultWildCard->setNamespaceList(uriListC);
- return;
- }
- ValueVectorOf<unsigned int> tmpURIList(*uriListR);
- for (unsigned int i = 0; i < listSizeC; i++) {
- unsigned int uriName = uriListC->elementAt(i);
- if (!uriListR->containsElement(uriName)) {
- tmpURIList.addElement(uriName);
- }
- }
- resultWildCard->setNamespaceList(&tmpURIList);
- }
- return;
- }
- // If the two are negations of different namespace names, then not and
- // absent must be the value
- if (typeR == XMLAttDef::Any_Other && typeC == XMLAttDef::Any_Other) {
- QName* qnameR = resultWildCard->getAttName();
- if (qnameR->getURI() != compareWildCard->getAttName()->getURI()) {
- qnameR->setURI(fEmptyNamespaceURI);
- resultWildCard->setType(XMLAttDef::Any_Other);
- }
- }
- // 5. If either O1 or O2 is a pair of not and a namespace name and the
- // other is a set, then:
- // 1. If the set includes both the negated namespace name and absent
- // then any must be the value.
- // 2. If the set includes the negated namespace name but not absent,
- // then a pair of not and absent must be the value.
- // 3. If the set includes absent but not the negated namespace name,
- // then the union is not expressible.
- // 4. If the set does not include either the negated namespace or
- // absent, then whichever of O1 or O2 is a pair of not and a
- // namespace name.
- //
- // 6. If either O1 or O2 is a pair of not and absent and the other is a
- // set, then:
- // 1. If the set includes absent then any must be the value.
- // 2. If the set does not include absent, then a pair of not and
- // absent.
- if ((typeC == XMLAttDef::Any_Other && typeR == XMLAttDef::Any_List) ||
- (typeR == XMLAttDef::Any_Other && typeC == XMLAttDef::Any_List)) {
- ValueVectorOf<unsigned int>* nameURIList = 0;
- QName* attNameR = resultWildCard->getAttName();
- unsigned int compareURI = 0;
- if (typeC == XMLAttDef::Any_List) {
- nameURIList = compareWildCard->getNamespaceList();
- compareURI = attNameR->getURI();
- }
- else {
- nameURIList = resultWildCard->getNamespaceList();
- compareURI = compareWildCard->getAttName()->getURI();
- }
- // 6. not and absent
- if (compareURI == (unsigned int) fEmptyNamespaceURI) {
- if (nameURIList) {
- // 6.1 result is any
- if (nameURIList->containsElement(compareURI)) {
- resultWildCard->setType(XMLAttDef::Any_Any);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- // 6.2 result is not and absent
- else if (typeR == XMLAttDef::Any_List){
- resultWildCard->setType(XMLAttDef::Any_Other);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- }
- // 6.2 result is not and absent
- else if (typeR == XMLAttDef::Any_List) {
- resultWildCard->setType(XMLAttDef::Any_Other);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- }
- // 5. not and namespace
- else {
- // 5.3 result is not expressible
- if (!nameURIList) {
- resultWildCard->setType(XMLAttDef::AttTypes_Unknown);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- else {
- bool containsAbsent =
- nameURIList->containsElement(fEmptyNamespaceURI);
- bool containsNamespace =
- nameURIList->containsElement(compareURI);
- // 5.1 result is any
- if (containsAbsent && containsNamespace) {
- resultWildCard->setType(XMLAttDef::Any_Any);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- // 5.2 result is not and absent
- else if (containsNamespace) {
- resultWildCard->setType(XMLAttDef::Any_Other);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- // 5.3 result is not expressible
- else if (containsAbsent) {
- resultWildCard->setType(XMLAttDef::AttTypes_Unknown);
- attNameR->setURI(fEmptyNamespaceURI);
- }
- // 5.4. whichever is not and namespace
- else if (typeR == XMLAttDef::Any_List) {
- resultWildCard->setType(XMLAttDef::Any_Other);
- attNameR->setURI(compareURI);
- }
- }
- }
- resultWildCard->resetNamespaceList();
- }
- }
- void TraverseSchema::checkAttDerivationOK(const DOMElement* const elem,
- const ComplexTypeInfo* const baseTypeInfo,
- const ComplexTypeInfo* const childTypeInfo) {
- SchemaAttDefList& childAttList = (SchemaAttDefList&) childTypeInfo->getAttDefList();
- const SchemaAttDef* baseAttWildCard = baseTypeInfo->getAttWildCard();
- while (childAttList.hasMoreElements()) {
- SchemaAttDef& childAttDef = (SchemaAttDef&) childAttList.nextElement();
- QName* childAttName = childAttDef.getAttName();
- const XMLCh* childLocalPart = childAttName->getLocalPart();
- const SchemaAttDef* baseAttDef = baseTypeInfo->getAttDef(childLocalPart, childAttName->getURI());
- if (baseAttDef) {
- XMLAttDef::DefAttTypes baseAttDefType = baseAttDef->getDefaultType();
- XMLAttDef::DefAttTypes childAttDefType = childAttDef.getDefaultType();
- // Constraint 2.1.1 & 3 + check for prohibited base attribute
- if (baseAttDefType == XMLAttDef::Prohibited
- && childAttDefType != XMLAttDef::Prohibited) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_8, childLocalPart);
- }
- if ((baseAttDefType & XMLAttDef::Required)
- && !(childAttDefType & XMLAttDef::Required)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_2, childLocalPart);
- }
- // Constraint 2.1.2
- DatatypeValidator* baseDV = baseAttDef->getDatatypeValidator();
- DatatypeValidator* childDV = childAttDef.getDatatypeValidator();
- if (!baseDV || !baseDV->isSubstitutableBy(childDV)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_3, childLocalPart);
- }
- // Constraint 2.1.3
- if ((baseAttDefType & XMLAttDef::Fixed) &&
- (!(childAttDefType & XMLAttDef::Fixed) ||
- !XMLString::equals(baseAttDef->getValue(), childAttDef.getValue()))) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_4, childLocalPart);
- }
- }
- // Constraint 2.2
- else if (!baseAttWildCard ||
- !wildcardAllowsNamespace(baseAttWildCard, childAttName->getURI())) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_5, childLocalPart);
- }
- }
- // Constraint 4
- const SchemaAttDef* childAttWildCard = childTypeInfo->getAttWildCard();
- if (childAttWildCard) {
- if (!baseAttWildCard) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_6);
- }
- else if (!isWildCardSubset(baseAttWildCard, childAttWildCard)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_7);
- }
- else if (childAttWildCard->getDefaultType() < baseAttWildCard->getDefaultType()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_9);
- }
- }
- }
- void TraverseSchema::checkAttDerivationOK(const DOMElement* const elem,
- const XercesAttGroupInfo* const baseAttGrpInfo,
- const XercesAttGroupInfo* const childAttGrpInfo) {
- unsigned int baseAttCount = baseAttGrpInfo->attributeCount();
- unsigned int baseAnyAttCount = baseAttGrpInfo->anyAttributeCount();
- unsigned int childAttCount = childAttGrpInfo->attributeCount();
- unsigned int childAnyAttCount = childAttGrpInfo->anyAttributeCount();
- if ((childAttCount || childAnyAttCount) && (!baseAttCount && !baseAnyAttCount)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_1);
- }
- const SchemaAttDef* baseAttWildCard = (baseAnyAttCount) ? baseAttGrpInfo->anyAttributeAt(0) : 0;
- for (unsigned int i=0; i<childAttCount; i++) {
- const SchemaAttDef* childAttDef = childAttGrpInfo->attributeAt(i);
- QName* childAttName = childAttDef->getAttName();
- const XMLCh* childLocalPart = childAttName->getLocalPart();
- const SchemaAttDef* baseAttDef = baseAttGrpInfo->getAttDef(childLocalPart, childAttName->getURI());
- if (baseAttDef) {
- XMLAttDef::DefAttTypes baseAttDefType = baseAttDef->getDefaultType();
- XMLAttDef::DefAttTypes childAttDefType = childAttDef->getDefaultType();
- // Constraint 2.1.1 & 3 + check for prohibited base attribute
- if (baseAttDefType == XMLAttDef::Prohibited
- && childAttDefType != XMLAttDef::Prohibited) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_8, childLocalPart);
- }
- if ((baseAttDefType & XMLAttDef::Required)
- && !(childAttDefType & XMLAttDef::Required)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_2, childLocalPart);
- }
- // Constraint 2.1.2
- DatatypeValidator* baseDV = baseAttDef->getDatatypeValidator();
- DatatypeValidator* childDV = childAttDef->getDatatypeValidator();
- if (!baseDV || !baseDV->isSubstitutableBy(childDV)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_3, childLocalPart);
- }
- // Constraint 2.1.3
- if ((baseAttDefType & XMLAttDef::Fixed) &&
- (!(childAttDefType & XMLAttDef::Fixed) ||
- !XMLString::equals(baseAttDef->getValue(), childAttDef->getValue()))) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_4, childLocalPart);
- }
- }
- // Constraint 2.2
- else if (!baseAttWildCard ||
- !wildcardAllowsNamespace(baseAttWildCard, childAttName->getURI())) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_5, childLocalPart);
- }
- }
- // Constraint 4
- const SchemaAttDef* childAttWildCard = (childAnyAttCount) ? childAttGrpInfo->anyAttributeAt(0) : 0;
- if (childAttWildCard) {
- if (!baseAttWildCard) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_6);
- }
- else if (!isWildCardSubset(baseAttWildCard, childAttWildCard)) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_7);
- }
- else if (childAttWildCard->getDefaultType() < baseAttWildCard->getDefaultType()) {
- reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::BadAttDerivation_9);
- }
- }
- }
- bool TraverseSchema::wildcardAllowsNamespace(const SchemaAttDef* const wildCard,
- const unsigned int nameURI) {
- XMLAttDef::AttTypes wildCardType = wildCard->getType();
- // The constraint must be any
- if (wildCardType == XMLAttDef::Any_Any) {
- return true;
- }
- // All of the following must be true:
- // 2.1 The constraint is a pair of not and a namespace name or 穉bsent
- // 2.2 The value must not be identical to the 穘amespace test