[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, JÃrgen,

OCL, as UML, does not distinguish between "attributes" and "references" as
Ecore does; these are all just Properties.  Thus, "der:" constraints
specified in OCL can derive read-only values for either of these kinds of
properties.

You can use OCL in the EMF code generation process to specify derived
properties as described in this article:

http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL/article.html

There are also plans for the UML2 UML and OCL components to implement
support for specifying OCL constraints such as property derivations in UML
models:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=163808
https://bugs.eclipse.org/bugs/show_bug.cgi?id=105199

I am not sure whether the latter item is intended to support generating code
from the OCL constraints, as in the article or otherwise.

Cheers,

Christian


JG wrote:

> 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