void XSModel::addS4SToXSModel(XSNamespaceItem* const namespaceItem, RefHashTableOf<DatatypeValidator>* const builtInDV) { addComponentToNamespace ( namespaceItem , fObjFactory->addOrFind ( ComplexTypeInfo::getAnyType ( fURIStringPool->getId(XMLUni::fgZeroLenString) ) , this ) , XSConstants::TYPE_DEFINITION - 1 ); // Loop through built-in simple types // First add 'anySimpleType' which is the base for the other built-ins DatatypeValidator* dv = builtInDV->get(SchemaSymbols::fgDT_ANYSIMPLETYPE); addComponentToNamespace ( namespaceItem , fObjFactory->addOrFind(dv, this, true) , XSConstants::TYPE_DEFINITION - 1 ); // add remaining built-in RefHashTableOfEnumerator<DatatypeValidator> simpleEnum = RefHashTableOfEnumerator<DatatypeValidator> (builtInDV, false, fMemoryManager); while (simpleEnum.hasMoreElements()) { DatatypeValidator& curSimple = simpleEnum.nextElement(); if (&curSimple == dv) continue; addComponentToNamespace ( namespaceItem , fObjFactory->addOrFind(&curSimple, this) , XSConstants::TYPE_DEFINITION - 1 ); } // Set flag to indicate that we have added S4S grammar info fAddedS4SGrammar = true; }
DOMDocument* XQillaBuilderImpl::getDocumentAndAddGrammar() { DOMDocument *doc = 0; #if _XERCES_VERSION >= 30000 if (getParameter(XMLUni::fgXercesUserAdoptsDOMDocument) != 0) #else if (getFeature(XMLUni::fgXercesUserAdoptsDOMDocument)) #endif doc = adoptDocument(); else doc = getDocument(); if(doc == 0) { return 0; } if(getParameter(XMLUni::fgXercesDOMHasPSVIInfo)) { //we copy this gramamr and reset the parser one in the process. XMLGrammarPool *oldGrPool = getGrammarResolver()->getGrammarPool(); XQillaXMLGrammarPoolImpl *gr = new (getMemoryManager()) XQillaXMLGrammarPoolImpl(getMemoryManager()); // manually copy string pool contents to work around XERCESC-1798. const XMLStringPool* src = oldGrPool->getURIStringPool(); XMLStringPool* dst = gr->getURIStringPool(); for (unsigned int i = 1; i < src->getStringCount() + 1; ++i) dst->addOrFind (src->getValueForId(i)); RefHashTableOfEnumerator< Grammar> enumerator = oldGrPool->getGrammarEnumerator(); while(enumerator.hasMoreElements()) { Grammar &g = enumerator.nextElement(); gr->cacheGrammar(getGrammarResolver()->orphanGrammar(g.getGrammarDescription()->getGrammarKey())); } ((XQillaDocumentImpl*)doc)->setGrammarPool(gr, true); } return doc; }
void XSModel::addGrammarToXSModel(XSNamespaceItem* namespaceItem) { // Loop through top-level attribute declarations in the grammar... RefHashTableOf<XMLAttDef>* attDeclRegistry = namespaceItem->fGrammar->getAttributeDeclRegistry(); if(attDeclRegistry) { RefHashTableOfEnumerator<XMLAttDef> attrEnum = RefHashTableOfEnumerator<XMLAttDef> (attDeclRegistry, false, fMemoryManager); while (attrEnum.hasMoreElements()) { XSAttributeDeclaration* xsAttrDecl = fObjFactory->addOrFind ( (SchemaAttDef*) &(attrEnum.nextElement()), this ); 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 ); 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... RefHashTableOf<ComplexTypeInfo>* complexTypeRegistry = namespaceItem->fGrammar->getComplexTypeRegistry(); if(complexTypeRegistry) { RefHashTableOfEnumerator<ComplexTypeInfo> complexEnum = RefHashTableOfEnumerator<ComplexTypeInfo> (complexTypeRegistry, 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... RefHashTableOf<XercesAttGroupInfo>* attGroupInfoRegistry = namespaceItem->fGrammar->getAttGroupInfoRegistry(); if(attGroupInfoRegistry) { RefHashTableOfEnumerator<XercesAttGroupInfo> attrGroupEnum = RefHashTableOfEnumerator<XercesAttGroupInfo> (attGroupInfoRegistry, 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... RefHashTableOf<XercesGroupInfo>* groupInfoRegistry = namespaceItem->fGrammar->getGroupInfoRegistry(); if(groupInfoRegistry) { RefHashTableOfEnumerator<XercesGroupInfo> modelGroupEnum = RefHashTableOfEnumerator<XercesGroupInfo> (groupInfoRegistry, 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); addComponentToIdVector(annot, XSConstants::ANNOTATION -1); annot = annot->getNext(); } // end of annotation loop }
XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // XSModel: Constructors and Destructor // --------------------------------------------------------------------------- XSModel::XSModel( XMLGrammarPool *grammarPool , MemoryManager* const manager) : fMemoryManager(manager) , fNamespaceStringList(0) , fXSNamespaceItemList(0) , fURIStringPool(0) , fXSAnnotationList(0) , fHashNamespace(0) , fObjFactory(0) , fDeleteNamespace(0) , fParent(0) , fDeleteParent(false) , fAddedS4SGrammar(false) { fURIStringPool = grammarPool->getURIStringPool(); fObjFactory = new (fMemoryManager) XSObjectFactory(manager); // Populate XSNamedMaps by going through the components for (unsigned int i=0; i<XSConstants::MULTIVALUE_FACET; i++) { switch (i+1) { case XSConstants::ATTRIBUTE_DECLARATION: case XSConstants::ELEMENT_DECLARATION: case XSConstants::TYPE_DEFINITION: case XSConstants::ATTRIBUTE_GROUP_DEFINITION: case XSConstants::MODEL_GROUP_DEFINITION: case XSConstants::NOTATION_DECLARATION: fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject> ( 20, // size 29, // modulus fURIStringPool, false, // adoptElems fMemoryManager ); break; default: // ATTRIBUTE_USE // MODEL_GROUP // PARTICLE // IDENTITY_CONSTRAINT // WILDCARD // ANNOTATION // FACET // MULTIVALUE fComponentMap[i] = 0; break; } fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager); } fNamespaceStringList = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager); fXSNamespaceItemList = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager); fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (10, false, manager); fHashNamespace = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager); // Loop through all grammars in the grammar pool to create the XSNamespaceItem's // which will have access to Annotation Information which can be used later when // we create all the XS components. XSNamespaceItem* namespaceItem = 0; RefHashTableOfEnumerator<Grammar> grammarEnum = grammarPool->getGrammarEnumerator(); while (grammarEnum.hasMoreElements()) { SchemaGrammar& sGrammar = (SchemaGrammar&) grammarEnum.nextElement(); if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType || XMLString::equals(sGrammar.getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) continue; // NOTE: In the grammarpool, preprocessed grammars without targetnamespace // will use an empty string... XMLCh* NameSpace = XMLString::replicate(sGrammar.getTargetNamespace(), manager); fNamespaceStringList->addElement(NameSpace); namespaceItem = new (manager) XSNamespaceItem(this, &sGrammar, manager); fXSNamespaceItemList->addElement(namespaceItem); fHashNamespace->put(NameSpace, namespaceItem); } // Now loop through all of the NamespaceItem's // First, we add S4S namespace (irrespective of whether we have any grammars) namespaceItem = new (manager) XSNamespaceItem ( this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager ); fNamespaceStringList->addElement ( XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager) ); fXSNamespaceItemList->addElement(namespaceItem); fHashNamespace->put ( (void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA , namespaceItem ); DatatypeValidatorFactory dvFactory(manager); dvFactory.expandRegistryToFullSchemaSet(); addS4SToXSModel ( namespaceItem , dvFactory.getBuiltInRegistry() ); // don't include S4S (thus the -1) unsigned int numberOfNamespaces = fXSNamespaceItemList->size() -1; for (unsigned int j = 0; j < numberOfNamespaces; j++) addGrammarToXSModel(fXSNamespaceItemList->elementAt(j)); }