Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCLExpressions
OCLExpressions [message #478753] Thu, 06 August 2009 17:02 Go to next message
mary is currently offline maryFriend
Messages: 22
Registered: July 2009
Junior Member
Hello,
I am new to OCL and I am trying to use it with QVT. I want to create an
OCL Expression from a string. I created a type StringLiteralExp and in the
stringSymbol attribute i give it the OCL string.

var strExp:=object
OCL::expressions::StringLiteralExp{stringSymbol:='self.name= Class1'};

now i want to use this OCLExpression inside an if condition to evaluate it
and check if it is true or false. However, it seems that the if condidtion
always returns false. Which I guess because it is not correctly evaluating
the ocl expression.

if(strExp=true) then 'true'.dump() else 'false'.dump() endif;

So my questions are : 1. Am-I using the correct way to build an OCL
Expression from a string?

2. Is it possible to use the OCL expression inside an IF statement and to
evaluate it ?

Thanks in advance..
Mary
Re: OCLExpressions [message #478771 is a reply to message #478753] Thu, 06 August 2009 19:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Mary

You should ask this question on the M2M newsgroup with a [QVTo] subject
prefix.

What you are doing does not seem to make sense. OCL is built-in to all
the QVT languages so you do not have to construct OCL expressions from
their AST elements. You appear to be working at what seems like two
extra levels of encoding.

I would have thought that

if (self.name=Class1) then 'true'.dump() else 'false'.dump() endif

would have met your requirements.

Regards

Ed Willink

mary wrote:
> Hello, I am new to OCL and I am trying to use it with QVT. I want to
> create an OCL Expression from a string. I created a type
> StringLiteralExp and in the stringSymbol attribute i give it the OCL
> string.
>
> var strExp:=object
> OCL::expressions::StringLiteralExp{stringSymbol:='self.name= Class1'};
>
> now i want to use this OCLExpression inside an if condition to evaluate
> it and check if it is true or false. However, it seems that the if
> condidtion always returns false. Which I guess because it is not
> correctly evaluating the ocl expression.
>
> if(strExp=true) then 'true'.dump() else 'false'.dump() endif;
>
> So my questions are : 1. Am-I using the correct way to build an OCL
> Expression from a string?
>
> 2. Is it possible to use the OCL expression inside an IF statement and
> to evaluate it ?
>
> Thanks in advance.. Mary
>
>
Re: OCLExpressions [message #478777 is a reply to message #478771] Thu, 06 August 2009 19:50 Go to previous message
mary is currently offline maryFriend
Messages: 22
Registered: July 2009
Junior Member
Hi Ed,

Please find my answers in-line..

Thanks,

Ed Willink wrote:

> Hi Mary

> You should ask this question on the M2M newsgroup with a [QVTo] subject
> prefix.

Actually I did ask in the M2M newsgroup and they provided help but then i
had this question about OCL and i thought its better to ask it here.


> What you are doing does not seem to make sense. OCL is built-in to all
> the QVT languages so you do not have to construct OCL expressions from
> their AST elements. You appear to be working at what seems like two
> extra levels of encoding.

> I would have thought that

> if (self.name=Class1) then 'true'.dump() else 'false'.dump() endif

> would have met your requirements.

Actually you are right.. this would meet my requirement. However, my
problem is that the expression inside the if statement is not static. It
should depend on an elemnet in the user model. So, i need to read this
element from the user model and then test it. Thats why i had to build the
OCL expression !

> Regards
> Ed Willink
Previous Topic:UML OCL and Date
Next Topic:OCL, AnyType and FeatureMaps
Goto Forum:
  


Current Time: Thu Mar 28 17:36:05 GMT 2024

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

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

Back to the top