Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Using 'literal value' elements in OCL expressions
Using 'literal value' elements in OCL expressions [message #1283504] Thu, 03 April 2014 13:48 Go to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
Hi,

I hope I'm not too vague with this:

Imagine I want to have a constraint on a class that specifies that an
integer typed property is smaller or bigger than some literal value:

self.age < 18

Now, rather than using the literal '18', our users would like to define
the value as a 'Literal Integer' element in the model. (In the UML tree
editor I do: Add child -> Packaged Element -> Literal Integer

So now, somewhere in my model there's a Literal Integer element named
'MY_LITERAL'.

Users would now like to use this in the expression:

self.age < MY_LITERAL

or maybe

self.age < the::namespace::MY_LITERAL


Is this a sound use case? I only talk about parsing the constraint, not
evaluating it.


Thanks for comments,
Felix
Re: Using 'literal value' elements in OCL expressions [message #1283586 is a reply to message #1283504] Thu, 03 April 2014 15:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

'somewhere in my model ' is not a good place.

UML models use Properties to host values by name within a Namespace
hierarchy, so you should probably create a Class called e.g.
GlobalConstants with a read-only (static) Property called MY_LITERAL.

Regards

Ed Willink


On 03/04/2014 14:48, Felix Dorner wrote:
> Hi,
>
> I hope I'm not too vague with this:
>
> Imagine I want to have a constraint on a class that specifies that an
> integer typed property is smaller or bigger than some literal value:
>
> self.age < 18
>
> Now, rather than using the literal '18', our users would like to
> define the value as a 'Literal Integer' element in the model. (In the
> UML tree editor I do: Add child -> Packaged Element -> Literal Integer
>
> So now, somewhere in my model there's a Literal Integer element named
> 'MY_LITERAL'.
>
> Users would now like to use this in the expression:
>
> self.age < MY_LITERAL
>
> or maybe
>
> self.age < the::namespace::MY_LITERAL
>
>
> Is this a sound use case? I only talk about parsing the constraint,
> not evaluating it.
>
>
> Thanks for comments,
> Felix
Re: Using 'literal value' elements in OCL expressions [message #1319874 is a reply to message #1283586] Mon, 28 April 2014 12:49 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
Hi Ed,

On 03/04/2014 17:39, Ed Willink wrote:

> UML models use Properties to host values by name within a Namespace
> hierarchy, so you should probably create a Class called e.g.
> GlobalConstants with a read-only (static) Property called MY_LITERAL.

Ok, and once I have defined this class, I can access its static
properties from 'everywhere', by using a qualified acessor like:

myModel::corePackage::GlobalConstants::MY_LITERAL

?


Thanks for clarification,
Felix
Re: Using 'literal value' elements in OCL expressions [message #1327615 is a reply to message #1283586] Fri, 02 May 2014 08:43 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
Hey Ed,

On 03/04/2014 17:39, Ed Willink wrote:
> Hi
>
> 'somewhere in my model ' is not a good place.
>
> UML models use Properties to host values by name within a Namespace
> hierarchy, so you should probably create a Class called e.g.
> GlobalConstants with a read-only (static) Property called MY_LITERAL.
>

If the user doesn't want to modify the model (let's not talk about that
...), do you think this would work:

I inject classifiers/static properties into the pivot representation:

For a given value defined in namespace some::prefix::MY_VALUE, I inject
a classifier 'some::prefix', with a static property 'MY_VALUE'. If
there's already a classifier with that qualified name, I just add the
property. If the property already exists, there's a conflict but I'll
just diss that case.

Objections?

In general, we were a bit surprised that UML offers a way to model a
value, yet there's no way to access that value in an OCL expression.



Felix
Re: Using 'literal value' elements in OCL expressions [message #1327683 is a reply to message #1327615] Fri, 02 May 2014 09:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You have not yet explained where in your model you have a literal that
should be accessible but is not accessible.

You don't want to change your model but you are prepared to inject
things into it.

You seem to ignore my suggestion for static properties.

I'm very confused and so obviously cannot help.

Regards

Ed


On 02/05/2014 09:43, Felix Dorner wrote:
> Hey Ed,
>
> On 03/04/2014 17:39, Ed Willink wrote:
>> Hi
>>
>> 'somewhere in my model ' is not a good place.
>>
>> UML models use Properties to host values by name within a Namespace
>> hierarchy, so you should probably create a Class called e.g.
>> GlobalConstants with a read-only (static) Property called MY_LITERAL.
>>
>
> If the user doesn't want to modify the model (let's not talk about
> that ...), do you think this would work:
>
> I inject classifiers/static properties into the pivot representation:
>
> For a given value defined in namespace some::prefix::MY_VALUE, I
> inject a classifier 'some::prefix', with a static property 'MY_VALUE'.
> If there's already a classifier with that qualified name, I just add
> the property. If the property already exists, there's a conflict but
> I'll just diss that case.
>
> Objections?
>
> In general, we were a bit surprised that UML offers a way to model a
> value, yet there's no way to access that value in an OCL expression.
>
>
>
> Felix
Re: Using 'literal value' elements in OCL expressions [message #1327747 is a reply to message #1327683] Fri, 02 May 2014 10:10 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 02/05/2014 11:25, Ed Willink wrote:

> You have not yet explained where in your model you have a literal that
> should be accessible but is not accessible.

Yes, sorry. I attached a papyrus screenshot with a trivial example.
Package A contains a 'LiteralInteger' element. Sibling package B
contains a class 'Adult' with an Integer typed property 'age'. I would
like to say in OCL:

context Adult
self.age > A::MIN_AGE

From your first reply, I understand that this is not possible.

> You don't want to change your model but you are prepared to inject
> things into it.

Only into the pivot presentation. The source model will stay untouched.

> You seem to ignore my suggestion for static properties.

I love your suggestion, but the client doesn't want to change its
models. I don't want to bite the feeding hand and look for a 'workaround'.

That's why I want to add these fake classifiers with static properties
into the pivot representation. LiteralValues in the UML model would then
be accessible using static classifier property syntax, like the one above.

Hope things are more clear now.

Felix
>
>
> On 02/05/2014 09:43, Felix Dorner wrote:
>> Hey Ed,
>>
>> On 03/04/2014 17:39, Ed Willink wrote:
>>> Hi
>>>
>>> 'somewhere in my model ' is not a good place.
>>>
>>> UML models use Properties to host values by name within a Namespace
>>> hierarchy, so you should probably create a Class called e.g.
>>> GlobalConstants with a read-only (static) Property called MY_LITERAL.
>>>
>>
>> If the user doesn't want to modify the model (let's not talk about
>> that ...), do you think this would work:
>>
>> I inject classifiers/static properties into the pivot representation:
>>
>> For a given value defined in namespace some::prefix::MY_VALUE, I
>> inject a classifier 'some::prefix', with a static property 'MY_VALUE'.
>> If there's already a classifier with that qualified name, I just add
>> the property. If the property already exists, there's a conflict but
>> I'll just diss that case.
>>
>> Objections?
>>
>> In general, we were a bit surprised that UML offers a way to model a
>> value, yet there's no way to access that value in an OCL expression.
>>
>>
>>
>> Felix
>
  • Attachment: literal.png
    (Size: 4.58KB, Downloaded 189 times)
Re: Using 'literal value' elements in OCL expressions [message #1327803 is a reply to message #1327747] Fri, 02 May 2014 10:46 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

For a name to be visible it must be in a namespace, such as a property
in a class or a class in a package. You can't just put junk anywhere and
expect that the 'name' property has your semantics.

Why can't you put your global constrants in a global package in a global
model. No need to chnage anything?

Regards

Ed Willink


On 02/05/2014 11:10, Felix Dorner wrote:
> On 02/05/2014 11:25, Ed Willink wrote:
>
>> You have not yet explained where in your model you have a literal that
>> should be accessible but is not accessible.
>
> Yes, sorry. I attached a papyrus screenshot with a trivial example.
> Package A contains a 'LiteralInteger' element. Sibling package B
> contains a class 'Adult' with an Integer typed property 'age'. I would
> like to say in OCL:
>
> context Adult
> self.age > A::MIN_AGE
>
> From your first reply, I understand that this is not possible.
>
>> You don't want to change your model but you are prepared to inject
>> things into it.
>
> Only into the pivot presentation. The source model will stay untouched.
>
>> You seem to ignore my suggestion for static properties.
>
> I love your suggestion, but the client doesn't want to change its
> models. I don't want to bite the feeding hand and look for a
> 'workaround'.
>
> That's why I want to add these fake classifiers with static properties
> into the pivot representation. LiteralValues in the UML model would
> then be accessible using static classifier property syntax, like the
> one above.
>
> Hope things are more clear now.
>
> Felix
>>
>>
>> On 02/05/2014 09:43, Felix Dorner wrote:
>>> Hey Ed,
>>>
>>> On 03/04/2014 17:39, Ed Willink wrote:
>>>> Hi
>>>>
>>>> 'somewhere in my model ' is not a good place.
>>>>
>>>> UML models use Properties to host values by name within a Namespace
>>>> hierarchy, so you should probably create a Class called e.g.
>>>> GlobalConstants with a read-only (static) Property called MY_LITERAL.
>>>>
>>>
>>> If the user doesn't want to modify the model (let's not talk about
>>> that ...), do you think this would work:
>>>
>>> I inject classifiers/static properties into the pivot representation:
>>>
>>> For a given value defined in namespace some::prefix::MY_VALUE, I
>>> inject a classifier 'some::prefix', with a static property 'MY_VALUE'.
>>> If there's already a classifier with that qualified name, I just add
>>> the property. If the property already exists, there's a conflict but
>>> I'll just diss that case.
>>>
>>> Objections?
>>>
>>> In general, we were a bit surprised that UML offers a way to model a
>>> value, yet there's no way to access that value in an OCL expression.
>>>
>>>
>>>
>>> Felix
>>
>
Previous Topic:Reflection example
Next Topic:Is org.eclipse.ocl.* for equinox only?
Goto Forum:
  


Current Time: Tue Apr 16 08:15:56 GMT 2024

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

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

Back to the top