Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Writing XML file from UML Model misses some data(Provided Interfaces of UML Port Element are not written to XML file)
Writing XML file from UML Model misses some data [message #1028796] Thu, 28 March 2013 14:51 Go to next message
Bjoern Steinemann is currently offline 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 16:49 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn Hussey
Messages: 1618
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
Re: Writing XML file from UML Model misses some data [message #1028873 is a reply to message #1028850] Thu, 28 March 2013 17:40 Go to previous messageGo to next message
Bjoern Steinemann is currently offline Bjoern Steinemann
Messages: 2
Registered: March 2013
Location: Berlin, Germany
Junior Member
Hi Kenn,
many thanks for that fast answer. I think, I understand the misconception now that led me the wrong path. I knew that Port::provided is a derived list of interfaces but since the Enterprise Architect produces nested <provided> XMI elements underneath the uml:Portelement I expected this to be nevertheless redundantly saved in XMI files. But I guess it is the EA here that is violating the XMI standard. Is this right?
Regards,
Björn
Re: Writing XML file from UML Model misses some data [message #1029260 is a reply to message #1028873] Fri, 29 March 2013 07:47 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4037
Registered: July 2009
Senior Member
Hi

You might want to study the very detailed
http://wiki.eclipse.org/MDT/UML2/UML2_4.0_Migration_Guide that outlines
the MDT/UML2 changes to support UML 2.4.1 before deciding whether EA is
wrong or just a different interpretation of a different standard.

Further minor clarifications of ambiguous/redundant serialization are
likely in UML 2.5.

Regards

Ed Willink


On 28/03/2013 21:40, Bjoern Steinemann wrote:
> Hi Kenn,
> many thanks for that fast answer. I think, I understand the
> misconception now that led me the wrong path. I knew that
> Port::provided is a derived list of interfaces but since the
> Enterprise Architect produces nested <provided> XMI elements
> underneath the uml:Portelement I expected this to be nevertheless
> redundantly saved in XMI files. But I guess it is the EA here that is
> violating the XMI standard. Is this right?
> Regards,
> Björn
>
Previous Topic:Applying stereotypes programmatically
Next Topic:UMLModeler class and shared elements
Goto Forum:
  


Current Time: Tue Sep 02 15:15:16 EDT 2014

Powered by FUDForum. Page generated in 0.10433 seconds