Computing derived attribute values with dynamic EMF [message #1727686] |
Fri, 25 March 2016 09:29 |
Yves BERNARD Messages: 152 Registered: July 2014 |
Senior Member |
|
|
I try to provide computation of derived attribute values for EMF models which are build dynamically. I think that the OCL plugin is able to do almost all for me assuming I use it properly.
The simplest approach seems to generate dynamically the EAnnotations that are used by the Ecore delegation mechanism.
According to this document: https://wiki.eclipse.org/OCL/OCLinEcore my understanding is that these annotations should be linked to the derived EStructuralFeature. So I tried something like this:
EcoreUtil.setAnnotation(structuralFeature, OCLConstants.OCL_DELEGATE_URI, "derivation","<...OCL code...>")
It still does not work because I guess I have to trigger the creation of the settingDelegates but I have not find how to do that so far.
Yves
|
|
|
|
|
Re: Computing derived attribute values with dynamic EMF [message #1728138 is a reply to message #1727703] |
Thu, 31 March 2016 10:20 |
Yves BERNARD Messages: 152 Registered: July 2014 |
Senior Member |
|
|
Hi Ed,
I think I'm not far away from success but a tricky point remains. Maybe you have a solution for it.
Following the instructions given by the OCLinEcore documentation (see my previous message), I can provide a string specifying the OCL code of the derivation. For example assuming two Boolean attributes "isOk" and "isNotOk", I can specify "not isOk" as the derived value of the "isNotOk" attribute. This works fine and the value of "isNotOk" is properly computed according to the value of the "isOK" attribute.
The point is that the derivation constraints shall be specified in a UML model, through UML::Constraints owned by the classifier. They look something like:
context MyClassifier::isNotOk : Boolean
derive: not isOk
Note that there can be more than one derivation per UML::Constraint::specification.
So, I need to parse the body of the specification to retrieve the constrained attribute and the OCL expression to configure the SettingDelegate. Once again, OCL does it for me. The parser provides a List of org.eclipse.ocl.ecore.Contraints that I can use for getting both the constrained attribute(s) and the corresponding OCL expression(s).
The point is that these expressions has the ExpressionInOCL type. The strings I can get from their "body expressions" are not valid OCL code that I could use to create the eAnnotation.
An ugly solution would be, once the derived attribute identified, to restart from the uml::Constraint::specification, trying to parse it using some specific code in order to retrieve the string of the OCL code... But this would be rather cumbersome!
Do you see a better solution, maybe using an OCLAnalyser or something like this?
Thanks,
Yves
|
|
|
|
Re: Computing derived attribute values with dynamic EMF [message #1728163 is a reply to message #1728138] |
Thu, 31 March 2016 12:49 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
Sorry, you require too much telepathy and intuition.
There is no org.eclipse.ocl.ecore.Contraint class. The classic OCL has
an org.eclipse.ocl.ecore.Constraint but then you refer to
ExpressionInOCL which rather suggests that you are using the Pivot OCL
as does your consideration of OCLinEcore.
If you want me to look at something, please provide code so that I can
understand rather than guess at what you are really doing.
See https://wiki.eclipse.org/OCL/ForumNetiquette
Regards
Ed Willink
On 31/03/2016 11:20, Yves BERNARD wrote:
> Hi Ed,
>
> I think I'm not far away from success but a tricky point remains.
> Maybe you have a solution for it.
>
> Following the instructions given by the OCLinEcore documentation (see
> my previous message), I can provide a string specifying the OCL code
> of the derivation. For example assuming two Boolean attributes "isOk"
> and "isNotOk", I can specify "not isOk" as the derived value of the
> "isNotOk" attribute. This works fine and the value of "isNotOk" is
> properly computed according to the value of the "isOK" attribute.
>
> The point is that the derivation constraints shall be specified in a
> UML model, through UML::Constraints owned by the classifier. They look
> something like:
>
> context MyClassifier::isNotOk : Boolean
> derive: not isOk
>
>
> Note that there can be more than one derivation per
> UML::Constraint::specification.
>
> So, I need to parse the body of the specification to retrieve the
> constrained attribute and the OCL expression to configure the
> SettingDelegate. Once again, OCL does it for me. The parser provides a
> List of org.eclipse.ocl.ecore.Contraints that I can use for getting
> both the constrained attribute(s) and the corresponding OCL
> expression(s).
>
> The point is that these expressions has the ExpressionInOCL type. The
> strings I can get from their "body expressions" are not valid OCL code
> that I could use to create the eAnnotation.
>
> An ugly solution would be, once the derived attribute identified, to
> restart from the uml::Constraint::specification, trying to parse it
> using some specific code in order to retrieve the string of the OCL
> code... But this would be rather cumbersome!
>
> Do you see a better solution, maybe using an OCLAnalyser or something
> like this?
>
> Thanks,
>
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03003 seconds