Writing XML file from UML Model misses some data [message #1028796] |
Thu, 28 March 2013 18:51 |
Bjoern Steinemann Messages: 2 Registered: March 2013 Location: Berlin, Germany |
Junior Member |
|
|
Hi all,
I have created a small UML model using the org.eclipse.uml2.uml API and could get managed most of what I wanted to do. My goal is to get an XML (XMI) representation of that model which in turn I want to read into another graphical UML tool. But unfortunately the uml:Port element is not fully exported to the XML (.uml) file.
Here is the relevant part of my Java code.
[...]
Component myComponent = ExtUMLModelUtil.createComponent(myPackage, "AComponentName");
Interface if1 = ExtUMLModelUtil.createInterface(myPackage, "InterfaceName");
Interface if2 = ExtUMLModelUtil.createInterface(masterPackage, "AnotherName");
org.eclipse.uml2.uml.Class myPortClass = ExtUMLModelUtil.createClassFromName(myPackage, "APortName");
Realization portReal1 = ExtUMLModelUtil.createRealization(myPackage, if1, myPortClass);
Realization portReal2 = ExtUMLModelUtil.createRealization(myPackage, if2, myPortClass);
Port myPort = myComponent.createOwnedPort("myConnector", myPortClass);
Here is the code from the util class ExtUMLModelUtil:
[...]
public static Realization createRealization(Package package_, Interface theIf, Class implementingClass){
Realization ifReal = UMLFactory.eINSTANCE.createRealization();
ifReal.getClients().add(implementingClass);
ifReal.getSuppliers().add(theIf);
ifReal.setName(theIf.getName()+"_real");
package_.getPackagedElements().add(ifReal);
out("Realization '" + ifReal.getQualifiedName() + "' created.");
return ifReal;
}
public static Class createClassFromName(Package package_, String name){
Class theClass = UMLFactory.eINSTANCE.createClass();
theClass.setName(name);
package_.getPackagedElements().add(theClass);
out("Class '" + theClass.getQualifiedName() + "' created.");
return theClass;
}
[...]
After creating the Port element, I can programmatically access its provided interfaces:
[...]
if (elem instanceof Port){
output.append(String.format("Element is a Port of Type %s\n", ((Port)elem).getType() ));
EList<Interface> interfaces = ((Port) elem).getProvideds();
if (interfaces == null || interfaces.iterator().hasNext()==false)
output.append("No interface yet provided by this Port.\n");
else{
Iterator<Interface> iter = interfaces.iterator();
while(iter.hasNext())
output.append(String.format("--Port is connected with Interface %s\n", ((Interface)iter.next()).getName()));
}
}
[...]
But when I save the model to XML I only get the uml:Port inside the uml:Component element but without the provided interfacec. Here is the excerpt from the created XMI document:
<packagedElement xmi:type="uml:Package" xmi:id="_bBvQIZcMEeKkBLD318CJ8A" name="Components">
<packagedElement xmi:type="uml:Component" xmi:id="_bBvQIpcMEeKkBLD318CJ8A" name="AComponentName">
<ownedAttribute xmi:type="uml:Port" xmi:id="_bBvQI5cMEeKkBLD318CJ8A" name="myConnector" type="_bBvQKJcMEeKkBLD318CJ8A"/>
</packagedElement>
I was expecting to find the two interfaces nested in <provided> tags.
When running the code in the Eclipse debugger the method getProvideds() of class org.eclipse.uml2.uml.internal.impl.PortImpl is not being called by XMLHelperImpl or XMLSaveImpl which do the XMI export. org.eclipse.uml2.uml.internal.impl.PortImpl.getName() and org.eclipse.uml2.uml.internal.impl.PortImpl.getType() in turn do get called as expected.
Did I miss something in my code or is this a bug?
Many thanks in advance
Björn
|
|
|
Re: Writing XML file from UML Model misses some data [message #1028850 is a reply to message #1028796] |
Thu, 28 March 2013 20:49 |
Kenn Hussey Messages: 1620 Registered: July 2009 |
Senior Member |
|
|
Port::provided is a derived property (calculated from other information)
and so its values are not redundantly serialized, per the XMI specification.
Kenn
On 13-03-28 3:38 PM, Bjoern Steinemann wrote:
> Hi all,
> I have created a small UML model using the org.eclipse.uml2.uml API and
> could get managed most of what I wanted to do. My goal is to get an XML
> (XMI) representation of that model which in turn I want to read into
> another graphical UML tool. But unfortunately the uml:Port element is
> not fully exported to the XML (.uml) file.
> Here is the relevant part of my Java code.
>
> [...]
> Component myComponent = ExtUMLModelUtil.createComponent(myPackage,
> "AComponentName");
> Interface if1 = ExtUMLModelUtil.createInterface(myPackage,
> "InterfaceName");
> Interface if2 = ExtUMLModelUtil.createInterface(masterPackage,
> "AnotherName");
>
> org.eclipse.uml2.uml.Class myPortClass =
> ExtUMLModelUtil.createClassFromName(myPackage, "APortName");
> Realization portReal1 = ExtUMLModelUtil.createRealization(myPackage,
> if1, myPortClass);
> Realization portReal2 = ExtUMLModelUtil.createRealization(myPackage,
> if2, myPortClass);
>
> Port myPort = myComponent.createOwnedPort("myConnector", myPortClass);
>
>
> Here is the code from the util class ExtUMLModelUtil:
>
> [...]
> public static Realization createRealization(Package package_, Interface
> theIf, Class implementingClass){
> Realization ifReal = UMLFactory.eINSTANCE.createRealization();
> ifReal.getClients().add(implementingClass);
> ifReal.getSuppliers().add(theIf);
> ifReal.setName(theIf.getName()+"_real");
> package_.getPackagedElements().add(ifReal);
> out("Realization '" + ifReal.getQualifiedName() + "' created.");
> return ifReal;
> }
>
> public static Class createClassFromName(Package package_, String
> name){
>
> Class theClass = UMLFactory.eINSTANCE.createClass();
> theClass.setName(name);
> package_.getPackagedElements().add(theClass);
> out("Class '" + theClass.getQualifiedName() + "' created.");
> return theClass;
> }
> [...]
>
>
> After creating the Port element, I can programmatically access its
> provided interfaces:
>
>
> [...]
> if (elem instanceof Port){
> output.append(String.format("Element is a Port of Type
> %s\n", ((Port)elem).getType() ));
> EList<Interface> interfaces = ((Port) elem).getProvideds();
> if (interfaces == null ||
> interfaces.iterator().hasNext()==false)
> output.append("No interface yet provided by this
> Port.\n");
> else{
> Iterator<Interface> iter = interfaces.iterator();
> while(iter.hasNext())
> output.append(String.format("--Port is connected
> with Interface %s\n", ((Interface)iter.next()).getName()));
> }
> }
> [...]
>
>
> But when I save the model to XML I only get the uml:Port inside the
> uml:Component element but without the provided interfacec. Here is the
> excerpt from the created XMI document:
>
> <packagedElement xmi:type="uml:Package"
> xmi:id="_bBvQIZcMEeKkBLD318CJ8A" name="Components">
> <packagedElement xmi:type="uml:Component"
> xmi:id="_bBvQIpcMEeKkBLD318CJ8A" name="AComponentName">
> <ownedAttribute xmi:type="uml:Port"
> xmi:id="_bBvQI5cMEeKkBLD318CJ8A" name="myConnector"
> type="_bBvQKJcMEeKkBLD318CJ8A"/>
> </packagedElement>
>
>
>
> I was expecting to find the two interfaces nested in <provided> tags.
> When running the code in the Eclipse debugger the method getProvideds()
> of class org.eclipse.uml2.uml.internal.impl.PortImpl is not being called
> by XMLHelperImpl or XMLSaveImpl which do the XMI export.
> org.eclipse.uml2.uml.internal.impl.PortImpl.getName() and
> org.eclipse.uml2.uml.internal.impl.PortImpl.getType() in turn do get
> called as expected.
> Did I miss something in my code or is this a bug?
>
> Many thanks in advance
>
> Björn
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03310 seconds