Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to get all instances of the same type as self?
How to get all instances of the same type as self? [message #65133] Wed, 10 December 2008 10:24 Go to next message
Andreas Werner is currently offline Andreas WernerFriend
Messages: 55
Registered: July 2009
Member
Hi,

I try to get all instances of the same type as self is:
SuperClass.allInstances()->select(obj | obj.oclIsKindOf(self))

SuperClass is an abstract super class of the type of self.

In the "Interactive OCL" console I get this output:
Cannot find operation (oclIsKindOf(SelfType)) for the type (SuperClass)

Instead of using self in the above expression, but using directly SelfType,
the expression is working:
SuperClass.allInstances()->select(obj | obj.oclIsKindOf(SelfType))

The problem is this static declaration does not allow the usage of the constraint
in SuperClass!

Has somebody any idea, please?

Kind Regards, Andreas
Re: How to get all instances of the same type as self? [message #65155 is a reply to message #65133] Wed, 10 December 2008 14:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Andreas,

The first expression that you quoted didn't work because 'self' is not a
classifier in your model, but rather an instance of one. That is to
say, the signature is oclIsKindOf(OclType), not oclIsKindOf(SelfType).

Why would this constraint not be be permitted in the context of
SuperClass? It can reference the SelfType if it needs to, even via its
package-qualified name, if needs be. Are you getting an error in parsing?

Cheers,

Christian

Andreas Werner wrote:
> Hi,
>
> I try to get all instances of the same type as self is:
> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(self))
>
> SuperClass is an abstract super class of the type of self.
> In the "Interactive OCL" console I get this output:
> Cannot find operation (oclIsKindOf(SelfType)) for the type (SuperClass)
>
> Instead of using self in the above expression, but using directly
> SelfType, the expression is working:
> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(SelfType))
>
> The problem is this static declaration does not allow the usage of the
> constraint in SuperClass!
>
> Has somebody any idea, please?
>
> Kind Regards, Andreas
>
>
Re: How to get all instances of the same type as self? [message #65219 is a reply to message #65155] Wed, 10 December 2008 15:49 Go to previous messageGo to next message
Andreas Werner is currently offline Andreas WernerFriend
Messages: 55
Registered: July 2009
Member
Hello Christian,

I'm a bit confused about your answer...
Perhaps I just try to explain the main problem:

There is an abstract class A which instances may reference other instances
of type A via a navigable association "referencedA". Now there also exist
two or more sub classes of A: call them B, C and so on. The thing is, that
I wan't B instances only to reference other B instances, and the same holds
for C instances etc. Thus I wanted to introduce a constraint in A in order
to have it in one place and generic for all sub classes of A...

The constraint I thought of was:
self.referencedA->forAll(obj| obj.oclIsKindOf(self))

But this doesn't seem to work, as you already explained. So, the alternative/ugly
solution for me would be to introduce the constraint in each sub class, for
example in B:
self.referencedA->forAll(obj| obj.oclIsKindOf(B))

This indeed works very well, but the disadvantage is in my opinion, that
I have to do it for all sub classes, and i must not forget about it, if new
sub classes will be added.

So, what do you think about it Christian (or anybody else)? How can I define
a constraint in an abstract super class which depends on the runtime type
of its objects?

Regards, Andreas

> Hi, Andreas,
>
> The first expression that you quoted didn't work because 'self' is not
> a classifier in your model, but rather an instance of one. That is to
> say, the signature is oclIsKindOf(OclType), not oclIsKindOf(SelfType).
>
> Why would this constraint not be be permitted in the context of
> SuperClass? It can reference the SelfType if it needs to, even via
> its package-qualified name, if needs be. Are you getting an error in
> parsing?
>
> Cheers,
>
> Christian
>
> Andreas Werner wrote:
>
>> Hi,
>>
>> I try to get all instances of the same type as self is:
>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(self))
>>
>> SuperClass is an abstract super class of the type of self.
>> In the "Interactive OCL" console I get this output:
>> Cannot find operation (oclIsKindOf(SelfType)) for the type
>> (SuperClass)
>> Instead of using self in the above expression, but using directly
>> SelfType, the expression is working:
>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(SelfType))
>>
>> The problem is this static declaration does not allow the usage of
>> the constraint in SuperClass!
>>
>> Has somebody any idea, please?
>>
>> Kind Regards, Andreas
>>
Re: How to get all instances of the same type as self? [message #65240 is a reply to message #65219] Wed, 10 December 2008 16:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Andreas,

I understand, now.

What you need is the OCL 1.x ability to access the class of an object
via oclType, thus:

self.referencedA->forAll(obj | obj.oclIsKindOf(self.oclType))

Unfortunately, OCL 2.0 removed the oclType attribute, so this is no
longer valid. You actually see this kind of expression in several
places in the UML 2.x specifications, erroneously.

Happily, the OCL 2.1 RTF recently passed a ballot which includes an
issue resolution that re-introduces oclType, but as an operation

oclType() : Classifier

(a bunch of issues were resolved in part by replacing the OclType
metaclass with UML Classifier/EMOF Type).

So, hopefully the next release of MDT OCL will be able to provide this.

In the mean-time, you can achieve the same thing by using the
ParsingOptions.implicitRootClass() parsing option to specify EObject as
the implicit root class in your model. Then, you will have access to
the EObject capabilities, thus:

self.referenceA->forAll(obj |
self.eClass().isSuperTypeOf(obj.eClass()))

One final note. MOF/UML provides an elegant solution to your problem:
property subsetting. Your superclass A can define referencedA as a
"derived union" and let each subclass define subsets of this union,
B::referencedB : B, C::referencedC, etc. The MDL UML2 component even
provides code-generation support for this. This approach obviates the
constraint by making A::referenceA derived and read-only.

Cheers,

Christian


Andreas Werner wrote:
> Hello Christian,
>
> I'm a bit confused about your answer...
> Perhaps I just try to explain the main problem:
>
> There is an abstract class A which instances may reference other
> instances of type A via a navigable association "referencedA". Now there
> also exist two or more sub classes of A: call them B, C and so on. The
> thing is, that I wan't B instances only to reference other B instances,
> and the same holds for C instances etc. Thus I wanted to introduce a
> constraint in A in order to have it in one place and generic for all sub
> classes of A...
>
> The constraint I thought of was:
> self.referencedA->forAll(obj| obj.oclIsKindOf(self))
>
> But this doesn't seem to work, as you already explained. So, the
> alternative/ugly solution for me would be to introduce the constraint in
> each sub class, for example in B:
> self.referencedA->forAll(obj| obj.oclIsKindOf(B))
>
> This indeed works very well, but the disadvantage is in my opinion, that
> I have to do it for all sub classes, and i must not forget about it, if
> new sub classes will be added.
>
> So, what do you think about it Christian (or anybody else)? How can I
> define a constraint in an abstract super class which depends on the
> runtime type of its objects?
>
> Regards, Andreas
>
>> Hi, Andreas,
>>
>> The first expression that you quoted didn't work because 'self' is not
>> a classifier in your model, but rather an instance of one. That is to
>> say, the signature is oclIsKindOf(OclType), not oclIsKindOf(SelfType).
>>
>> Why would this constraint not be be permitted in the context of
>> SuperClass? It can reference the SelfType if it needs to, even via
>> its package-qualified name, if needs be. Are you getting an error in
>> parsing?
>>
>> Cheers,
>>
>> Christian
>>
>> Andreas Werner wrote:
>>
>>> Hi,
>>>
>>> I try to get all instances of the same type as self is:
>>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(self))
>>>
>>> SuperClass is an abstract super class of the type of self.
>>> In the "Interactive OCL" console I get this output:
>>> Cannot find operation (oclIsKindOf(SelfType)) for the type
>>> (SuperClass)
>>> Instead of using self in the above expression, but using directly
>>> SelfType, the expression is working:
>>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(SelfType))
>>>
>>> The problem is this static declaration does not allow the usage of
>>> the constraint in SuperClass!
>>>
>>> Has somebody any idea, please?
>>>
>>> Kind Regards, Andreas
>>>
>
>
Re: How to get all instances of the same type as self? [message #65282 is a reply to message #65240] Wed, 10 December 2008 17:03 Go to previous messageGo to next message
Andreas Werner is currently offline Andreas WernerFriend
Messages: 55
Registered: July 2009
Member
Hello Christian,

thank you very much for your quick responses!

Regarding my problem I hope that the next OCL version will have this feature
(self.oclType())! I guess it would be very nice to use it, because I could
then define an operation body with OCL which will return possible objects
to reference as well.

For now I will have a look at the derived-union-thing, but if I remind it
correctly, then I have to introduce a new feature into each sub class, right?


Kind Regards,
Andreas

> Hi, Andreas,
>
> I understand, now.
>
> What you need is the OCL 1.x ability to access the class of an object
> via oclType, thus:
>
> self.referencedA->forAll(obj | obj.oclIsKindOf(self.oclType))
>
> Unfortunately, OCL 2.0 removed the oclType attribute, so this is no
> longer valid. You actually see this kind of expression in several
> places in the UML 2.x specifications, erroneously.
>
> Happily, the OCL 2.1 RTF recently passed a ballot which includes an
> issue resolution that re-introduces oclType, but as an operation
>
> oclType() : Classifier
>
> (a bunch of issues were resolved in part by replacing the OclType
> metaclass with UML Classifier/EMOF Type).
>
> So, hopefully the next release of MDT OCL will be able to provide
> this.
>
> In the mean-time, you can achieve the same thing by using the
> ParsingOptions.implicitRootClass() parsing option to specify EObject
> as the implicit root class in your model. Then, you will have access
> to the EObject capabilities, thus:
>
> self.referenceA->forAll(obj |
> self.eClass().isSuperTypeOf(obj.eClass()))
> One final note. MOF/UML provides an elegant solution to your problem:
> property subsetting. Your superclass A can define referencedA as a
> "derived union" and let each subclass define subsets of this union,
> B::referencedB : B, C::referencedC, etc. The MDL UML2 component even
> provides code-generation support for this. This approach obviates the
> constraint by making A::referenceA derived and read-only.
>
> Cheers,
>
> Christian
>
> Andreas Werner wrote:
>
>> Hello Christian,
>>
>> I'm a bit confused about your answer...
>> Perhaps I just try to explain the main problem:
>> There is an abstract class A which instances may reference other
>> instances of type A via a navigable association "referencedA". Now
>> there also exist two or more sub classes of A: call them B, C and so
>> on. The thing is, that I wan't B instances only to reference other B
>> instances, and the same holds for C instances etc. Thus I wanted to
>> introduce a constraint in A in order to have it in one place and
>> generic for all sub classes of A...
>>
>> The constraint I thought of was:
>> self.referencedA->forAll(obj| obj.oclIsKindOf(self))
>> But this doesn't seem to work, as you already explained. So, the
>> alternative/ugly solution for me would be to introduce the constraint
>> in
>> each sub class, for example in B:
>> self.referencedA->forAll(obj| obj.oclIsKindOf(B))
>> This indeed works very well, but the disadvantage is in my opinion,
>> that I have to do it for all sub classes, and i must not forget about
>> it, if new sub classes will be added.
>>
>> So, what do you think about it Christian (or anybody else)? How can I
>> define a constraint in an abstract super class which depends on the
>> runtime type of its objects?
>>
>> Regards, Andreas
>>
>>> Hi, Andreas,
>>>
>>> The first expression that you quoted didn't work because 'self' is
>>> not a classifier in your model, but rather an instance of one. That
>>> is to say, the signature is oclIsKindOf(OclType), not
>>> oclIsKindOf(SelfType).
>>>
>>> Why would this constraint not be be permitted in the context of
>>> SuperClass? It can reference the SelfType if it needs to, even via
>>> its package-qualified name, if needs be. Are you getting an error
>>> in parsing?
>>>
>>> Cheers,
>>>
>>> Christian
>>>
>>> Andreas Werner wrote:
>>>
>>>> Hi,
>>>>
>>>> I try to get all instances of the same type as self is:
>>>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(self))
>>>>
>>>> SuperClass is an abstract super class of the type of self.
>>>> In the "Interactive OCL" console I get this output:
>>>> Cannot find operation (oclIsKindOf(SelfType)) for the type
>>>> (SuperClass)
>>>> Instead of using self in the above expression, but using directly
>>>> SelfType, the expression is working:
>>>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(SelfType))
>>>> The problem is this static declaration does not allow the usage of
>>>> the constraint in SuperClass!
>>>>
>>>> Has somebody any idea, please?
>>>>
>>>> Kind Regards, Andreas
>>>>
Re: How to get all instances of the same type as self? [message #65303 is a reply to message #65240] Wed, 10 December 2008 17:39 Go to previous message
Andreas Werner is currently offline Andreas WernerFriend
Messages: 55
Registered: July 2009
Member
Hello Christian,

I tried your workaround with setting the parsing options and I think this
is a sufficient solution.

Thanks a lot for that point!

Kind Regards,
Andreas

> Hi, Andreas,
>
> I understand, now.
>
> What you need is the OCL 1.x ability to access the class of an object
> via oclType, thus:
>
> self.referencedA->forAll(obj | obj.oclIsKindOf(self.oclType))
>
> Unfortunately, OCL 2.0 removed the oclType attribute, so this is no
> longer valid. You actually see this kind of expression in several
> places in the UML 2.x specifications, erroneously.
>
> Happily, the OCL 2.1 RTF recently passed a ballot which includes an
> issue resolution that re-introduces oclType, but as an operation
>
> oclType() : Classifier
>
> (a bunch of issues were resolved in part by replacing the OclType
> metaclass with UML Classifier/EMOF Type).
>
> So, hopefully the next release of MDT OCL will be able to provide
> this.
>
> In the mean-time, you can achieve the same thing by using the
> ParsingOptions.implicitRootClass() parsing option to specify EObject
> as the implicit root class in your model. Then, you will have access
> to the EObject capabilities, thus:
>
> self.referenceA->forAll(obj |
> self.eClass().isSuperTypeOf(obj.eClass()))
> One final note. MOF/UML provides an elegant solution to your problem:
> property subsetting. Your superclass A can define referencedA as a
> "derived union" and let each subclass define subsets of this union,
> B::referencedB : B, C::referencedC, etc. The MDL UML2 component even
> provides code-generation support for this. This approach obviates the
> constraint by making A::referenceA derived and read-only.
>
> Cheers,
>
> Christian
>
> Andreas Werner wrote:
>
>> Hello Christian,
>>
>> I'm a bit confused about your answer...
>> Perhaps I just try to explain the main problem:
>> There is an abstract class A which instances may reference other
>> instances of type A via a navigable association "referencedA". Now
>> there also exist two or more sub classes of A: call them B, C and so
>> on. The thing is, that I wan't B instances only to reference other B
>> instances, and the same holds for C instances etc. Thus I wanted to
>> introduce a constraint in A in order to have it in one place and
>> generic for all sub classes of A...
>>
>> The constraint I thought of was:
>> self.referencedA->forAll(obj| obj.oclIsKindOf(self))
>> But this doesn't seem to work, as you already explained. So, the
>> alternative/ugly solution for me would be to introduce the constraint
>> in
>> each sub class, for example in B:
>> self.referencedA->forAll(obj| obj.oclIsKindOf(B))
>> This indeed works very well, but the disadvantage is in my opinion,
>> that I have to do it for all sub classes, and i must not forget about
>> it, if new sub classes will be added.
>>
>> So, what do you think about it Christian (or anybody else)? How can I
>> define a constraint in an abstract super class which depends on the
>> runtime type of its objects?
>>
>> Regards, Andreas
>>
>>> Hi, Andreas,
>>>
>>> The first expression that you quoted didn't work because 'self' is
>>> not a classifier in your model, but rather an instance of one. That
>>> is to say, the signature is oclIsKindOf(OclType), not
>>> oclIsKindOf(SelfType).
>>>
>>> Why would this constraint not be be permitted in the context of
>>> SuperClass? It can reference the SelfType if it needs to, even via
>>> its package-qualified name, if needs be. Are you getting an error
>>> in parsing?
>>>
>>> Cheers,
>>>
>>> Christian
>>>
>>> Andreas Werner wrote:
>>>
>>>> Hi,
>>>>
>>>> I try to get all instances of the same type as self is:
>>>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(self))
>>>>
>>>> SuperClass is an abstract super class of the type of self.
>>>> In the "Interactive OCL" console I get this output:
>>>> Cannot find operation (oclIsKindOf(SelfType)) for the type
>>>> (SuperClass)
>>>> Instead of using self in the above expression, but using directly
>>>> SelfType, the expression is working:
>>>> SuperClass.allInstances()->select(obj | obj.oclIsKindOf(SelfType))
>>>> The problem is this static declaration does not allow the usage of
>>>> the constraint in SuperClass!
>>>>
>>>> Has somebody any idea, please?
>>>>
>>>> Kind Regards, Andreas
>>>>
Previous Topic:OCL Constraint evaluation fail
Next Topic:OCL can not match operation and argument types if argument is EClass
Goto Forum:
  


Current Time: Fri Mar 29 13:56:12 GMT 2024

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

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

Back to the top