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: 7488
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 message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7488
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
Previous Topic:UML 2.5.1
Next Topic:[SOLVED] Profile and stereotypes are not applied in the "Intro to Profile" example
Goto Forum:
  


Current Time: Thu Jun 30 11:57:37 GMT 2022

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

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

Back to the top