문제

What's wrong with this model:

/** @model abstract="true" */
public interface ContainedObject {
   /** @model */
   public Container getContainer();
}

/** @model abstract="true" */
public interface Container extends ContainedObject { }

/* @model */
public interface Category extends Container {
   /** @model containment="true" opposite="container" */
   public List<Category> getCategories();   
   /** @model containment="true" opposite="container" */
   public List<Variable> getVariables();
}

/** @model */
public interface Variable extends ContainedObject { }

I want bidirectionality between the contained object and its container. For the above java i'm getting the following error message when i try to create the .genmodel:

the opposite 'container' already has attribute 'categories' of 'Category' 
as its opposite

what's wrong with this model?

도움이 되었습니까?

해결책

The opposite relation has to be a 1:1 relation. It is -- to the best of my knowledge -- not possible to have two references point to the same opposite reference. This is more clear when creating EMF models using the Ecore editor instead of annotated Java classes.

In your case, you could either have one List<ContainedObject> containedObjects and create two additional getter methods getVariables() and getCategories(), filtering the respective elements from that common list, or you could create two container references, one for categories and one for variables.

Alternatively, you could drop the explicit container reference and just use the implicit eContainer / eContents features of EObject.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top