Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Problem defining global variables
Problem defining global variables [message #64774] Mon, 01 December 2008 06:04 Go to next message
Eclipse User
Originally posted by: zzhangh.cn.ibm.com

Hi,
I defined a global variable "myVar" which represents a typed collection (java.util.List<MyType>), the expression
"myVar->size()" can be properly evaluated. However, the expression "myVar.myAttr->sum()" can not be evaluated, the
exception message is "Unrecognized variable: (myAttr)". What could the issue come from?

BTW, myAttr is an EDouble attribute defined under MyType.

Best Regards,
Hao
Re: Problem defining global variables [message #64797 is a reply to message #64774] Mon, 01 December 2008 16:11 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Hi, Hao,

What is the declared type of the "myVar" variable? If it is
EEList<MyType>, then the OCL parser will not understand it, because OCL
is not aware of generic types. It will only understand that this is an
opaque list, in OCL terms Sequence(OclAny).

Instead, you should set the type of the "myVar" Variable instance to
MyType and set its multiplicity to [0..*] (lower bound 0, upper bound -1).

HTH,

Christian

Hao Zhang wrote:
> Hi,
> I defined a global variable "myVar" which represents a typed collection (java.util.List<MyType>), the expression
> "myVar->size()" can be properly evaluated. However, the expression "myVar.myAttr->sum()" can not be evaluated, the
> exception message is "Unrecognized variable: (myAttr)". What could the issue come from?
>
> BTW, myAttr is an EDouble attribute defined under MyType.
>
> Best Regards,
> Hao
Re: Problem defining global variables [message #64819 is a reply to message #64797] Tue, 02 December 2008 01:59 Go to previous messageGo to next message
Eclipse User
Originally posted by: zzhangh.cn.ibm.com

Hi Christian,
myVar's type is declared as following:

EClassifier type = TypeUtil.resolveSequenceType(ocl.getEnvironment(), EcorePackage.Literals.ORDERED_SET_TYPE);
appContextVar.setType(type);

and I use following sentence to fill it:

List<Customer> customers = new ArrayList<Customer>();
customers.addAll(someCustomers);
query.getEvaluationEnvironment().add(appContextVar.getName() , customers);

So as far as I understood your reply, the type List<Customer> is treated as List<Object> by OCL, so "customers.age" can
not be parsed in an OCL expression, is it right? If yes, is there any work around to implement this (to let user use
"customers.age->sum()" in OCL expressions)?

BTW, I've tried to define the type to Customer, (EClassifier type = TypeUtil.resolveType(ocl.getEnvironment(),
CustomerPackage.Literals.CUSTOMER);), but evaluation of "customers->size()" always return 1.

Regards,
Hao

Christian W. Damus wrote:
> Hi, Hao,
>
> What is the declared type of the "myVar" variable? If it is
> EEList<MyType>, then the OCL parser will not understand it, because OCL
> is not aware of generic types. It will only understand that this is an
> opaque list, in OCL terms Sequence(OclAny).
>
> Instead, you should set the type of the "myVar" Variable instance to
> MyType and set its multiplicity to [0..*] (lower bound 0, upper bound -1).
>
> HTH,
>
> Christian
>
> Hao Zhang wrote:
>> Hi,
>> I defined a global variable "myVar" which represents a typed collection (java.util.List<MyType>), the expression
>> "myVar->size()" can be properly evaluated. However, the expression "myVar.myAttr->sum()" can not be evaluated, the
>> exception message is "Unrecognized variable: (myAttr)". What could the issue come from?
>>
>> BTW, myAttr is an EDouble attribute defined under MyType.
>>
>> Best Regards,
>> Hao
Re: Problem defining global variables [message #64842 is a reply to message #64819] Tue, 02 December 2008 14:34 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Hi, Hao,

See some replies in-line, below.

Cheers,

Christian

Hao Zhang wrote:
> Hi Christian,
> myVar's type is declared as following:
>
> EClassifier type = TypeUtil.resolveSequenceType(ocl.getEnvironment(), EcorePackage.Literals.ORDERED_SET_TYPE);
> appContextVar.setType(type);

This creates a type that is Sequence(OrderedSetType). I doubt that it
is what you want, because this is a type describing sequences (lists) of
instances of the OrderedSetType *metaclass* from OCL. That is to say, a
sequence of types of ordered sets.

Try this, instead:

EClassifier type = TypeUtil.resolveSequenceType(
ocl.getEnvironment(),
CustomerPackage.Literals.CUSTOMER);

This will give you the type describing sequences of customers.

> and I use following sentence to fill it:
>
> List<Customer> customers = new ArrayList<Customer>();
> customers.addAll(someCustomers);
> query.getEvaluationEnvironment().add(appContextVar.getName() , customers);
>
> So as far as I understood your reply, the type List<Customer> is treated as List<Object> by OCL, so "customers.age" can
> not be parsed in an OCL expression, is it right? If yes, is there any work around to implement this (to let user use
> "customers.age->sum()" in OCL expressions)?

No, the Ecore type EEList<Customer> is interpreted by OCL as
Sequence(OclAny) because OCL does not understand UML templates, and
Ecore generic types have no correspondence in EMOF. I was merely
guessing at the cause of your problem, without much information to go on
at the time.

OCL will understand the Sequence(Customer) type as I described above.


> BTW, I've tried to define the type to Customer, (EClassifier type = TypeUtil.resolveType(ocl.getEnvironment(),
> CustomerPackage.Literals.CUSTOMER);), but evaluation of "customers->size()" always return 1.

TypeUtil.resolveType(...) applied to an EClass in your model will always
result in the same EClass, because it has nothing to do with OCL. As
Customer is not a collection type, OCL thinks your value is a scalar and
will coerce a collection value accordingly.

TypeUtil.resolveSequenceType(...) will generate a collection type.

>
> Regards,
> Hao
>
> Christian W. Damus wrote:
>> Hi, Hao,
>>
>> What is the declared type of the "myVar" variable? If it is
>> EEList<MyType>, then the OCL parser will not understand it, because OCL
>> is not aware of generic types. It will only understand that this is an
>> opaque list, in OCL terms Sequence(OclAny).
>>
>> Instead, you should set the type of the "myVar" Variable instance to
>> MyType and set its multiplicity to [0..*] (lower bound 0, upper bound -1).
>>
>> HTH,
>>
>> Christian
>>
>> Hao Zhang wrote:
>>> Hi,
>>> I defined a global variable "myVar" which represents a typed collection (java.util.List<MyType>), the expression
>>> "myVar->size()" can be properly evaluated. However, the expression "myVar.myAttr->sum()" can not be evaluated, the
>>> exception message is "Unrecognized variable: (myAttr)". What could the issue come from?
>>>
>>> BTW, myAttr is an EDouble attribute defined under MyType.
>>>
>>> Best Regards,
>>> Hao
Re: Problem defining global variables [message #64958 is a reply to message #64842] Thu, 04 December 2008 03:05 Go to previous message
Eclipse User
Originally posted by: zzhangh.cn.ibm.com

Hi Christian,
You are right, I should use " resolveSequenceType(ocl.getEnvironment(),CustomerPackage.Lit erals.Customer) ", thanks a lot!

Regards,
Hao

Christian W. Damus wrote:
> Hi, Hao,
>
> See some replies in-line, below.
>
> Cheers,
>
> Christian
>
> Hao Zhang wrote:
>> Hi Christian,
>> myVar's type is declared as following:
>>
>> EClassifier type = TypeUtil.resolveSequenceType(ocl.getEnvironment(), EcorePackage.Literals.ORDERED_SET_TYPE);
>> appContextVar.setType(type);
>
> This creates a type that is Sequence(OrderedSetType). I doubt that it
> is what you want, because this is a type describing sequences (lists) of
> instances of the OrderedSetType *metaclass* from OCL. That is to say, a
> sequence of types of ordered sets.
>
> Try this, instead:
>
> EClassifier type = TypeUtil.resolveSequenceType(
> ocl.getEnvironment(),
> CustomerPackage.Literals.CUSTOMER);
>
> This will give you the type describing sequences of customers.
>
>> and I use following sentence to fill it:
>>
>> List<Customer> customers = new ArrayList<Customer>();
>> customers.addAll(someCustomers);
>> query.getEvaluationEnvironment().add(appContextVar.getName() , customers);
>>
>> So as far as I understood your reply, the type List<Customer> is treated as List<Object> by OCL, so "customers.age" can
>> not be parsed in an OCL expression, is it right? If yes, is there any work around to implement this (to let user use
>> "customers.age->sum()" in OCL expressions)?
>
> No, the Ecore type EEList<Customer> is interpreted by OCL as
> Sequence(OclAny) because OCL does not understand UML templates, and
> Ecore generic types have no correspondence in EMOF. I was merely
> guessing at the cause of your problem, without much information to go on
> at the time.
>
> OCL will understand the Sequence(Customer) type as I described above.
>
>
>> BTW, I've tried to define the type to Customer, (EClassifier type = TypeUtil.resolveType(ocl.getEnvironment(),
>> CustomerPackage.Literals.CUSTOMER);), but evaluation of "customers->size()" always return 1.
>
> TypeUtil.resolveType(...) applied to an EClass in your model will always
> result in the same EClass, because it has nothing to do with OCL. As
> Customer is not a collection type, OCL thinks your value is a scalar and
> will coerce a collection value accordingly.
>
> TypeUtil.resolveSequenceType(...) will generate a collection type.
>
>> Regards,
>> Hao
>>
>> Christian W. Damus wrote:
>>> Hi, Hao,
>>>
>>> What is the declared type of the "myVar" variable? If it is
>>> EEList<MyType>, then the OCL parser will not understand it, because OCL
>>> is not aware of generic types. It will only understand that this is an
>>> opaque list, in OCL terms Sequence(OclAny).
>>>
>>> Instead, you should set the type of the "myVar" Variable instance to
>>> MyType and set its multiplicity to [0..*] (lower bound 0, upper bound -1).
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>> Hao Zhang wrote:
>>>> Hi,
>>>> I defined a global variable "myVar" which represents a typed collection (java.util.List<MyType>), the expression
>>>> "myVar->size()" can be properly evaluated. However, the expression "myVar.myAttr->sum()" can not be evaluated, the
>>>> exception message is "Unrecognized variable: (myAttr)". What could the issue come from?
>>>>
>>>> BTW, myAttr is an EDouble attribute defined under MyType.
>>>>
>>>> Best Regards,
>>>> Hao
Previous Topic:[Announce] MDT OCL 1.3.0 I200812021600 is available
Next Topic:RE: org.eclipse.emf.validation.examples.ocl example
Goto Forum:
  


Current Time: Wed Sep 17 23:43:28 GMT 2014

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

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