Skip to main content


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 16:16 Go to next message
Dominik Sojer is currently offline Dominik SojerFriend
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 16:33 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
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, EMF, Eclipse IDE?
Go to: http://devhub.karakun.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 17:11 Go to previous messageGo to next message
Dominik Sojer is currently offline Dominik SojerFriend
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 12:57 Go to previous messageGo to next message
Dominik Sojer is currently offline Dominik SojerFriend
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 18:58 Go to previous messageGo to next message
Volker Wegert is currently offline Volker WegertFriend
Messages: 182
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 12:30 Go to previous message
Dominik Sojer is currently offline Dominik SojerFriend
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: Fri Apr 19 22:17:31 GMT 2024

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

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

Back to the top