[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.modeling.mdt.uml2.ocl] Re: ocl in ecore meta model
|
Hello, Luis,
The screenshots in the article show "ocl" as the "source" of the constraint
annotations, but that is just the editor's presentation of what is really a
longer namespace URI: http://www.eclipse.org/OCL/examples/ocl.
With this, your "body" detail should be picked up as the body expression for
the EOperation.
Now, having said that, what you are trying to specify as an operation is not
valid. If I read correctly, you are attempting to specify an operation
that changes the state of the context element (by setting a property). OCL
cannot do this; it is a read-only language, providing no syntax for
assignment. It can only specify constraints and query expressions.
HTH,
Christian
Luis Pedro wrote:
> Hi there,
> I've defined my metamodel using ecore but now I want to give some
> behavior to some operations that I want to define. I've tried to use
> some OCL, but it looks like nothing changes between the version without
> or with OCL.
>
> - I added an operation in the ecore model named addName(EString);
> - To this operation I added an EAnotation and I named it ocl;
> - To the EAnotation I added a "Detail Entry" which has as key "body" and
> as Value the constraint :
> "if(myName)
> self.name = myName
> else
> false
> endif"
> where name is an attribute from my class.
>
> When I validate the ecore model everything goes fine; when I "Generate
> All" from the .genemodel I don't get any errors; but, in the java
> generated code I don't have any difference appart from the fact that I
> have new comments in the method signature:
> * @model annotation="ocl invariant='if(myName)\r self.name =
> myName\relse\r false\rendif'"
>
> So... it looks like my invariant is just transformed into a comment.
> Besides this, I added to "Model Plug-in Variables" the following:
> EMFT_OCL=org.eclipse.emf.ocl; Switched to True the "Dinamic Templates"
> and added "Templates Directory" equal to
> /org.eclipse.emf.ocl.examples.codegen/templates
>
> Any hints?
>
> Thanks very much for your help
>
> Luis Pedro