Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » how to create programatically an instance of given DataType in UML
how to create programatically an instance of given DataType in UML [message #1073724] Thu, 25 July 2013 07:27 Go to next message
hongyu liu is currently offline hongyu liu
Messages: 6
Registered: March 2012
Junior Member
Need:

Given a UML self-defined DataType, not UML pre-defined DataType (e.g. MyType), how to create its instance programatically?

Use case:

In a UML profile, we define a stereotype which has some attributes of MyType. In order to specify a UML model correctly, we need to create an instance of MyType after we apply the stereotype.

Current Papyrus UI Capability

In the "applied stereotype view", we can select the stereotype and a panel to create those instance is ready on the right side. It needs only to click "+" to open a dialog and initialize an instance. How this is done by code ?

Example Pseudo Code:

Element target;
Stereotype st = getStereotypeByName("name");
target.applyStereotype(st);

DataType dt = getDataTypeByName("MyType");

EObject instance = createInstance(dt);


target.setValue(st, "myTypeAttr", instance);


Question:

How this method "EObject createInstance(DataType dt)" can be implemented ?


Thanks in advance.
Re: how to create programatically an instance of given DataType in UML [message #1073729 is a reply to message #1073724] Thu, 25 July 2013 07:44 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon Schwichtenberg
Messages: 126
Registered: September 2011
Senior Member
UMLFactory.eINSTANCE.createDataType();
Re: how to create programatically an instance of given DataType in UML [message #1073738 is a reply to message #1073729] Thu, 25 July 2013 08:01 Go to previous messageGo to next message
hongyu liu is currently offline hongyu liu
Messages: 6
Registered: March 2012
Junior Member
In fact, your response is to create a DataType, while the question is for "create an instance of given DataType". Do you have some ideas ?
Re: how to create programatically an instance of given DataType in UML [message #1073776 is a reply to message #1073738] Thu, 25 July 2013 09:13 Go to previous messageGo to next message
Simon Schwichtenberg is currently offline Simon Schwichtenberg
Messages: 126
Registered: September 2011
Senior Member
If I understand correctly you have a stereotype with a tagged value of type MyDataType. I am not sure if it is possible at all to create an instance of MyDataType. Is it possible to move the MyDataType's attributes (assuming they are primitive datatypes or enumerations) to the stereotype directly? That would be much easier.
Re: how to create programatically an instance of given DataType in UML [message #1073830 is a reply to message #1073776] Thu, 25 July 2013 11:08 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille Letavernier
Messages: 440
Registered: February 2011
Senior Member
Hi,

You can instantiate the definition of the DataType, which is an Ecore EClass.

To retrieve the definition:

Profile p = ...;
DataType dt = ...;
EClass datatypeDefinition = (EClass)p.getDefinition(dt);
EObject datatypeInstance = datatypeDefinition.getEPackage().getEFactoryInstance().create(datatypeDefinition);


It is however much simpler to use static profiles and generate the Java API. Then this snippet becomes:

MyType = MyProfileFactory.eINSTANCE.createMyType();


Regards,
Camille
Re: how to create programatically an instance of given DataType in UML [message #1077200 is a reply to message #1073830] Thu, 01 August 2013 07:08 Go to previous message
hongyu liu is currently offline hongyu liu
Messages: 6
Registered: March 2012
Junior Member
Thanks a lot.
Previous Topic:The interpretation of action Execution Specification in Papyrus
Next Topic:EMF transaction for inserting a new Element in a diagram
Goto Forum:
  


Current Time: Thu Aug 28 23:33:34 EDT 2014

Powered by FUDForum. Page generated in 0.01915 seconds