xsobjectfactory.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,121 行 · 第 1/3 页
CPP
1,121 行
bool primitiveTypeSelf = false; //REVISIT: the getFixed method is protected so added friend XSObjectFactory // to DatatypeValidator class... DatatypeValidator::ValidatorType dvType = validator->getType(); DatatypeValidator* baseDV = validator->getBaseValidator(); if (dvType == DatatypeValidator::Union) { typeVariety = XSSimpleTypeDefinition::VARIETY_UNION; RefVectorOf<DatatypeValidator>* membersDV = ((UnionDatatypeValidator*)validator)->getMemberTypeValidators(); unsigned int size = membersDV->size(); if (size) { memberTypes = new (fMemoryManager) RefVectorOf<XSSimpleTypeDefinition>(size, false, fMemoryManager); for (unsigned int i=0; i<size; i++) memberTypes->addElement(addOrFind(membersDV->elementAt(i), xsModel)); } if (baseDV) { baseType = addOrFind(baseDV, xsModel); } else { baseType = (XSSimpleTypeDefinition*) xsModel->getTypeDefinition ( SchemaSymbols::fgDT_ANYSIMPLETYPE , SchemaSymbols::fgURI_SCHEMAFORSCHEMA ); } } else if (dvType == DatatypeValidator::List) { typeVariety = XSSimpleTypeDefinition::VARIETY_LIST; if (baseDV->getType() == DatatypeValidator::List) { baseType = addOrFind(baseDV, xsModel); primitiveOrItemType = ((XSSimpleTypeDefinition*) baseType)->getItemType(); } else { baseType = (XSSimpleTypeDefinition*) xsModel->getTypeDefinition ( SchemaSymbols::fgDT_ANYSIMPLETYPE , SchemaSymbols::fgURI_SCHEMAFORSCHEMA ); primitiveOrItemType = addOrFind(baseDV, xsModel); } } else if (!isAnySimpleType) { if (baseDV) { baseType = addOrFind(baseDV, xsModel); primitiveOrItemType = ((XSSimpleTypeDefinition*) baseType)->getPrimitiveType(); } else // built-in { baseType = (XSSimpleTypeDefinition*) xsModel->getTypeDefinition ( SchemaSymbols::fgDT_ANYSIMPLETYPE , SchemaSymbols::fgURI_SCHEMAFORSCHEMA ); primitiveTypeSelf = true; } } else { baseType = xsModel->getTypeDefinition(SchemaSymbols::fgATTVAL_ANYTYPE, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); } xsObj = new (fMemoryManager) XSSimpleTypeDefinition ( validator , typeVariety , baseType , primitiveOrItemType , memberTypes , getAnnotationFromModel(xsModel, validator) , xsModel , fMemoryManager ); putObjectInMap(validator, xsObj); if (primitiveTypeSelf) xsObj->setPrimitiveType(xsObj); // process facets processFacets(validator, xsModel, xsObj); } return xsObj;}XSElementDeclaration*XSObjectFactory::addOrFind(SchemaElementDecl* const elemDecl, XSModel* const xsModel, XSComplexTypeDefinition* const enclosingTypeDef){ XSElementDeclaration* xsObj = (XSElementDeclaration*) xsModel->getXSObject(elemDecl); if (xsObj) { if (!xsObj->getEnclosingCTDefinition() && enclosingTypeDef) xsObj->setEnclosingCTDefinition(enclosingTypeDef); } else { XSElementDeclaration* xsSubElem = 0; XSTypeDefinition* xsType = 0; XSNamedMap<XSIDCDefinition>* icMap = 0; if (elemDecl->getSubstitutionGroupElem()) xsSubElem = addOrFind(elemDecl->getSubstitutionGroupElem(), xsModel); // defer checking for complexTypeInfo until later as it could // eventually need this elemement // but don't check simple type unless no complexTypeInfo present if (!elemDecl->getComplexTypeInfo() && elemDecl->getDatatypeValidator()) xsType = addOrFind(elemDecl->getDatatypeValidator(), xsModel); unsigned int count = elemDecl->getIdentityConstraintCount(); if (count) { //REVISIT: size of hash table.... icMap = new (fMemoryManager) XSNamedMap<XSIDCDefinition> ( count , 29 , xsModel->getURIStringPool() , false , fMemoryManager ); for (unsigned int i = 0; i < count; i++) { XSIDCDefinition* icDef = addOrFind ( elemDecl->getIdentityConstraintAt(i) , xsModel ); if (icDef) { icMap->addElement ( icDef , icDef->getName() , icDef->getNamespace() ); } } } XSConstants::SCOPE elemScope = XSConstants::SCOPE_ABSENT; if (elemDecl->getPSVIScope() == PSVIDefs::SCP_LOCAL) elemScope = XSConstants::SCOPE_LOCAL; else if (elemDecl->getPSVIScope() == PSVIDefs::SCP_GLOBAL) elemScope = XSConstants::SCOPE_GLOBAL; xsObj = new (fMemoryManager) XSElementDeclaration ( elemDecl , xsType , xsSubElem , getAnnotationFromModel(xsModel, elemDecl) , icMap , xsModel , elemScope , enclosingTypeDef , fMemoryManager ); putObjectInMap(elemDecl, xsObj); if (elemDecl->getComplexTypeInfo()) { xsType = addOrFind(elemDecl->getComplexTypeInfo(), xsModel); xsObj->setTypeDefinition(xsType); } else if (!xsType) { xsType = xsModel->getTypeDefinition ( SchemaSymbols::fgATTVAL_ANYTYPE , SchemaSymbols::fgURI_SCHEMAFORSCHEMA ); xsObj->setTypeDefinition(xsType); } } return xsObj;}XSComplexTypeDefinition*XSObjectFactory::addOrFind(ComplexTypeInfo* const typeInfo, XSModel* const xsModel){ XSComplexTypeDefinition* xsObj = (XSComplexTypeDefinition*) xsModel->getXSObject(typeInfo); if (!xsObj) { XSWildcard* xsWildcard = 0; XSSimpleTypeDefinition* xsSimpleType = 0; XSAttributeUseList* xsAttList = 0; XSTypeDefinition* xsBaseType = 0; XSParticle* xsParticle = 0; if (typeInfo->getAttWildCard()) xsWildcard = createXSWildcard(typeInfo->getAttWildCard(), xsModel); if ((typeInfo->getContentType() == SchemaElementDecl::Simple) && (typeInfo->getDatatypeValidator())) xsSimpleType = addOrFind(typeInfo->getDatatypeValidator(), xsModel); unsigned int attCount; if (typeInfo->hasAttDefs()) { SchemaAttDefList& attDefList = (SchemaAttDefList&) typeInfo->getAttDefList(); attCount = attDefList.getAttDefCount(); xsAttList = new (fMemoryManager) RefVectorOf<XSAttributeUse>(attCount, false, fMemoryManager); // create list now put fill it in after we put complextype into map // otherwise we may encounter an infinite loop: complextype needs to // addorfind attdef, which does an addorfind on the enclosingCTdefintion. } // compute fBase bool isAnyType = false; if (typeInfo->getBaseComplexTypeInfo() == typeInfo) // case of anyType isAnyType = true; else if (typeInfo->getBaseComplexTypeInfo()) xsBaseType = addOrFind(typeInfo->getBaseComplexTypeInfo(), xsModel); else if (typeInfo->getBaseDatatypeValidator()) xsBaseType = addOrFind(typeInfo->getBaseDatatypeValidator(), xsModel); else // base is anyType xsBaseType = xsModel->getTypeDefinition(SchemaSymbols::fgATTVAL_ANYTYPE, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); // compute particle ContentSpecNode* contentSpec = typeInfo->getContentSpec(); if (contentSpec) xsParticle = createModelGroupParticle(contentSpec, xsModel); xsObj = new (fMemoryManager) XSComplexTypeDefinition ( typeInfo , xsWildcard , xsSimpleType , xsAttList , xsBaseType , xsParticle , getAnnotationFromModel(xsModel, typeInfo) , xsModel , fMemoryManager ); putObjectInMap(typeInfo, xsObj); if (isAnyType) xsObj->setBaseType(xsObj); if (typeInfo->hasAttDefs()) { // now create the xsattributedeclarations... SchemaAttDefList& attDefList = (SchemaAttDefList&) typeInfo->getAttDefList(); for(unsigned int i=0; i<attCount; i++) { XSAttributeDeclaration* xsAttDecl = 0; SchemaAttDef& attDef = (SchemaAttDef&) attDefList.getAttDef(i); if (attDef.getBaseAttDecl()) { xsAttDecl = addOrFind(attDef.getBaseAttDecl(), xsModel); fXercesToXSMap->put(&attDef, xsAttDecl); } else xsAttDecl = addOrFind(&attDef, xsModel, xsObj); if (attDef.getDefaultType() != XMLAttDef::Prohibited) { XSAttributeUse* attUse = createXSAttributeUse(xsAttDecl, xsModel); xsAttList->addElement(attUse); processAttUse(&attDef, attUse); } } } // process local elements unsigned int elemCount = typeInfo->elementCount(); for (unsigned int j=0; j<elemCount; j++) { SchemaElementDecl* elemDecl = typeInfo->elementAt(j); if (elemDecl->getEnclosingScope() == typeInfo->getScopeDefined() && elemDecl->getPSVIScope() == PSVIDefs::SCP_LOCAL) addOrFind(elemDecl, xsModel, xsObj); } } return xsObj;}XSIDCDefinition* XSObjectFactory::addOrFind(IdentityConstraint* const ic, XSModel* const xsModel){ XSIDCDefinition* xsObj = (XSIDCDefinition*) xsModel->getXSObject(ic); if (!xsObj) { XSIDCDefinition* keyIC = 0; StringList* stringList = 0; unsigned int fieldCount = ic->getFieldCount(); if (fieldCount) { stringList = new (fMemoryManager) RefArrayVectorOf<XMLCh>( fieldCount, true, fMemoryManager); for(unsigned int i=0; i<fieldCount; i++) { XMLCh* expr = XMLString::replicate ( ic->getFieldAt(i)->getXPath()->getExpression() , fMemoryManager ); stringList->addElement(expr); } } if (ic->getType() == IdentityConstraint::KEYREF) keyIC = addOrFind(((IC_KeyRef*) ic)->getKey(), xsModel); xsObj= new (fMemoryManager) XSIDCDefinition ( ic , keyIC , getAnnotationFromModel(xsModel, ic) , stringList , xsModel , fMemoryManager ); putObjectInMap(ic, xsObj); } return xsObj;}XSNotationDeclaration* XSObjectFactory::addOrFind(XMLNotationDecl* const notDecl, XSModel* const xsModel){ XSNotationDeclaration* xsObj = (XSNotationDeclaration*) xsModel->getXSObject(notDecl); if (!xsObj) { xsObj = new (fMemoryManager) XSNotationDeclaration ( notDecl , getAnnotationFromModel(xsModel, notDecl) , xsModel , fMemoryManager ); putObjectInMap(notDecl, xsObj); } return xsObj;}XSAttributeUse*XSObjectFactory::createXSAttributeUse(XSAttributeDeclaration* const xsAttDecl, XSModel* const xsModel){ XSAttributeUse* attrUse = new (fMemoryManager) XSAttributeUse(xsAttDecl, xsModel, fMemoryManager); fDeleteVector->addElement(attrUse); return attrUse;}XSWildcard*XSObjectFactory::createXSWildcard(SchemaAttDef* const attDef, XSModel* const xsModel){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?