Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » (no subject)
(no subject) [message #716858] Thu, 18 August 2011 14:55 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 327
Registered: July 2009
Senior Member
Hi there,

here a naïve beginners OCL question:

I understand I can use OCL for platform independent validation and query.

Can I also use it to specify operations like a model object's constructor?

In OCL I can state:
"Object A has to contain two instances of Object B with the names 'X'
and 'Y'."

Can I also use this to enforce this rule by construction?
E.g. when EMF creates a new instance of Object A, it automatically
creates two instances of B where one gets the name 'X' and one gets the
name 'Y' and moves them into A?

So far in EMF I used ResourceSetListener to react on model changes and
then add some stuff automatically. However, these rules then are
hardcoded in Java and I'd like to have them on the higher abstraction level.

Can I at least use the MDT OCL for live validation? I.e. if A already
has two Objects B, tooling like the generated EMF sample editor will not
offer the operation of adding another B?

Cheers,
Hauke
Re: (no subject) [message #716872 is a reply to message #716858] Thu, 18 August 2011 16:10 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 40
Registered: July 2009
Member
Hauke,

Eclipse OCL does not contain a "solver" that could "auto-magically" establish a model that satisfies all constraints you expressed in OCL. However, since Indigo, Eclipse OCL comes with an Impact Analyzer which you may use to track only those changes affecting the value of one or more of your constraints and tell you the EObjects on which you may have to re-evaluate them. Especially for large models and large numbers of constraints this can be a major time-saver.

See, e.g., here: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FImpactAnalyzer.html for more information on how to use the Impact Analyzer.

Best,
-- Axel
(no subject) [message #716879 is a reply to message #716858] Thu, 18 August 2011 16:34 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4153
Registered: July 2009
Senior Member
Hi
> here a naïve beginners OCL question:
Not thant naive.
> Can I also use it to specify operations like a model object's
> constructor?
No. Simplistically, OCL is a side effect free language and constructing
an object has side effects. You need a model transfoprmation language
extension to give OCL the ability to mutate a model.

However, the side effect of construction is localized, so there is a
proposal to generalize the Tuple construction syntax to support
arbitrary construction.
> In OCL I can state:
> "Object A has to contain two instances of Object B with the names 'X'
> and 'Y'."
>
> Can I also use this to enforce this rule by construction?
> E.g. when EMF creates a new instance of Object A, it automatically
> creates two instances of B where one gets the name 'X' and one gets
> the name 'Y' and moves them into A?
No. As above.

No. Clearly simple equality constraints can be analyzed to produce
constructional assignments, but arbitrary constraints such as, there
shall be 26 children, each with an uppercase distinct name of unit
length, in ASCII order, may require intractable symbolic analysis to
produce an efficient solution, even if one exists.
> So far in EMF I used ResourceSetListener to react on model changes and
> then add some stuff automatically. However, these rules then are
> hardcoded in Java and I'd like to have them on the higher abstraction
> level.
I'd be inclined to go for defining derived properties in OCL and perhaps
using caches so that you evaluate lazily on demand rather than eagerly
on change, which may have race condition issues. There could be OCL to
Java code generation for Juno, so your higher level of abstraction
should become much less costly.
> Can I at least use the MDT OCL for live validation? I.e. if A already
> has two Objects B, tooling like the generated EMF sample editor will
> not offer the operation of adding another B?
It's only software; of course it's possible. But you would need to
upgrade the generated EMF sample editor to produce a candidate new state
for every possible change if you want OCL constraints of arbitrary
complexity. This approach was used in conjunction with OCL analysis to
exploit the combination of fast modern computers and efficient optimized
OCL update to perform brute force analysis of thousands of quickfix
suggestions so as to offer a short list of practical suggestions to
resolve refactoring issues.
http://researchr.org/publication/Egyed-ICMT-2011.

More practically you may want to find a simple declarative (OCL) model
of the constraints in your system and then use M2M to transform these
constraints into a form that different tools can consume, so a Java
callable filter on generated EMF sample editor menu entries would be
quite sensible.

Regards

Ed Willink
Previous Topic:OCLSettingDelegate extension
Next Topic:OCL Nightly Builds
Goto Forum:
  


Current Time: Tue Nov 25 23:25:53 GMT 2014

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

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