Skip to main content


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 18:51 Go to next message
Bjoern Steinemann is currently offline Bjoern SteinemannFriend
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 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
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
Re: Writing XML file from UML Model misses some data [message #1028873 is a reply to message #1028850] Thu, 28 March 2013 21:40 Go to previous messageGo to next message
Bjoern Steinemann is currently offline Bjoern SteinemannFriend
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 11:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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
>
Re: Writing XML file from UML Model misses some data [message #1773331 is a reply to message #1029260] Tue, 26 September 2017 13:48 Go to previous message
Irimia Andreea is currently offline Irimia AndreeaFriend
Messages: 1
Registered: September 2017
Junior Member
Hello Bjoern! Can you help me please with the full code?
Previous Topic:Reusing OMG Profiles created with Magic Draw
Next Topic:Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML)
Goto Forum:
  


Current Time: Fri Apr 19 22:12:18 GMT 2024

Powered by FUDForum. Page generated in 0.03152 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top