Commit c0d58b3b authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Initial work on loading UML2/XMI2 files, e.g.

  https://bugs.kde.org/attachment.cgi?id=86180 (Eclipse UML2)
and
  http://www.omg.org/spec/UML/20110701/Infrastructure.xmi

umbrello/model_utils.{h,cpp}
- New function getXmiId(QDomElement) encapsulates access to xmi.id (XMI-1)
  and xmi:id (XMI-2)

umbrello/{umlobject,folder,operation}.cpp
- Replace direct accesses to QDomElement::attribute("xmi.id") by
  Model_Utils::getXmiId()

umbrello/{folder,package}.cpp
- In function load(QDomElement&), decode UML2 tags packagedElement and
  ownedElement.

umbrello/umldoc.cpp
- In function loadFromXMI(QIODevice&, short), decode outerTag values
  "Model" and "Package" for UML2;
- In function loadUMLObjectsFromXMI(QDomElement&),
  - decode UML2 tags packagedElement and ownedElement;
  - admit XMI2 syntax "xmi:id" to the check for xmi.id presence.

umbrello/classifier.cpp
- In function makeChildObject(const QString&), support UML2 tags
  ownedOperation and ownedAttribute.

CCBUG:56184
parent a9d4efc3
......@@ -1490,9 +1490,11 @@ void UMLClassifier::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
UMLClassifierListItem* UMLClassifier::makeChildObject(const QString& xmiTag)
{
UMLClassifierListItem* pObject = NULL;
if (UMLDoc::tagEq(xmiTag, "Operation")) {
if (UMLDoc::tagEq(xmiTag, "Operation") ||
UMLDoc::tagEq(xmiTag, "ownedOperation")) {
pObject = new UMLOperation(this);
} else if (UMLDoc::tagEq(xmiTag, "Attribute")) {
} else if (UMLDoc::tagEq(xmiTag, "Attribute") ||
UMLDoc::tagEq(xmiTag, "ownedAttribute")) {
if (baseType() != UMLObject::ot_Class)
return NULL;
pObject = new UMLAttribute(this);
......
......@@ -465,6 +465,9 @@ bool UMLFolder::load(QDomElement& element)
totalSuccess = false;
}
continue;
} else if (UMLDoc::tagEq(type, "packagedElement") ||
UMLDoc::tagEq(type, "ownedElement")) {
type = tempElement.attribute("xmi:type", "");
} else if (type == "XMI.extension") {
for (QDomNode xtnode = node.firstChild(); !xtnode.isNull();
xtnode = xtnode.nextSibling()) {
......@@ -501,7 +504,7 @@ bool UMLFolder::load(QDomElement& element)
}
UMLObject *pObject = 0;
// Avoid duplicate creation of forward declared object
QString idStr = tempElement.attribute("xmi.id", "");
QString idStr = Model_Utils::getXmiId(tempElement);
if (!idStr.isEmpty()) {
Uml::ID::Type id = Uml::ID::fromString(idStr);
pObject = umldoc->findObjectById(id);
......
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2004-2013 *
* copyright (C) 2004-2014 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -495,7 +495,18 @@ QString uniqObjectName(UMLObject::ObjectType type, UMLPackage *parentPkg, QStrin
}
/**
* Return true if the given tag is a one of the common XMI
* Return the xmi.id (XMI-1) or xmi:id (XMI-2) of a QDomElement.
*/
QString getXmiId(QDomElement element)
{
QString idStr = element.attribute("xmi.id", "");
if (idStr.isEmpty())
idStr = element.attribute("xmi:id", "");
return idStr;
}
/**
* Return true if the given tag is one of the common XMI
* attributes, such as:
* "name" | "visibility" | "isRoot" | "isLeaf" | "isAbstract" |
* "isActive" | "ownerScope"
......
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2004-2013 *
* copyright (C) 2004-2014 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -62,6 +62,7 @@ QString uniqObjectName(UMLObject::ObjectType type,
UMLPackage *parentPkg,
QString prefix = QString());
QString getXmiId(QDomElement element);
bool isCommonXMIAttribute(const QString &tag);
bool isCommonDataType(QString type);
bool isClassifierListitem(UMLObject::ObjectType ot);
......
......@@ -14,6 +14,7 @@
// app includes
#include "attribute.h"
#include "classifier.h"
#include "model_utils.h"
#include "debug_utils.h"
#include "uml.h"
#include "umldoc.h"
......@@ -530,7 +531,7 @@ bool UMLOperation::load(QDomElement & element)
}
}
if (kind == "return") {
QString returnId = attElement.attribute("xmi.id", "");
QString returnId = Model_Utils::getXmiId(attElement);
if (!returnId.isEmpty())
m_returnId = Uml::ID::fromString(returnId);
m_SecondaryId = attElement.attribute("type", "");
......@@ -548,13 +549,13 @@ bool UMLOperation::load(QDomElement & element)
node = node.nextSibling();
continue;
}
m_SecondaryId = tempElement.attribute("xmi.id", "");
m_SecondaryId = Model_Utils::getXmiId(tempElement);
if (m_SecondaryId.isEmpty())
m_SecondaryId = tempElement.attribute("xmi.idref", "");
if (m_SecondaryId.isEmpty()) {
QDomNode inner = node.firstChild();
QDomElement tmpElem = inner.toElement();
m_SecondaryId = tmpElem.attribute("xmi.id", "");
m_SecondaryId = Model_Utils::getXmiId(tmpElem);
if (m_SecondaryId.isEmpty())
m_SecondaryId = tmpElem.attribute("xmi.idref", "");
}
......
......@@ -475,6 +475,9 @@ bool UMLPackage::load(QDomElement& element)
if (! load(tempElement))
return false;
continue;
} else if (UMLDoc::tagEq(type, "packagedElement") ||
UMLDoc::tagEq(type, "ownedElement")) {
type = tempElement.attribute("xmi:type", "");
}
UMLObject *pObject = Object_Factory::makeObjectFromXMI(type);
if(!pObject) {
......
......@@ -2005,6 +2005,16 @@ bool UMLDoc::loadFromXMI(QIODevice & file, short encode)
extensionsNode = extensionsNode.nextSibling();
}
recognized = true;
} else if (tagEq(outerTag, "Model") ||
tagEq(outerTag, "Package")) {
if(!loadUMLObjectsFromXMI(element)) {
uWarning() << "failed load on objects";
return false;
}
m_Name = element.attribute("name", i18n("UML Model"));
UMLListView *lv = UMLApp::app()->listView();
lv->setTitle(0, m_Name);
recognized = true;
}
if (outerTag != "XMI.content") {
if (!recognized) {
......@@ -2251,8 +2261,12 @@ bool UMLDoc::loadUMLObjectsFromXMI(QDomElement& element)
// and foreign files
if (Model_Utils::isCommonXMIAttribute(type)) {
continue;
} else if (tagEq(type, "packagedElement") ||
tagEq(type, "ownedElement")) {
type = tempElement.attribute("xmi:type");
}
if (! tempElement.hasAttribute("xmi.id")) {
if (!tempElement.hasAttribute("xmi.id") &&
!tempElement.hasAttribute("xmi:id")) {
QString idref = tempElement.attribute("xmi.idref", "");
if (! idref.isEmpty()) {
DEBUG(DBG_SRC) << "resolution of xmi.idref " << idref
......
......@@ -919,7 +919,7 @@ bool UMLObject::loadFromXMI(QDomElement & element)
// Read the name first so that if we encounter a problem, the error
// message can say the name.
m_name = element.attribute("name", "");
QString id = element.attribute("xmi.id", "");
QString id = Model_Utils::getXmiId(element);
if (id.isEmpty() || id == "-1") {
if (m_BaseType == ot_Role) {
// Before version 1.4, Umbrello did not save the xmi.id
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment