knowledge-database (beta)

Current group: comp.constraints

OCL Query

OCL Query  
OCL Beginner
 Re: OCL Query  
OCL Beginner
 Re: OCL Query  
Andreas Awenius
 Re: OCL Query  
OCL Beginner
 Re: OCL Query  
Andreas Awenius
 Re: OCL Query  
OCL Beginner
 Re: OCL Query  
Andreas Awenius
From:OCL Beginner
Subject:OCL Query
Date:14 Jan 2005 08:33:47 -0800
Hello,

I am new to OCL and have been trying without success to come up with
the right code for a particular query.

I would like to get a set like this:

Set { actor->select (name ) }

Where actor is a class, and name is an attribute of that class.

However, I don't know how to code/model .

The string can be any separated list eg "Alan, John, Deidre, Sophie".
Can anyone shed any light on this ?

Thanks in advance.

Rupes
From:OCL Beginner
Subject:Re: OCL Query
Date:17 Jan 2005 07:13:33 -0800
Ah thanks for your reply

....only the string of separated names must be in a variable of type
string.

i.e. actor->select( name in sNameList)
only of course "in" doesn't exist as an operator.
From:Andreas Awenius
Subject:Re: OCL Query
Date:Mon, 17 Jan 2005 12:12:29 +0100
Hello rikill,

On 14 Jan 2005 08:33:47 -0800, "OCL Beginner"
wrote:


>I would like to get a set like this:
>
>Set { actor->select (name ) }
>
>Where actor is a class, and name is an attribute of that class.
>
>However, I don't know how to code/model .
>
>The string can be any separated list eg "Alan, John, Deidre, Sophie".

actor.select(Set {'Alan', 'John', 'Deidre', 'Sophie'}.includes(name))

This code was checked with our OCL-AdIn for Rational Rose.

Regards,
Andreas

>Can anyone shed any light on this ?
>
>Thanks in advance.
>
>Rupes

--
Andreas Awenius
Enhance your UML models: http://www.empowertec.de
From:OCL Beginner
Subject:Re: OCL Query
Date:17 Jan 2005 07:17:29 -0800
Ah thanks for your reply

....only the string of separated names must be in a variable of type
string.

i.e. actor->select( name in sNameList)
only of course "in" doesn't exist as an operator.
From:Andreas Awenius
Subject:Re: OCL Query
Date:Wed, 19 Jan 2005 22:06:39 +0100
Hello,

On 17 Jan 2005 07:17:29 -0800, "OCL Beginner"
wrote:

>Ah thanks for your reply
>
>...only the string of separated names must be in a variable of type
>string.
>
>i.e. actor->select( name in sNameList)
>only of course "in" doesn't exist as an operator.

That cannot be done with the OCL standard library.
You need to define a method in your model that performs a
'SplitString' operation and call that in your OCL expression.

actor.select(SplitString(sNameList).includes(name))

This assumes that SplitString(stringToSplit: String): Set(String) is
defined in the class that is used as context for the expression.

Kind regards,
Andreas

--
Andreas Awenius
Enhance your UML models: http://www.empowertec.de
From:OCL Beginner
Subject:Re: OCL Query
Date:21 Jan 2005 02:29:14 -0800
Thanks for your reply Andreas.

Not absolutely sure what you mean by:

> This assumes that SplitString(stringToSplit: String): Set(String) is
> defined in the class that is used as context for the expression.

I can't define it in the class "actor" as this is already defined in
the product I'm using - which is Compuware's UnifaceFlow (formerly
OptimalFlow). This product contains an OCL editor and compiler to
allocate tasks to a set of actors. Perhaps there is a way of adding
methods to an existing class, or perhaps I could create a child class
that inherits from class "actor" ? Unfortunately my OO is a little
rusty.

Cheers,

Rupes

Andreas Awenius wrote:
> Hello,
>
> On 17 Jan 2005 07:17:29 -0800, "OCL Beginner"
> wrote:
>
> >Ah thanks for your reply
> >
> >...only the string of separated names must be in a variable of type
> >string.
> >
> >i.e. actor->select( name in sNameList)
> >only of course "in" doesn't exist as an operator.
>
> That cannot be done with the OCL standard library.
> You need to define a method in your model that performs a
> 'SplitString' operation and call that in your OCL expression.
>
> actor.select(SplitString(sNameList).includes(name))
>
> This assumes that SplitString(stringToSplit: String): Set(String) is
> defined in the class that is used as context for the expression.
>
> Kind regards,
> Andreas
>
> --
> Andreas Awenius
> Enhance your UML models: http://www.empowertec.de
From:Andreas Awenius
Subject:Re: OCL Query
Date:Sat, 22 Jan 2005 16:29:58 +0100
Hello Rupes,

On 21 Jan 2005 02:29:14 -0800, "OCL Beginner"
wrote:

>Thanks for your reply Andreas.
>
>Not absolutely sure what you mean by:
>
>> This assumes that SplitString(stringToSplit: String): Set(String) is
>> defined in the class that is used as context for the expression.

Each method used in an OCL expression must be defined either in the
OCL standard library or in the model that defines the context for the
expression evaluation. Since the OCL standard library does not contain
a method to split strings, such a method must be defined in the model.
UML/OCL does not have a notion of 'free functions', therefore
SplitString() (or a similar method) bust be defined as a method of a
class. If you want to use a given method in an expression, an object
(of a class) that defines this method must be in the scope of the
expression.
In your example, I simply assumed SplitString() is a method of the
context class (the context declaration was missing in your example).

>
>I can't define it in the class "actor" as this is already defined in
>the product I'm using - which is Compuware's UnifaceFlow (formerly
>OptimalFlow). This product contains an OCL editor and compiler to
>allocate tasks to a set of actors. Perhaps there is a way of adding
>methods to an existing class, or perhaps I could create a child class
>that inherits from class "actor" ? Unfortunately my OO is a little
>rusty.

Maybe this platform defines its own string class that has a method to
split strings. Then you can use this class instead of 'String'.
Otherwise, it could be possible to define an according static method
within a helper class.

StringUtil::SplitString(String stringToSplit, String separator):
Set(String)

Then you can call it like this:
context SomeClass
inv:
actor.exists(StringUtils::SplitString(sNameList, ',').includes(name))

This assumes, that SomeClass has an association to Actor with a role
name of 'actor' and an attribute sNameList that holds the names
separated by a comma.

If your OCL expression is for documentation only, you could add an
appropriate method to SomeClass at the level of OCL using a 'def' OCL
expression:

context SomeClass
def: SplitString(stringToSplit: String, separator: String):
Set(String) = Set {''}
inv:
actor.exists(StringUtils::SplitString(sNameList, ',').includes(name))

However, this is a slight misuse of a def expression because it does
not define the operations behavior.

Kind regards,
Andreas

>
>Cheers,
>
>Rupes
>
>Andreas Awenius wrote:
>> Hello,
>>
>> On 17 Jan 2005 07:17:29 -0800, "OCL Beginner"
>> wrote:
>>
>> >Ah thanks for your reply
>> >
>> >...only the string of separated names must be in a variable of type
>> >string.
>> >
>> >i.e. actor->select( name in sNameList)
>> >only of course "in" doesn't exist as an operator.
>>
>> That cannot be done with the OCL standard library.
>> You need to define a method in your model that performs a
>> 'SplitString' operation and call that in your OCL expression.
>>
>> actor.select(SplitString(sNameList).includes(name))
>>
>> This assumes that SplitString(stringToSplit: String): Set(String) is
>> defined in the class that is used as context for the expression.
>>
>> Kind regards,
>> Andreas
>>
>> --
>> Andreas Awenius
>> Enhance your UML models: http://www.empowertec.de

--
Andreas Awenius
Enhance your UML models: http://www.empowertec.de
   

Copyright © 2006 knowledge-database   -   All rights reserved