Hello,
The issue with changing the URI of a resource with resource.setURI is that incoming reference from other resource will not be updated.
I think you will have less trouble, by moving the resource content. The approach I would recommand is the following:
- First, create the new resource:
Resource newSemanticResource =resourceSet().createResource(newSemanticResourceURI);
newSemanticResource.save(null);
- Next, Add the resource to the session
session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
session.addSemanticResource(semanticResource4uri, new NullProgressMonitor());
}
});
- Finally, move the resource root to the new resource and save
EObject toMove = semanticResource3.getContents().get(0);
session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
semanticResource4.getContents().add(toMove);
}
});
session.save(new NullProgressMonitor());
I checked with a JUnit where I had a model A with a model element referencing a model element from model B. I moved this model element from B to a new resource C. In model A, the reference was updated to model C automatically.
Regards,
Steve