Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » how to define operations?
how to define operations? [message #499456] Sun, 22 November 2009 18:31 Go to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi,
I'd like to define an operation for a certain class context via OCL.

I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of how to invoke the OCLHelper.defineOperation() method.
In the DefExpressionTest class, the context is set via helper.setContext() prior to defining the operation.

Is there a way to specify the context textually, as one expression together with the operation definition? Or is there
another way to retrieve the context class from a textual expression? The problem is that I cannot hard code the context
classifier as it is done in the DefExpressionTest class.

Could anyone please provide an example expression and/or small code snippet in how to do that?
Thanks for helping.

Joel
Re: how to define operations? [message #499541 is a reply to message #499456] Mon, 23 November 2009 10:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Joel

From Warmer and Kleppe's book

context CustomerCard::getTransactions(until:Date, from:Date) :
Set(Transaction)
body: self.transactions->select( i_Transaction : Transaction |
i_Transaction.date.isAfter(from)
and i_Transaction.date.isBefore(until) )

The full example may be found

/org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl

which may be found in /cvsroot/modeling
org.eclipse.m2m/org.eclipse.qvt.declarative/examples

I'm working on the QVT Declarative build right now, so watch
http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor for a more friendly
installation process.

Regards

Ed Willink



Joel Greenyer wrote:
> Hi,
> I'd like to define an operation for a certain class context via OCL.
>
> I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of how
> to invoke the OCLHelper.defineOperation() method. In the
> DefExpressionTest class, the context is set via helper.setContext()
> prior to defining the operation.
>
> Is there a way to specify the context textually, as one expression
> together with the operation definition? Or is there another way to
> retrieve the context class from a textual expression? The problem is
> that I cannot hard code the context classifier as it is done in the
> DefExpressionTest class.
>
> Could anyone please provide an example expression and/or small code
> snippet in how to do that?
> Thanks for helping.
>
> Joel
Re: how to define operations? [message #499585 is a reply to message #499541] Mon, 23 November 2009 12:29 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Ed,
thanks for your answer.
....and process that expression via OCLHelper.defineOperation()?

Ed Willink wrote:
> Hi Joel
>
> From Warmer and Kleppe's book
>
> context CustomerCard::getTransactions(until:Date, from:Date) :
> Set(Transaction)
> body: self.transactions->select( i_Transaction : Transaction |
> i_Transaction.date.isAfter(from)
> and i_Transaction.date.isBefore(until) )
>
> The full example may be found
>
> /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
>
>
> which may be found in /cvsroot/modeling
> org.eclipse.m2m/org.eclipse.qvt.declarative/examples
>
> I'm working on the QVT Declarative build right now, so watch
> http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor for a more friendly
> installation process.
>
> Regards
>
> Ed Willink
>
>
>
> Joel Greenyer wrote:
>> Hi,
>> I'd like to define an operation for a certain class context via OCL.
>>
>> I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of how
>> to invoke the OCLHelper.defineOperation() method. In the
>> DefExpressionTest class, the context is set via helper.setContext()
>> prior to defining the operation.
>>
>> Is there a way to specify the context textually, as one expression
>> together with the operation definition? Or is there another way to
>> retrieve the context class from a textual expression? The problem is
>> that I cannot hard code the context classifier as it is done in the
>> DefExpressionTest class.
>>
>> Could anyone please provide an example expression and/or small code
>> snippet in how to do that?
>> Thanks for helping.
>>
>> Joel
Re: how to define operations? [message #499595 is a reply to message #499585] Mon, 23 November 2009 13:03 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
sorry, there is an "I" missing: my question is if I use OCLHelper.defineOperation() to process these expressions?

Joel Greenyer wrote:
> Hi Ed,
> thanks for your answer.
> ...and process that expression via OCLHelper.defineOperation()?
>
> Ed Willink wrote:
>> Hi Joel
>>
>> From Warmer and Kleppe's book
>>
>> context CustomerCard::getTransactions(until:Date, from:Date) :
>> Set(Transaction)
>> body: self.transactions->select( i_Transaction : Transaction |
>> i_Transaction.date.isAfter(from)
>> and i_Transaction.date.isBefore(until) )
>>
>> The full example may be found
>>
>> /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
>>
>>
>> which may be found in /cvsroot/modeling
>> org.eclipse.m2m/org.eclipse.qvt.declarative/examples
>>
>> I'm working on the QVT Declarative build right now, so watch
>> http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor for a more friendly
>> installation process.
>>
>> Regards
>>
>> Ed Willink
>>
>>
>>
>> Joel Greenyer wrote:
>>> Hi,
>>> I'd like to define an operation for a certain class context via OCL.
>>>
>>> I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of
>>> how to invoke the OCLHelper.defineOperation() method. In the
>>> DefExpressionTest class, the context is set via helper.setContext()
>>> prior to defining the operation.
>>>
>>> Is there a way to specify the context textually, as one expression
>>> together with the operation definition? Or is there another way to
>>> retrieve the context class from a textual expression? The problem is
>>> that I cannot hard code the context classifier as it is done in the
>>> DefExpressionTest class.
>>>
>>> Could anyone please provide an example expression and/or small code
>>> snippet in how to do that?
>>> Thanks for helping.
>>>
>>> Joel
Re: how to define operations? [message #499838 is a reply to message #499595] Tue, 24 November 2009 10:45 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Joel

The missing "I" makes no difference. I have absolutely no idea what your
new/original question is, or whether my previous answer was helpful.

Regards

Ed Willink

Joel Greenyer wrote:
> sorry, there is an "I" missing: my question is if I use
> OCLHelper.defineOperation() to process these expressions?
>
> Joel Greenyer wrote:
>> Hi Ed,
>> thanks for your answer.
>> ...and process that expression via OCLHelper.defineOperation()?
>>
>> Ed Willink wrote:
>>> Hi Joel
>>>
>>> From Warmer and Kleppe's book
>>>
>>> context CustomerCard::getTransactions(until:Date, from:Date) :
>>> Set(Transaction)
>>> body: self.transactions->select( i_Transaction : Transaction |
>>> i_Transaction.date.isAfter(from)
>>> and i_Transaction.date.isBefore(until) )
>>>
>>> The full example may be found
>>>
>>> /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
>>>
>>>
>>> which may be found in /cvsroot/modeling
>>> org.eclipse.m2m/org.eclipse.qvt.declarative/examples
>>>
>>> I'm working on the QVT Declarative build right now, so watch
>>> http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor for a more friendly
>>> installation process.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>>
>>>
>>> Joel Greenyer wrote:
>>>> Hi,
>>>> I'd like to define an operation for a certain class context via OCL.
>>>>
>>>> I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of
>>>> how to invoke the OCLHelper.defineOperation() method. In the
>>>> DefExpressionTest class, the context is set via helper.setContext()
>>>> prior to defining the operation.
>>>>
>>>> Is there a way to specify the context textually, as one expression
>>>> together with the operation definition? Or is there another way to
>>>> retrieve the context class from a textual expression? The problem
>>>> is that I cannot hard code the context classifier as it is done in
>>>> the DefExpressionTest class.
>>>>
>>>> Could anyone please provide an example expression and/or small code
>>>> snippet in how to do that?
>>>> Thanks for helping.
>>>>
>>>> Joel
Re: how to define operations? [message #499875 is a reply to message #499585] Tue, 24 November 2009 12:48 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

--=-Ryv4AKQdpC0aUJ2IxmIZ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Joel,

The OCLHelper API is intended primarily for the processing of OCL
constraints, definitions, and queries that are embedded in a model,
where the contextual classifier/operation/etc. is determined by the
placement of the expression.

For specification of OCL constraints and definitions with the textual
syntax of the context, that is typically done in *.ocl resources and
parsed using the parse(...) methods of the org.eclipse.ocl.OCL class and
its specializations. This "loads" the constraints defined in the *.ocl
into one environment; the parsed results can be retrieved if necessary
from the OCL facade instance, but in the case of definitions, they will
be available in the environment for any subsequent OCL expressions to
use.

Since you evidently have the JUnit test suite on hand, look for uses of
the OCL class such as in (I hope this is the name) OCLDocumentTest.

HTH,

Christian


On Mon, 2009-11-23 at 13:29 +0100, Joel Greenyer wrote:

> Hi Ed,
> thanks for your answer.
> ...and process that expression via OCLHelper.defineOperation()?
>
> Ed Willink wrote:
> > Hi Joel
> >
> > From Warmer and Kleppe's book
> >
> > context CustomerCard::getTransactions(until:Date, from:Date) :
> > Set(Transaction)
> > body: self.transactions->select( i_Transaction : Transaction |
> > i_Transaction.date.isAfter(from)
> > and i_Transaction.date.isBefore(until) )
> >
> > The full example may be found
> >
> > /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
> >
> >
> > which may be found in /cvsroot/modeling
> > org.eclipse.m2m/org.eclipse.qvt.declarative/examples
> >
> > I'm working on the QVT Declarative build right now, so watch
> > http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor for a more friendly
> > installation process.
> >
> > Regards
> >
> > Ed Willink
> >
> >
> >
> > Joel Greenyer wrote:
> >> Hi,
> >> I'd like to define an operation for a certain class context via OCL.
> >>
> >> I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of how
> >> to invoke the OCLHelper.defineOperation() method. In the
> >> DefExpressionTest class, the context is set via helper.setContext()
> >> prior to defining the operation.
> >>
> >> Is there a way to specify the context textually, as one expression
> >> together with the operation definition? Or is there another way to
> >> retrieve the context class from a textual expression? The problem is
> >> that I cannot hard code the context classifier as it is done in the
> >> DefExpressionTest class.
> >>
> >> Could anyone please provide an example expression and/or small code
> >> snippet in how to do that?
> >> Thanks for helping.
> >>
> >> Joel

--=-Ryv4AKQdpC0aUJ2IxmIZ
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Joel,<BR>
<BR>
The OCLHelper API is intended primarily for the processing of OCL constraints, definitions, and queries that are embedded in a model, where the contextual classifier/operation/etc. is determined by the placement of the expression.<BR>
<BR>
For specification of OCL constraints and definitions with the textual syntax of the context, that is typically done in *.ocl resources and parsed using the parse(...) methods of the org.eclipse.ocl.OCL class and its specializations.&nbsp; This &quot;loads&quot; the constraints defined in the *.ocl into one environment; the parsed results can be retrieved if necessary from the OCL facade instance, but in the case of definitions, they will be available in the environment for any subsequent OCL expressions to use.<BR>
<BR>
Since you evidently have the JUnit test suite on hand, look for uses of the OCL class such as in (I hope this is the name) OCLDocumentTest.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Mon, 2009-11-23 at 13:29 +0100, Joel Greenyer wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Ed,
thanks for your answer.
....and process that expression via OCLHelper.defineOperation()?

Ed Willink wrote:
&gt; Hi Joel
&gt;
&gt; From Warmer and Kleppe's book
&gt;
&gt; context CustomerCard::getTransactions(until:Date, from:Date) :
&gt; Set(Transaction)
&gt; body: self.transactions-&gt;select( i_Transaction : Transaction |
&gt; i_Transaction.date.isAfter(from)
&gt; and i_Transaction.date.isBefore(until) )
&gt;
&gt; The full example may be found
&gt;
&gt; /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
&gt;
&gt;
&gt; which may be found in /cvsroot/modeling
&gt; org.eclipse.m2m/org.eclipse.qvt.declarative/examples
&gt;
&gt; I'm working on the QVT Declarative build right now, so watch
&gt; <A HREF="http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor">http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor</A> for a more friendly
&gt; installation process.
&gt;
&gt; Regards
&gt;
&gt; Ed Willink
&gt;
&gt;
&gt;
&gt; Joel Greenyer wrote:
&gt;&gt; Hi,
&gt;&gt; I'd like to define an operation for a certain class context via OCL.
&gt;&gt;
&gt;&gt; I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of how
&gt;&gt; to invoke the OCLHelper.defineOperation() method. In the
&gt;&gt; DefExpressionTest class, the context is set via helper.setContext()
&gt;&gt; prior to defining the operation.
&gt;&gt;
&gt;&gt; Is there a way to specify the context textually, as one expression
&gt;&gt; together with the operation definition? Or is there another way to
&gt;&gt; retrieve the context class from a textual expression? The problem is
&gt;&gt; that I cannot hard code the context classifier as it is done in the
&gt;&gt; DefExpressionTest class.
&gt;&gt;
&gt;&gt; Could anyone please provide an example expression and/or small code
&gt;&gt; snippet in how to do that?
&gt;&gt; Thanks for helping.
&gt;&gt;
&gt;&gt; Joel
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-Ryv4AKQdpC0aUJ2IxmIZ--
Re: how to define operations? [message #500084 is a reply to message #499875] Tue, 24 November 2009 21:19 Go to previous message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Christian,
you make my day! It works with the parse() method. I guess I was totally on the wrong track here.
Thanks for the explanation!

Best

Joel


Christian W. Damus wrote:
> Hi, Joel,
>
> The OCLHelper API is intended primarily for the processing of OCL
> constraints, definitions, and queries that are embedded in a model,
> where the contextual classifier/operation/etc. is determined by the
> placement of the expression.
>
> For specification of OCL constraints and definitions with the textual
> syntax of the context, that is typically done in *.ocl resources and
> parsed using the parse(...) methods of the org.eclipse.ocl.OCL class and
> its specializations. This "loads" the constraints defined in the *.ocl
> into one environment; the parsed results can be retrieved if necessary
> from the OCL facade instance, but in the case of definitions, they will
> be available in the environment for any subsequent OCL expressions to use.
>
> Since you evidently have the JUnit test suite on hand, look for uses of
> the OCL class such as in (I hope this is the name) OCLDocumentTest.
>
> HTH,
>
> Christian
>
>
> On Mon, 2009-11-23 at 13:29 +0100, Joel Greenyer wrote:
>> Hi Ed,
>> thanks for your answer.
>> ...and process that expression via OCLHelper.defineOperation()?
>>
>> Ed Willink wrote:
>> > Hi Joel
>> >
>> > From Warmer and Kleppe's book
>> >
>> > context CustomerCard::getTransactions(until:Date, from:Date) :
>> > Set(Transaction)
>> > body: self.transactions->select( i_Transaction : Transaction |
>> > i_Transaction.date.isAfter(from)
>> > and i_Transaction.date.isBefore(until) )
>> >
>> > The full example may be found
>> >
>> > /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
>> >
>> >
>> > which may be found in /cvsroot/modeling
>> > org.eclipse.m2m/org.eclipse.qvt.declarative/examples
>> >
>> > I'm working on the QVT Declarative build right now, so watch
>> > http://wiki.eclipse.org/MDT/OCL/FAQ#OCL_Editor for a more friendly
>> > installation process.
>> >
>> > Regards
>> >
>> > Ed Willink
>> >
>> >
>> >
>> > Joel Greenyer wrote:
>> >> Hi,
>> >> I'd like to define an operation for a certain class context via OCL.
>> >>
>> >> I see in org.eclipse.ocl.ecore.tests.DefExpressionTest examples of how
>> >> to invoke the OCLHelper.defineOperation() method. In the
>> >> DefExpressionTest class, the context is set via helper.setContext()
>> >> prior to defining the operation.
>> >>
>> >> Is there a way to specify the context textually, as one expression
>> >> together with the operation definition? Or is there another way to
>> >> retrieve the context class from a textual expression? The problem is
>> >> that I cannot hard code the context classifier as it is done in the
>> >> DefExpressionTest class.
>> >>
>> >> Could anyone please provide an example expression and/or small code
>> >> snippet in how to do that?
>> >> Thanks for helping.
>> >>
>> >> Joel
Previous Topic:query for class and interface check
Next Topic:eGet(ref) does not return a collection but only its first element
Goto Forum:
  


Current Time: Sat Apr 20 02:00:30 GMT 2024

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

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

Back to the top