Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to generate UMLPackage object from .uml file?(org.eclipse.uml2.uml api)
How to generate UMLPackage object from .uml file? [message #1850929] Tue, 22 March 2022 15:00 Go to next message
qiaosen liu is currently offline qiaosen liuFriend
Messages: 9
Registered: March 2022
Junior Member
I want to read in .UML files and generate UMLPackage (from org.eclipse.uml2.uml) objects so that I can manipulate these model elements (eg lifelines), how would I go about doing this?
Re: How to generate UMLPackage object from .uml file? [message #1850931 is a reply to message #1850929] Tue, 22 March 2022 15:03 Go to previous messageGo to next message
qiaosen liu is currently offline qiaosen liuFriend
Messages: 9
Registered: March 2022
Junior Member
I took some approaches as follows:

I want to create a UMLPackage object using ResourceSet so that I can parse the UML model. However, I can only get the object of EPackage.

code show as below:

URI uri = URI.createURI("src/model/test.uml");
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource res = set.getResource(uri, true);
EObject root=res.getContents().get(0);
UMLPackage umlPackage=null;
for(EObject e:root.eContents()){
if("Interaction".equals(e.eClass().getName())){
umlPackage=(UMLPackage) e.eClass().getEPackage();
}
}
if(null!=umlPackage){
System.out.println(umlPackage.getLifeline());
}
Re: How to generate UMLPackage object from .uml file? [message #1850932 is a reply to message #1850931] Tue, 22 March 2022 15:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I suggest that you follow the UML tutorials where you should find UMLResourcesUtil.init that helps avoid numerous mistakes that newbies struggle with.

You might find that UMLPackage.eINSTANCE is what you want.

UMLPackage.Literals.INTERACTION might also interest you.

Regards

Ed Willink
Re: How to generate UMLPackage object from .uml file? [message #1850938 is a reply to message #1850932] Wed, 23 March 2022 01:11 Go to previous messageGo to next message
qiaosen liu is currently offline qiaosen liuFriend
Messages: 9
Registered: March 2022
Junior Member
Thank you, your answer is very helpful for me, where can I find UML tutorials?
Re: How to generate UMLPackage object from .uml file? [message #1850945 is a reply to message #1850938] Wed, 23 March 2022 07:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Googling "Eclipse UML tutorial" gives many interesting hits but no onger the ones I meant: https://help.eclipse.org/latest/nav/85_0

https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues/1037 raised

Regards

Ed Willink
Re: How to generate UMLPackage object from .uml file? [message #1860773 is a reply to message #1850945] Sat, 02 September 2023 08:19 Go to previous message
Firstname Lastname is currently offline Firstname LastnameFriend
Messages: 7
Registered: July 2023
Junior Member
Hi,

somehow your link to the "help" does point to vagrant.

Probably useful for future readers is: https://wiki.eclipse.org/MDT/UML2/Getting_Started_with_UML2

Furthermore, there is a Project that provides basic functionality with UML2. After one has papyrus installed, you can get this by following the steps "New" > "Other..." - now a new window should open whith a lot of different options to choose from > In the search Bar type: "Getting Started with UML2".

Previous Topic:Programatically load and save sequence diagram
Next Topic:How to set multiple values for a property of a stereotype?
Goto Forum:
  


Current Time: Thu Apr 18 20:12:26 GMT 2024

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

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

Back to the top