changing context of existing query [message #482717] |
Thu, 27 August 2009 12:20  |
Eclipse User |
|
|
|
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 09:15  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03827 seconds