Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Parsing Error: Iterator variable must have same type as source element.
Parsing Error: Iterator variable must have same type as source element. [message #32401] Mon, 09 July 2007 12:37 Go to next message
Juan Pedro Silva is currently offline Juan Pedro SilvaFriend
Messages: 258
Registered: July 2009
Senior Member
Hello everybody, I'm back to this temple of enlightening again.
My current problem is the following: I'm trying to check if the value
(of type Class) of the 'binding' property of the stereotype I'm applying
is present within a set of values ('allowedBindings') of the component
owning one of the ports connected by this connector.

In OCL (context = an stereotype applicable to a Connector) it would go
something like this:

self.base_Connector.end.role->exists
(
r : Port | r.owner.getValue(SomeStereotype , 'allowedBindings')->
SomeOCLOperationToDetermine()->includes(self.binding)

)

I believe I am getting something like a problem of incompatible types.
'getValue(Stereotype, String)' returns Object, so I would probably be
able to solve this with a ".oclAsType(Set(Class))" operation (which is
currently not supported, as I read in a old post from Christian and Irina).

However, in that post Christian suggested the use of an iterator
(because she had a Set(something) and wanted a Set(someOtherThing)), but
I think I have an Object, which I want to turn into a Set(Class).

Any suggestion would be very much appreciated, either to cast the Object
to Set(Class) or to achieve my objective in some other way.
Thank you,
Juan Pedro
Re: Parsing Error: Iterator variable must have same type as source element. [message #32539 is a reply to message #32401] Mon, 09 July 2007 15:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Juan Pedro,

First, you would have to get past the problem of OCL not understand a
reference to the SomeStereotype by name in invocation of the getValue(...)
operation. This kind of reference to a type only works for OCL's
predefined allInstances(), oclIsKindOf(), oclIsTypeOf(), and oclAsType()
operations. You would have to do something like this:

self.base_Connector.end.role->exists( r : Port |
r.owner.getValue(
r.owner.getApplicableStereotype('SomeProfile::SomeStereotype '),
'allowedBindings')->someOCLOperation()->includes(self.binding))

to get the appropriate Stereotype object to pass to getValue(...).

As you have discovered, OCL does not provide for casting collection types
using oclAsType(). Perhaps you can try using the stereotype application as
an instance of the Stereotype, viewed as a pseudo-metaclass:

self.base_Connector.end.role->exists( r : Port |
let stereo : Stereotype =
r.owner.getApplicableStereotype('SomeProfile::SomeStereotype ')
in
r.owner.isStereotypeApplied(stereo) and
let s : SomeStereotype =
r.owner.getStereotypeApplication(stereo).oclAsType(SomeStere otype)
in
s.allowedBindings->someOCLOperation()->includes(self.binding))

I don't know whether this would work in RSA; it should work in MDT OCL 1.1's
UML environment implementation.

HTH,

Christian

Juan Pedro Silva wrote:

> Hello everybody, I'm back to this temple of enlightening again.
> My current problem is the following: I'm trying to check if the value
> (of type Class) of the 'binding' property of the stereotype I'm applying
> is present within a set of values ('allowedBindings') of the component
> owning one of the ports connected by this connector.
>
> In OCL (context = an stereotype applicable to a Connector) it would go
> something like this:
>
> self.base_Connector.end.role->exists
> (
> r : Port | r.owner.getValue(SomeStereotype , 'allowedBindings')->
> SomeOCLOperationToDetermine()->includes(self.binding)
>
> )
>
> I believe I am getting something like a problem of incompatible types.
> 'getValue(Stereotype, String)' returns Object, so I would probably be
> able to solve this with a ".oclAsType(Set(Class))" operation (which is
> currently not supported, as I read in a old post from Christian and
> Irina).
>
> However, in that post Christian suggested the use of an iterator
> (because she had a Set(something) and wanted a Set(someOtherThing)), but
> I think I have an Object, which I want to turn into a Set(Class).
>
> Any suggestion would be very much appreciated, either to cast the Object
> to Set(Class) or to achieve my objective in some other way.
> Thank you,
> Juan Pedro
Re: Parsing Error: Iterator variable must have same type as source element. [message #32608 is a reply to message #32539] Tue, 10 July 2007 13:30 Go to previous message
Juan Pedro Silva is currently offline Juan Pedro SilvaFriend
Messages: 258
Registered: July 2009
Senior Member
Thanks Christian for your answer.
I had realized about the 'Stereotype' issue. I had found some other
(very similar, but more complicated) workaround:

r.owner.getAppliedStereotypes()->select (name='someStereotype')
->asOrderedSet()->first()

Your approached seems to work (haven't tried the rule yet, but it
parses). I had to change a few things in order for it to work in RSA,
though. I'll put it here for if someone has a similar problem in the
future and browses/searches the newsgroup archives, so that the solution
is complete.

First thing to change, the order of factors: I had to order it in the
traditional "let x in let y in boolean_expression_with_x_and_y" way (you
had a complete let expression "and" another let expression). The second
thing was that I had to take out the type 'Port' from 'r' definition,
because it was a 'ConnectableElement' and I wasn't casting it to 'Port'.
So, the resulting expression was:

if not self.binding.oclIsUndefined() then
self.base_Connector.end.role->exists
(
r | let stereo : Stereotype =
r.owner.getApplicableStereotype('SomeProfile::someStereotype ')
in let s : Perfil_SOA::serviceProvider =
r.owner.getStereotypeApplication(stereo).oclAsType
(SomeProfile::someStereotype)
in ( r.owner.isStereotypeApplied(stereo) and
s.allowedBindings->includes(self.binding))
)
else false endif

Christian, as usual, you were of great help.
Thank you very much,
Juan Pedro



Christian W. Damus escribió:
> Hi, Juan Pedro,
>
> First, you would have to get past the problem of OCL not understand a
> reference to the SomeStereotype by name in invocation of the getValue(...)
> operation. This kind of reference to a type only works for OCL's
> predefined allInstances(), oclIsKindOf(), oclIsTypeOf(), and oclAsType()
> operations. You would have to do something like this:
>
> self.base_Connector.end.role->exists( r : Port |
> r.owner.getValue(
> r.owner.getApplicableStereotype('SomeProfile::SomeStereotype '),
> 'allowedBindings')->someOCLOperation()->includes(self.binding))
>
> to get the appropriate Stereotype object to pass to getValue(...).
>
> As you have discovered, OCL does not provide for casting collection types
> using oclAsType(). Perhaps you can try using the stereotype application as
> an instance of the Stereotype, viewed as a pseudo-metaclass:
>
> self.base_Connector.end.role->exists( r : Port |
> let stereo : Stereotype =
> r.owner.getApplicableStereotype('SomeProfile::SomeStereotype ')
> in
> r.owner.isStereotypeApplied(stereo) and
> let s : SomeStereotype =
> r.owner.getStereotypeApplication(stereo).oclAsType(SomeStere otype)
> in
> s.allowedBindings->someOCLOperation()->includes(self.binding))
>
> I don't know whether this would work in RSA; it should work in MDT OCL 1.1's
> UML environment implementation.
>
> HTH,
>
> Christian
>
> Juan Pedro Silva wrote:
>
>> Hello everybody, I'm back to this temple of enlightening again.
>> My current problem is the following: I'm trying to check if the value
>> (of type Class) of the 'binding' property of the stereotype I'm applying
>> is present within a set of values ('allowedBindings') of the component
>> owning one of the ports connected by this connector.
>>
>> In OCL (context = an stereotype applicable to a Connector) it would go
>> something like this:
>>
>> self.base_Connector.end.role->exists
>> (
>> r : Port | r.owner.getValue(SomeStereotype , 'allowedBindings')->
>> SomeOCLOperationToDetermine()->includes(self.binding)
>>
>> )
>>
>> I believe I am getting something like a problem of incompatible types.
>> 'getValue(Stereotype, String)' returns Object, so I would probably be
>> able to solve this with a ".oclAsType(Set(Class))" operation (which is
>> currently not supported, as I read in a old post from Christian and
>> Irina).
>>
>> However, in that post Christian suggested the use of an iterator
>> (because she had a Set(something) and wanted a Set(someOtherThing)), but
>> I think I have an Object, which I want to turn into a Set(Class).
>>
>> Any suggestion would be very much appreciated, either to cast the Object
>> to Set(Class) or to achieve my objective in some other way.
>> Thank you,
>> Juan Pedro
>
Previous Topic:OCL Grammar for Validation
Next Topic:Re: Integrating OCL - providing EvaluationEnvironment
Goto Forum:
  


Current Time: Sun Dec 21 16:49:09 GMT 2014

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

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