Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-14 08:42:22 +0000
committerEike Stepper2012-09-14 08:42:22 +0000
commitc2f161e3e9119d80d47085eace302aecbc7949bd (patch)
treebf20f0f85f4e3b7b4abd9dccdbabec76ca77ca4b /plugins/org.eclipse.emf.cdo.transfer/src
parentb82dd9ea01b7aff1522cf269267eabf1dd453e81 (diff)
downloadcdo-c2f161e3e9119d80d47085eace302aecbc7949bd.tar.gz
cdo-c2f161e3e9119d80d47085eace302aecbc7949bd.tar.xz
cdo-c2f161e3e9119d80d47085eace302aecbc7949bd.zip
[388928] Develop a resource transfer framework
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388928
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.transfer/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java164
1 files changed, 143 insertions, 21 deletions
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
index be1714d55b..3221e26956 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
@@ -16,9 +16,10 @@ import org.eclipse.net4j.util.event.Event;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.event.INotifier;
import org.eclipse.net4j.util.event.Notifier;
-import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
@@ -26,11 +27,11 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
@@ -513,9 +514,15 @@ public class CDOTransfer implements INotifier
private Map<URI, ModelTransferResolution> resolutions = new HashMap<URI, ModelTransferResolution>();
+ private ResolveProxyAdapter resolveProxyAdapter;
+
+ private Copier copier;
+
protected ModelTransferContext(CDOTransfer transfer)
{
this.transfer = transfer;
+ resolveProxyAdapter = new ResolveProxyAdapter();
+ copier = createCopier();
}
public final CDOTransfer getTransfer()
@@ -593,24 +600,18 @@ public class CDOTransfer implements INotifier
{
if (unmappedModels == null)
{
- unmappedModels = new HashSet<Resource>();
+ Set<Resource> mappedModels = resourceElements.keySet();
ResourceSet resourceSet = getSourceResourceSet();
EList<Resource> resources = resourceSet.getResources();
- resources.clear();
- Set<Resource> mappedModels = resourceElements.keySet();
- resources.addAll(mappedModels);
- EcoreUtil.resolveAll(resourceSet);
-
- for (Resource resource : resources)
- {
- if (!mappedModels.contains(resource))
- {
- unmappedModels.add(resource);
- }
- }
+ // if (resources.addAll(mappedModels))
+ // {
+ // EcoreUtil.resolveAll(resourceSet);
+ // }
+ unmappedModels = new HashSet<Resource>(resources);
+ unmappedModels.removeAll(mappedModels);
fireUnmappedModelsEvent();
}
@@ -683,10 +684,17 @@ public class CDOTransfer implements INotifier
return targetSystem.createModel(targetResourceSet, path);
}
+ protected Copier createCopier()
+ {
+ return new Copier();
+ }
+
protected ResourceSet createResourceSet(CDOTransferSystem system)
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.setResourceFactoryRegistry(new ResourceFactoryRegistryWithoutDefaults());
+ resourceSet.eAdapters().add(resolveProxyAdapter);
+
return resourceSet;
}
@@ -705,7 +713,7 @@ public class CDOTransfer implements INotifier
Resource targetResource = getTargetResource(mapping);
EList<EObject> sourceContents = sourceResource.getContents();
- Collection<EObject> targetContents = EcoreUtil.copyAll(sourceContents);
+ Collection<EObject> targetContents = EcoreUtil.copyAll(sourceContents); // copier.copyAll(sourceContents);
EList<EObject> contents = targetResource.getContents();
contents.addAll(targetContents);
@@ -713,16 +721,130 @@ public class CDOTransfer implements INotifier
protected void save()
{
- try
+ copier.copyReferences();
+
+ // try
+ // {
+ // for (Resource resource : elementResources.values())
+ // {
+ // resource.save(null);
+ // }
+ // }
+ // catch (IOException ex)
+ // {
+ // throw new IORuntimeException(ex);
+ // }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ResolveProxyAdapter extends AdapterImpl
+ {
+ private LoadResourceAdapter loadResourceAdapter;
+
+ public ResolveProxyAdapter()
+ {
+ loadResourceAdapter = new LoadResourceAdapter();
+ }
+
+ @Override
+ public void notifyChanged(Notification msg)
{
- for (Resource resource : elementResources.values())
+ int eventType = msg.getEventType();
+ switch (eventType)
{
- resource.save(null);
+ case Notification.SET:
+ {
+ Resource oldValue = (Resource)msg.getOldValue();
+ if (oldValue != null)
+ {
+ removeResource(oldValue);
+ }
+ Resource newValue = (Resource)msg.getNewValue();
+ if (newValue != null)
+ {
+ addResource(newValue);
+ }
+ break;
}
+ case Notification.ADD:
+ {
+ Resource newValue = (Resource)msg.getNewValue();
+ if (newValue != null)
+ {
+ addResource(newValue);
+ }
+ break;
+ }
+ case Notification.ADD_MANY:
+ {
+ @SuppressWarnings("unchecked")
+ Collection<Resource> newValues = (Collection<Resource>)msg.getNewValue();
+ for (Resource newValue : newValues)
+ {
+ addResource(newValue);
+ }
+ break;
+ }
+ case Notification.REMOVE:
+ {
+ Resource oldValue = (Resource)msg.getOldValue();
+ if (oldValue != null)
+ {
+ removeResource(oldValue);
+ }
+ break;
+ }
+ case Notification.REMOVE_MANY:
+ {
+ @SuppressWarnings("unchecked")
+ Collection<Resource> oldValues = (Collection<Resource>)msg.getOldValue();
+ for (Resource oldContentValue : oldValues)
+ {
+ removeResource(oldContentValue);
+ }
+ break;
+ }
+ }
+ }
+
+ private void addResource(Resource resource)
+ {
+ EcoreUtil.resolveAll(resource);
+ resource.eAdapters().add(loadResourceAdapter);
+ }
+
+ private void removeResource(Resource resource)
+ {
}
- catch (IOException ex)
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LoadResourceAdapter extends AdapterImpl
{
- throw new IORuntimeException(ex);
+ @Override
+ public void notifyChanged(Notification msg)
+ {
+ if (msg.getFeatureID(Resource.class) == Resource.RESOURCE__IS_LOADED)
+ {
+ int eventType = msg.getEventType();
+ switch (eventType)
+ {
+ case Notification.SET:
+ {
+ boolean isLoaded = msg.getNewBooleanValue();
+ if (isLoaded)
+ {
+ Resource resource = (Resource)msg.getNotifier();
+ EcoreUtil.resolveAll(resource);
+ }
+ break;
+ }
+ }
+ }
+ }
}
}
}

Back to the top