Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to get OCL variable from Java code
How to get OCL variable from Java code [message #1068078] Fri, 12 July 2013 00:23 Go to next message
Archevo tarek is currently offline Archevo tarekFriend
Messages: 21
Registered: July 2013
Junior Member
Hi,
I want to get an OCL variable after its evaluation from Java code.
For example, for the following expression:

context Application inv :
let seq : OrderedSet(AA)=
self.activity->select(a: AA| a.oclIsKindOf(xx)) in
seq->forAll(aa: AA| if aa.oclIsKindOf(xx)
and aa.oclAsType(xx).name='yyy' then
(let pos: Integer = seq->indexOf(aa) in
if pos>100000 then pos=0 else pos= seq->indexOf(aa) endif )
else false endif )

This is just an example.
I want to get the value of "pos" variable into an integer variable so i can use it after in my Java code, like:
int var= pos; or int var= (result of the evaluated expression)

Usualy, i used OCL expressions to impose some constraints that are evaluated to true or false using the "check" method.

Can any body give me some help here.

Re: How to get OCL variable from Java code [message #1068114 is a reply to message #1068078] Fri, 12 July 2013 09:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Invariants 'return' just a boolean value.

You probably want to define an operation

def: computePos(seq : OrderedSet(AA), aa : AA) : Integer = seq->indexOf(aa)

however this is an additional operation for use by OCL. It is not
tricvially callable by Java.

You may find it easier to define an operation in Ecore using the
OCLinEcore editor so that it forms part of the standard Ecore class
interface.

Regards

Ed Willink


On 12/07/2013 04:03, zernadji tarek wrote:
> Hi,
> I want to get an OCL variable after its evaluation from Java code.
> For example, for the following expression:
>
> context Application inv :
> let seq : OrderedSet(AA)= self.activity->select(a: AA|
> a.oclIsKindOf(xx)) in
> seq->forAll(aa: AA| if aa.oclIsKindOf(xx)
> and aa.oclAsType(xx).name='yyy' then
> (let pos: Integer = seq->indexOf(aa) in
> if pos>100000 then pos=0 else pos= seq->indexOf(aa) endif )
> else false endif )
>
> This is just an example.
> I want to get the value of "pos" variable into an integer variable so
> i can use it after in my Java code, like:
> int var= pos; or int var= (result of the evaluated expression)
>
> Usualy, i used OCL expressions to impose some constraints that are
> evaluated to true or false using the "check" method.
>
> Can any body give me some help here.
>
Re: How to get OCL variable from Java code [message #1068174 is a reply to message #1068114] Fri, 12 July 2013 14:17 Go to previous messageGo to next message
Archevo tarek is currently offline Archevo tarekFriend
Messages: 21
Registered: July 2013
Junior Member
Hi,
Thanks for your response.
I'm afraid that i'm not really experienced with OCLinEcore editor and also novice in the domain, but i'm investigating your solution which i find interesting.
However, i did not understand what do you mean by "not trivially callable by Java.", i want to test the first solution for now, you mean that it is not possible to call it from Java code as i mentioned in my previous post: int var= result of OCL operation call

Thanks in advance.
Re: How to get OCL variable from Java code [message #1068186 is a reply to message #1068174] Fri, 12 July 2013 14:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The OCL tooling is all implemented with Java so you can certainly call
it, but the whole point of modeling is to abstract away from the Java,
so if as a novice you are already reaching for java, I strongly suspect
that you are either doing something foolish or have assumed that I
actually understood your very vague original question.

Regards

Ed Willink


On 12/07/2013 15:17, zernadji tarek wrote:
> Hi,
> Thanks for your response.
> I'm afraid that i'm not really experienced with OCLinEcore editor and
> also novice in the domain, but i'm investigating your solution which i
> find interesting.
> However, i did not understand what do you mean by "not trivially
> callable by Java.", i want to test the first solution for now, you
> mean that it is not possible to call it from Java code as i mentioned
> in my previous post: int var= result of OCL operation call
>
> Thanks in advance.
Re: How to get OCL variable from Java code [message #1068191 is a reply to message #1068186] Fri, 12 July 2013 15:29 Go to previous messageGo to next message
Archevo tarek is currently offline Archevo tarekFriend
Messages: 21
Registered: July 2013
Junior Member
Hi,
Well, i don't really think that i'm doing something foolish. I'm coding in Java an interpreter of a lightweight language that i specified. I'm using OCL expressions inside as a query language of the models representing a certain application.
So, i would like simply while interpreting some statements in the language to use OCL expressions like the one i presented in the previous posts. I want to make a generic search function that returns the position of an element in a instance of the model (Ecore model)that represents the application.
That's why i want to get the result of the given OCL expression.

I agree a 100% that modeling is to abstract from any implementation details.

Thanks.
Re: How to get OCL variable from Java code [message #1068194 is a reply to message #1068191] Fri, 12 July 2013 15:38 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you want multiple results you should code a query rthat returns a
Collection or a Tuple.

If you really want to see the hidden results, dig into the query
evaluation path and replicate sufficient code to give you access to the
Environment where all the variables are held.

Regards

Ed Willink


On 12/07/2013 16:29, zernadji tarek wrote:
> Hi,
> Well, i don't really think that i'm doing something foolish. I'm
> coding in Java an interpreter of a lightweight language that i
> specified. I'm using OCL expressions inside as a query language of the
> models representing a certain application.
> So, i would like simply while interpreting some statements in the
> language to use OCL expressions like the one i presented in the
> previous posts. I want to make a generic search function that returns
> the position of an element in a instance of the model (Ecore
> model)that represents the application.
> That's why i want to get the result of the given OCL expression.
>
> I agree a 100% that modeling is to abstract from any implementation
> details.
>
> Thanks.
Previous Topic:ClassCastException thrown when using ecore::EDouble
Next Topic:Problem when opening Ecore file with OCLInEcore using Juno
Goto Forum:
  


Current Time: Fri Apr 26 08:55:48 GMT 2024

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

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

Back to the top