/** * \brief Helper function for initializing the Declaration. * * \param particle The XSParticle to create the Declaration from. * \param xsdcontent The XSDContent to create the Declaration from. * \param type The Type of the Declaration. */ void Declaration::init(XSParticle& particle, XSDContent* xsdcontent, const Type* type) { mMinOccurs = particle.getMinOccurs(); mMaxOccurs = particle.getMaxOccurs(); mUnbounded = particle.getMaxOccursUnbounded(); XSElementDeclaration* dec = particle.getElementTerm(); if (dec) { StrX name(dec->getName()); mName = name.str(); if (type) { mType = type; } else if (xsdcontent) { mType = &xsdcontent->getType(StrX(dec->getTypeDefinition()->getName()).str(), StrX(dec->getTypeDefinition()->getNamespace()).str()); } else { Error e("Neither Type nor XSDContent in Declaration constructor."); throw e; } } else { Error e("No XSElementDeclaration in Declaration constructor."); throw e; } }
void processParticle(XSParticle *xsParticle) { if (!xsParticle) { XERCES_STD_QUALIFIER cout << "xsParticle is NULL"; return; } XSParticle::TERM_TYPE termType = xsParticle->getTermType(); if (termType == XSParticle::TERM_ELEMENT) { XSElementDeclaration *xsElement = xsParticle->getElementTerm(); XERCES_STD_QUALIFIER cout << StrX(xsElement->getName()); } else if (termType == XSParticle::TERM_MODELGROUP) { XERCES_STD_QUALIFIER cout << "("; XSModelGroup *xsModelGroup = xsParticle->getModelGroupTerm(); XSModelGroup::COMPOSITOR_TYPE compositorType = xsModelGroup->getCompositor(); XSParticleList *xsParticleList = xsModelGroup->getParticles(); for (unsigned i = 0; i < xsParticleList->size()-1; i++) { processParticle(xsParticleList->elementAt(i)); printCompositorTypeConnector(compositorType); } processParticle(xsParticleList->elementAt(xsParticleList->size()-1)); XERCES_STD_QUALIFIER cout << ")"; } else if (termType == XSParticle::TERM_WILDCARD) { XERCES_STD_QUALIFIER cout << "* (wildcard)"; } }
void processElements(XSNamedMap<XSObject> *xsElements) { if (!xsElements || xsElements->getLength() == 0) { XERCES_STD_QUALIFIER cout << "no elements\n\n" << XERCES_STD_QUALIFIER endl; return; } for (XMLSize_t i=0; i < xsElements->getLength(); i++) { XSElementDeclaration *xsElement = (XSElementDeclaration *)xsElements->item(i); printBasic(xsElement, "Element"); // Content Model XSTypeDefinition *xsTypeDef = xsElement->getTypeDefinition(); XERCES_STD_QUALIFIER cout << "Content Model" << "\n"; XERCES_STD_QUALIFIER cout << "\tType:\t"; if (xsTypeDef->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE) { XERCES_STD_QUALIFIER cout << "Simple\n"; } else { XERCES_STD_QUALIFIER cout << "Complex\n"; } XERCES_STD_QUALIFIER cout << "\tName:\t" << StrX(xsTypeDef->getName()) << "\n"; XERCES_STD_QUALIFIER cout << "\n--------------------------------------------" << XERCES_STD_QUALIFIER endl; } }
/** * \brief Handles a single XSParticle. * * \param xsParticle The XSParticle to handle. */ void TypeDefinition::processParticle(XSParticle& xsParticle) { XSParticle::TERM_TYPE termType = xsParticle.getTermType(); if (termType == XSParticle::TERM_ELEMENT) { XSElementDeclaration* dec = xsParticle.getElementTerm(); string nameSpace = StrX(mXSTypeDefinition.getNamespace()).str(); if (getName() == StrX(dec->getTypeDefinition()->getName() ).str() && nameSpace == StrX(dec->getTypeDefinition()->getNamespace()).str()) { Declaration* dec = new Declaration(xsParticle, this); appendSubElement(*dec); } else { Declaration *dec = new Declaration(xsParticle, mXSDContent); appendSubElement(*dec); } } else if (termType == XSParticle::TERM_MODELGROUP) { processParticles(*xsParticle.getModelGroupTerm()); } else if (termType == XSParticle::TERM_WILDCARD) { approxsimDebug("* (wildcard) NOT IMPLEMENTED"); } }
void XSModel::addGrammarToXSModel(XSNamespaceItem* namespaceItem) { // Loop through top-level attribute declarations in the grammar... RefHashTableOfEnumerator<XMLAttDef> attrEnum = RefHashTableOfEnumerator<XMLAttDef> (namespaceItem->fGrammar->getAttributeDeclRegistry(), false, fMemoryManager); while (attrEnum.hasMoreElements()) { XSAttributeDeclaration* xsAttrDecl = fObjFactory->addOrFind ( (SchemaAttDef*) &(attrEnum.nextElement()), this ); xsAttrDecl->setId(fAttributeDeclarationVector->size()); fAttributeDeclarationVector->addElement(xsAttrDecl); addComponentToNamespace ( namespaceItem, xsAttrDecl, XSConstants::ATTRIBUTE_DECLARATION - 1 ); } // end of attribute loop // Loop through top-level elements in the grammar... RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = namespaceItem->fGrammar->getElemEnumerator(); while (elemEnum.hasMoreElements()) { SchemaElementDecl& curElem = elemEnum.nextElement(); if (curElem.getEnclosingScope() == Grammar::TOP_LEVEL_SCOPE) { XSElementDeclaration* xsElemDecl = fObjFactory->addOrFind ( &curElem, this ); xsElemDecl->setId(fElementDeclarationVector->size()); fElementDeclarationVector->addElement(xsElemDecl); addComponentToNamespace ( namespaceItem, xsElemDecl, XSConstants::ELEMENT_DECLARATION -1 ); } } // end of element loop // Now loop through top-level User Defined simple type definitions in the grammar... DVHashTable* dvHT = namespaceItem->fGrammar->getDatatypeRegistry()->getUserDefinedRegistry(); if (dvHT) { RefHashTableOfEnumerator<DatatypeValidator> simpleUserEnum = RefHashTableOfEnumerator<DatatypeValidator> (dvHT, false, fMemoryManager); while (simpleUserEnum.hasMoreElements()) { DatatypeValidator& curSimple = simpleUserEnum.nextElement(); if (!curSimple.getAnonymous()) { addComponentToNamespace ( namespaceItem , fObjFactory->addOrFind(&curSimple, this) , XSConstants::TYPE_DEFINITION - 1 ); } } // end of simple User loop } // Loop through top-level COMPLEX type definitions in the grammar... RefHashTableOfEnumerator<ComplexTypeInfo> complexEnum = RefHashTableOfEnumerator<ComplexTypeInfo> (namespaceItem->fGrammar->getComplexTypeRegistry(), false, fMemoryManager); while (complexEnum.hasMoreElements()) { ComplexTypeInfo& curComplex = complexEnum.nextElement(); if (!curComplex.getAnonymous()) { addComponentToNamespace ( namespaceItem , fObjFactory->addOrFind(&curComplex, this) , XSConstants::TYPE_DEFINITION - 1 ); } } // end of type definition loop // Loop through top-level attribute group definitions in the grammar... RefHashTableOfEnumerator<XercesAttGroupInfo> attrGroupEnum = RefHashTableOfEnumerator<XercesAttGroupInfo> (namespaceItem->fGrammar->getAttGroupInfoRegistry(), false, fMemoryManager); while (attrGroupEnum.hasMoreElements()) { addComponentToNamespace ( namespaceItem , fObjFactory->createXSAttGroupDefinition ( &(attrGroupEnum.nextElement()), this ) , XSConstants::ATTRIBUTE_GROUP_DEFINITION - 1 ); } // end of attribute group loop // Loop through top-level model group definitions in the grammar... RefHashTableOfEnumerator<XercesGroupInfo> modelGroupEnum = RefHashTableOfEnumerator<XercesGroupInfo> (namespaceItem->fGrammar->getGroupInfoRegistry(), false, fMemoryManager); while (modelGroupEnum.hasMoreElements()) { addComponentToNamespace ( namespaceItem , fObjFactory->createXSModelGroupDefinition ( &(modelGroupEnum.nextElement()), this ) , XSConstants::MODEL_GROUP_DEFINITION - 1 ); } // end of model group loop // Loop through notations in the grammar... NameIdPoolEnumerator<XMLNotationDecl> notationEnum = namespaceItem->fGrammar->getNotationEnumerator(); while (notationEnum.hasMoreElements()) { addComponentToNamespace ( namespaceItem , fObjFactory->addOrFind(&(notationEnum.nextElement()), this) , XSConstants::NOTATION_DECLARATION - 1 ); } // end of notation loop // Loop through annotations in the grammar... // As annotations are already created as XSAnnotations no need to create them // or store them in the XercesToXSMap. XSAnnotation* annot = namespaceItem->fGrammar->getAnnotation(); while (annot) { fXSAnnotationList->addElement(annot); namespaceItem->fXSAnnotationList->addElement(annot); annot = annot->getNext(); } // end of annotation loop }
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); XMLSize_t count = elemDecl->getIdentityConstraintCount(); if (count) { //REVISIT: size of hash table.... icMap = new (fMemoryManager) XSNamedMap<XSIDCDefinition> ( count , 29 , xsModel->getURIStringPool() , false , fMemoryManager ); for (XMLSize_t 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; }