Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » model query(problems)
model query [message #663703] Wed, 06 April 2011 09:19 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
hello guys!
i'm using model query to do some queries and update on my model...

the steps that i done, are:

-generate from genmodel of my metamodel every model classes ...
-register metamodel and after call a method that has to read a model...
-in this method :

ResourceSet resourceSet = new ResourceSetImpl();
URI modelUri = URI.createFileURI(new File("model/mymodel.ecore").getAbsolutePath());

EcoreResourceFactoryImpl ecoreFactory = new EcoreResourceFactoryImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "ecore", ecoreFactory);


// Demand load resource for this file.
Resource resource = resourceSet.getResource(modelUri, true);
System.out.println("Loaded " + modelUri);

OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance();
EObjectCondition condition = new BooleanOCLCondition<EClassifier, EClass, EObject>( ocl.getEnvironment(), "self.elements", MyMMPackage.Literals.MOD);
SELECT statement = new SELECT(SELECT.UNBOUNDED, false, new FROM(resource.getContents()), new WHERE(condition));
IQueryResult results = statement.execute(); // do something with the results


System.out.println("SIZE: " + results.size());

============================================================ ======
but i receive error like that: java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EFactoryImpl cannot be cast to MyMM.MyMMFactory

the problem is solved if I change query from "self.elements" to for example self.oclIsTypeOf("MyMM::metaclass")

what it's wrong?!?!?

thx
Re: model query [message #663812 is a reply to message #663703] Wed, 06 April 2011 14:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
Chuck,

This sounds more likely to be an OCL question so I've added the OCL
newsgroup/forum to the to list of my reply.


chuck wrote:
> hello guys!
> i'm using model query to do some queries and update on my model...
>
> the steps that i done, are:
>
> -generate from genmodel of my metamodel every model classes ...
> -register metamodel and after call a method that has to read a model...
> -in this method :
>
> ResourceSet resourceSet = new ResourceSetImpl();
> URI modelUri = URI.createFileURI(new
> File("model/mymodel.ecore").getAbsolutePath());
>
> EcoreResourceFactoryImpl ecoreFactory = new
> EcoreResourceFactoryImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto
> ryMap().put( "ecore", ecoreFactory);
>
>
> // Demand load resource for this file.
> Resource resource = resourceSet.getResource(modelUri, true);
> System.out.println("Loaded " + modelUri);
>
> OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance();
> EObjectCondition condition = new
> BooleanOCLCondition<EClassifier, EClass, EObject>(
> ocl.getEnvironment(), "self.elements", MyMMPackage.Literals.MOD);
> SELECT statement = new SELECT(SELECT.UNBOUNDED, false, new
> FROM(resource.getContents()), new WHERE(condition));
> IQueryResult results = statement.execute(); // do something with the
> results
>
>
> System.out.println("SIZE: " + results.size());
>
> ============================================================ ======
> but i receive error like that: java.lang.ClassCastException:
> org.eclipse.emf.ecore.impl.EFactoryImpl cannot be cast to
> MyMM.MyMMFactory
> the problem is solved if I change query from "self.elements" to for
> example self.oclIsTypeOf("MyMM::metaclass")
>
> what it's wrong?!?!?
>
> thx
Re: model query [message #663849 is a reply to message #663812] Wed, 06 April 2011 15:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6481
Registered: July 2009
Senior Member
Hi

This isn't actually an OCL problem, but an EMF Query issue.

As Axel observes, you may not be using Boolean. The CCE certainly looks
like a data type construction issue, but since you only provide 25% of
the problem report we can only provide 25% of the answer.

Regards

Ed Willink

On 06/04/2011 15:49, Ed Merks wrote:
> Chuck,
>
> This sounds more likely to be an OCL question so I've added the OCL
> newsgroup/forum to the to list of my reply.
>
>
> chuck wrote:
>> hello guys!
>> i'm using model query to do some queries and update on my model...
>>
>> the steps that i done, are:
>>
>> -generate from genmodel of my metamodel every model classes ...
>> -register metamodel and after call a method that has to read a model...
>> -in this method :
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>> URI modelUri = URI.createFileURI(new
>> File("model/mymodel.ecore").getAbsolutePath());
>> EcoreResourceFactoryImpl ecoreFactory = new
>> EcoreResourceFactoryImpl();
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto
>> ryMap().put( "ecore", ecoreFactory);
>> // Demand load resource for this file.
>> Resource resource = resourceSet.getResource(modelUri, true);
>> System.out.println("Loaded " + modelUri);
>> OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance();
>> EObjectCondition condition = new
>> BooleanOCLCondition<EClassifier, EClass, EObject>(
>> ocl.getEnvironment(), "self.elements", MyMMPackage.Literals.MOD);
>> SELECT statement = new SELECT(SELECT.UNBOUNDED, false, new
>> FROM(resource.getContents()), new WHERE(condition));
>> IQueryResult results = statement.execute(); // do something with the
>> results
>>
>> System.out.println("SIZE: " + results.size());
>>
>> ============================================================ ======
>> but i receive error like that: java.lang.ClassCastException:
>> org.eclipse.emf.ecore.impl.EFactoryImpl cannot be cast to
>> MyMM.MyMMFactory
>> the problem is solved if I change query from "self.elements" to for
>> example self.oclIsTypeOf("MyMM::metaclass")
>>
>> what it's wrong?!?!?
>>
>> thx
Re: model query [message #664355 is a reply to message #663849] Fri, 08 April 2011 14:08 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
sorry but i don' t understand what you say...
i need a simple code to query an ecore model and update some element properties...

but there is very little documentation on emf query...i can't found example from an execution on my topic Sad
Re: model query [message #664466 is a reply to message #664355] Sat, 09 April 2011 06:14 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6446
Registered: July 2009
Senior Member
Am 08.04.2011 16:08, schrieb chuck:
> sorry but i don' t understand what you say...
I guess Ed is wondering why you talk about an exception and don't give us the corresponding stack trace.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Previous Topic:"Class variable"-like behaviour in Ecore model
Next Topic:XMI and "vendor independent" paradigm
Goto Forum:
  


Current Time: Sun Oct 20 00:43:18 GMT 2019

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

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

Back to the top