Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » changing context of existing query
changing context of existing query [message #482717] Thu, 27 August 2009 16:20 Go to next message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Hi everyone,

I have a very specific problem: I'd like to change the EClassifier context
of an existing OCL query.
In my project, there are several (meta)model repositories whose contents
are replicated through EMF copy at certain times.
E.g. eClass1 is located in repository A and copied to repository B.
Because this can happen multiple times, to avoid a severe performance hit
I'd like to prepare the OCL queries for the elements in repository A only
once and exchange their context with the copied elements in B each time a
copy is created, so they can be executed for B.

I realized that the bindings are kept in the OCL environment, so I tried
resetting them there (metaModelMap redirects to the eclass copies in B
according to their name)

for (Iterator iter = OCL_ENV.getEnvironment().getTypeResolver()
.getResource().getAllContents(); iter.hasNext();)
{
Object object = iter.next();

if (object instanceof Variable)
{
String eClassName = ((Variable)object).getEType().getName();
EClass newEClass = metaModelMap.get(eClassName);
((Variable)object).setEType(newEClass);
}
}

but this doesn't seem to do the trick. Maybe you've got some suggestions.

Thanks in advance,
Chris
Re: changing context of existing query [message #482761 is a reply to message #482717] Thu, 27 August 2009 20:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Chris

I doubt that you have fixed up even a quarter of the references.

Use EcoreUtil.CrossReferencer to find the references and then loop
over them to change them.

Regards

Ed Willink


Chris wrote:
> Hi everyone,
>
> I have a very specific problem: I'd like to change the EClassifier
> context of an existing OCL query. In my project, there are several
> (meta)model repositories whose contents are replicated through EMF copy
> at certain times.
> E.g. eClass1 is located in repository A and copied to repository B.
> Because this can happen multiple times, to avoid a severe performance
> hit I'd like to prepare the OCL queries for the elements in repository A
> only once and exchange their context with the copied elements in B each
> time a copy is created, so they can be executed for B.
>
> I realized that the bindings are kept in the OCL environment, so I tried
> resetting them there (metaModelMap redirects to the eclass copies in B
> according to their name)
>
> for (Iterator iter = OCL_ENV.getEnvironment().getTypeResolver()
> .getResource().getAllContents(); iter.hasNext();)
> {
> Object object = iter.next();
>
> if (object instanceof Variable)
> {
> String eClassName = ((Variable)object).getEType().getName();
> EClass newEClass = metaModelMap.get(eClassName);
> ((Variable)object).setEType(newEClass);
> }
> }
>
> but this doesn't seem to do the trick. Maybe you've got some suggestions.
>
> Thanks in advance,
> Chris
>
Re: changing context of existing query [message #482886 is a reply to message #482761] Fri, 28 August 2009 13:15 Go to previous message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Hi Ed,

thanks for your quick help. I tried using the UsageCrossReferences and it
seems that it's working:

// search for features of old classes
Set<EStructuralFeature> feats = new HashSet<EStructuralFeature>();
for (EClass oldEClass : oldEClasses)
{
feats.addAll(oldEClass.getEAllStructuralFeatures());
}

// find referring features
Map<EObject, Collection<EStructuralFeature.Setting>> usesOfOldEClasses =
EcoreUtil.UsageCrossReferencer
.findAll(feats, OCL_ENV.getEnvironment().getTypeResolver()
.getResource());

// switch old features with new ones
for (Entry<EObject, Collection<EStructuralFeature.Setting>> entry :
usesOfOldEClasses
.entrySet())
{
EStructuralFeature oldFeature = (EStructuralFeature) entry.getKey();
EClass oldClass = (EClass) oldFeature.eContainer();
EClass newClass = metaModelMap.get(oldClass.getName());
EStructuralFeature newFeature = newClass
.getEStructuralFeature(oldFeature.getName());

for (EStructuralFeature.Setting setting : entry.getValue())
{
setting.set(newFeature);
}
}

Regards,
Chris
Previous Topic:def expression?
Next Topic:extending the OCL parser and evaluation
Goto Forum:
  


Current Time: Thu Apr 25 08:25:20 GMT 2024

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

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

Back to the top