Hi Jens,
I think I might have an idea what the problem is. This is how
you construct your EGraph:
model.setModelGraph(new EGraphImpl(resource));
The constructor of EGraphImpl you are using does the following:
public EGraphImpl(Resource resource) {
for (EObject root : resource.getContents()) {
addGraph(root);
}
}
So it calls the method addGraph(EObject) on all root objects of
the resource. Now there are two methods in EGraph:
- addTree(EObject)
- addGraph(EObject)
The first one adds the object and all contained objects to the
EGraph. The second method adds the object and all *reachable*
objects to the EGraph. See also the JavaDoc. The second one is
used in the constructor you are using.
The problem is that in your application, all reachable objects
also include the metamodels and/or the profiles. When you later
do this:
resource2.getContents().addAll(model.getModelGraph().getRoots());
you remove the metamodels / profiles from their original
resources. The next time you are trying to load them EMF can't
find them anymore and you get these strange errors.
The solution is that you select only those root objects that you
really want to save. So just iterate over the root objects and
see what you get. Select only those which are meant to be saved
in the resource.
For the Henshin developers: we should discuss whether we should
use addGraph() or addTree() in the EGraphImpl(Resource)
constructor (or whether we remove this constructor to avoid such
confusions). Both addTree() and addGraph() have pros and cons.
Cheers,
Christian
On 12/17/2012 03:08 PM, Jens Bürger wrote:
Hello all,
Whilst developing my Henshin-application in Eclipse, I came
across a very strange error I can't explain.
A co-worker of mine, having experience with Eclipse and EMF,
already hat a look at my source but doesn't have a clue, too.
What am I doing:
I'm developing my application as a Eclipse plugin. I'm running
the plugin in a Eclipse runtime environment via clicking on the
Toolbar-button, which instantiates/runs a
IWorkbenchWindowActionDelegate.
the run()-Method of this action does the following:
public void run(IAction action) {
model=new DataModel();
input =new InputDataDialog(window.getShell(),model);
input.open();
if (model.getModelFile().endsWith(".uml")){
patchEngine= new UMLPatchEngine(model);
} else
if (model.getModelFile().endsWith(".bpmn2")){
patchEngine= new BPMNPatchEngine(model);
}
patchEngine.load();
patchEngine.test();
patchEngine.match();
new PatchDialog(window.getShell(),model,patchEngine).open();
patchEngine.save();
}
patchEngine.load() especially does:
Resource resource =
resourceSet.getResource(model.getModelFile());
model.setModelGraph(new EGraphImpl(resource));
Now my problem: I start the runtime-Eclipse, do a transformation
or not (via the PatchDialog) and the window closes normally.
Now, If I instantiate my Plugin-Action a second time, I get a
wild bunch of exceptions which read as if there is a problem
loading the UML standard-profile (see attached file).
The only hint I got so far is the following:
If I comment out the following line in my save-method (which
saves the transformed model), the exceptions don't occur:
resource2.getContents().addAll(model.getModelGraph().getRoots());
(resource2 is of type org.eclipse.emf.ecore.resource.Resource).
Strangely enough, this problem doesn't occur in in the class
working with BPMN-Files.
As you can see from my source-excerpts, every objects are newly
created when activating the action (Henshin ResourceSets,
Eclipse ResourceSets, TransformationEngines and so on). I don't
have static variables in my program, but maybe there is a
problem when re-instanciating Henshin-Classes or something
getting cached or so?
Any hints?
Slightly confused,
Jens
_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/henshin-dev
|