Skip to content

Commit

Permalink
#781 Fixed resource URI duplication issue
Browse files Browse the repository at this point in the history
copied resource now uses a memory:/ uri instead of its scheme
this fixes issues for CDO, which raised an exception if the same uri was
used twice

fix npe where copier would be null if edting domain is null

Change-Id: I593a4cbf078d63bb80d82338cb927328e957a237
Signed-off-by: Erwann Traisnel <[email protected]>
  • Loading branch information
etraisnel2 authored and pdulth committed Jan 31, 2024
1 parent 4d0683c commit d4ff5b8
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
Expand All @@ -27,6 +28,7 @@
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.sirius.business.api.query.URIQuery;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.polarsys.kitalpha.doc.gen.business.core.messages.Messages;

Expand Down Expand Up @@ -254,8 +256,14 @@ protected final Resource copyResource(final EObject anySourceModelElement){
this.domain = TransactionUtil.getEditingDomain(anySourceModelElement);
if (this.domain != null)
{
final Resource resource = domain.createResource(anySourceModelElement.eResource().getURI().toString());
this.domain.getResourceSet().getResources().add(resource);
URI resourceURI = anySourceModelElement.eResource().getURI();
URI copiedResourceURI = URI.createHierarchicalURI(URIQuery.INMEMORY_URI_SCHEME, resourceURI.authority(),
resourceURI.device(), resourceURI.segments(), resourceURI.query(), resourceURI.fragment());

final Resource resource = domain.createResource(anySourceModelElement.eResource().getURI().toString());

this.domain.getResourceSet().getResources().add(resource);

this.copier = new EcoreUtil.Copier();
this.domain.getCommandStack().execute(new RecordingCommand(domain) {
@Override
Expand All @@ -271,6 +279,7 @@ protected void doExecute() {
}
else
{
this.copier = new EcoreUtil.Copier();
final Resource resource = new ResourceImpl();
final EObject rootContainer = EcoreUtil.getRootContainer(anySourceModelElement);
final EObject copyModelRootElement = copier.copy(rootContainer);
Expand Down

0 comments on commit d4ff5b8

Please sign in to comment.