Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_443281_Test.java110
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java87
2 files changed, 163 insertions, 34 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_443281_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_443281_Test.java
new file mode 100644
index 0000000000..85008eeeac
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_443281_Test.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Esteban Dugueperoux - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.EresourcePackage;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.util.TestAdapter;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+
+import java.io.File;
+
+/**
+ * Test that {@link CDOResource#setURI(org.eclipse.emf.common.util.URI)} notify adapters of Set {@link Notification} on Resource.RESOURCE__URI.
+ *
+ * @author Esteban Dugueperoux
+ */
+public class Bugzilla_443281_Test extends AbstractCDOTest
+{
+ private Object oldResourceFactory;
+
+ private ResourceSetImpl resourceSet;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ oldResourceFactory = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*",
+ new XMIResourceFactoryImpl());
+ resourceSet = new ResourceSetImpl();
+ }
+
+ public void testCDOResource_setURI() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction(resourceSet);
+ String resourceName = "resource1.model1";
+ CDOResource resource1 = tx.createResource(getResourcePath(resourceName));
+
+ // Test
+ TestAdapter testAdapter = new TestAdapter();
+ resource1.eAdapters().add(testAdapter);
+ URI uri = resource1.getURI();
+ String newResourceName = "resource2.model1";
+ URI newURI = uri.trimSegments(1).appendSegment(newResourceName);
+ resource1.setURI(newURI);
+ assertEquals(2, testAdapter.getNotifications().length);
+
+ Notification notification1 = testAdapter.getNotifications()[0];
+ assertEquals(resource1, notification1.getNotifier());
+ assertEquals(EresourcePackage.Literals.CDO_RESOURCE_NODE__NAME, notification1.getFeature());
+ assertEquals(Notification.SET, notification1.getEventType());
+ assertEquals(resourceName, notification1.getOldValue());
+ assertEquals(newResourceName, notification1.getNewValue());
+
+ Notification notification2 = testAdapter.getNotifications()[1];
+ assertEquals(resource1, notification2.getNotifier());
+ assertEquals(Resource.RESOURCE__URI, notification2.getFeatureID(null));
+ assertEquals(Notification.SET, notification2.getEventType());
+ assertEquals(uri, notification2.getOldValue());
+ assertEquals(newURI, notification2.getNewValue());
+
+ }
+
+ public void testXMIResource_setURI() throws Exception
+ {
+ String path = new File("./localResource.xmi").getCanonicalPath();
+ URI localResourceURI = URI.createFileURI(path);
+ Resource resource1 = resourceSet.createResource(localResourceURI);
+
+ // Test
+ TestAdapter testAdapter = new TestAdapter();
+ resource1.eAdapters().add(testAdapter);
+ URI uri = resource1.getURI();
+ URI newURI = uri.trimSegments(1).appendSegment("resource2.model1");
+ resource1.setURI(newURI);
+ assertEquals(1, testAdapter.getNotifications().length);
+ Notification notification = testAdapter.getNotifications()[0];
+ assertEquals(resource1, notification.getNotifier());
+ assertEquals(Resource.RESOURCE__URI, notification.getFeatureID(null));
+ assertEquals(Notification.SET, notification.getEventType());
+ assertEquals(uri, notification.getOldValue());
+ assertEquals(newURI, notification.getNewValue());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ resourceSet = null;
+ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", oldResourceFactory);
+ oldResourceFactory = null;
+ resourceSet = null;
+ super.tearDown();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index ed1cf67155..6852e2516a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -344,8 +344,27 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
*/
public void setURI(URI newURI)
{
+ URI uri = getURI();
String newPath = CDOURIUtil.extractResourcePath(newURI);
setPath(newPath);
+ if (eNotificationRequired())
+ {
+ Notification notification = new NotificationImpl(Notification.SET, uri, newURI)
+ {
+ @Override
+ public Object getNotifier()
+ {
+ return CDOResourceImpl.this;
+ }
+
+ @Override
+ public int getFeatureID(Class<?> expectedClass)
+ {
+ return RESOURCE__URI;
+ }
+ };
+ eNotify(notification);
+ }
}
@Override
@@ -551,7 +570,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
if (errors == null)
{
errors = new NotifyingListImpl<Diagnostic>()
- {
+ {
private static final long serialVersionUID = 1L;
@Override
@@ -571,7 +590,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
{
return EresourcePackage.CDO_RESOURCE__ERRORS;
}
- };
+ };
}
return errors;
@@ -587,7 +606,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
if (warnings == null)
{
warnings = new NotifyingListImpl<Diagnostic>()
- {
+ {
private static final long serialVersionUID = 1L;
@Override
@@ -607,7 +626,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
{
return EresourcePackage.CDO_RESOURCE__WARNINGS;
}
- };
+ };
}
return warnings;
@@ -638,7 +657,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
public TreeIterator<EObject> getAllContents()
{
return new AbstractTreeIterator<EObject>(this, false)
- {
+ {
private static final long serialVersionUID = 1L;
@Override
@@ -647,7 +666,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
return object == CDOResourceImpl.this ? CDOResourceImpl.this.getContents().iterator() : ((EObject)object)
.eContents().iterator();
}
- };
+ };
}
/**
@@ -863,7 +882,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
protected TreeIterator<EObject> getAllProperContents(List<EObject> contents)
{
return new ContentTreeIterator<EObject>(contents, false)
- {
+ {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@@ -873,7 +892,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
return object == this.object ? ((List<EObject>)object).iterator() : new ProperContentIterator<EObject>(
(EObject)object);
}
- };
+ };
}
/**
@@ -1227,16 +1246,16 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
IProgressMonitor progressMonitor = options != null ? (IProgressMonitor)options
.get(CDOResource.OPTION_SAVE_PROGRESS_MONITOR) : null;
- try
- {
- transaction.commit(progressMonitor);
- }
- catch (CommitException ex)
- {
- throw new TransactionException(ex);
- }
+ try
+ {
+ transaction.commit(progressMonitor);
+ }
+ catch (CommitException ex)
+ {
+ throw new TransactionException(ex);
+ }
- setModified(false);
+ setModified(false);
}
/**
@@ -1247,20 +1266,20 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
CDOTransaction transaction = options != null ? (CDOTransaction)options
.get(CDOResource.OPTION_SAVE_OVERRIDE_TRANSACTION) : null;
- if (transaction == null)
- {
- CDOView view = cdoView();
- if (view instanceof CDOTransaction)
- {
- transaction = (CDOTransaction)view;
- }
- else
- {
- throw new IllegalStateException("No transaction available");
- }
- }
+ if (transaction == null)
+ {
+ CDOView view = cdoView();
+ if (view instanceof CDOTransaction)
+ {
+ transaction = (CDOTransaction)view;
+ }
+ else
+ {
+ throw new IllegalStateException("No transaction available");
+ }
+ }
- return transaction;
+ return transaction;
}
/**
@@ -1472,13 +1491,13 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
{
InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(resourceSet);
viewSet.executeWithoutNotificationHandling(new Callable<Boolean>()
- {
+ {
public Boolean call() throws Exception
{
resourceSet.getResources().remove(CDOResourceImpl.this);
return true;
}
- });
+ });
}
}
@@ -1543,12 +1562,12 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(oldResourceSet);
notifications = viewSet.executeWithoutNotificationHandling(new Callable<NotificationChain>()
- {
+ {
public NotificationChain call() throws Exception
{
return ((InternalEList<Resource>)oldResourceSet.getResources()).basicRemove(this, finalNotifications);
}
- });
+ });
}
setResourceSet(resourceSet);

Back to the top