XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // XSWildcard: Constructors and Destructor // --------------------------------------------------------------------------- XSWildcard::XSWildcard(SchemaAttDef* const attWildCard, XSAnnotation* const annot, XSModel* const xsModel, MemoryManager* const manager) : XSObject(XSConstants::WILDCARD, xsModel, manager) , fConstraintType(NSCONSTRAINT_ANY) , fProcessContents(PC_STRICT) , fNsConstraintList(0) , fAnnotation(annot) { XMLAttDef::AttTypes attType = attWildCard->getType(); if (attType == XMLAttDef::Any_Other) { fConstraintType = NSCONSTRAINT_NOT; fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(1, true, manager); fNsConstraintList->addElement ( XMLString::replicate(fXSModel->getURIStringPool()->getValueForId( attWildCard->getAttName()->getURI()), manager) ); } else if (attType == XMLAttDef::Any_List) { fConstraintType = NSCONSTRAINT_DERIVATION_LIST; ValueVectorOf<unsigned int>* nsList = attWildCard->getNamespaceList(); if (nsList) { unsigned int nsListSize = nsList->size(); if (nsListSize) { fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(nsListSize, true, manager); for (unsigned int i=0; i < nsListSize; i++) { fNsConstraintList->addElement ( XMLString::replicate ( fXSModel->getURIStringPool()->getValueForId ( nsList->elementAt(i) ) , manager ) ); } } } } XMLAttDef::DefAttTypes attDefType = attWildCard->getDefaultType(); if (attDefType == XMLAttDef::ProcessContents_Skip) fProcessContents = PC_SKIP; else if (attDefType == XMLAttDef::ProcessContents_Lax) fProcessContents = PC_LAX; }
bool SubstitutionGroupComparator::isAllowedByWildcard(SchemaGrammar* const pGrammar, QName* const element, unsigned int wuri, bool wother) { // whether the uri is allowed directly by the wildcard unsigned int uriId = element->getURI(); if ((!wother && uriId == wuri) || (wother && uriId != wuri && uriId != XMLContentModel::gEOCFakeId && uriId != XMLContentModel::gEpsilonFakeId && uriId != XMLElementDecl::fgPCDataElemId && uriId != XMLElementDecl::fgInvalidElemId)) { return true; } // get all elements that can substitute the current element RefHash2KeysTableOf<ElemVector>* theValidSubstitutionGroups = pGrammar->getValidSubstitutionGroups(); if (!theValidSubstitutionGroups) return false; ValueVectorOf<SchemaElementDecl*>* subsElements = theValidSubstitutionGroups->get(element->getLocalPart(), uriId); if (!subsElements) return false; // then check whether there exists one element that is allowed by the wildcard int size = subsElements->size(); for (int i = 0; i < size; i++) { unsigned int subUriId = subsElements->elementAt(i)->getElementName()->getURI(); if ((!wother && subUriId == wuri) || (wother && subUriId != wuri && subUriId != XMLContentModel::gEOCFakeId && subUriId != XMLContentModel::gEpsilonFakeId && subUriId != XMLElementDecl::fgPCDataElemId && subUriId != XMLElementDecl::fgInvalidElemId)) { return true; } } return false; }
XSModel::XSModel( XSModel *baseModel , GrammarResolver *grammarResolver , MemoryManager* const manager) : fMemoryManager(manager) , fNamespaceStringList(0) , fXSNamespaceItemList(0) , fURIStringPool(0) , fXSAnnotationList(0) , fHashNamespace(0) , fObjFactory(0) , fDeleteNamespace(0) , fParent(baseModel) , fDeleteParent(true) , fAddedS4SGrammar(false) { fURIStringPool = grammarResolver->getStringPool(); fObjFactory = new (manager) XSObjectFactory(manager); unsigned int i; // Populate XSNamedMaps by going through the components for (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, false, manager); fDeleteNamespace = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager); fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (10, false, manager); fHashNamespace = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager); if (fParent) { if (fParent->fAddedS4SGrammar) fAddedS4SGrammar = true; // Need to copy information from parent so it can be returned in this object... for (i=0; i<fParent->fXSNamespaceItemList->size(); i++) { XSNamespaceItem* namespaceItem = fParent->fXSNamespaceItemList->elementAt(i); fXSNamespaceItemList->addElement(namespaceItem); fNamespaceStringList->addElement ( XMLString::replicate ( namespaceItem->getSchemaNamespace(), manager ) ); } for (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: for (unsigned int j=0; j<fParent->fComponentMap[i]->getLength(); j++) { XSObject* copyObj = fParent->fComponentMap[i]->item(j); fComponentMap[i]->addElement(copyObj, copyObj->getName(), copyObj->getNamespace()); } break; } for (unsigned int j=0; j<fParent->fIdVector[i]->size(); j++) { fIdVector[i]->addElement(fParent->fIdVector[i]->elementAt(j)); } } for (i=0; i<fParent->fXSAnnotationList->size(); i++) { fXSAnnotationList->addElement(fParent->fXSAnnotationList->elementAt(i)); } } // end of copying parent info // Now add information from the new grammars but first create the // XSNamespaceItem's so we can have access to the XSAnnotations... ValueVectorOf<SchemaGrammar*>* grammarsToAdd = grammarResolver->getGrammarsToAddToXSModel(); unsigned int numberOfNamespaces = fXSNamespaceItemList->size(); unsigned int numberOfNamespacesToAdd = 0; for (i=0; i < grammarsToAdd->size(); i++) { SchemaGrammar* lGrammar = grammarsToAdd->elementAt(i); if (lGrammar->getGrammarType() != Grammar::SchemaGrammarType || XMLString::equals(lGrammar->getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) continue; XMLCh* NameSpace = XMLString::replicate(lGrammar->getTargetNamespace(), manager); fNamespaceStringList->addElement(NameSpace); XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem(this, lGrammar, manager); fXSNamespaceItemList->addElement(namespaceItem); fHashNamespace->put(NameSpace, namespaceItem); fDeleteNamespace->addElement(namespaceItem); ++numberOfNamespacesToAdd; } // Add S4S namespace if needed if (!fAddedS4SGrammar) { DatatypeValidatorFactory dvFactory(manager); dvFactory.expandRegistryToFullSchemaSet(); XSNamespaceItem* 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 ); fDeleteNamespace->addElement(namespaceItem); addS4SToXSModel ( namespaceItem , dvFactory.getBuiltInRegistry() ); } // Now loop through all of the newly created NamespaceItem's for (i=numberOfNamespaces; i<(numberOfNamespaces+numberOfNamespacesToAdd); i++) { addGrammarToXSModel(fXSNamespaceItemList->elementAt(i)); } // end of namespaceItem loop }
void XSDDOMParser::startAnnotation( const XMLElementDecl& elemDecl , const RefVectorOf<XMLAttr>& attrList , const unsigned int attrCount) { fAnnotationBuf.append(chOpenAngle); fAnnotationBuf.append(elemDecl.getFullName()); fAnnotationBuf.append(chSpace); // attributes are a bit of a pain. To get this right, we have to keep track // of the namespaces we've seen declared, then examine the namespace context // for other namespaces so that we can also include them. // optimized for simplicity and the case that not many // namespaces are declared on this annotation... fURIs->removeAllElements(); for (unsigned int i=0; i < attrCount; i++) { const XMLAttr* oneAttrib = attrList.elementAt(i); const XMLCh* attrValue = oneAttrib->getValue(); if (XMLString::equals(oneAttrib->getName(), XMLUni::fgXMLNSString)) fURIs->addElement(fScanner->getPrefixId(XMLUni::fgZeroLenString)); else if (!XMLString::compareNString(oneAttrib->getQName(), XMLUni::fgXMLNSColonString, 6)) fURIs->addElement(fScanner->getPrefixId(oneAttrib->getName())); fAnnotationBuf.append(oneAttrib->getQName()); fAnnotationBuf.append(chEqual); fAnnotationBuf.append(chDoubleQuote); fAnnotationBuf.append(attrValue); fAnnotationBuf.append(chDoubleQuote); fAnnotationBuf.append(chSpace); } // now we have to look through currently in-scope namespaces to see what // wasn't declared here ValueVectorOf<PrefMapElem*>* namespaceContext = fScanner->getNamespaceContext(); for (unsigned int j=0; j < namespaceContext->size(); j++) { unsigned int prefId = namespaceContext->elementAt(j)->fPrefId; if (!fURIs->containsElement(prefId)) { const XMLCh* prefix = fScanner->getPrefixForId(prefId); if (XMLString::equals(prefix, XMLUni::fgZeroLenString)) { fAnnotationBuf.append(XMLUni::fgXMLNSString); } else { fAnnotationBuf.append(XMLUni::fgXMLNSColonString); fAnnotationBuf.append(prefix); } fAnnotationBuf.append(chEqual); fAnnotationBuf.append(chDoubleQuote); fAnnotationBuf.append(fScanner->getURIText(namespaceContext->elementAt(j)->fURIId)); fAnnotationBuf.append(chDoubleQuote); fAnnotationBuf.append(chSpace); } } fAnnotationBuf.append(chCloseAngle); fAnnotationBuf.append(chLF); }
DOMElement* SchemaInfo::getTopLevelComponent(const unsigned short compCategory, const XMLCh* const compName, const XMLCh* const name) { if (compCategory >= C_Count) return 0; DOMElement* child = XUtil::getFirstChildElement(fSchemaRootElement); if (!child) return 0; ValueVectorOf<DOMElement*>* compList = fTopLevelComponents[compCategory]; if (fTopLevelComponents[compCategory] == 0) { compList= new (fMemoryManager) ValueVectorOf<DOMElement*>(16, fMemoryManager); fTopLevelComponents[compCategory] = compList; } else { unsigned int listLen = compList->size(); for (unsigned int i= 0; i < listLen; i++) { child = compList->elementAt(i); if (XMLString::equals(child->getAttribute(SchemaSymbols::fgATT_NAME), name)) return child; } } DOMElement* redefParent = (DOMElement*) child->getParentNode(); // Parent is not "redefine" if (!XMLString::equals(redefParent->getLocalName(),SchemaSymbols::fgELT_REDEFINE)) redefParent = 0; while (child != 0) { if (XMLString::equals(child->getLocalName(), compName)) { compList->addElement(child); if (XMLString::equals(child->getAttribute(SchemaSymbols::fgATT_NAME), name)) return child; } else if (XMLString::equals(child->getLocalName(),SchemaSymbols::fgELT_REDEFINE) && (!fFailedRedefineList || !fFailedRedefineList->containsElement(child))) { // if redefine DOMElement* redefineChild = XUtil::getFirstChildElement(child); while (redefineChild != 0) { if ((!fFailedRedefineList || !fFailedRedefineList->containsElement(redefineChild)) && XMLString::equals(redefineChild->getLocalName(), compName)) { compList->addElement(redefineChild); if (XMLString::equals(redefineChild->getAttribute(SchemaSymbols::fgATT_NAME), name)) return redefineChild; } redefineChild = XUtil::getNextSiblingElement(redefineChild); } } child = XUtil::getNextSiblingElement(child); if (child == 0 && redefParent) { child = XUtil::getNextSiblingElement(redefParent); redefParent = 0; } } return child; }