[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.modeling.mdt.uml2.ocl] Re: Using OCL to specify derived References (NOT attributes)

Hi Kenn,

Kenn Hussey wrote:
> Yes, one of the goals of the latter feature would be to enhance the UML2 
> code generator to support generating code based on OCL constraints.


I gave a manual implementation a try. I browsed through the many
different special EList implementations in the
org.eclipse.uml2.common.util package. But I am still unsure, which one
to use, since there is no documentation telling me when to use which
list, maybe you can help me.
My model has two classes ModelElement and Namespace. A Namespace can
"contain" ModelElements (roles container and content, respectively)
(BTW: Namespace is a subclass of ModelElement ). As the name implies,
the "contain" relationship is a containment relationship (i.e., the
containment flag is set to true in the Ecore model), and as such the
original implementation for the "contain" relationship is done with
"EObjectContainmentWithInverseEList".

I have an SQL metamodel, where Columns are contained in a ColumnSet
(roles column and columnset). This containment relationship is a
subrelationship of the one between ModelElement and Namespace, so the
reference "content" is a superset of "columns". Maybe I should have
picked an easier subset, because maybe having Containment is causing me
trouble.
Since I have containment and an inverse, I decided to use
SubsetSupersetEObjectContainmentWithInverseEList to implement the EList
on the "n side" of the relationships (i.e., columns and content"

My modified "getContent" method in NamespaceImpl looks like this, I have
commented out the old implementation:

*********************************************************
protected static final int[] NAMESPACE_CONTENT_ESUBSETS =
	new int[]{RelationalPackage.COLUMN_SET__COLUMNS};

public EList getContent() {
	if (content == null) {
//content = new EObjectContainmentWithInverseEList(ModelElement.class,
//this, CorePackage.NAMESPACE__CONTENT,
//CorePackage.MODEL_ELEMENT__CONTAINER);
			
content = new SubsetSupersetEObjectContainmentWithInverseEList(
	ModelElement.class, //(Class dataClass,
	this, //InternalEObject owner,
	CorePackage.NAMESPACE__CONTENT, //int featureID,
	null, //int[] supersetFeatureIDs,
	NAMESPACE_CONTENT_ESUBSETS, //int[] subsetFeatureIDs
	CorePackage.MODEL_ELEMENT__CONTAINER);//, int inverseFeatureID)
}
return content;
}
*********************************************************

This is the getColumns() in ColumnSetImpl:

*********************************************************
protected static final int[] COLUMN_SET_ESUPERSETS =
	new int[]{CorePackage.NAMESPACE__CONTENT};
		
public EList getColumns() {
	if (columns == null) {
//columns = new EObjectWithInverseResolvingEList(Column.class,
//this, RelationalPackage.COLUMN_SET__COLUMNS,
//RelationalPackage.COLUMN__COLUMN_SET);
			
columns = new SubsetSupersetEObjectContainmentWithInverseEList(
	Column.class, //(Class dataClass,
	this, //InternalEObject owner,
	RelationalPackage.COLUMN_SET__COLUMNS, //int featureID,
	COLUMN_SET_ESUPERSETS, //int[] supersetFeatureIDs,
	null, //int[] subsetFeatureIDs
	RelationalPackage.COLUMN__COLUMN_SET);//, int inverseFeatureID)
	}
return columns;
}
*********************************************************


I did not modify the association ends with multiplicity 1 (since I don't
know how). Well, it doesn't work this way. If I add a column to a
columnset using the EList returned from getColumns(), i.e.
colSet.getColumns().add(myColumn);

I will later receive a "null" when I try to access the ColumnSet of this
column:

myColumn.getColumnSet();


How should I modify the other association ends (those with multiplicity
1)? Or did I use the wrong UML2 Elist? Or did I get it all wrong? Is
there any documentation on the usage of the different types of UML2 ELists?


Regards

Jürgen