Home » Modeling » OCL » OCL console: querying when having multiples resources
OCL console: querying when having multiples resources [message #842190] |
Thu, 12 April 2012 04:16 |
Rômulo rpini Messages: 36 Registered: July 2009 |
Member |
|
|
Hi,
I have an ecore metamodel that has an eReference to an EClass of another ecore metamodel.
I created the dynamic instances for both of them, and I was wondering if there is any way to access the model referenced when querying through the ocl console, because the context is set to the element that is selected, so when I try Eclass1.allInstances() in the OCl Console (with this Eclass1 pertaining to the other xmi) , it gives me "Unrecognized Variable (Eclass1)".
Is there any way to access the other xmis loaded in the environment, by means of specifying the full path of the other xmi? I tried doing package::Eclass1.allInstances() but it returns an empty result, because I think it is looking into the ecore metamodel, not the instance xmi.
Any help is appreciated, thanks.
|
|
|
Re: OCL console: querying when having multiples resources [message #842256 is a reply to message #842190] |
Thu, 12 April 2012 05:58 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
In principle the current selection just defines the type of self, so by
selecting an appropriate referenced child you can workaround the
limitations on qualified name access
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=376555 raised).
If you use the OCL XText Console you get the new evaluator for which
oclType() is fully reflective so you can navigate to an appropriate
class: self.aRef.oclType().allInstances().
Regards
Ed Willink
On 12/04/2012 05:16, Rômulo rpini wrote:
> Hi,
>
> I have an ecore metamodel that has an eReference to an EClass of
> another ecore metamodel.
> I created the dynamic instances for both of them, and I was wondering
> if there is any way to access the model referenced when querying
> through the ocl console, because the context is set to the element
> that is selected, so when I try Eclass1.allInstances() in the OCl
> Console (with this Eclass1 pertaining to the other xmi) , it gives me
> "Unrecognized Variable (Eclass1)".
>
> Is there any way to access the other xmis loaded in the environment,
> by means of specifying the full path of the other xmi? I tried doing
> package::Eclass1.allInstances() but it returns an empty result,
> because I think it is looking into the ecore metamodel, not the
> instance xmi.
>
> Any help is appreciated, thanks.
|
|
| | | | | | | |
Re: OCL console: querying when having multiples resources [message #851576 is a reply to message #842190] |
Sat, 21 April 2012 04:35 |
Rômulo rpini Messages: 36 Registered: July 2009 |
Member |
|
|
Hi Ed, sorry for answering so late.
Anyway, my queries arent that simple. I mean, Eclass.allInstances() will be the starting point for an OClExpression. To ilustrate what I am trying to do, I did a quick project that I attached on this post.
Basically, the project contains two ecore models: Human.ecore and Dog.Ecore. Human.ecore has a Eclass named Model1, which contains 0..* Human eclass. The Dog.Ecore is the same... it has a Model2, which contains 0..* Dogs. A Human class also has an eReference to Dog. So I created two instances of these ecores, Model1.xmi and Mode2.xmi, and populated them. Model1.xmi has humans who have dogs of Model2.xmi.
Now I get the problem: I generated the code for the metamodels, and then in the package proj, I created the class 'TestAllInstances' and basically tried to query in OCL those XMI models.
If I set the query to be "Human.allInstances()", everything goes fine (as expected, because I set the context to be Model1 from Model1.xmi. But, when I try "Dog.alLInstances()" it says that the Dog variable is not define.
That is the problem. I mean, the context for me is not essential, because I want to start query using Eclass.allInstances(), with the Eclass being any Eclass from any of the ecore metamodels. So basically what I want is: is there any way to load all the resources, so the OCL query can use the "allInstances()" in any of the Eclasses pertaining to the resources?
Hope you can understand the problem.
Best regards,
-
Attachment: TestPJ.zip
(Size: 51.66KB, Downloaded 196 times)
|
|
|
Re: OCL console: querying when having multiples resources [message #851612 is a reply to message #851576] |
Sat, 21 April 2012 05:29 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
Firstly, allInstances() should be avoided wherever possible since it is
inefficient and subject to an implementation-defined scope. Generally
there is a more appropriate way of solving problems that does not need
to start with 'search the universe for ...'.
Your problem is easily demonstrated with your examples in the
interactive OCL Console, which avoids Java-hacking for simple experiments.
Selecting a human from Model1.xmi gives the observed error from
Dog.allInstances().
This is exactly the same as Java you cannot access a Class of Package
dog from Package human without qualification.
In OCL you should do dog::Dog.allInstances() and you then get an empty
list since there is nothing in the ResourceSet.
If you load the attached hybrid multi-model you get cross-package
allInstances() interactively and in your Java code.
Regards
Ed Willink
On 21/04/2012 05:35, Rômulo rpini wrote:
> Hi Ed, sorry for answering so late.
>
> Anyway, my queries arent that simple. I mean, Eclass.allInstances() will be the starting point for an OClExpression. To ilustrate what I am trying to do, I did a quick project that I attached on this post.
>
> Basically, the project contains two ecore models: Human.ecore and Dog.Ecore. Human.ecore has a Eclass named Model1, which contains 0..* Human eclass. The Dog.Ecore is the same... it has a Model2, which contains 0..* Dogs. A Human class also has an eReference to Dog. So I created two instances of these ecores, Model1.xmi and Mode2.xmi, and populated them. Model1.xmi has humans who have dogs of Model2.xmi.
>
> Now I get the problem: I generated the code for the metamodels, and then in the package proj, I created the class 'TestAllInstances' and basically tried to query in OCL those XMI models.
>
> If I set the query to be "Human.allInstances()", everything goes fine (as expected, because I set the context to be Model1 from Model1.xmi. But, when I try "Dog.alLInstances()" it says that the Dog variable is not define.
>
> That is the problem. I mean, the context for me is not essential, because I want to start query using Eclass.allInstances(), with the Eclass being any Eclass from any of the ecore metamodels. So basically what I want is: is there any way to load all the resources, so the OCL query can use the "allInstances()" in any of the Eclasses pertaining to the resources?
>
> Hope you can understand the problem.
>
> Best regards,
|
|
| | | | | | | | |
Goto Forum:
Current Time: Wed Sep 25 02:36:08 GMT 2024
Powered by FUDForum. Page generated in 0.06170 seconds
|