Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » problem with OCL.validate(OCLExpression)
problem with OCL.validate(OCLExpression) [message #67378] Mon, 09 February 2009 16:19 Go to next message
Hannes Moesl is currently offline Hannes MoeslFriend
Messages: 3
Registered: July 2009
Junior Member
Hi there,

regarding the following code snippet:

****************************************************
// create OCL instance (UMLEnvironment)
// create OCLHelper

ocl.parse(new OCLInput(def)) ; // parsing attribute -> works
helper.setContext(...) ;
OCLExpression<Classifier> expr = helper.createQuery(...) ; // works

ocl = OCL.newInstance(..) // create new OCL instance
ocl.parse(new OCLInput(def)) ; // parsing of same attribute works

ocl.validate(expr) ; // validation fails, OCL instance does not know
// anything about the parsed attribute
****************************************************


is this really the correct behavior of OCL.validate()? Is the same OCL
instance(which was used for query creation) needed in order to make this
working?
Or am I doing something wrong?

Best regards, Hannes
Re: problem with OCL.validate(OCLExpression) [message #67418 is a reply to message #67378] Mon, 09 February 2009 16:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Hannes,

Your deduction is correct. You need to use the same OCL instance to
validate the OCL expression because the second OCL instance created a
distinct instance of the defined attribute. The expression you are
validating reference a different attribute, being the one defined in the
first environment.

Note that, once you have successfully parsed an OCL expression, there is
usually no need to validate it (parsing does this implicitly).
Validation is most interesting for expressions that are constructed not
by parsing, such as by AST transformation from some other language.

Cheers,

Christian


Hannes Moesl wrote:
> Hi there,
>
> regarding the following code snippet:
> ****************************************************
> // create OCL instance (UMLEnvironment)
> // create OCLHelper
>
> ocl.parse(new OCLInput(def)) ; // parsing attribute -> works
> helper.setContext(...) ;
> OCLExpression<Classifier> expr = helper.createQuery(...) ; // works
>
> ocl = OCL.newInstance(..) // create new OCL instance
> ocl.parse(new OCLInput(def)) ; // parsing of same attribute works
>
> ocl.validate(expr) ; // validation fails, OCL instance does not know
> // anything about the parsed attribute
> ****************************************************
>
>
> is this really the correct behavior of OCL.validate()? Is the same OCL
> instance(which was used for query creation) needed in order to make this
> working?
> Or am I doing something wrong?
>
> Best regards, Hannes
>
>
>
>
>
Re: problem with OCL.validate(OCLExpression) [message #67440 is a reply to message #67418] Mon, 09 February 2009 17:15 Go to previous messageGo to next message
Hannes Moesl is currently offline Hannes MoeslFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Christian,

Thanks for your reply.

My problem is that I have to efficiently determine which (already created)
queries are affected after some OCL constraints are changed and have to be
parsed again. In this case I have to deal with about 70 queries or more at
a time. Creating every single query again takes about 10-12 seconds
(including parsing the OCL constraints like operations, attributes, ...),
which is actually too much for a background parsing job in an editor.

So I thought OCL.validate() will do the job for me, but a new OCL instance
is created in every parsing process of the constraints.

But what's the best way to determine which OCL constraints are used by a
query? OCLExpression.eAllContents()?

Best regards, Hannes
Re: problem with OCL.validate(OCLExpression) [message #67540 is a reply to message #67440] Tue, 10 February 2009 15:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Hannes,

I see. I would suggest, then, that the OCL with which the original
parsing was done be retained for this purpose. The Environment API
allows to undefine an additional operation or property definition, if
and when its body/derivation expression should change. Just undefine
the feature in question and define it again. Then, validating a
constraint or query that used it, in the same Environment, should catch
the dependency in the way that you intend.

Alternatively, you can implement a custom visitor (subclass of
org.eclipse.ocl.utilities.AbstractVisitor) to analyze an OCLExpression's
usage of defined operations and properties. This would be largely
similar to what the ValidationVisitor does, anyway.

HTH,

Christian

Hannes Moesl wrote:
> Hi Christian,
>
> Thanks for your reply.
> My problem is that I have to efficiently determine which (already
> created) queries are affected after some OCL constraints are changed and
> have to be parsed again. In this case I have to deal with about 70
> queries or more at a time. Creating every single query again takes about
> 10-12 seconds (including parsing the OCL constraints like operations,
> attributes, ...), which is actually too much for a background parsing
> job in an editor.
>
> So I thought OCL.validate() will do the job for me, but a new OCL
> instance is created in every parsing process of the constraints.
>
> But what's the best way to determine which OCL constraints are used by a
> query? OCLExpression.eAllContents()?
>
> Best regards, Hannes
>
Re: problem with OCL.validate(OCLExpression) [message #67675 is a reply to message #67540] Thu, 12 February 2009 16:13 Go to previous message
Hannes Moesl is currently offline Hannes MoeslFriend
Messages: 3
Registered: July 2009
Junior Member
Hi, Christian,

I decided to implement a custom visitor and it works perfectly! I am not
finished, so I don't know the actual speedup yet.

Big thanks for your suggestions! ;-)

Best regards,
Hannes
Previous Topic:Navigate through a model
Next Topic:OCL Thread Safety
Goto Forum:
  


Current Time: Fri Apr 26 10:17:06 GMT 2024

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

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

Back to the top