Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Problem: Cannot find operation
Problem: Cannot find operation [message #38029] Mon, 24 September 2007 16:20 Go to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
Hi,
In my ecore file I defined an EClass named ClassA, which has some
EAttributes such as ClassA#weight. I need to call generated getWeight()
method in an OCL expression using a instance of ClassA as the context, for
example "self.getWeight()", but I got an exception saying "Cannot find
operation (getWeight()) for the type (LoaderModel)", however "self.weight"
is no problem.

Can anyone give me some instructions on evaluating methods defined on
context object? thanks in advance.

Regards,
Hao
Re: Problem: Cannot find operation [message #38060 is a reply to message #38029] Mon, 24 September 2007 16:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Hao,

The "getWeight()" operation is not modeled as an operation in Ecore; it is
purely a figment of the Ecore-to-Java transformation performed by EMF.

You can define an EOperation named "getWeight" in your Ecore model, and the
OCL constraint will be able to call it. EMF is smart enough to realize
that this EOperation corresponds, in the generated code, to the Java
accessor method of your "weight" attribute. This shouldn't be necessary,
though, since OCL can access the property simply by "self.weight" as you
indicated.

Cheers,

Christian


Hao Zhang wrote:

> Hi,
> In my ecore file I defined an EClass named ClassA, which has some
> EAttributes such as ClassA#weight. I need to call generated getWeight()
> method in an OCL expression using a instance of ClassA as the context, for
> example "self.getWeight()", but I got an exception saying "Cannot find
> operation (getWeight()) for the type (LoaderModel)", however "self.weight"
> is no problem.
>
> Can anyone give me some instructions on evaluating methods defined on
> context object? thanks in advance.
>
> Regards,
> Hao
Re: Problem: Cannot find operation [message #38093 is a reply to message #38060] Mon, 24 September 2007 16:59 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
Thanks it helps. Actually here is another question about calling user
defined EOperations.
In my ecore file I also defined an EOperation named "validate" which takes a
list as argument:

<eOperations name="validate">
<eParameters name="commodities" upperBound="-1" eType="#//Commodity"/>
</eOperations>

I have problem calling this EOperation in OCL expression:

self.validate(Commodity.allInstances()->asSequence())

I found that "Commodity.allInstances()->asSequence()" returns an ArrayList
instance, so I also suppressed EMF types so that in java interface
corresponding method is defined as following:

public void remove(List<Commodity> commodities);

Yet I always get "(Cannot find operation (validate(Sequence(Commodity))) for
the type (ClassA))" exception. I don't know why OCL can't find the
operation.

BTW, is there any way to get all operations for a specified context object?


"Christian W. Damus" <cdamus@ca.ibm.com>
??????:fd8p0v$8j8$2@build.eclipse.org...
> Hi, Hao,
>
> The "getWeight()" operation is not modeled as an operation in Ecore; it is
> purely a figment of the Ecore-to-Java transformation performed by EMF.
>
> You can define an EOperation named "getWeight" in your Ecore model, and
> the
> OCL constraint will be able to call it. EMF is smart enough to realize
> that this EOperation corresponds, in the generated code, to the Java
> accessor method of your "weight" attribute. This shouldn't be necessary,
> though, since OCL can access the property simply by "self.weight" as you
> indicated.
>
> Cheers,
>
> Christian
>
>
> Hao Zhang wrote:
>
>> Hi,
>> In my ecore file I defined an EClass named ClassA, which has some
>> EAttributes such as ClassA#weight. I need to call generated getWeight()
>> method in an OCL expression using a instance of ClassA as the context,
>> for
>> example "self.getWeight()", but I got an exception saying "Cannot find
>> operation (getWeight()) for the type (LoaderModel)", however
>> "self.weight"
>> is no problem.
>>
>> Can anyone give me some instructions on evaluating methods defined on
>> context object? thanks in advance.
>>
>> Regards,
>> Hao
>
Re: Problem: Cannot find operation [message #38126 is a reply to message #38093] Mon, 24 September 2007 17:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Hao,

You don't need to worry about the declaration of multiplicity-many
EParameters with the EList<Commodity> type (you don't need to suppress the
EList API).

The original problem that you had is that, because the parameter has

isUnique = true
isOrdered = true

by default (these attributes do not appear in your Ecore snippet), the OCL
type of the parameter is OrderedSet(Commodity), not Sequence(Commodity).

So, do this instead:

self.validate(Commodity.allInstances()->asOrderedSet())

HTH,

Christian


Hao Zhang wrote:

> Thanks it helps. Actually here is another question about calling user
> defined EOperations.
> In my ecore file I also defined an EOperation named "validate" which takes
> a list as argument:
>
> <eOperations name="validate">
> <eParameters name="commodities" upperBound="-1"
> eType="#//Commodity"/>
> </eOperations>
>
> I have problem calling this EOperation in OCL expression:
>
> self.validate(Commodity.allInstances()->asSequence())
>
> I found that "Commodity.allInstances()->asSequence()" returns an ArrayList
> instance, so I also suppressed EMF types so that in java interface
> corresponding method is defined as following:
>
> public void remove(List<Commodity> commodities);
>
> Yet I always get "(Cannot find operation (validate(Sequence(Commodity)))
> for the type (ClassA))" exception. I don't know why OCL can't find the
> operation.
>
> BTW, is there any way to get all operations for a specified context
> object?

------8<------
Re: Problem: Cannot find operation [message #38191 is a reply to message #38126] Tue, 25 September 2007 02:39 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
It works, thanks a lot!

"Christian W. Damus" <cdamus@ca.ibm.com>
??????:fd8t8v$jsb$1@build.eclipse.org...
> Hi, Hao,
>
> You don't need to worry about the declaration of multiplicity-many
> EParameters with the EList<Commodity> type (you don't need to suppress the
> EList API).
>
> The original problem that you had is that, because the parameter has
>
> isUnique = true
> isOrdered = true
>
> by default (these attributes do not appear in your Ecore snippet), the OCL
> type of the parameter is OrderedSet(Commodity), not Sequence(Commodity).
>
> So, do this instead:
>
> self.validate(Commodity.allInstances()->asOrderedSet())
>
> HTH,
>
> Christian
>
>
> Hao Zhang wrote:
>
>> Thanks it helps. Actually here is another question about calling user
>> defined EOperations.
>> In my ecore file I also defined an EOperation named "validate" which
>> takes
>> a list as argument:
>>
>> <eOperations name="validate">
>> <eParameters name="commodities" upperBound="-1"
>> eType="#//Commodity"/>
>> </eOperations>
>>
>> I have problem calling this EOperation in OCL expression:
>>
>> self.validate(Commodity.allInstances()->asSequence())
>>
>> I found that "Commodity.allInstances()->asSequence()" returns an
>> ArrayList
>> instance, so I also suppressed EMF types so that in java interface
>> corresponding method is defined as following:
>>
>> public void remove(List<Commodity> commodities);
>>
>> Yet I always get "(Cannot find operation (validate(Sequence(Commodity)))
>> for the type (ClassA))" exception. I don't know why OCL can't find the
>> operation.
>>
>> BTW, is there any way to get all operations for a specified context
>> object?
>
> ------8<------
Re: Problem: Cannot find operation [message #38221 is a reply to message #38126] Tue, 25 September 2007 02:44 Go to previous messageGo to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
Just to satisfy my curiosity, how should I define my ecore file to accept
"asSequence()" parameters in ocl?
e.g., self.validate(Commodity.allInstances()->asSequence())

"Christian W. Damus" <cdamus@ca.ibm.com>
??????:fd8t8v$jsb$1@build.eclipse.org...
> Hi, Hao,
>
> You don't need to worry about the declaration of multiplicity-many
> EParameters with the EList<Commodity> type (you don't need to suppress the
> EList API).
>
> The original problem that you had is that, because the parameter has
>
> isUnique = true
> isOrdered = true
>
> by default (these attributes do not appear in your Ecore snippet), the OCL
> type of the parameter is OrderedSet(Commodity), not Sequence(Commodity).
>
> So, do this instead:
>
> self.validate(Commodity.allInstances()->asOrderedSet())
>
> HTH,
>
> Christian
>
>
> Hao Zhang wrote:
>
>> Thanks it helps. Actually here is another question about calling user
>> defined EOperations.
>> In my ecore file I also defined an EOperation named "validate" which
>> takes
>> a list as argument:
>>
>> <eOperations name="validate">
>> <eParameters name="commodities" upperBound="-1"
>> eType="#//Commodity"/>
>> </eOperations>
>>
>> I have problem calling this EOperation in OCL expression:
>>
>> self.validate(Commodity.allInstances()->asSequence())
>>
>> I found that "Commodity.allInstances()->asSequence()" returns an
>> ArrayList
>> instance, so I also suppressed EMF types so that in java interface
>> corresponding method is defined as following:
>>
>> public void remove(List<Commodity> commodities);
>>
>> Yet I always get "(Cannot find operation (validate(Sequence(Commodity)))
>> for the type (ClassA))" exception. I don't know why OCL can't find the
>> operation.
>>
>> BTW, is there any way to get all operations for a specified context
>> object?
>
> ------8<------
Re: Problem: Cannot find operation [message #38417 is a reply to message #38221] Tue, 25 September 2007 13:37 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, hao,

EMF's generated Java code uses EList for all collection types. In the Ecore
model, you want to specify an ETypedElement (such as an EParameter) with
multiplicity many (upper bound -1 (unlimited) or greater than 1) and the
isUnique and isOrdered properties set as follows:

Collection Type isUnique isOrdered
=============== ======== =========
Bag N N
Sequence N Y
Set Y N
OrderedSet Y Y

Cheers,

Christian

Hao Zhang wrote:

> Just to satisfy my curiosity, how should I define my ecore file to accept
> "asSequence()" parameters in ocl?
> e.g., self.validate(Commodity.allInstances()->asSequence())
>

------8<------
Previous Topic:org.eclipse.ocl.uml.impl.BagTypeImpl not contained in the resource
Next Topic:About OCLFactory Interface
Goto Forum:
  


Current Time: Sat Apr 27 05:22:54 GMT 2024

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

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

Back to the top