Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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: Wed Jul 23 17:21:55 EDT 2025

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

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

Back to the top