Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Re: model query
Re: model query [message #663819] Wed, 06 April 2011 14:49 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
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 #663828 is a reply to message #663819] Wed, 06 April 2011 15:19 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
Chuck,

(Ed, thanks for forwarding)

not sure if you attached a stack trace for the class case exception to the original post, but it's not in here. Could you please post it here so we can see where things fail exactly? Also, can you give us a few clues as to the type of the feature that "self.elements" navigates?

Thanks,
-- Axel
Re: model query [message #663833 is a reply to message #663819] Wed, 06 April 2011 15:21 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
BTW, one more hint: I suppose that self.elements does not evaluate to a Boolean, does it? According to my understanding of BooleanOCLCondition it should evaluate to a Boolean value.
Re: model query [message #663844 is a reply to message #663819] Wed, 06 April 2011 15:47 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
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
Previous Topic:Evaluate Ecore Instances programatically
Next Topic:Permanent violation of invariants after closing and opening the validated file
Goto Forum:
  


Current Time: Thu Apr 25 16:30:59 GMT 2024

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

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

Back to the top