Skip to main content



      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 12:04 Go to next message
Eclipse UserFriend
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();
UMLUtil.init(resourceSet);
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
cmps.stream().map(Component.class::cast).forEach(cp -> 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);
		cmps.stream().map(Component.class::cast).filter(cp -> !cp.getAppliedStereotypes().isEmpty()).findFirst()
				.orElse(null).applyStereotype(st);


//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(ElementOperations.java:1499)
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(ElementImpl.java:504)
	at it.univaq.disim.sealab.easier.managers.uml.TestUMLManager.shallApplyStereotypes(TestUMLManager.java:104)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)


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?

Thanks,
BR
Daniele

[Updated on: Fri, 18 September 2020 12:05] by Moderator

Re: Reading and applying profile geneated through MagicDraw [message #1832486 is a reply to message #1832483] Fri, 18 September 2020 14:05 Go to previous message
Eclipse UserFriend
Hi

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.

Regards

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


Current Time: Sat Jul 12 09:28:32 EDT 2025

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

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

Back to the top