model query [message #663703] |
Wed, 06 April 2011 09:19 |
chuck 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 |
Ed Merks Messages: 33137 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: model query [message #663849 is a reply to message #663812] |
Wed, 06 April 2011 15:47 |
Ed Willink Messages: 7655 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04598 seconds