Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Re: [OCL] String Operations
Re: [OCL] String Operations [message #1230] Tue, 30 January 2007 07:47 Go to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

Ian,

OCL has its own newsgroup now: eclipse.modeling.mdt.ocl.


Ian Bull wrote:
> Does OCL support String regular expression operations. I need to
> select items whose name matches a particular regex. (Actually I just
> need startWith) but I could imagine the need for more powerful
> operations.
>
> Cheers,
> Ian
Re: [OCL] String Operations [message #1255 is a reply to message #1230] Tue, 30 January 2007 09:45 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Ian, Ed,

OCL defines the following operations on Strings:

size() : Integer

concat(s : String) : String

substring(lower : Integer, upper : Integer) : String

toInteger() : Integer

toReal() : Real

You can implement startsWith and endsWith using the substring operation:

context String
def: startsWith(s : String) : Boolean =
s.size() <= self.size() and self.substring(1, s.size()) = s
def: endsWith(s : String) : Boolean =
let start : Integer = self.size() - s.size() + 1 in
start > 0 and self.substring(start, self.size()) = s

In the latest build of OCL, you can actually implement def expressions of
this nature on the String library class! Or, you can follow Chris Lenz's
example on the OCL Wiki of extending the OCL Environment to add custom
operations to suit your needs:

http://wiki.eclipse.org/index.php/CustomizingOclEnvironments

I will need to update this example for M5 when it comes.

Cheers,

Christian

Ed Merks wrote:

> Ian,
>
> OCL has its own newsgroup now: eclipse.modeling.mdt.ocl.
>
>
> Ian Bull wrote:
>> Does OCL support String regular expression operations. I need to
>> select items whose name matches a particular regex. (Actually I just
>> need startWith) but I could imagine the need for more powerful
>> operations.
>>
>> Cheers,
>> Ian
Re: [OCL] String Operations [message #1276 is a reply to message #1255] Tue, 30 January 2007 12:55 Go to previous messageGo to next message
Eclipse User
Originally posted by: irbull.cs.uvic.ca

Thanks Christian,

I looked at the example on the wiki about extending the environment.
What is the OCLHelperFactory? Do I have to define this (Is this where
my extensions come from)?

Do you have any advice on how to implement def expressions directly on
the String Class?

Thanks,
Ian
P.S. Sorry Ed, I'm sure it must get tiring when everyone posts in the
wrong spot :(

Christian W. Damus wrote:
> Hi, Ian, Ed,
>
> OCL defines the following operations on Strings:
>
> size() : Integer
>
> concat(s : String) : String
>
> substring(lower : Integer, upper : Integer) : String
>
> toInteger() : Integer
>
> toReal() : Real
>
> You can implement startsWith and endsWith using the substring operation:
>
> context String
> def: startsWith(s : String) : Boolean =
> s.size() <= self.size() and self.substring(1, s.size()) = s
> def: endsWith(s : String) : Boolean =
> let start : Integer = self.size() - s.size() + 1 in
> start > 0 and self.substring(start, self.size()) = s
>
> In the latest build of OCL, you can actually implement def expressions of
> this nature on the String library class! Or, you can follow Chris Lenz's
> example on the OCL Wiki of extending the OCL Environment to add custom
> operations to suit your needs:
>
> http://wiki.eclipse.org/index.php/CustomizingOclEnvironments
>
> I will need to update this example for M5 when it comes.
>
> Cheers,
>
> Christian
>
> Ed Merks wrote:
>
>> Ian,
>>
>> OCL has its own newsgroup now: eclipse.modeling.mdt.ocl.
>>
>>
>> Ian Bull wrote:
>>> Does OCL support String regular expression operations. I need to
>>> select items whose name matches a particular regex. (Actually I just
>>> need startWith) but I could imagine the need for more powerful
>>> operations.
>>>
>>> Cheers,
>>> Ian
>
Re: [OCL] String Operations [message #3134 is a reply to message #1276] Wed, 31 January 2007 10:31 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Ian,

See some replies in-line, below.

HTH,

Christian


Ian Bull wrote:

> Thanks Christian,
>
> I looked at the example on the wiki about extending the environment.
> What is the OCLHelperFactory? Do I have to define this (Is this where
> my extensions come from)?

No. This is just Chris's way of modeling his OCL extension. He modeled
(using Ecore) an object that he injects into the every OCL environment via
a "global" variable named "helper".


>
> Do you have any advice on how to implement def expressions directly on
> the String Class?

Just do this, for example:

import org.eclipse.ocl.ecore.OCL;

OCL ocl = OCL.newInstance();
OCL.Helper helper = ocl.createHelper();
EClassifier stringType =
ocl.getEnvironment().getOCLStandardLibrary().getString();
helper.setContextClassifier(stringType);
helper.defineOperation("startsWith(s : String) : Boolean = ...");

I haven't tried this, so YMMV ;-)

>
> Thanks,
> Ian
> P.S. Sorry Ed, I'm sure it must get tiring when everyone posts in the
> wrong spot :(
>

<snip>
Re: [OCL] String Operations [message #3198 is a reply to message #3134] Wed, 31 January 2007 17:52 Go to previous messageGo to next message
Eclipse User
Originally posted by: irbull.cs.uvic.ca

Ok, I see what you have done here. I could write my routines in OCL
like this, but for some routines it might be easier to write them in
Java (for example, regex routines since they already exist in Java
libraries).

I have hacked together a way of doing this using a custom
EcoreEnvironment and Ecore Evaluation Environment.

I then added my operation to the environment, and in the evaluation
environment, if I get my operation I execute the appropriate method on
the String class.

Does this make sense? Do you expect people to use OCL in this way? If
this is an expected use of OCL I can post the code on the wiki. It is
similar to what Chris Lenz's did, but it extends primitive types with
additional operations.

cheers,
ian



Christian W. Damus wrote:
> Hi, Ian,
>
> See some replies in-line, below.
>
> HTH,
>
> Christian
>
>
> Ian Bull wrote:
>
>> Thanks Christian,
>>
>> I looked at the example on the wiki about extending the environment.
>> What is the OCLHelperFactory? Do I have to define this (Is this where
>> my extensions come from)?
>
> No. This is just Chris's way of modeling his OCL extension. He modeled
> (using Ecore) an object that he injects into the every OCL environment via
> a "global" variable named "helper".
>
>
>> Do you have any advice on how to implement def expressions directly on
>> the String Class?
>
> Just do this, for example:
>
> import org.eclipse.ocl.ecore.OCL;
>
> OCL ocl = OCL.newInstance();
> OCL.Helper helper = ocl.createHelper();
> EClassifier stringType =
> ocl.getEnvironment().getOCLStandardLibrary().getString();
> helper.setContextClassifier(stringType);
> helper.defineOperation("startsWith(s : String) : Boolean = ...");
>
> I haven't tried this, so YMMV ;-)
>
>> Thanks,
>> Ian
>> P.S. Sorry Ed, I'm sure it must get tiring when everyone posts in the
>> wrong spot :(
>>
>
> <snip>
>
Re: [OCL] String Operations [message #3264 is a reply to message #3198] Thu, 01 February 2007 15:42 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Ian,

Yes, this does make sense. It is one way in which the OCL
parser/interpreter is meant to be extended by clients. I think it's more
interesting to support the overriding of existing operation
implementations. Otherwise, you run the risk of creating OCL constraints
that aren't portable between applications because they don't adhere to the
spec or the model. Of course, that's why OCL allows to define "additional
operations" as helpers, which are also portable. It kinda breaks down,
though, when what's missing is primitives provided by OCL, itself ...

This would make a fine contribution to the Wiki examples corner.

Thanks!

Christian


Ian Bull wrote:

> Ok, I see what you have done here. I could write my routines in OCL
> like this, but for some routines it might be easier to write them in
> Java (for example, regex routines since they already exist in Java
> libraries).
>
> I have hacked together a way of doing this using a custom
> EcoreEnvironment and Ecore Evaluation Environment.
>
> I then added my operation to the environment, and in the evaluation
> environment, if I get my operation I execute the appropriate method on
> the String class.
>
> Does this make sense? Do you expect people to use OCL in this way? If
> this is an expected use of OCL I can post the code on the wiki. It is
> similar to what Chris Lenz's did, but it extends primitive types with
> additional operations.
>
> cheers,
> ian

<snip>
Re: [OCL] String Operations [message #31056 is a reply to message #3198] Thu, 28 June 2007 03:21 Go to previous message
Eclipse User
Originally posted by: asma.charfi.com

Hi Bull,

can you post your code on the wiki
I am interested in working with regex in ocl
thank you
asma

"Ian Bull" <irbull@cs.uvic.ca> a
Previous Topic:OCL on meta-models
Next Topic:Transformate OclText2OclModel
Goto Forum:
  


Current Time: Wed Jul 23 05:57:59 EDT 2014

Powered by FUDForum. Page generated in 0.03396 seconds