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.

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.

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...

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.