Pregunta

I have generated model code from Ecore. Within my model I have a derived reference: derivedThings.

What I want to do in the derivedThingsImpl is the following:

I want to traverse the whole model and depending on the element, I want to add it to a collection or not.

for(TreeIterator iter = EcoreUtil.getAllContents(rootObject); iter.hasNext();)
 ...

The problem is, how can I access the root object from the derivedThingsImpl ?! is there something like getRootObject() ?!

Thanks

UPDATE:

EObject e = this;
while(e.eContainer() != null) {
  e =  e.eContainer()
  if (e instanceof RootElement)
    break;
}
// No I should have the root element. Is this a good and clean way ?!
¿Fue útil?

Solución

There is a better way of doing it:

EcoreUtil.getRootContainer(eObject);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top