bool ViewWindowImp::fromXml(DOMNode* pDocument, unsigned int version) { if (pDocument == NULL) { return false; } if (!WindowImp::fromXml(pDocument, version)) { return false; } DOMElement* pElement = static_cast<DOMElement*>(pDocument); if (pElement->hasAttribute(X("viewId"))) { View* pOldView = mpView; setView(dynamic_cast<View*>(SessionManagerImp::instance()->getSessionItem( A(pElement->getAttribute(X("viewId")))))); Service<DesktopServices>()->deleteView(pOldView); } else { setView(NULL); } return true; }
bool DataElementImp::deserialize(SessionItemDeserializer &deserializer) { XmlReader reader(NULL, false); DOMDocument* pDoc = deserializer.deserialize(reader); if (pDoc == NULL) { return false; } DOMElement* pRoot = pDoc->getDocumentElement(); VERIFY(pRoot != NULL); if (pRoot->hasAttribute(X("parentId"))) { DataElement* pParent = dynamic_cast<DataElement*>(Service<SessionManager>()->getSessionItem(A(pRoot->getAttribute(X("parentId"))))); if (pParent == NULL) { return false; } Service<ModelServices>()->setElementParent(dynamic_cast<DataElement*>(this), pParent); } Service<ModelServices>()->setElementName(dynamic_cast<DataElement*>(this), A(pRoot->getAttribute(X("name")))); unsigned int formatVersion = 0; stringstream str(A(pRoot->getAttribute(X("version")))); str >> formatVersion; return SessionItemImp::fromXml(pRoot, formatVersion) && fromXml(pRoot, formatVersion); }
static void parseSequence(DOMElement *parent, DOMElement *sequence, Class *cl, bool choice = false) { //we expect to see a whole bunch of <element>s here //if choice is true then this is a choice sequence - every element is optional CHECK(parent); CHECK(sequence); vector<DOMElement*> children = getChildElementsByTagName(sequence, "element"); //support <sequence> in <choice> by simply recursing //simply put this means the <sequence> tags are ignored vector<DOMElement*> subSequences = getChildElementsByTagName(sequence, "sequence"); if(subSequences.size() > 0 && !choice) throw runtime_error("Found <sequence> element in another <sequence> element"); children.insert(children.end(), subSequences.begin(), subSequences.end()); for(size_t x = 0; x < children.size(); x++) { DOMElement *child = children[x]; int minOccurs = 1; int maxOccurs = 1; XercesString typeStr("type"); XercesString minOccursStr("minOccurs"); XercesString maxOccursStr("maxOccurs"); string name = fixIdentifier(XercesString(child->getAttribute(XercesString("name")))); if(child->hasAttribute(minOccursStr)) { stringstream ss; ss << XercesString(child->getAttribute(minOccursStr)); ss >> minOccurs; } if(child->hasAttribute(maxOccursStr)) { XercesString str(child->getAttribute(maxOccursStr)); if(str == "unbounded") maxOccurs = UNBOUNDED; else { stringstream ss; ss << str; ss >> maxOccurs; } }
void PLMXMLParser::addInstance(char *id, osg::Group *parent) { std::map<char *, Element *, ltstr>::iterator it = instances.find(id); if (it != instances.end()) { Element *instance = it->second; osg::Group *group = instance->group; DOMElement *element = instance->element; parent->addChild(group); coVRSelectionManager::markAsHelperNode(group); osg::MatrixTransform *transformNode = getTransformNode(id, element); if (transformNode) { group->addChild(transformNode); group = transformNode; } else { if (element->hasAttribute(TAG_name)) group->setName(XMLString::transcode(element->getAttribute(TAG_name))); else group->setName(id); } const XMLCh *partRef = element->getAttribute(TAG_partRef); char *partName = XMLString::transcode(partRef); if (partName[0] == '#') addPart(partName + 1, group); else addPart(partName, group); XMLString::release(&partName); } }
bool DataDescriptorImp::fromXml(DOMNode* pDocument, unsigned int version) { if (pDocument == NULL) { return false; } DOMElement* pElement = static_cast<DOMElement*>(pDocument); if (mName != A(pElement->getAttribute(X("name")))) { throw XmlBase::XmlException("Element name does not match this element"); } if (!Service<SessionManager>()->isSessionLoading() && mType != A(pElement->getAttribute(X("type")))) { throw XmlBase::XmlException("Element type does not match this element"); } mProcessingLocation = StringUtilities::fromXmlString<ProcessingLocation>( A(pElement->getAttribute(X("processingLocation")))); for (DOMNode* pChild = pDocument->getFirstChild(); pChild != NULL; pChild = pChild->getNextSibling()) { if (XMLString::equals(pChild->getNodeName(), X("classification"))) { if (mClassification.fromXml(pChild, version) == false) { throw XmlReader::DomParseException("Can't deserialize classification", pDocument); } } else if (XMLString::equals(pChild->getNodeName(), X("metadata"))) { if (mMetadata.fromXml(pChild, version) == false) { throw XmlReader::DomParseException("Can't deserialize metadata", pDocument); } } else if (XMLString::equals(pChild->getNodeName(), X("FileDescriptor"))) { // create a new FileDescriptor to make sure we have the correct type of FileDescriptor delete mpFileDescriptor; DOMElement* pChildElement = static_cast<DOMElement*>(pChild); string fileDescriptorType = A(pChildElement->getAttribute(X("type"))); ModelServicesImp* pModel = ModelServicesImp::instance(); if (pModel != NULL) { if (pModel->isKindOfFileDescriptor(fileDescriptorType, "RasterFileDescriptor") == true) { mpFileDescriptor = new RasterFileDescriptorAdapter(); } else if (pModel->isKindOfFileDescriptor(fileDescriptorType, "SignatureFileDescriptor") == true) { mpFileDescriptor = new SignatureFileDescriptorAdapter(); } else if (pModel->isKindOfFileDescriptor(fileDescriptorType, "FileDescriptor") == true) { mpFileDescriptor = new FileDescriptorAdapter(); } } if (mpFileDescriptor == NULL) { throw XmlReader::DomParseException("Cannot create file descriptor", pDocument); } if (mpFileDescriptor->fromXml(pChild, version) == false) { throw XmlReader::DomParseException("Cannot deserialize file descriptor", pDocument); } } } if (pElement->hasAttribute(X("importerName")) == true) { mImporterName = A(pElement->getAttribute(X("importerName"))); } else { mImporterName.clear(); } notify(SIGNAL_NAME(Subject, Modified)); return true; }