Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » OCL expressions in Rose models
OCL expressions in Rose models [message #59360] |
Thu, 26 October 2006 12:15 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: gkibebew.yahoo.com
Hi,
I have started learning EMFT. I could not find material on how OCL
expressions should be applied to Rational Rose model elements to be read
by the EMFT parser. In the documentation part of each element or as an
attached note or ...? What should I have installed to be able to add
constraints to my Ecore models in Eclipse environment?
Some ideas? Thank you,
Kibebew
|
|
|
Re: OCL expressions in Rose models [message #59728 is a reply to message #59360] |
Tue, 31 October 2006 13:17 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Kibebew,
If I recall correctly, invariant constraints are typically modeled in Rose
as Operations stereotyped as <<inv>>. The operation body then contains
that OCL constraint expression.
However, as indicated in reply to your other question, you can specify
arbitrary Ecore annotations in your Rose model using the properties defined
in Ecore.pty. In order for the EMFT Validation framework to find and
evaluate these constraints at run-time, you could define a dynamic
constraint provider (a class implementing the IModelConstraintProvider
interface) that finds the annotations for invariant constraints on the
EClasses of your model elements and extracts the OCL expressions from them.
Then, it is a matter of using the OCL interpreter to evaluate these
constraints. The EMFT OCL programmer's guide in the OCL SDK has examples
of evaluating OCL constraint expressions, as does the on-line article at
http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL /article.html.
HTH,
Christian
Kibebew wrote:
> Hi,
> I have started learning EMFT. I could not find material on how OCL
> expressions should be applied to Rational Rose model elements to be read
> by the EMFT parser. In the documentation part of each element or as an
> attached note or ...? What should I have installed to be able to add
> constraints to my Ecore models in Eclipse environment?
>
> Some ideas? Thank you,
>
> Kibebew
|
|
|
Re: OCL expressions in Rose models [message #59864 is a reply to message #59728] |
Thu, 02 November 2006 11:03 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: gkibebew.yahoo.com
Hi Christian,
Thank you. Rational told me that OCL is not supported at all. I am using
ecore.pty to specify OCL expressions in the models.
The expressions imported from Rose models this way are attached to classes
in the Ecore model. For example an annotation defined on class
IsotropicMaterial as
http://www.eclipse.org/OCL/examples/ocl invariant="nhu>-1.0 and nhu<0.5"
derived='G=E/(2.0*(1+nhu))'
results in
<eClassifiers xsi:type="ecore:EClass" name="IsotropicMaterial"
eSuperTypes="#//Material">
<eAnnotations source="http://www.eclipse.org/OCL/examples/ocl">
<details key="invariant" value="nhu>-1.0 and nhu<0.5"/>
<details key="derived" value="G=E/(2.0*(1+nhu))"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="E"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="G"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="nhu"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject"/>
</eClassifiers>
..
I think that should not make a difference. I later reorganised it to
<eStructuralFeatures xsi:type="ecore:EAttribute" name="nhu"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject">
<eAnnotations source="http://www.eclipse.org/OCL/examples/ocl">
<details key="invariant" value="nhu>-1.0 and nhu<0.5"/>
</eAnnotations>
</eStructuralFeatures>
same thing for G.
The problem I have now is that the annotations are ignored by the
generated code and the getter has only "return nhu" and there is the usual
setter method. I appreciate your help.
Below is my .genModel content just if needed
thank you,
kibebew
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
modelDirectory="/test2/src"
modelPluginID="test2" modelName="MaterialCatalog"
importerID="org.eclipse.emf.importer.rose">
<foreignModel>C:\Home\OCL\Exercises\MaterialCatalog.mdl</foreignModel >
<genPackages prefix="Catalog" disposableProviderFactory="true"
ecorePackage="MaterialCatalog.ecore#/">
<genClasses ecoreClass="MaterialCatalog.ecore#//MaterialCatalog">
<genFeatures property="None" children="true" createChild="true"
ecoreFeature="ecore:EReference
MaterialCatalog.ecore#//MaterialCatalog/materials"/>
</genClasses>
<genClasses ecoreClass="MaterialCatalog.ecore#//Material">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//Material/ID"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//Material/temperature"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//Material/density"/>
</genClasses>
<genClasses ecoreClass="MaterialCatalog.ecore#//IsotropicMaterial">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//IsotropicMaterial/E"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//IsotropicMaterial/G"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//IsotropicMaterial/nhu"/>
</genClasses>
</genPackages>
</genmodel:GenModel>
|
|
| |
Re: OCL expressions in Rose models [message #59986 is a reply to message #59912] |
Fri, 03 November 2006 07:56 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: gkibebew.yahoo.com
Hi Christian,
Thank you. Yes I use your article. I have used your template too. I have
tried your latest recommendation.
As you stated in the article, I expect the generated getG() or getNhu()
method to have a TODO part and every thing but OCL related code. But what
is generated in my workspace (for class IsotropicMaterialImpl) is just
public Float getG() {
return g;
}
and there is a setter method
public void setG(Float newG) {
Float oldG = g;
g = newG;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
CatalogPackage.ISOTROPIC_MATERIAL__G, oldG, g));
}
It seems that the code generator is not looking at the annotations. Your
template would replace the TODO parts if the generated code considered the
annotations.
Greetings,
Kibebew
|
|
|
Re: OCL expressions in Rose models [message #60053 is a reply to message #59986] |
Fri, 03 November 2006 18:50 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Kibebew,
Sorry, I was mistaken in the set-up of the invariant constraint. The
invariant annotation is attached to an EOperation having the
(EDiagnosticChain, EMap) signature of EMF's validation methods. See, for
example, the validateEmployees operation in the article's example model.
These "validate" operations are what the generated EValidator
implementation for your metamodel will invoke when you select the
"Validate" context menu action.
Regarding the generation of the derived structural features. They must be
set as transient and volatile, which is EMF's way of indicating that a
feature's value is derived from other features.
Have a look at the sample Ecore model in the article, to see how the
operations and structural features are defined and how they differ from
yours.
HTH,
Christian
Kibebew wrote:
> Hi Christian,
>
> Thank you. Yes I use your article. I have used your template too. I have
> tried your latest recommendation.
>
> As you stated in the article, I expect the generated getG() or getNhu()
> method to have a TODO part and every thing but OCL related code. But what
> is generated in my workspace (for class IsotropicMaterialImpl) is just
>
> public Float getG() {
> return g;
> }
>
> and there is a setter method
>
> public void setG(Float newG) {
> Float oldG = g;
> g = newG;
> if (eNotificationRequired())
> eNotify(new ENotificationImpl(this, Notification.SET,
> CatalogPackage.ISOTROPIC_MATERIAL__G, oldG, g));
> }
>
> It seems that the code generator is not looking at the annotations. Your
> template would replace the TODO parts if the generated code considered the
> annotations.
>
> Greetings,
> Kibebew
|
|
|
Re: OCL expressions in Rose models [message #595010 is a reply to message #59360] |
Tue, 31 October 2006 13:17 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Kibebew,
If I recall correctly, invariant constraints are typically modeled in Rose
as Operations stereotyped as <<inv>>. The operation body then contains
that OCL constraint expression.
However, as indicated in reply to your other question, you can specify
arbitrary Ecore annotations in your Rose model using the properties defined
in Ecore.pty. In order for the EMFT Validation framework to find and
evaluate these constraints at run-time, you could define a dynamic
constraint provider (a class implementing the IModelConstraintProvider
interface) that finds the annotations for invariant constraints on the
EClasses of your model elements and extracts the OCL expressions from them.
Then, it is a matter of using the OCL interpreter to evaluate these
constraints. The EMFT OCL programmer's guide in the OCL SDK has examples
of evaluating OCL constraint expressions, as does the on-line article at
http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL /article.html
HTH,
Christian
Kibebew wrote:
> Hi,
> I have started learning EMFT. I could not find material on how OCL
> expressions should be applied to Rational Rose model elements to be read
> by the EMFT parser. In the documentation part of each element or as an
> attached note or ...? What should I have installed to be able to add
> constraints to my Ecore models in Eclipse environment?
>
> Some ideas? Thank you,
>
> Kibebew
|
|
|
Re: OCL expressions in Rose models [message #595078 is a reply to message #59728] |
Thu, 02 November 2006 11:03 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: gkibebew.yahoo.com
Hi Christian,
Thank you. Rational told me that OCL is not supported at all. I am using
ecore.pty to specify OCL expressions in the models.
The expressions imported from Rose models this way are attached to classes
in the Ecore model. For example an annotation defined on class
IsotropicMaterial as
http://www.eclipse.org/OCL/examples/ocl invariant="nhu>-1.0 and nhu<0.5"
derived='G=E/(2.0*(1+nhu))'
results in
<eClassifiers xsi:type="ecore:EClass" name="IsotropicMaterial"
eSuperTypes="#//Material">
<eAnnotations source="http://www.eclipse.org/OCL/examples/ocl">
<details key="invariant" value="nhu>-1.0 and nhu<0.5"/>
<details key="derived" value="G=E/(2.0*(1+nhu))"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="E"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="G"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="nhu"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject"/>
</eClassifiers>
..
I think that should not make a difference. I later reorganised it to
<eStructuralFeatures xsi:type="ecore:EAttribute" name="nhu"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EFloatObject">
<eAnnotations source="http://www.eclipse.org/OCL/examples/ocl">
<details key="invariant" value="nhu>-1.0 and nhu<0.5"/>
</eAnnotations>
</eStructuralFeatures>
same thing for G.
The problem I have now is that the annotations are ignored by the
generated code and the getter has only "return nhu" and there is the usual
setter method. I appreciate your help.
Below is my .genModel content just if needed
thank you,
kibebew
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
modelDirectory="/test2/src"
modelPluginID="test2" modelName="MaterialCatalog"
importerID="org.eclipse.emf.importer.rose">
<foreignModel>C:\Home\OCL\Exercises\MaterialCatalog.mdl</foreignModel >
<genPackages prefix="Catalog" disposableProviderFactory="true"
ecorePackage="MaterialCatalog.ecore#/">
<genClasses ecoreClass="MaterialCatalog.ecore#//MaterialCatalog">
<genFeatures property="None" children="true" createChild="true"
ecoreFeature="ecore:EReference
MaterialCatalog.ecore#//MaterialCatalog/materials"/>
</genClasses>
<genClasses ecoreClass="MaterialCatalog.ecore#//Material">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//Material/ID"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//Material/temperature"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//Material/density"/>
</genClasses>
<genClasses ecoreClass="MaterialCatalog.ecore#//IsotropicMaterial">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//IsotropicMaterial/E"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//IsotropicMaterial/G"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute
MaterialCatalog.ecore#//IsotropicMaterial/nhu"/>
</genClasses>
</genPackages>
</genmodel:GenModel>
|
|
| |
Re: OCL expressions in Rose models [message #595116 is a reply to message #59912] |
Fri, 03 November 2006 07:56 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: gkibebew.yahoo.com
Hi Christian,
Thank you. Yes I use your article. I have used your template too. I have
tried your latest recommendation.
As you stated in the article, I expect the generated getG() or getNhu()
method to have a TODO part and every thing but OCL related code. But what
is generated in my workspace (for class IsotropicMaterialImpl) is just
public Float getG() {
return g;
}
and there is a setter method
public void setG(Float newG) {
Float oldG = g;
g = newG;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
CatalogPackage.ISOTROPIC_MATERIAL__G, oldG, g));
}
It seems that the code generator is not looking at the annotations. Your
template would replace the TODO parts if the generated code considered the
annotations.
Greetings,
Kibebew
|
|
|
Re: OCL expressions in Rose models [message #595137 is a reply to message #59986] |
Fri, 03 November 2006 18:50 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Kibebew,
Sorry, I was mistaken in the set-up of the invariant constraint. The
invariant annotation is attached to an EOperation having the
(EDiagnosticChain, EMap) signature of EMF's validation methods. See, for
example, the validateEmployees operation in the article's example model.
These "validate" operations are what the generated EValidator
implementation for your metamodel will invoke when you select the
"Validate" context menu action.
Regarding the generation of the derived structural features. They must be
set as transient and volatile, which is EMF's way of indicating that a
feature's value is derived from other features.
Have a look at the sample Ecore model in the article, to see how the
operations and structural features are defined and how they differ from
yours.
HTH,
Christian
Kibebew wrote:
> Hi Christian,
>
> Thank you. Yes I use your article. I have used your template too. I have
> tried your latest recommendation.
>
> As you stated in the article, I expect the generated getG() or getNhu()
> method to have a TODO part and every thing but OCL related code. But what
> is generated in my workspace (for class IsotropicMaterialImpl) is just
>
> public Float getG() {
> return g;
> }
>
> and there is a setter method
>
> public void setG(Float newG) {
> Float oldG = g;
> g = newG;
> if (eNotificationRequired())
> eNotify(new ENotificationImpl(this, Notification.SET,
> CatalogPackage.ISOTROPIC_MATERIAL__G, oldG, g));
> }
>
> It seems that the code generator is not looking at the annotations. Your
> template would replace the TODO parts if the generated code considered the
> annotations.
>
> Greetings,
> Kibebew
|
|
|
Goto Forum:
Current Time: Tue Aug 27 23:43:53 GMT 2024
Powered by FUDForum. Page generated in 0.04558 seconds
|