For the pivot-based implementation oclType() is fully reflective, so if
you really want to do string-based type checking you can do:
self.name.oclType().name = 'Integer'
and type literals are functional so you can do
self.name.oclType() = Integer
as well as
self.name.oclIsKindOf(Integer)
[1] is an association qualifier not list index. See at().
Regards
Ed Willink
On 05/04/2012 18:54, sohrab Mising name wrote:
> Hi,
>
> I use interactive OCL console for validating dynamic instances of my
> ecore model. Can I write OCl expression that check type of some objects?
>
> for example like this :
> case 1) if 'name' is attribute of selected object
>
> self.name.type='integer'
> ------------------------------
> case 2) if 'values' is list of classes
>
> self.values[1].type=self.values[2].type
>
> thanks
'classes' is the List of EClass. This list contains some objects (same type, different name), and I want ocl checks when their types are different.
for example if type of all objects in the 'classes' is 'ejob', this expression returns false (but if it cheks type of objects, it should return true).
On 05/04/2012 19:39, sohrab Mising name wrote:
> Thanks Ed,
>
> But I didn't use java primitive data types at all. I use often user
> defined classes.
So replace Integer in my examples by YourClass.
> for example I write
>
> 'self.values.classes->at(1)=self.values.classes->at(2)'
>
> 'classes' is the List of EClass. This list contains some objects (same
> type, different name), and I want ocl checks when their types are
> different.
> for example if type of all objects in the 'classes' is 'ejob', this
> expression returns false (but if it cheks type of objects, it should
> return true).
So you need to use oclType()
But in my problem, I don't know class names. Indeed my constraint should be independent of class names (I can't determine class names implicitly). for example 'ejob' can be other classes like 'etask'.
Is 'oclType()' supported for any object in OCL? (i.e. can I write this: "self.oclType()='ejob'")
It not works for my models ("self.values.classes->at(1).oclType()")!
As I wrote earlier oclType() is supported in a fully reflective fashion
the new pivot-based Eclipse OCL.
oclType() is not supported on the Ecore-based Eclipse OCL; where you may
find that eClass() works.
Regards
Ed Willink
On 05/04/2012 20:16, sohrab Mising name wrote:
> Thanks Ed,
>
> But in my problem, I don't know class names. Indeed my constraint
> should be independent of class names (I can't determine class names
> implicitly). for example 'ejob' can be other classes like 'etask'.
>
> Is 'oclType()' supported for any object in OCL? (i.e. can I write
> this: "self.oclType()='ejob'")
> It not works for my models ("self.values.classes->at(1).oclType()")!