Skip to main content



      Home
Home » Modeling » EMF » model query(problems)
model query [message #663703] Wed, 06 April 2011 05:19 Go to next message
Eclipse UserFriend
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 10:49 Go to previous messageGo to next message
Eclipse UserFriend
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 11:47 Go to previous messageGo to next message
Eclipse UserFriend
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 10:08 Go to previous messageGo to next message
Eclipse UserFriend
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 02:14 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 13:46:23 EDT 2025

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

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

Back to the top