[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)

Jürgen,

This kind of subsetting is quite common in UML; in the metamodel 
implementation we identify the feature as a derived and volatile and 
implement it like this (for example):

protected static final int[] OWNED_TYPE_ESUPERSETS = new 
int[]{UMLPackage.PACKAGE__PACKAGED_ELEMENT};

public EList getOwnedTypes() {
    return new DerivedSubsetEObjectEList(Type.class, this, 
UMLPackage.PACKAGE__OWNED_TYPE, OWNED_TYPE_ESUPERSETS);
}

Here the accessor returns a changeable list for the Package::ownedType 
feature, which derives its contents from the Package::packagedElement 
feature (based on type, i.e. instances of the Type metaclass) and which 
automatically delegates changes to the superset feature 
(Package::packagedElement).

Kenn

"JG" <jguni@xxxxxx> wrote in message news:ekm066$v0g$1@xxxxxxxxxxxxxxxxxxxx
> Hi all,
>
> I am using Rose/Ecore to model my application models (for the
> representation of database metadata). I have a number of a
> Associations/EReferences whose members are actually a subset of another
> Association. For example, a Schema contains among other things tables
> and structured types (which are both subclasses of ModelElement). I have
> a "content" reference from schema which can contain both of these (via
> the common superclass). But I also want specific references like
> "tables" and "structuredTypes" in the Schema class, which only contain
> the tables and structured types, respectively.
> Of course I could always write my own getters and setters into the
> generated code that would use the "content" relationship and filter only
> those classes that are needed. But I am hesitant to do so, as this would
> mean a lot of effort and would make it more difficult to keep my still
> evolving model in sync with the code.
> I considered adding annotations and modify the way EMF generates its
> code (so that EMF creates the getters and setters for these "derived"
> references for me), but when I took a look at the EMF codegen templates
> I lost my courage, as they are quite hard to read, and I did not want to
> invest effort in modify the EMF 2.2 templates and have to do the
> modification again for the next version of EMF that might change these
> templates.
>
> My current "solution" is to have these derived references redundantly,
> and setting them via a Helper class. For example, I have an
> "attachTableToSchema method, which adds the given table both to the
> "content" and to the "tables" relationship. This is however, quite
> cumbersome and was only intended as a temporary fix.
>
> So to come to the question: I understand that OCL can (or is meant to be
> able to?) specify derived attributes. Could this mechanism also be used
> to specify a derived relationship (which is usually many-valued).
>
> Regards
>
> Jürgen