Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to make query operation visible for OCL
How to make query operation visible for OCL [message #843684] Fri, 13 April 2012 09:17 Go to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi,
I have a simple (hopefully) question. I am trying to figure out how I can make query operation that would be persisted for UML model and visible for OCL.

I am using OCL evaluation to help to execute UML model. I need query operations for evaluations of guards.

Currently my query operation is defined to have body constraint with opaque expression which language is 'ocl' and body is OCL expression that should be evaluated.
I run OCL evaluation in context of InstanceSpecification but OCL cannot see query operation. OCL looks for source annotation and 'ExpressionInOCL' (not OpaqueExpression). How can I add ExpressionInOCL of this query operation to UML model? Are there any good tutorials how to do it?

I looked at slideshare.net/EdWillink/enrich-your-models-with-ocl presentation but I couldn't find example for UML.

Regards,
Piotr
Re: How to make query operation visible for OCL [message #843712 is a reply to message #843684] Fri, 13 April 2012 09:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

UML support is currently a bit patchy and I'm trying to fix it even
though I'm not a UML expert.

ExpressionInOCL is not part of UML, so you cannot use it in a pure UML
model. Arguably you might be able to Load Resource for ocl.uml and get
the extension within the editor, but that wouldn't really help you. You
would have to enter the OCL as a compiled AST tree - painful.

Therefore you use OpaqueExpression with an "OCL" language and OCL
concrete syntax expression body. Simple UML tooling will allow you to
enter this as a String. Papyrus should allow you to invoke the
EssentialOCL Xtext editor as a direct text editor so that you get
syntactic and semantic validation.

I think that I've fixed some annotation URI bit rot so that when you
genmodel from UML you now get the OCL as EMF delegates, or if you use
the Juno code generator as direct Java.

You write that "OCL looks for source annotation and 'ExpressionInOCL'
(not OpaqueExpression)". Which OCL and where is this particular
functionality? Maybe it can be fixed.

Documentation may appear for Juno;
https://bugs.eclipse.org/bugs/show_bug.cgi?id=376701 raised to gather ideas.

Regards

Ed Willink

On 13/04/2012 10:17, Piotr J. Puczynski wrote:
> Hi,
> I have a simple (hopefully) question. I am trying to figure out how I
> can make query operation that would be persisted for UML model and
> visible for OCL.
>
> I am using OCL evaluation to help to execute UML model. I need query
> operations for evaluations of guards.
>
> Currently my query operation is defined to have body constraint with
> opaque expression which language is 'ocl' and body is OCL expression
> that should be evaluated.
> I run OCL evaluation in context of InstanceSpecification but OCL
> cannot see query operation. OCL looks for source annotation and
> 'ExpressionInOCL' (not OpaqueExpression). How can I add
> ExpressionInOCL of this query operation to UML model? Are there any
> good tutorials how to do it?
>
> I looked at slideshare.net/EdWillink/enrich-your-models-with-ocl
> presentation but I couldn't find example for UML.
>
> Regards, Piotr
Re: How to make query operation visible for OCL [message #843810 is a reply to message #843712] Fri, 13 April 2012 11:36 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Ed,
I am using 3.1.0 ocl uml.
I am using org.eclipse.ocl.uml.OCL.evaluate to evaluate the guard in context of InstanceSpecification.

If the guard is 'm() = 10' and query operation m() is defined in UML model with body constraint with opaque behavior with body 'self.i', then OCL will not find it.

What I would need is the possibility to annotate existing query operation with the UML constraint that will own opaque expression in string format that the OCL would then honor and parse on demand when I evaluate the mentioned guard.

Regards,
Piotr
Re: How to make query operation visible for OCL [message #843845 is a reply to message #843810] Fri, 13 April 2012 12:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think https://bugs.eclipse.org/bugs/show_bug.cgi?id=286931 shows that
this has never worked.

It is possible that it now (JunoM6) works for the new Pivot model
binding. If not it can probably be fixed.

I'm afraid that fixing the old UML-binding is unlikely for Juno.

Regards

Ed Willink

On 13/04/2012 12:36, Piotr J. Puczynski wrote:
> Hi Ed,
> I am using 3.1.0 ocl uml.
> I am using org.eclipse.ocl.uml.OCL.evaluate to evaluate the guard in
> context of InstanceSpecification.
>
> If the guard is 'm() = 10' and query operation m() is defined in UML
> model with body constraint with opaque behavior with body 'self.i',
> then OCL will not find it.
>
> What I would need is the possibility to annotate existing query
> operation with the UML constraint that will own opaque expression in
> string format that the OCL would then honor and parse on demand when I
> evaluate the mentioned guard.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #843860 is a reply to message #843845] Fri, 13 April 2012 12:44 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Ed, thanks for finding it. It looks like my issue here.

Never used the Pivot model, is it stable by now?

Right now I am trying to extend the UMLEnvironment and change getDefinition operation to return compiled constraint. Not sure if this is a good idea though.

Cheers,
Piotr
Re: How to make query operation visible for OCL [message #843864 is a reply to message #843860] Fri, 13 April 2012 12:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
On 13/04/2012 13:44, Piotr J. Puczynski wrote:
> Hi Ed, thanks for finding it. It looks like my issue here.
>
> Never used the Pivot model, is it stable by now?
No, but evolution should be minor.
>
> Right now I am trying to extend the UMLEnvironment and change
> getDefinition operation to return compiled constraint. Not sure if
> this is a good idea though.
>
I'm afraid it's a difficult choice. You appear to have some initiative
so you might decide to help get the pivot UML into shape. Of course if
you want production quality stability you should not touch the pivot model.

Regards

Ed Willink
Re: How to make query operation visible for OCL [message #844064 is a reply to message #843864] Fri, 13 April 2012 16:45 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Ed,
I was able to do it with old OCL.

But now I have a problem when I call the query operation on the source that was evaluated by traversing InstanceSpecification of link which one end has type of interface. Old OCL evaluator throws Null pointer exception error and it cannot downcast to InstanceSpecification of class,
e.g. I have 'self.barrier.isOpened()' that is query operation and barrier is InstanceSpecification of type Barrier connected through link to 'self'. The end of the link has type of interface (where the same operation is also declared).

When I invoke evaluation in context of self null pointer exception is thrown org.eclipse.ocl.uml.getJavaMethodFor()

from this reason:

// get the corresponding Ecore classifier
EClassifier eclassifier = getEClassifier(container, receiver);
//!!!!!here eclassifier is null
// get the corresponding java instance class
java.lang.Class<?> containerClass = eclassifier.getInstanceClass();

OK but when I use this hacked-expression:
'self.barrier.oclAsType(Barrier).isOpened()'
evaluation works fine.

Is this fixed in Pivot model? Are there any good tutorials on how to invoke Pivot from Java?

Regards,
Piotr
Re: How to make query operation visible for OCL [message #844704 is a reply to message #844064] Sat, 14 April 2012 08:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You've successfully tracked the problem to

EClassifier eclassifier = getEClassifier(container, receiver);
//!!!!!here eclassifier is null

but you've not provided a repro for me to look at, or traced through
getEClassifier which is relatively short and which will reveal where the
mismatch between the expectations of the routine and your model lie.

Regards

Ed Willink


On 13/04/2012 17:45, Piotr J. Puczynski wrote:
> Hi Ed,
> I was able to do it with old OCL.
> But now I have a problem when I call the query operation on the source
> that was evaluated by traversing InstanceSpecification of link which
> one end has type of interface. Old OCL evaluator throws Null pointer
> exception error and it cannot downcast to InstanceSpecification of
> class, e.g. I have 'self.barrier.isOpened()' that is query operation
> and barrier is InstanceSpecification of type Barrier connected through
> link to 'self'. The end of the link has type of interface (where the
> same operation is also declared).
>
> When I invoke evaluation in context of self null pointer exception is
> thrown org.eclipse.ocl.uml.getJavaMethodFor()
>
> from this reason:
>
> // get the corresponding Ecore classifier
> EClassifier eclassifier = getEClassifier(container, receiver);
> //!!!!!here eclassifier is null
> // get the corresponding java instance class
> java.lang.Class<?> containerClass =
> eclassifier.getInstanceClass();
>
> OK but when I use this hacked-expression:
> 'self.barrier.oclAsType(Barrier).isOpened()'
> evaluation works fine.
>
> Is this fixed in Pivot model? Are there any good tutorials on how to
> invoke Pivot from Java?
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #844739 is a reply to message #844704] Sat, 14 April 2012 09:41 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Ed, it is difficult to provide repo of it Smile
The model used for evaluation is hxxp://esculapa-uml.eclipselabs.org.codespot.com/git-history/c86b0ec7dac4d9a43ecb00f121a62651f7f20f73/ExampleModels/Models/ToolTest.uml
and hxxp://esculapa-uml.eclipselabs.org.codespot.com/git-history/c86b0ec7dac4d9a43ecb00f121a62651f7f20f73/ExampleModels/Models/ToolTest.umldi

(change hxxp to http)

The difficult part is that my tool will register the bodies constraints of query operation in class at start.
The problematic query 'self.barrier.isOpened()' is executed in context of ToolTest::CheckIn::lane Instance specification.

Cheers,
Piotr
Re: How to make query operation visible for OCL [message #844912 is a reply to message #844739] Sat, 14 April 2012 14:08 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
I will add also some comment: it is easy to see the problem when you look at the model.
What I am trying to do is to call query operation "through" the interface in OCL. It is quotation because of course instance specifications connected with links have type of classes, not interfaces. But one end of the link is defined to be type of the interface. I think this is the problem for OCL evaluator.

Regards,
Piotr
Re: How to make query operation visible for OCL [message #845170 is a reply to message #844912] Sat, 14 April 2012 20:31 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Piotr,

IIRC, the semantics of interface implementation in UML (where I think
it's actually called "realization") is very different from Java.

In UML, when a class realizes an interface, this indicates only that
the class provides, in some form, the features described by the
interface. In particular, there is no generalization semantics between
classes and interfaces. In UML, a class only conforms to other classes
to which it has generalization relationships. An interface conforms to
other interfaces to which it has generalizations. The two do not mix.

The class is free to realize the features of the interface in an
undefined way (a "semantic variation point" in the verbiage of the UML
spec). For example, in an UML model describing a Java application, a
class may realize properties of an interface by defining accessor
methods (getter/setter) in Java Bean style.

Anyways, because the type of your instance is a class, that class
doesn't inherit features of the interfaces that it realizes, so your
OCL expression won't be expected to work.

HTH,

Christian

On 2012-04-14 14:08:43 +0000, Piotr J. Puczynski said:

> I will add also some comment: it is easy to see the problem when you
> look at the model.
> What I am trying to do is to call query operation "through" the
> interface in OCL. It is quotation because of course instance
> specifications connected with links have type of classes, not
> interfaces. But one end of the link is defined to be type of the
> interface. I think this is the problem for OCL evaluator.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #845255 is a reply to message #845170] Sat, 14 April 2012 22:50 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Christian,
yes, there is a variation point for attributes of an interface, not for operations.

Operations declared in interface must be realized in classifier that realize interface (as operations). It is also because protocol may be attached to the interface that checks call order of these operations.

The link that is instance specification can have one end defined as Interface type and use the query operation in this way it is used in my model.

Regards,
Piotr
Re: How to make query operation visible for OCL [message #845502 is a reply to message #844912] Sun, 15 April 2012 05:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It seems you've got close to the problem. Can you provide a simple repro
so that I can work on it?

Regards

Ed Willink


On 14/04/2012 15:08, Piotr J. Puczynski wrote:
> I will add also some comment: it is easy to see the problem when you
> look at the model.
> What I am trying to do is to call query operation "through" the
> interface in OCL. It is quotation because of course instance
> specifications connected with links have type of classes, not
> interfaces. But one end of the link is defined to be type of the
> interface. I think this is the problem for OCL evaluator.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #845507 is a reply to message #844912] Sun, 15 April 2012 05:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It seems you've got close to the problem. Can you provide a simple repro
so that I can work on it?

Regards

Ed Willink


On 14/04/2012 15:08, Piotr J. Puczynski wrote:
> I will add also some comment: it is easy to see the problem when you
> look at the model.
> What I am trying to do is to call query operation "through" the
> interface in OCL. It is quotation because of course instance
> specifications connected with links have type of classes, not
> interfaces. But one end of the link is defined to be type of the
> interface. I think this is the problem for OCL evaluator.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #845512 is a reply to message #844912] Sun, 15 April 2012 05:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It seems you've got close to the problem. Can you provide a simple repro
so that I can work on it?

Regards

Ed Willink


On 14/04/2012 15:08, Piotr J. Puczynski wrote:
> I will add also some comment: it is easy to see the problem when you
> look at the model.
> What I am trying to do is to call query operation "through" the
> interface in OCL. It is quotation because of course instance
> specifications connected with links have type of classes, not
> interfaces. But one end of the link is defined to be type of the
> interface. I think this is the problem for OCL evaluator.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #845518 is a reply to message #844912] Sun, 15 April 2012 05:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It seems you've got close to the problem. Can you provide a simple repro
so that I can work on it?

Regards

Ed Willink


On 14/04/2012 15:08, Piotr J. Puczynski wrote:
> I will add also some comment: it is easy to see the problem when you
> look at the model.
> What I am trying to do is to call query operation "through" the
> interface in OCL. It is quotation because of course instance
> specifications connected with links have type of classes, not
> interfaces. But one end of the link is defined to be type of the
> interface. I think this is the problem for OCL evaluator.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #845936 is a reply to message #845255] Sun, 15 April 2012 15:22 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Piotr,

Yes, an interface operation should be realized by an operation, but
nonetheless, the realizing class must independently define that
operation, because it does not inherit it from the interface.

In your case, the end of the link is an InstanceSpecification whose
type is an Interface? I don't expect that the OCL interpreter handles
that case. The OCL specification doesn't have anything to say about
interfaces, so the interpreter probably doesn't recognize them. But,
my knowledge of the code is out-of-date. Perhaps the current committer
team can comment further.

Cheers,

Christian


On 2012-04-14 22:50:44 +0000, Piotr J. Puczynski said:

> Hi Christian,
> yes, there is a variation point for attributes of an interface, not for
> operations.
>
> Operations declared in interface must be realized in classifier that
> realize interface (as operations). It is also because protocol may be
> attached to the interface that checks call order of these operations.
>
> The link that is instance specification can have one end defined as
> Interface type and use the query operation in this way it is used in my
> model.
>
> Regards,
> Piotr
Re: How to make query operation visible for OCL [message #845952 is a reply to message #845936] Sun, 15 April 2012 15:45 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Christian,
Christian W. Damus wrote on Sun, 15 April 2012 11:22

Yes, an interface operation should be realized by an operation, but
nonetheless, the realizing class must independently define that
operation, because it does not inherit it from the interface.


Yes, this is what I just said in my previous post.

Christian W. Damus wrote on Sun, 15 April 2012 11:22

In your case, the end of the link is an InstanceSpecification whose
type is an Interface?

No, it isn't. If you red my previous post carefully, you will know it. Saying more in UML language: I have a link with one slot that has defining feature set to property to association of type of Interface. Simply saying, this is not unusual to refer to class "through" interface and call method in the class by referring to operation in the interface. Of course, the linked instance specification's classifier is Class (that realizes the interface), not Interface and I call query operation in this Class.

Ed, I will try to provide repro soon.

Regards,
Piotr J. Puczynski
Re: How to make query operation visible for OCL [message #845963 is a reply to message #845952] Sun, 15 April 2012 16:03 Go to previous messageGo to next message
Piotr J. Puczynski is currently offline Piotr J. PuczynskiFriend
Messages: 17
Registered: January 2012
Junior Member
Hi Christian again,
I am not OCL expert but I found something about interfaces in OCL specs:

Quote:
Note that for a definition of the semantics of OCL, UML's distinction between classes and interfaces does not matter.
OCL specifies constraints for instances of a given interface specification. Whether this specification is stated in the form
of a class or interface definition makes no difference.


But I am not sure if they tackled this specific case in particular for query operations. I would not agree that OCL should be ignorant to this problem, I think it is just a question of if we want to have it and conform to UML specs or if we can live without it.

Cheers,
Piotr
Re: How to make query operation visible for OCL [message #846001 is a reply to message #845963] Sun, 15 April 2012 16:52 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Piotr,

Cool. I did not know that. Whether this is a recent development or
not, I clearly am too long out of touch to be of any help on this
issue. Thanks for the update!

Christian

On 2012-04-15 16:03:05 +0000, Piotr J. Puczynski said:

> Hi Christian again,
> I am not OCL expert but I found something about interfaces in OCL specs:
>
> Quote:
>> Note that for a definition of the semantics of OCL, UML's distinction
>> between classes and interfaces does not matter. OCL specifies
>> constraints for instances of a given interface specification. Whether
>> this specification is stated in the form of a class or interface
>> definition makes no difference.
>
>
> But I am not sure if they tackled this specific case in particular for
> query operations. I would not agree that OCL should be ignorant to this
> problem, I think it is just a question of if we want to have it and
> conform to UML specs or if we can live without it.
>
> Cheers,
> Piotr
Re: How to make query operation visible for OCL [message #846706 is a reply to message #846001] Mon, 16 April 2012 09:11 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Very very little has intentionally changed on the UML-binding. This is
variously through lack of detailed understanding, concern about
inadvertently breaking legacy customers and the difficulty of migrating
the existing code to Xtext, polymorphic values, UML-alignment and a
modeled library.

Enhanced UML behaviour is gradually appearing as the UML-aligned code
evolves.

That said a simple uncontroversial fix to the UML-binding can be done;
six weeks is the deadline to get the fix into the Juno release.

Regards

Ed Willink

On 15/04/2012 17:52, Christian W. Damus wrote:
> Hi, Piotr,
>
> Cool. I did not know that. Whether this is a recent development or
> not, I clearly am too long out of touch to be of any help on this
> issue. Thanks for the update!
>
> Christian
>
> On 2012-04-15 16:03:05 +0000, Piotr J. Puczynski said:
>
>> Hi Christian again,
>> I am not OCL expert but I found something about interfaces in OCL specs:
>>
>> Quote:
>>> Note that for a definition of the semantics of OCL, UML's
>>> distinction between classes and interfaces does not matter. OCL
>>> specifies constraints for instances of a given interface
>>> specification. Whether this specification is stated in the form of a
>>> class or interface definition makes no difference.
>>
>>
>> But I am not sure if they tackled this specific case in particular
>> for query operations. I would not agree that OCL should be ignorant
>> to this problem, I think it is just a question of if we want to have
>> it and conform to UML specs or if we can live without it.
>>
>> Cheers,
>> Piotr
>
>
Previous Topic:Using CompleteOCLEObjectValidator to validate Ecore model using OCL constraints defined in text file
Next Topic:Parse OCL Constraints - Model Instance of an UML Profile
Goto Forum:
  


Current Time: Thu Mar 28 10:36:55 GMT 2024

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

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

Back to the top