Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Query evaluate DynamicEObjectImpl problem.
Query evaluate DynamicEObjectImpl problem. [message #43381] Fri, 16 November 2007 09:44 Go to next message
Eclipse UserFriend
Originally posted by: yann.davin.gmail.com

Hi all,

I've some problems with query evaluation.
I have a ocl file with my constraints I parse it and for each invariant,
I do a query on my emf resource to get all eobjects concerned by the
context.But when I try to execute the query statement on the eobjects
returned by the query I have a exception with a
org.eclipse.emf.ecore.impl.DynamicEObjectImpl message.

For the moment to solve the problem I create a tmp resource where I put
a copy of the eojects returned by the query but it is not really clean.

I would like to know if there is a way to apply evaluate directly on the
eobjects return by the ocl query without copying eobjects in a tmp resource.

---sample of code that fails----
for (Constraint constraint : ocl.parse(oclInput)) {
if (isInvariant(constraint)) {

Query<EClassifier, EClass, EObject> eval = ocl
.createQuery(constraint);
Condition contextTypeCondition = new
BooleanOCLCondition<EClassifier, EClass, EObject>(
ocl.getEnvironment(), "self.oclIsTypeOf("
+ constraint.getSpecification()
.getContextVariable().getType()
.getName() + ")",
FractaladlPackage.Literals.SYSTEM);

SELECT contextTypeStatement = new SELECT(SELECT.UNBOUNDED,
false, new FROM(modifiedResource.getContents()),
new WHERE((EObjectCondition) contextTypeCondition),
new NullProgressMonitor());

IQueryResult iresults2 = contextTypeStatement.execute();

//problem evaluate on iresults2.getObjects raises
// exception DynamicEObjectImpl
//problem solved if iresults2.getObjects are copied and put in a
//temp resource.
Collection<?> result = (Collection<?>) eval
.evaluate(iresults2.getEObjects());

System.out.println(eval.queryText() + ":" + result);

}
}

Thanks

Yann
Re: Query evaluate DynamicEObjectImpl problem. [message #43412 is a reply to message #43381] Fri, 16 November 2007 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Yann,

I don't quite follow your scenario. The exception has a message stating
simply "org.eclipse.emf.ecore.impl.DynamicEObjectImpl?" That sounds like a
ClassCastException. It would help greatly if you can post the exception's
stack trace.

I can't think of any reason why copying the objects to a temporary resource
should fix anything. They would still be dynamic EObjects ... In any case,
you shouldn't need to do this. I'll need a stack trace to see what is
happening.

BTW, did you know that you can simply do EcoreUtil.getObjectsByType(...) to
select all of the objects conforming to an EClassifier from a collection?

Collection<?> iresults2 = EcoreUtil.getObjectsByType(
modifiedResource.getContents(),
FractaladlPackage.Literals.SYSTEM);

Cheers,

Christian


yann davin wrote:

> Hi all,
>
> I've some problems with query evaluation.
> I have a ocl file with my constraints I parse it and for each invariant,
> I do a query on my emf resource to get all eobjects concerned by the
> context.But when I try to execute the query statement on the eobjects
> returned by the query I have a exception with a
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl message.
>
> For the moment to solve the problem I create a tmp resource where I put
> a copy of the eojects returned by the query but it is not really clean.
>
> I would like to know if there is a way to apply evaluate directly on the
> eobjects return by the ocl query without copying eobjects in a tmp
> resource.
>
> ---sample of code that fails----
> for (Constraint constraint : ocl.parse(oclInput)) {
> if (isInvariant(constraint)) {
>
> Query<EClassifier, EClass, EObject> eval = ocl
> .createQuery(constraint);
> Condition contextTypeCondition = new
> BooleanOCLCondition<EClassifier, EClass, EObject>(
> ocl.getEnvironment(), "self.oclIsTypeOf("
> + constraint.getSpecification()
> .getContextVariable().getType()
> .getName() + ")",
> FractaladlPackage.Literals.SYSTEM);
>
> SELECT contextTypeStatement = new SELECT(SELECT.UNBOUNDED,
> false, new FROM(modifiedResource.getContents()),
> new WHERE((EObjectCondition) contextTypeCondition),
> new NullProgressMonitor());
>
> IQueryResult iresults2 = contextTypeStatement.execute();
>
> //problem evaluate on iresults2.getObjects raises
> // exception DynamicEObjectImpl
> //problem solved if iresults2.getObjects are copied and put in a
> //temp resource.
> Collection<?> result = (Collection<?>) eval
> .evaluate(iresults2.getEObjects());
>
> System.out.println(eval.queryText() + ":" + result);
>
> }
> }
>
> Thanks
>
> Yann
Re: Query evaluate DynamicEObjectImpl problem. [message #43472 is a reply to message #43412] Fri, 16 November 2007 14:24 Go to previous message
Eclipse UserFriend
Originally posted by: yann.davin.gmail.com

Hi,

Hi,

Yes it is a cast exception, you are right.
eval.evaluate(iresults2.getEObjects()); works
but the (Collection<?>) cast fails. Collection<?> result = (Collection<?>) eval.evaluate(iresults2.getEObjects());
So it's not a ocl issue, sorry...
Anyway thanks very much you for your help, I don't have to do a copy anymore, and I use EcoreUtil.getObjectsByType() as
you told me, it works pretty well :)

Christian W. Damus a écrit :
> Hi, Yann,
>
> I don't quite follow your scenario. The exception has a message stating
> simply "org.eclipse.emf.ecore.impl.DynamicEObjectImpl?" That sounds like a
> ClassCastException. It would help greatly if you can post the exception's
> stack trace.
>
> I can't think of any reason why copying the objects to a temporary resource
> should fix anything. They would still be dynamic EObjects ... In any case,
> you shouldn't need to do this. I'll need a stack trace to see what is
> happening.
>
> BTW, did you know that you can simply do EcoreUtil.getObjectsByType(...) to
> select all of the objects conforming to an EClassifier from a collection?
>
> Collection<?> iresults2 = EcoreUtil.getObjectsByType(
> modifiedResource.getContents(),
> FractaladlPackage.Literals.SYSTEM);
>
> Cheers,
>
> Christian
>
>
> yann davin wrote:
>
>> Hi all,
>>
>> I've some problems with query evaluation.
>> I have a ocl file with my constraints I parse it and for each invariant,
>> I do a query on my emf resource to get all eobjects concerned by the
>> context.But when I try to execute the query statement on the eobjects
>> returned by the query I have a exception with a
>> org.eclipse.emf.ecore.impl.DynamicEObjectImpl message.
>>
>> For the moment to solve the problem I create a tmp resource where I put
>> a copy of the eojects returned by the query but it is not really clean.
>>
>> I would like to know if there is a way to apply evaluate directly on the
>> eobjects return by the ocl query without copying eobjects in a tmp
>> resource.
>>
>> ---sample of code that fails----
>> for (Constraint constraint : ocl.parse(oclInput)) {
>> if (isInvariant(constraint)) {
>>
>> Query<EClassifier, EClass, EObject> eval = ocl
>> .createQuery(constraint);
>> Condition contextTypeCondition = new
>> BooleanOCLCondition<EClassifier, EClass, EObject>(
>> ocl.getEnvironment(), "self.oclIsTypeOf("
>> + constraint.getSpecification()
>> .getContextVariable().getType()
>> .getName() + ")",
>> FractaladlPackage.Literals.SYSTEM);
>>
>> SELECT contextTypeStatement = new SELECT(SELECT.UNBOUNDED,
>> false, new FROM(modifiedResource.getContents()),
>> new WHERE((EObjectCondition) contextTypeCondition),
>> new NullProgressMonitor());
>>
>> IQueryResult iresults2 = contextTypeStatement.execute();
>>
>> //problem evaluate on iresults2.getObjects raises
>> // exception DynamicEObjectImpl
>> //problem solved if iresults2.getObjects are copied and put in a
>> //temp resource.
>> Collection<?> result = (Collection<?>) eval
>> .evaluate(iresults2.getEObjects());
>>
>> System.out.println(eval.queryText() + ":" + result);
>>
>> }
>> }
>>
>> Thanks
>>
>> Yann
>
Previous Topic:Re: OCL constraint problems with data types
Next Topic:accessing dynamic eobject api + function libraries
Goto Forum:
  


Current Time: Wed Apr 24 13:32:49 GMT 2024

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

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

Back to the top