Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » How to access enumeration literals defined in UML Profiles?
How to access enumeration literals defined in UML Profiles? [message #1730865] Fri, 29 April 2016 12:03 Go to next message
Rene Meis is currently offline Rene MeisFriend
Messages: 19
Registered: June 2015
Junior Member
Hi all,

I defined enumerations in UML profiles and also have stereotypes that use these enumerations as types of properties. Now I have the problem that I cannot assign an enumeration literal of the enumerations defined in the UML profile using the # notation.

Minimal example:
I have defined an enumeration Level in a profile with the literals easy, normal, and hard. I apply the profile to a UML model and run the following wizard on this model:

wizard EnumTest {
	title : "Test Level Enum"
	do {
		(Model!AggregationKind#shared).println();
		var enum = Model!Enumeration.all.selectOne(e|e.name = "Level").println();
		enum.getOwnedLiterals().println();
                (Model!Level#easy).println();
	}
}


The result is (executed in Papyrus):

shared
Enumeration [name=Level, qualifiedName=Levels::Level, visibility=public, isLeaf=false, isAbstract=false, isFinalSpecialization=false, ]
OrderedSet {EnumerationLiteral [name=easy, qualifiedName=Levels::Level::easy, visibility=public, ], EnumerationLiteral [name=normal, qualifiedName=Levels::Level::normal, visibility=public, ], EnumerationLiteral [name=hard, qualifiedName=Levels::Level::hard, visibility=public, ]}
Cannot find enumeration literal Level#easy in model Model
	at (/home/rene/Programme/Mars/workspaceVanilla/Wizard/test.ewl@7:3-7:19)
	at (/home/rene/Programme/Mars/workspaceVanilla/Wizard/test.ewl@7:2-7:31)

	at org.eclipse.epsilon.emc.emf.AbstractEmfModel.getEnumerationValue(AbstractEmfModel.java:159)
	at org.eclipse.epsilon.eol.models.ModelRepository.getEnumerationValue(ModelRepository.java:130)
	at org.eclipse.epsilon.eol.dom.EnumerationLiteralExpression.execute(EnumerationLiteralExpression.java:20)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
	at org.eclipse.epsilon.eol.dom.ExpressionInBrackets.execute(ExpressionInBrackets.java:19)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
	at org.eclipse.epsilon.eol.dom.OperationCallExpression.execute(OperationCallExpression.java:68)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
	at org.eclipse.epsilon.eol.dom.ExpressionStatement.execute(ExpressionStatement.java:19)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
	at org.eclipse.epsilon.eol.dom.StatementBlock.execute(StatementBlock.java:43)
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
	at org.eclipse.epsilon.eol.dom.ExecutableBlock.executeBlockOrExpressionAst(ExecutableBlock.java:74)
	at org.eclipse.epsilon.eol.dom.ExecutableBlock.execute(ExecutableBlock.java:88)
	at org.eclipse.epsilon.ewl.dom.Wizard.process(Wizard.java:57)
	at org.eclipse.epsilon.ewl.execute.WizardInstance.process(WizardInstance.java:66)
	at org.eclipse.epsilon.ewl.emf.ExecuteWizardInstanceCommand.execute(ExecuteWizardInstanceCommand.java:44)
	at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:119)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
	at org.eclipse.papyrus.commands.CheckedOperationHistory.execute(CheckedOperationHistory.java:184)
	at org.eclipse.papyrus.commands.NotifyingWorkspaceCommandStack.doExecute(NotifyingWorkspaceCommandStack.java:261)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	at org.eclipse.papyrus.commands.NestingNotifyingWorkspaceCommandStack.execute(NestingNotifyingWorkspaceCommandStack.java:130)
	at org.eclipse.epsilon.ewl.emf.AbstractContributeWizardsAction.execute(AbstractContributeWizardsAction.java:140)
	at org.eclipse.epsilon.ewl.emf.AbstractContributeWizardsAction$1.widgetSelected(AbstractContributeWizardsAction.java:254)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)


The result shows that the enumeration literal AggregationKind#shared can be accessed and that the enumeration Level is also known, but the # notation does not work as expected.

What am I doing wrong?


Thanks in advance,
Rene
Re: How to access enumeration literals defined in UML Profiles? [message #1731238 is a reply to message #1730865] Tue, 03 May 2016 17:01 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

Hi Rene,

Could you please package up an executable example containing a minimal UML profile and a small EOL file that exercises this feature as discussed in [1]?

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/
Re: How to access enumeration literals defined in UML Profiles? [message #1731285 is a reply to message #1730865] Wed, 04 May 2016 07:14 Go to previous messageGo to next message
Rene Meis is currently offline Rene MeisFriend
Messages: 19
Registered: June 2015
Junior Member
Hi Dimitris,

I attached a minimal example. It contains the minimal profile (project Profile), a model which has this (local) profile applied (project Model) and the wizard (project Wizard) that causes the undesired behavior. The model and profile were created with Papyrus and also the wizard is executed from Papyrus. The wizard is registered with the Namespace URI: http://www.eclipse.org/uml2/5.0.0/UML.


Cheers,
Rene
  • Attachment: Example.zip
    (Size: 7.92KB, Downloaded 142 times)
Re: How to access enumeration literals defined in UML Profiles? [message #1731310 is a reply to message #1731285] Wed, 04 May 2016 08:52 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

Hi Rene,

This seems to be working fine using the tree-based UML editor. I wasn't able to get Papyrus (1.1.2.201509161440 - installed on top of the 1.3 Epsilon distribution) to open the diagram at all I'm afraid.

Cheers,
Dimitris
Re: How to access enumeration literals defined in UML Profiles? [message #1731314 is a reply to message #1731310] Wed, 04 May 2016 09:15 Go to previous messageGo to next message
Rene Meis is currently offline Rene MeisFriend
Messages: 19
Registered: June 2015
Junior Member
Hi Dimitris,

sorry, the provided model does not cause the error. Maybe because it already contains an application of the stereotype that has an attribute of the type of the enumeration.

I attached an empty UML model with only the profile applied. For this model, the error occurs also in the UML Model Editor.


Cheers,
Rene
  • Attachment: Test.zip
    (Size: 1.84KB, Downloaded 131 times)
Re: How to access enumeration literals defined in UML Profiles? [message #1731330 is a reply to message #1731314] Wed, 04 May 2016 11:01 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

Hi Rene,

I've investigated a bit and in EOL this seems to be working fine when "test.uml" is added to the launch configuration as a "UML Model" (but not when it's added as an "EMF Model"). Looking at UMLModel.java [1], I suspect that the following line makes the difference:

UMLUtil.init(resourceSet);


To work around this, I'd suggest creating a Java tool [2, 3] that calls this method on the underlying EMF resource before you do anything else with it in your EWL code.

Cheers,
Dimitris

[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/plugins/org.eclipse.epsilon.emc.uml/src/org/eclipse/epsilon/emc/uml/UmlModel.java
[2] https://www.eclipse.org/epsilon/examples/index.php?example=org.eclipse.epsilon.examples.tools
[3] https://www.eclipse.org/epsilon/doc/articles/call-java-from-epsilon/
Re: How to access enumeration literals defined in UML Profiles? [message #1731555 is a reply to message #1731330] Fri, 06 May 2016 18:45 Go to previous messageGo to next message
Rene Meis is currently offline Rene MeisFriend
Messages: 19
Registered: June 2015
Junior Member
Hi Dimitris,

I tried your suggested work around and created the following custom tool (tested with comment line and without) (also attached as a plug-in project):

package de.uni.due.swe.epsilon.lib.inituml;

import org.eclipse.epsilon.eol.tools.AbstractTool;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.util.UMLUtil;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.epsilon.emc.emf.AbstractEmfModel;

public class InitUML extends AbstractTool {
	public void initUML() {
		AbstractEmfModel model = (AbstractEmfModel) this.context.getModelRepository().getModelByNameSafe("Model");
		ResourceSet resourceSet = model.getResource().getResourceSet();
		UMLUtil.init(resourceSet);
		//resourceSet.getPackageRegistry().put(UMLPackage.eINSTANCE.getNsURI(), UMLPackage.eINSTANCE);
		System.out.println("Initialized UML Model");
	}
}


And the method provided by the tool is called as first action of the wizard:
wizard EnumTest {
	title : "Test Level Enum"
	do {
		var init : new Native("de.uni.due.swe.epsilon.lib.inituml.InitUML");
		init.initUML();
		
		(Model!AggregationKind#shared).println();
		var enum = Model!Enumeration.all.selectOne(e|e.name = "Level").println();
		enum.getOwnedLiterals().println();
		(Model!Level#easy).println();
	}
}



Unfortunately, invoking the tool has no effect. The same error as before occurs. It is strange that sometimes the UML model is loaded as UML model and sometimes "only" as EMF model when invoking EWL scripts.

I hope that I correctly invoked the operation on the right underlying EMF resource.


Cheers,
Rene
Re: How to access enumeration literals defined in UML Profiles? [message #1732664 is a reply to message #1731555] Wed, 18 May 2016 22:22 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

Hi Rene,

Apologies for the slow response - this was a tricky one. It appears that you don't need the custom tool after all. Modifying your wizard as follows should do the trick.

wizard EnumTest {
	title : "Test Level Enum"
	do {
		
		var ePackage = ProfileApplication.all.first().getAppliedDefinition();
		Model.resource.resourceSet.packageRegistry.put(ePackage.nsURI, ePackage);
		
		Game.all.println();
		(Model!Level#easy).println();
	}
}


Cheers,
Dimitris
Re: How to access enumeration literals defined in UML Profiles? [message #1732934 is a reply to message #1732664] Mon, 23 May 2016 08:30 Go to previous message
Rene Meis is currently offline Rene MeisFriend
Messages: 19
Registered: June 2015
Junior Member
Hi Dimitris,

thanks a lot for your help and the effort you put into solving my problem.

As I use several profiles in my applications, I modified the code as follows:

for (ePackage in Model!ProfileApplication.all.collect(p|p.getAppliedDefinition())) {
	Model.resource.resourceSet.packageRegistry.put(ePackage.nsURI, ePackage); 
}


Now everthing works as expected. Smile


Cheers,
Rene
Previous Topic:EVL: An stack overflow exception error!
Next Topic:How to manipulate UML Diagram Elements
Goto Forum:
  


Current Time: Thu Mar 28 18:07:41 GMT 2024

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

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

Back to the top