Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Reading and applying profile geneated through MagicDraw(I cannot apply a stereotype to a UML element)
Reading and applying profile geneated through MagicDraw [message #1832483] Fri, 18 September 2020 16:04 Go to next message
daniele di pompeo is currently offline daniele di pompeoFriend
Messages: 20
Registered: February 2015
Junior Member
Dear all,
I'm dealing with a problem with UML profiling in a standalone Java application.

I have generated and profiled (with MARTE, DAM, and a CUSTOM profile) a UML model by MagicDraw, then I have exported it as "Eclipse UML2 XMI v5".
I would like to use it in a standalone Java application where I need to read stereotypes and (if applicable) apply them to some elements in the models.

Unfortunately I haven't found any solution and I would like you to help me to solve this problem.

What I have done is the following.

To load the model, I use the following routine, but I guess it is not enough.

ResourceSet resourceSet = super.createResourceSet();
resourceSet.getPackageRegistry().put(UMLPackage.eINSTANCE.getNsURI(), UMLPackage.eINSTANCE);
return resourceSet;

I can read the model well, and I can walk through its elements as well as I can read a stereotype (see the code and the message below)

//is a list of Component -> cp.getAppliedStereotypes().forEach(System.out::println));

org.eclipse.uml2.uml.internal.impl.StereotypeImpl@abbc908 (name: DaComponent, visibility: public) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
org.eclipse.uml2.uml.internal.impl.StereotypeImpl@3a3ad8e7 (name: myStereotype, visibility: public) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
org.eclipse.uml2.uml.internal.impl.StereotypeImpl@27438750 (name: GaExecHost, visibility: public) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)

As you can see, in the second log there are all Stereotypes that I have attached to the only one component within the list.
As far as I understand, I shall be able to use the stereotype, and I can apply them to another component.

But, if I try to run the following snippet of code, I catch the Exception (reported later).

//I'm sure that all Stereotypes can be applied to a Component
Stereotype st = ((Component) cmps.get(0)).getAppliedStereotypes().get(0); -> !cp.getAppliedStereotypes().isEmpty()).findFirst()

//The exception of stereotype application
java.lang.IllegalArgumentException: stereotype "Core::DaComponent" is not applicable to Component
	at org.eclipse.uml2.uml.internal.operations.ElementOperations.applyStereotype(
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(
	at it.univaq.disim.sealab.easier.managers.uml.TestUMLManager.shallApplyStereotypes(
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.base/java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.junit.internal.runners.statements.RunBefores.evaluate(
	at org.junit.runners.ParentRunner$3.evaluate(
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$100(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.junit.runners.ParentRunner$3.evaluate(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Also, I have only the .uml files exported by MagicDraw, and every solution I have read points to put the package into the registry.

I read on this forum many different solutions (as I said before), but no one is similar to my problem.

Can you provide a solution (if any) as close to mine as possible?


[Updated on: Fri, 18 September 2020 16:05]

Report message to a moderator

Re: Reading and applying profile geneated through MagicDraw [message #1832486 is a reply to message #1832483] Fri, 18 September 2020 18:05 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7506
Registered: July 2009
Senior Member

You should be using UMLResourcesUtil.init.

Without a copy of your code, I doubt that you will find anyone prepared to examine your snippets to try and guess at the problem. Imported UML and stereotypes are just too hard for guesswork. The IAE tells me exactly what to look for, but I can't look at the model.

Probably not a problem, but you may be the first user to actively use Java > 8 with Eclipse UML2.


Ed Willink
Previous Topic:View UML Abstract Metamodel XMI file in Eclipse
Next Topic:Change parent/owner
Goto Forum:

Current Time: Tue Aug 16 05:13:02 GMT 2022

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

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

Back to the top