Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » OCL and Context
OCL and Context [message #44091] Wed, 09 August 2006 11:31 Go to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
Hi,

I have looked to org.eclipse.emf.ocl, but I'am wondering that I cant
find in the whole model any context attribute.


Why not, if I would safe an OCLExpression, isn't it important to save
also the context.

Chris
Re: OCL and Context [message #44124 is a reply to message #44091] Wed, 09 August 2006 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

As far as the serialized OCLExpression is concerned, it only needs to know
about the variables that it references, including "self" (which is typed by
the context classifier). How these references are saved is determined by
the implementation of persistence support in the Environment that was used
to parse the expression. The EcoreEnvironment provides persistence of
variables, but this can certainly be customized by a client.

The problem of persisting the OCLExpression *in context* is up to the client
application to solve, depending on its need. I could imagine attaching an
OCLExpression via an EAnnotation to an EClassifier, EOperation, or
EStructuralFeature in an Ecore model; this would define the context as the
owner of the annotation. Or, a separate model could be devised that
associates an OCLExpression with its context via some kind of
association-class (which references both). An application could even
define its own Environment implementation that is serializable and contains
the expressions that it parsed; presumably it would reference the context
in some way.

HTH,

Christian


Chris Lenz wrote:

> Hi,
>
> I have looked to org.eclipse.emf.ocl, but I'am wondering that I cant
> find in the whole model any context attribute.
>
>
> Why not, if I would safe an OCLExpression, isn't it important to save
> also the context.
>
> Chris
Re: OCL and Context [message #44154 is a reply to message #44124] Wed, 09 August 2006 14:09 Go to previous messageGo to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
Shure that's clear, the client can save this in the way it wants.

Another question: I am not clear I understand the following thing right:

package organisation context Organisation::testString():String
body: result = 'Hallo'
endpackage

if I let parse the following thing, I get from the parser one
OCLExpression: body: result = 'Hallo'
If I evaluate this I allways get back false. What does this statement
mean???

The other thing ist the postcondition:
package organisation context Organisation::testBoolean():Boolean
pre: self.name='test'
body: result = ('test'=self.name)
post: self.name=self.name@pre
endpackage

When I evaluate the postcondition, where do I get the @pre of name.

Maybe my problem is how to execute this whole statement! Do I have to
build an Environment to execute this Expressions.


Christian W. Damus schrieb:
> Hi, Chris,
>
> As far as the serialized OCLExpression is concerned, it only needs to know
> about the variables that it references, including "self" (which is typed by
> the context classifier). How these references are saved is determined by
> the implementation of persistence support in the Environment that was used
> to parse the expression. The EcoreEnvironment provides persistence of
> variables, but this can certainly be customized by a client.
>
> The problem of persisting the OCLExpression *in context* is up to the client
> application to solve, depending on its need. I could imagine attaching an
> OCLExpression via an EAnnotation to an EClassifier, EOperation, or
> EStructuralFeature in an Ecore model; this would define the context as the
> owner of the annotation. Or, a separate model could be devised that
> associates an OCLExpression with its context via some kind of
> association-class (which references both). An application could even
> define its own Environment implementation that is serializable and contains
> the expressions that it parsed; presumably it would reference the context
> in some way.
>
> HTH,
>
> Christian
>
>
> Chris Lenz wrote:
>
>> Hi,
>>
>> I have looked to org.eclipse.emf.ocl, but I'am wondering that I cant
>> find in the whole model any context attribute.
>>
>>
>> Why not, if I would safe an OCLExpression, isn't it important to save
>> also the context.
>>
>> Chris
>
Re: OCL and Context [message #44185 is a reply to message #44154] Wed, 09 August 2006 15:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

EMFT OCL does not provide evaluation support for operation pre/post/body
condition constraints out-of-the-box. You can use techniques such as are
demonstrated in the article on eclipse.org (announced recently in this
newsgroup) to evaluate preconditions and to implement operation body
*expressions* (as opposed to body condition "constraints"). These are
relatively straight-forward problems, as they require only adding a
variable to the environment for each operation parameter.

In attempting to evaluate your body condition constraint, I suspect that you
were evaluating it out of context as though it were an invariant
constraint. I am surprised that it didn't actually fail with a run-time
exception, because the "result" variable would not have been bound.

Postconditions are another matter, and are complicated by two problems:
- @pre expressions evaluate to the pre-condition value of
an expression (as you indicated)
- oclIsNew() in a postcondition queries whether an object was created
during the execution of the operation

EMFT OCL provides nothing to help with either of these. It should be fairly
straight-forward to analyze an operation's postconditions to see what the
@pre expressions are and to evaluate them at the beginning of the
operation, capturing the values. However, the EvaluationEnvironment API
does not provide the means to store or access these values and isn't
extensible enough to allow a client to add this capability (besides which,
the internal EvaluationVisitor would need changes). This sounds like rich
material for enhancement requests in Bugzilla.

oclIsNew() is a trickier problem, and I won't speculate on a solution for
because I don't even know that it would be feasible in Java.

Cheers,

Christian

Chris Lenz wrote:

> Shure that's clear, the client can save this in the way it wants.
>
> Another question: I am not clear I understand the following thing right:
>
> package organisation context Organisation::testString():String
> body: result = 'Hallo'
> endpackage
>
> if I let parse the following thing, I get from the parser one
> OCLExpression: body: result = 'Hallo'
> If I evaluate this I allways get back false. What does this statement
> mean???
>
> The other thing ist the postcondition:
> package organisation context Organisation::testBoolean():Boolean
> pre: self.name='test'
> body: result = ('test'=self.name)
> post: self.name=self.name@pre
> endpackage
>
> When I evaluate the postcondition, where do I get the @pre of name.
>
> Maybe my problem is how to execute this whole statement! Do I have to
> build an Environment to execute this Expressions.
>

<snip>
Re: OCL and Context [message #53691 is a reply to message #44185] Thu, 28 September 2006 10:01 Go to previous messageGo to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
I tried a realy simple thing (see code below)
I want to add a variable for the evaluation. The variable is called
test. But I get now the error (Unrecognized variable: (test)). I
understand this, but how can I make this right?
private static void oclCheckEnvironment(Organisation org) throws
OCLParsingException {
EClass context =
OrganisationPackage.eINSTANCE.getOrganisation();

IOCLHelper helper = HelperUtil.createOCLHelper();
helper.setContext(context);

OCLExpression ex = helper.createQuery("self.name =
test");
Query query = QueryFactory.eINSTANCE.createQuery(ex);
EvaluationEnvironment evalEnv = new EvalEnvironment();

evalEnv.add("test",org.getName());
query.setEvaluationEnvironment(evalEnv);
System.out.println(query.evaluate(org));

}
Christian W. Damus schrieb:
> Hi, Chris,
>
> EMFT OCL does not provide evaluation support for operation pre/post/body
> condition constraints out-of-the-box. You can use techniques such as are
> demonstrated in the article on eclipse.org (announced recently in this
> newsgroup) to evaluate preconditions and to implement operation body
> *expressions* (as opposed to body condition "constraints"). These are
> relatively straight-forward problems, as they require only adding a
> variable to the environment for each operation parameter.
>
> In attempting to evaluate your body condition constraint, I suspect that you
> were evaluating it out of context as though it were an invariant
> constraint. I am surprised that it didn't actually fail with a run-time
> exception, because the "result" variable would not have been bound.
>
> Postconditions are another matter, and are complicated by two problems:
> - @pre expressions evaluate to the pre-condition value of
> an expression (as you indicated)
> - oclIsNew() in a postcondition queries whether an object was created
> during the execution of the operation
>
> EMFT OCL provides nothing to help with either of these. It should be fairly
> straight-forward to analyze an operation's postconditions to see what the
> @pre expressions are and to evaluate them at the beginning of the
> operation, capturing the values. However, the EvaluationEnvironment API
> does not provide the means to store or access these values and isn't
> extensible enough to allow a client to add this capability (besides which,
> the internal EvaluationVisitor would need changes). This sounds like rich
> material for enhancement requests in Bugzilla.
>
> oclIsNew() is a trickier problem, and I won't speculate on a solution for
> because I don't even know that it would be feasible in Java.
>
> Cheers,
>
> Christian
>
> Chris Lenz wrote:
>
>> Shure that's clear, the client can save this in the way it wants.
>>
>> Another question: I am not clear I understand the following thing right:
>>
>> package organisation context Organisation::testString():String
>> body: result = 'Hallo'
>> endpackage
>>
>> if I let parse the following thing, I get from the parser one
>> OCLExpression: body: result = 'Hallo'
>> If I evaluate this I allways get back false. What does this statement
>> mean???
>>
>> The other thing ist the postcondition:
>> package organisation context Organisation::testBoolean():Boolean
>> pre: self.name='test'
>> body: result = ('test'=self.name)
>> post: self.name=self.name@pre
>> endpackage
>>
>> When I evaluate the postcondition, where do I get the @pre of name.
>>
>> Maybe my problem is how to execute this whole statement! Do I have to
>> build an Environment to execute this Expressions.
>>
>
> <snip>
Re: OCL and Context [message #53716 is a reply to message #53691] Thu, 28 September 2006 10:31 Go to previous messageGo to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
I also tried the following:

EClass context = OrganisationPackage.eINSTANCE.getOrganisation();
Environment env =
ExpressionsUtil.createClassifierContext(context.eClass());
OCLExpression ex = ExpressionsUtil.createQuery(env,"self.name = test",
true);

Query query = QueryFactory.eINSTANCE.createQuery(ex);
EvaluationEnvironment evalEnv = new EvalEnvironment();

evalEnv.add("test",org.getName());
query.setEvaluationEnvironment(evalEnv);
System.out.println(query.evaluate(org));



Thats nearly the same what is done in
http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL /article.html
But I aways get the ERROR in (variableExpCS): (Unrecognized variable:
(test));

Chris
Re: OCL and Context [message #54041 is a reply to message #53716] Thu, 28 September 2006 13:22 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

You need not only to add the variable to the evaluation environment, but
also to the parser environment. You're almost there.

Just do:

Variable var = ExpressionsFactory.eINSTANCE.createVariable();
var.setName("test");
var.setType(EcorePackage.Literals.EString);
env.addElement("test", var, false);

before parsing the expression with the ExpressionsUtil.createQuery() call.

The GMF project does something similar with OCL constraints on connections
in diagrams, if you'd like to see a working example.

HTH,

Christian


Chris Lenz wrote:

> I also tried the following:
>
> EClass context = OrganisationPackage.eINSTANCE.getOrganisation();
> Environment env =
> ExpressionsUtil.createClassifierContext(context.eClass());
> OCLExpression ex = ExpressionsUtil.createQuery(env,"self.name = test",
> true);
>
> Query query = QueryFactory.eINSTANCE.createQuery(ex);
> EvaluationEnvironment evalEnv = new EvalEnvironment();
>
> evalEnv.add("test",org.getName());
> query.setEvaluationEnvironment(evalEnv);
> System.out.println(query.evaluate(org));
>
>
>
> Thats nearly the same what is done in
> http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL /article.html
> But I aways get the ERROR in (variableExpCS): (Unrecognized variable:
> (test));
>
> Chris
Re: OCL and Context [message #584889 is a reply to message #44091] Wed, 09 August 2006 13:51 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

As far as the serialized OCLExpression is concerned, it only needs to know
about the variables that it references, including "self" (which is typed by
the context classifier). How these references are saved is determined by
the implementation of persistence support in the Environment that was used
to parse the expression. The EcoreEnvironment provides persistence of
variables, but this can certainly be customized by a client.

The problem of persisting the OCLExpression *in context* is up to the client
application to solve, depending on its need. I could imagine attaching an
OCLExpression via an EAnnotation to an EClassifier, EOperation, or
EStructuralFeature in an Ecore model; this would define the context as the
owner of the annotation. Or, a separate model could be devised that
associates an OCLExpression with its context via some kind of
association-class (which references both). An application could even
define its own Environment implementation that is serializable and contains
the expressions that it parsed; presumably it would reference the context
in some way.

HTH,

Christian


Chris Lenz wrote:

> Hi,
>
> I have looked to org.eclipse.emf.ocl, but I'am wondering that I cant
> find in the whole model any context attribute.
>
>
> Why not, if I would safe an OCLExpression, isn't it important to save
> also the context.
>
> Chris
Re: OCL and Context [message #584907 is a reply to message #44124] Wed, 09 August 2006 14:09 Go to previous message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
Shure that's clear, the client can save this in the way it wants.

Another question: I am not clear I understand the following thing right:

package organisation context Organisation::testString():String
body: result = 'Hallo'
endpackage

if I let parse the following thing, I get from the parser one
OCLExpression: body: result = 'Hallo'
If I evaluate this I allways get back false. What does this statement
mean???

The other thing ist the postcondition:
package organisation context Organisation::testBoolean():Boolean
pre: self.name='test'
body: result = ('test'=self.name)
post: self.name=self.name@pre
endpackage

When I evaluate the postcondition, where do I get the @pre of name.

Maybe my problem is how to execute this whole statement! Do I have to
build an Environment to execute this Expressions.


Christian W. Damus schrieb:
> Hi, Chris,
>
> As far as the serialized OCLExpression is concerned, it only needs to know
> about the variables that it references, including "self" (which is typed by
> the context classifier). How these references are saved is determined by
> the implementation of persistence support in the Environment that was used
> to parse the expression. The EcoreEnvironment provides persistence of
> variables, but this can certainly be customized by a client.
>
> The problem of persisting the OCLExpression *in context* is up to the client
> application to solve, depending on its need. I could imagine attaching an
> OCLExpression via an EAnnotation to an EClassifier, EOperation, or
> EStructuralFeature in an Ecore model; this would define the context as the
> owner of the annotation. Or, a separate model could be devised that
> associates an OCLExpression with its context via some kind of
> association-class (which references both). An application could even
> define its own Environment implementation that is serializable and contains
> the expressions that it parsed; presumably it would reference the context
> in some way.
>
> HTH,
>
> Christian
>
>
> Chris Lenz wrote:
>
>> Hi,
>>
>> I have looked to org.eclipse.emf.ocl, but I'am wondering that I cant
>> find in the whole model any context attribute.
>>
>>
>> Why not, if I would safe an OCLExpression, isn't it important to save
>> also the context.
>>
>> Chris
>
Re: OCL and Context [message #584924 is a reply to message #44154] Wed, 09 August 2006 15:55 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

EMFT OCL does not provide evaluation support for operation pre/post/body
condition constraints out-of-the-box. You can use techniques such as are
demonstrated in the article on eclipse.org (announced recently in this
newsgroup) to evaluate preconditions and to implement operation body
*expressions* (as opposed to body condition "constraints"). These are
relatively straight-forward problems, as they require only adding a
variable to the environment for each operation parameter.

In attempting to evaluate your body condition constraint, I suspect that you
were evaluating it out of context as though it were an invariant
constraint. I am surprised that it didn't actually fail with a run-time
exception, because the "result" variable would not have been bound.

Postconditions are another matter, and are complicated by two problems:
- @pre expressions evaluate to the pre-condition value of
an expression (as you indicated)
- oclIsNew() in a postcondition queries whether an object was created
during the execution of the operation

EMFT OCL provides nothing to help with either of these. It should be fairly
straight-forward to analyze an operation's postconditions to see what the
@pre expressions are and to evaluate them at the beginning of the
operation, capturing the values. However, the EvaluationEnvironment API
does not provide the means to store or access these values and isn't
extensible enough to allow a client to add this capability (besides which,
the internal EvaluationVisitor would need changes). This sounds like rich
material for enhancement requests in Bugzilla.

oclIsNew() is a trickier problem, and I won't speculate on a solution for
because I don't even know that it would be feasible in Java.

Cheers,

Christian

Chris Lenz wrote:

> Shure that's clear, the client can save this in the way it wants.
>
> Another question: I am not clear I understand the following thing right:
>
> package organisation context Organisation::testString():String
> body: result = 'Hallo'
> endpackage
>
> if I let parse the following thing, I get from the parser one
> OCLExpression: body: result = 'Hallo'
> If I evaluate this I allways get back false. What does this statement
> mean???
>
> The other thing ist the postcondition:
> package organisation context Organisation::testBoolean():Boolean
> pre: self.name='test'
> body: result = ('test'=self.name)
> post: self.name=self.name@pre
> endpackage
>
> When I evaluate the postcondition, where do I get the @pre of name.
>
> Maybe my problem is how to execute this whole statement! Do I have to
> build an Environment to execute this Expressions.
>

<snip>
Re: OCL and Context [message #592377 is a reply to message #44185] Thu, 28 September 2006 10:01 Go to previous message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
I tried a realy simple thing (see code below)
I want to add a variable for the evaluation. The variable is called
test. But I get now the error (Unrecognized variable: (test)). I
understand this, but how can I make this right?
private static void oclCheckEnvironment(Organisation org) throws
OCLParsingException {
EClass context =
OrganisationPackage.eINSTANCE.getOrganisation();

IOCLHelper helper = HelperUtil.createOCLHelper();
helper.setContext(context);

OCLExpression ex = helper.createQuery("self.name =
test");
Query query = QueryFactory.eINSTANCE.createQuery(ex);
EvaluationEnvironment evalEnv = new EvalEnvironment();

evalEnv.add("test",org.getName());
query.setEvaluationEnvironment(evalEnv);
System.out.println(query.evaluate(org));

}
Christian W. Damus schrieb:
> Hi, Chris,
>
> EMFT OCL does not provide evaluation support for operation pre/post/body
> condition constraints out-of-the-box. You can use techniques such as are
> demonstrated in the article on eclipse.org (announced recently in this
> newsgroup) to evaluate preconditions and to implement operation body
> *expressions* (as opposed to body condition "constraints"). These are
> relatively straight-forward problems, as they require only adding a
> variable to the environment for each operation parameter.
>
> In attempting to evaluate your body condition constraint, I suspect that you
> were evaluating it out of context as though it were an invariant
> constraint. I am surprised that it didn't actually fail with a run-time
> exception, because the "result" variable would not have been bound.
>
> Postconditions are another matter, and are complicated by two problems:
> - @pre expressions evaluate to the pre-condition value of
> an expression (as you indicated)
> - oclIsNew() in a postcondition queries whether an object was created
> during the execution of the operation
>
> EMFT OCL provides nothing to help with either of these. It should be fairly
> straight-forward to analyze an operation's postconditions to see what the
> @pre expressions are and to evaluate them at the beginning of the
> operation, capturing the values. However, the EvaluationEnvironment API
> does not provide the means to store or access these values and isn't
> extensible enough to allow a client to add this capability (besides which,
> the internal EvaluationVisitor would need changes). This sounds like rich
> material for enhancement requests in Bugzilla.
>
> oclIsNew() is a trickier problem, and I won't speculate on a solution for
> because I don't even know that it would be feasible in Java.
>
> Cheers,
>
> Christian
>
> Chris Lenz wrote:
>
>> Shure that's clear, the client can save this in the way it wants.
>>
>> Another question: I am not clear I understand the following thing right:
>>
>> package organisation context Organisation::testString():String
>> body: result = 'Hallo'
>> endpackage
>>
>> if I let parse the following thing, I get from the parser one
>> OCLExpression: body: result = 'Hallo'
>> If I evaluate this I allways get back false. What does this statement
>> mean???
>>
>> The other thing ist the postcondition:
>> package organisation context Organisation::testBoolean():Boolean
>> pre: self.name='test'
>> body: result = ('test'=self.name)
>> post: self.name=self.name@pre
>> endpackage
>>
>> When I evaluate the postcondition, where do I get the @pre of name.
>>
>> Maybe my problem is how to execute this whole statement! Do I have to
>> build an Environment to execute this Expressions.
>>
>
> <snip>
Re: OCL and Context [message #592386 is a reply to message #53691] Thu, 28 September 2006 10:31 Go to previous message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
I also tried the following:

EClass context = OrganisationPackage.eINSTANCE.getOrganisation();
Environment env =
ExpressionsUtil.createClassifierContext(context.eClass());
OCLExpression ex = ExpressionsUtil.createQuery(env,"self.name = test",
true);

Query query = QueryFactory.eINSTANCE.createQuery(ex);
EvaluationEnvironment evalEnv = new EvalEnvironment();

evalEnv.add("test",org.getName());
query.setEvaluationEnvironment(evalEnv);
System.out.println(query.evaluate(org));



Thats nearly the same what is done in
http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL /article.html
But I aways get the ERROR in (variableExpCS): (Unrecognized variable:
(test));

Chris
Re: OCL and Context [message #592517 is a reply to message #53716] Thu, 28 September 2006 13:22 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

You need not only to add the variable to the evaluation environment, but
also to the parser environment. You're almost there.

Just do:

Variable var = ExpressionsFactory.eINSTANCE.createVariable();
var.setName("test");
var.setType(EcorePackage.Literals.EString);
env.addElement("test", var, false);

before parsing the expression with the ExpressionsUtil.createQuery() call.

The GMF project does something similar with OCL constraints on connections
in diagrams, if you'd like to see a working example.

HTH,

Christian


Chris Lenz wrote:

> I also tried the following:
>
> EClass context = OrganisationPackage.eINSTANCE.getOrganisation();
> Environment env =
> ExpressionsUtil.createClassifierContext(context.eClass());
> OCLExpression ex = ExpressionsUtil.createQuery(env,"self.name = test",
> true);
>
> Query query = QueryFactory.eINSTANCE.createQuery(ex);
> EvaluationEnvironment evalEnv = new EvalEnvironment();
>
> evalEnv.add("test",org.getName());
> query.setEvaluationEnvironment(evalEnv);
> System.out.println(query.evaluate(org));
>
>
>
> Thats nearly the same what is done in
> http://www.eclipse.org/articles/Article-EMF-Codegen-with-OCL /article.html
> But I aways get the ERROR in (variableExpCS): (Unrecognized variable:
> (test));
>
> Chris
Previous Topic:Conat download Validation SDK 1.0.1
Next Topic:OCL Query Plugins Required
Goto Forum:
  


Current Time: Sat Apr 20 04:05:52 GMT 2024

Powered by FUDForum. Page generated in 0.03918 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top