Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Problem with creating model elements from Java
[Xpand] Problem with creating model elements from Java [message #494784] Mon, 02 November 2009 11:16 Go to next message
Dominik Sojer is currently offline Dominik Sojer
Messages: 4
Registered: November 2009
Junior Member
Hi,

I am working with a MDD tool, that is based on oAW and I am trying to create new model elements with Java during the model-to-code transformation.

However, I faced the problem, that I cannot instanciate new model elements, because they exist only as Java Interfaces in the model code. The documentation of oAW mentions in a very short passage, that one should use "DataFactory", to create new model elements from Java, but it then only references to the EMF documentation for further details, where I did not find any further information.

My problem is, that I did not find out, how to use this "DataFactory": I did not find it in the API documentation, nor via Eclipse's code completion feature.

So maybe one of you can explain to me, how I can instantiate new model elements from Java.

Thank you in advance!

Best regards,

Dominik
Re: [Xpand] Problem with creating model elements from Java [message #494789 is a reply to message #494784] Mon, 02 November 2009 11:33 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

Dominik,

if you follow the tutorial one of the steps is to create the EMF implementation classes for the Ecore model created, whose NS Prefix is 'data' in this example. When you create the implementation from the .genmodel, one of those artifacts EMF creates is a Factory, which will be named as DataFactory after the NS Prefix defined for the metamodel. With this factory (more specific: with its implementation, since DataFactory is just the interface, and the implementation is accessible through that interface) instances for your EPackage can be created.
The documentation refers here to EMF, since all this is scope of the EMF framework.

Maybe your problem is just that you have this Factory interface and don't know how to use it? The factory will have en eINSTANCE field which is an instance of the factory implementation. Through this instance you can create instances of the types defined in the package.

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [Xpand] Problem with creating model elements from Java [message #494803 is a reply to message #494784] Mon, 02 November 2009 12:11 Go to previous messageGo to next message
Dominik Sojer is currently offline Dominik Sojer
Messages: 4
Registered: November 2009
Junior Member
Karsten,

thank you very much, your explanation made this whole topic clear to me and I was able to the Factory.

Thank you!

Dominik
Re: [Xpand] Problem with creating model elements from Java [message #495268 is a reply to message #494784] Wed, 04 November 2009 07:57 Go to previous messageGo to next message
Dominik Sojer is currently offline Dominik Sojer
Messages: 4
Registered: November 2009
Junior Member
Hi,

with the help of Karsten, I am now able to instantiate new objects during the model-to-code transformation. However, a new problem has arisen at this point:

The objects, I instantiate will be put in a list, that is an attribute of an already existing model element. But later in the M2C transformation, the workflow stops and puts an error to the console, stating that my newly created objects "[are] not contained in a resource".

Does anyone of you have an idea, what I did wrong? In my opinion, these objects should be contained in the list, where I put them and so there should be a transitive containment relation up to the root element of my model. However, there seems to be some kind of problem...

Thank you in advance for your help!

Dominik
Re: [Xpand] Problem with creating model elements from Java [message #495421 is a reply to message #495268] Wed, 04 November 2009 13:58 Go to previous messageGo to next message
Volker Wegert is currently offline Volker Wegert
Messages: 169
Registered: July 2009
Senior Member
Hi.

Dominik Sojer <sojer@in.tum.de> writes:
> The objects, I instantiate will be put in a list, that is an attribute of an
> already existing model element. But later in the M2C transformation, the
> workflow stops and puts an error to the console, stating that my newly
> created objects "[are] not contained in a resource".
>
> Does anyone of you have an idea, what I did wrong? In my opinion, these
> objects should be contained in the list, where I put them and so there
> should be a transitive containment relation up to the root element of my
> model.

There should be, yes. But is it really there? Your list - I assume you've got
a reference with multiplicity of ..*? Check whether the containment attribute
on that reference is set, otherwise there's a 'gap' in your containment
relations.

HTH
Volker


--
* Volker Wegert * http://www.volker-wegert.de/contact *
The computer revolution is over. The computers won.
Re: [Xpand] Problem with creating model elements from Java [message #495585 is a reply to message #494784] Thu, 05 November 2009 07:30 Go to previous message
Dominik Sojer is currently offline Dominik Sojer
Messages: 4
Registered: November 2009
Junior Member
Thank you Volker!. You were right, the containment attribute was not set.

Best regards,

Dominik
Previous Topic:Xpand is very slow in IDE mode
Next Topic:GRAVE: Error in Component of type org.eclipse.xpand2.Generator:
Goto Forum:
  


Current Time: Sun Apr 20 12:22:13 EDT 2014

Powered by FUDForum. Page generated in 0.02421 seconds