Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL console: querying when having multiples resources
OCL console: querying when having multiples resources [message #842190] Thu, 12 April 2012 00:16 Go to next message
Rômulo  rpini is currently offline 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 01:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
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 #842600 is a reply to message #842256] Thu, 12 April 2012 08:55 Go to previous messageGo to next message
Rômulo  rpini is currently offline Rômulo rpini
Messages: 36
Registered: July 2009
Member
Hi Ed,

Thanks for replying.

Is there any other way to query something like this, like using the ocl java api? If so, could you please show me an example?

Best regards,
Re: OCL console: querying when having multiples resources [message #842643 is a reply to message #842600] Thu, 12 April 2012 09:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

The OCL Console is mainly for interactive practice of OCL to be used in
a real modeling application; OCLinEcore/Complete OCL/Acceleo/QVTo/...

If you want to use the Java API see the "Evaluating Constraints and
Queries" section in the documentation, which has direct examples for the
Ecore binding. The new pivot-binding has a very similar API with
different package names. There are numerous examples of queries
throughout the org.eclipse.ocl.examples.xtext.tests plugin.

Regards

Ed Willink


On 12/04/2012 13:55, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks for replying.
> Is there any other way to query something like this, like using the
> ocl java api? If so, could you please show me an example?
>
> Best regards,
Re: OCL console: querying when having multiples resources [message #842647 is a reply to message #842600] Thu, 12 April 2012 09:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

The OCL Console is mainly for interactive practice of OCL to be used in
a real modeling application; OCLinEcore/Complete OCL/Acceleo/QVTo/...

If you want to use the Java API see the "Evaluating Constraints and
Queries" section in the documentation, which has direct examples for the
Ecore binding. The new pivot-binding has a very similar API with
different package names. There are numerous examples of queries
throughout the org.eclipse.ocl.examples.xtext.tests plugin.

Regards

Ed Willink


On 12/04/2012 13:55, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks for replying.
> Is there any other way to query something like this, like using the
> ocl java api? If so, could you please show me an example?
>
> Best regards,
Re: OCL console: querying when having multiples resources [message #842824 is a reply to message #842643] Thu, 12 April 2012 12:35 Go to previous messageGo to next message
Rômulo  rpini is currently offline Rômulo rpini
Messages: 36
Registered: July 2009
Member
Hi Ed,

I am a little overwhelmed with all these possibilities.

Basically, I want to make a query which has to have allInstances() from eclasses pertaining to different xmis (instances of ecores) and present the results of them. What would be the recommended way to do that right now?

The examples I saw only involved querying a single ecore. And I cant find the plugin you mentioned in my eclipse plugins folder, am I doing something wrong?

Thank you again and sorry for the beginner questions.

Best regards,
Re: OCL console: querying when having multiples resources [message #842839 is a reply to message #842824] Thu, 12 April 2012 12:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

Tests plugins do noit form part of the default distribution. You need to
get it from the GIT repo.

How best to perform the query depends on where you want to invoke it
from and how often you want to invoke it.

Regards

Ed Willink

On 12/04/2012 17:35, Rômulo rpini wrote:
> Hi Ed,
>
> I am a little overwhelmed with all these possibilities.
>
> Basically, I want to make a query which has to have allInstances()
> from eclasses pertaining to different xmis (instances of ecores) and
> present the results of them. What would be the recommended way to do
> that right now?
> The examples I saw only involved querying a single ecore. And I cant
> find the plugin you mentioned in my eclipse plugins folder, am I doing
> something wrong?
>
> Thank you again and sorry for the beginner questions.
>
> Best regards,
Re: OCL console: querying when having multiples resources [message #842861 is a reply to message #842839] Thu, 12 April 2012 13:28 Go to previous messageGo to next message
Rômulo  rpini is currently offline Rômulo rpini
Messages: 36
Registered: July 2009
Member
Hi Ed,

Thanks again. I want to invoke it just to see the query. So it wont be often. And I want to evoke it in a way that I can use the query and the results in my java application code.

Thanks
Re: OCL console: querying when having multiples resources [message #842881 is a reply to message #842861] Thu, 12 April 2012 13:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

Well, you could invoke the query interactively and cut and paste the
results into Java code, which will require a bit of formatting.

Or if you don't mind the extra dependencies, you could invoke the query
using the Java API and be fully automated.

Or since the query is so simple you could easily hand code it in Java in
the first place.

Regards

Ed Willink

On 12/04/2012 18:28, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks again. I want to invoke it just to see the query. So it wont be
> often. And I want to evoke it in a way that I can use the query and
> the results in my java application code.
>
> Thanks
Re: OCL console: querying when having multiples resources [message #851576 is a reply to message #842190] Sat, 21 April 2012 00:35 Go to previous messageGo to next message
Rômulo  rpini is currently offline 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 59 times)
Re: OCL console: querying when having multiples resources [message #851612 is a reply to message #851576] Sat, 21 April 2012 01:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
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,
Re: OCL console: querying when having multiples resources [message #852034 is a reply to message #851612] Sat, 21 April 2012 11:52 Go to previous messageGo to next message
Rômulo  rpini is currently offline Rômulo rpini
Messages: 36
Registered: July 2009
Member
Hi Ed,

Thanks. I know that allInstances in a modelling point of view should be avoided and so on, and in this example it does not make any sense to use it, but I will have to use it.

What you did sure is what I'd like to be able to do. You put both resources in a single resourceset, is that it? If so, how did you do that? Maybe via the text editor? : )

Thanks

[Updated on: Sat, 21 April 2012 11:55]

Report message to a moderator

Re: OCL console: querying when having multiples resources [message #852581 is a reply to message #852034] Sun, 22 April 2012 01:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I created the combined multi-rooted XMI file using a text editor.

The Sample (Reflective) Ecore Editors discourage multi-rooted resources
by omitting the ability to create additional roots; however once created
they support viewing and manipulating them.

Programmatically, you can add as many roots to the root container
returned by Resource.getContents() as you like.

Regards

Ed Willink


On 21/04/2012 16:52, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks. I know that allInstances should be avoided and so on, and in
> this example it does not make any sense to use it, but I will have to
> use it.
>
> What you did sure is what I'd like to be able to do. You put both
> resources in a single resourceset, is that it? If so, how did you do
> that?
> Thanks
Re: OCL console: querying when having multiples resources [message #852589 is a reply to message #852034] Sun, 22 April 2012 01:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I created the combined multi-rooted XMI file using a text editor.

The Sample (Reflective) Ecore Editors discourage multi-rooted resources
by omitting the ability to create additional roots; however once created
they support viewing and manipulating them.

Programmatically, you can add as many roots to the root container
returned by Resource.getContents() as you like.

Regards

Ed Willink


On 21/04/2012 16:52, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks. I know that allInstances should be avoided and so on, and in
> this example it does not make any sense to use it, but I will have to
> use it.
>
> What you did sure is what I'd like to be able to do. You put both
> resources in a single resourceset, is that it? If so, how did you do
> that?
> Thanks
Re: OCL console: querying when having multiples resources [message #852597 is a reply to message #852034] Sun, 22 April 2012 01:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I created the combined multi-rooted XMI file using a text editor.

The Sample (Reflective) Ecore Editors discourage multi-rooted resources
by omitting the ability to create additional roots; however once created
they support viewing and manipulating them.

Programmatically, you can add as many roots to the root container
returned by Resource.getContents() as you like.

Regards

Ed Willink


On 21/04/2012 16:52, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks. I know that allInstances should be avoided and so on, and in
> this example it does not make any sense to use it, but I will have to
> use it.
>
> What you did sure is what I'd like to be able to do. You put both
> resources in a single resourceset, is that it? If so, how did you do
> that?
> Thanks
Re: OCL console: querying when having multiples resources [message #852605 is a reply to message #852034] Sun, 22 April 2012 01:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I created the combined multi-rooted XMI file using a text editor.

The Sample (Reflective) Ecore Editors discourage multi-rooted resources
by omitting the ability to create additional roots; however once created
they support viewing and manipulating them.

Programmatically, you can add as many roots to the root container
returned by Resource.getContents() as you like.

Regards

Ed Willink


On 21/04/2012 16:52, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks. I know that allInstances should be avoided and so on, and in
> this example it does not make any sense to use it, but I will have to
> use it.
>
> What you did sure is what I'd like to be able to do. You put both
> resources in a single resourceset, is that it? If so, how did you do
> that?
> Thanks
Re: OCL console: querying when having multiples resources [message #852613 is a reply to message #852034] Sun, 22 April 2012 01:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I created the combined multi-rooted XMI file using a text editor.

The Sample (Reflective) Ecore Editors discourage multi-rooted resources
by omitting the ability to create additional roots; however once created
they support viewing and manipulating them.

Programmatically, you can add as many roots to the root container
returned by Resource.getContents() as you like.

Regards

Ed Willink


On 21/04/2012 16:52, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks. I know that allInstances should be avoided and so on, and in
> this example it does not make any sense to use it, but I will have to
> use it.
>
> What you did sure is what I'd like to be able to do. You put both
> resources in a single resourceset, is that it? If so, how did you do
> that?
> Thanks
Re: OCL console: querying when having multiples resources [message #852621 is a reply to message #852034] Sun, 22 April 2012 01:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I created the combined multi-rooted XMI file using a text editor.

The Sample (Reflective) Ecore Editors discourage multi-rooted resources
by omitting the ability to create additional roots; however once created
they support viewing and manipulating them.

Programmatically, you can add as many roots to the root container
returned by Resource.getContents() as you like.

Regards

Ed Willink


On 21/04/2012 16:52, Rômulo rpini wrote:
> Hi Ed,
>
> Thanks. I know that allInstances should be avoided and so on, and in
> this example it does not make any sense to use it, but I will have to
> use it.
>
> What you did sure is what I'd like to be able to do. You put both
> resources in a single resourceset, is that it? If so, how did you do
> that?
> Thanks
Re: OCL console: querying when having multiples resources [message #853394 is a reply to message #852581] Sun, 22 April 2012 21:43 Go to previous message
Rômulo  rpini is currently offline Rômulo rpini
Messages: 36
Registered: July 2009
Member
Thanks Ed!

That was the kind of information I was looking for.

Best regards,
Previous Topic:how to use the context expressions in OCL
Next Topic:about the using of OCLinEcore
Goto Forum:
  


Current Time: Sat Jul 26 09:12:23 EDT 2014

Powered by FUDForum. Page generated in 0.03996 seconds