Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-13 14:59:34 +0000
committerEike Stepper2012-09-13 14:59:34 +0000
commitfcbc41822ee66299be45911598a87d16572e94d5 (patch)
treecbd9121c38aaff2fb496f578216a9910b32ea7d9 /plugins/org.eclipse.emf.cdo.transfer/src
parent1e471bbbeea7116481ea08522a43b58d8f2b9b47 (diff)
downloadcdo-fcbc41822ee66299be45911598a87d16572e94d5.tar.gz
cdo-fcbc41822ee66299be45911598a87d16572e94d5.tar.xz
cdo-fcbc41822ee66299be45911598a87d16572e94d5.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/spi/transfer/ResourceFactoryRegistryWithoutDefaults.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java81
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java15
5 files changed, 98 insertions, 43 deletions
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/ResourceFactoryRegistryWithoutDefaults.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/ResourceFactoryRegistryWithoutDefaults.java
new file mode 100644
index 0000000000..75dd22131b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/ResourceFactoryRegistryWithoutDefaults.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.spi.transfer;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Factory;
+import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
+
+/**
+ * @author Eike Stepper
+ */
+public class ResourceFactoryRegistryWithoutDefaults extends ResourceFactoryRegistryImpl
+{
+ public ResourceFactoryRegistryWithoutDefaults()
+ {
+ getProtocolToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
+ getExtensionToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
+ getContentTypeToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());
+
+ getExtensionToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_EXTENSION);
+ getContentTypeToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_CONTENT_TYPE_IDENTIFIER);
+ }
+
+ @Override
+ protected Factory delegatedGetFactory(URI uri, String contentTypeIdentifier)
+ {
+ return null;
+ }
+} \ No newline at end of file
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 867bb0171d..be1714d55b 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
@@ -10,6 +10,8 @@
*/
package org.eclipse.emf.cdo.transfer;
+import org.eclipse.emf.cdo.spi.transfer.ResourceFactoryRegistryWithoutDefaults;
+
import org.eclipse.net4j.util.event.Event;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.event.INotifier;
@@ -21,9 +23,7 @@ import org.eclipse.emf.common.util.EList;
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.Resource.Factory;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
@@ -54,7 +54,7 @@ public class CDOTransfer implements INotifier
private final Map<CDOTransferElement, CDOTransferMapping> mappings = new HashMap<CDOTransferElement, CDOTransferMapping>();
- private CDOTransferType defaultTransferType = CDOTransferType.UNKNOWN;
+ private CDOTransferType defaultTransferType = CDOTransferType.BINARY;
private ModelTransferContext modelTransferContext = createModelTransferContext();
@@ -182,7 +182,7 @@ public class CDOTransfer implements INotifier
protected ModelTransferContext createModelTransferContext()
{
- return new ModelTransferContext();
+ return new ModelTransferContext(this);
}
protected CDOTransferType getTransferType(CDOTransferElement source)
@@ -198,7 +198,7 @@ public class CDOTransfer implements INotifier
}
CDOTransferType type = sourceSystem.getDefaultTransferType(source);
- if (type == CDOTransferType.UNKNOWN)
+ if (type == null)
{
type = getDefaultTransferType();
}
@@ -484,8 +484,23 @@ public class CDOTransfer implements INotifier
/**
* @author Eike Stepper
*/
- public class ModelTransferContext
+ public static class UnmappedModelsEvent extends Event
+ {
+ private static final long serialVersionUID = 1L;
+
+ private UnmappedModelsEvent(CDOTransfer transfer)
+ {
+ super(transfer);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ModelTransferContext
{
+ private final CDOTransfer transfer;
+
private ResourceSet sourceResourceSet;
private ResourceSet targetResourceSet;
@@ -496,14 +511,23 @@ public class CDOTransfer implements INotifier
private Set<Resource> unmappedModels;
- protected ModelTransferContext()
+ private Map<URI, ModelTransferResolution> resolutions = new HashMap<URI, ModelTransferResolution>();
+
+ protected ModelTransferContext(CDOTransfer transfer)
{
+ this.transfer = transfer;
+ }
+
+ public final CDOTransfer getTransfer()
+ {
+ return transfer;
}
public final ResourceSet getSourceResourceSet()
{
if (sourceResourceSet == null)
{
+ CDOTransferSystem sourceSystem = transfer.getSourceSystem();
sourceResourceSet = sourceSystem.provideResourceSet();
if (sourceResourceSet == null)
{
@@ -518,6 +542,7 @@ public class CDOTransfer implements INotifier
{
if (targetResourceSet == null)
{
+ CDOTransferSystem targetSystem = transfer.getTargetSystem();
targetResourceSet = targetSystem.provideResourceSet();
if (targetResourceSet == null)
{
@@ -585,11 +610,34 @@ public class CDOTransfer implements INotifier
unmappedModels.add(resource);
}
}
+
+ fireUnmappedModelsEvent();
}
return unmappedModels;
}
+ public ModelTransferResolution getResolution(URI uri)
+ {
+ return resolutions.get(uri);
+ }
+
+ public ModelTransferResolution setResolution(URI uri, ModelTransferResolution resolution)
+ {
+ ModelTransferResolution old = resolutions.put(uri, resolution);
+ if (resolution != old)
+ {
+ fireUnmappedModelsEvent();
+ }
+
+ return old;
+ }
+
+ protected void fireUnmappedModelsEvent()
+ {
+ transfer.notifier.fireEvent(new UnmappedModelsEvent(transfer));
+ }
+
protected void addModelMapping(CDOTransferMapping mapping)
{
CDOTransferElement element = mapping.getSource();
@@ -600,6 +648,7 @@ public class CDOTransfer implements INotifier
elementResources.put(element, resource);
resourceElements.put(resource, element);
unmappedModels = null;
+ fireUnmappedModelsEvent();
}
protected void removeModelMapping(CDOTransferMapping mapping)
@@ -616,6 +665,7 @@ public class CDOTransfer implements INotifier
}
unmappedModels = null;
+ fireUnmappedModelsEvent();
}
protected Resource getSourceResource(CDOTransferMapping mapping)
@@ -629,6 +679,7 @@ public class CDOTransfer implements INotifier
{
IPath path = mapping.getFullPath();
ResourceSet targetResourceSet = getTargetResourceSet();
+ CDOTransferSystem targetSystem = transfer.getTargetSystem();
return targetSystem.createModel(targetResourceSet, path);
}
@@ -679,22 +730,8 @@ public class CDOTransfer implements INotifier
/**
* @author Eike Stepper
*/
- protected static class ResourceFactoryRegistryWithoutDefaults extends ResourceFactoryRegistryImpl
+ public interface ModelTransferResolution
{
- public ResourceFactoryRegistryWithoutDefaults()
- {
- getProtocolToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
- getExtensionToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
- getContentTypeToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());
-
- getExtensionToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_EXTENSION);
- getContentTypeToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_CONTENT_TYPE_IDENTIFIER);
- }
- @Override
- protected Factory delegatedGetFactory(URI uri, String contentTypeIdentifier)
- {
- return null;
- }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
index 336f169d94..2bd6b5907d 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
@@ -221,11 +221,6 @@ class CDOTransferMappingImpl implements CDOTransferMapping
{
if (!ObjectUtil.equals(this.transferType, transferType))
{
- // if (transferType == CDOTransferType.MODEL && !transfer.getModelTransferContext().hasResourceFactory(source))
- // {
- // throw new IllegalStateException("No resource factory registered for " + this);
- // }
-
CDOTransferType oldType = this.transferType;
this.transferType = transferType;
transfer.transferTypeChanged(this, oldType, transferType);
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
index 747b19f08a..0972286a83 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
@@ -51,7 +51,7 @@ public abstract class CDOTransferSystem
return CDOTransferType.FOLDER;
}
- return CDOTransferType.UNKNOWN;
+ return null;
}
public abstract URI getURI(IPath path);
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java
index 40b7d5b08d..2c538bf2ee 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java
@@ -15,12 +15,9 @@ import org.eclipse.emf.cdo.internal.transfer.bundle.OM;
import org.eclipse.net4j.util.ObjectUtil;
import java.nio.charset.Charset;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
/**
* @author Eike Stepper
@@ -33,15 +30,6 @@ public class CDOTransferType implements Comparable<CDOTransferType>
*/
private static final Map<String, CDOTransferType> MAP = new HashMap<String, CDOTransferType>();
- public static final CDOTransferType UNKNOWN = new CDOTransferType()
- {
- @Override
- public String toString()
- {
- return "<Unknown>";
- }
- };
-
public static final CDOTransferType FOLDER = new CDOTransferType()
{
@Override
@@ -71,9 +59,6 @@ public class CDOTransferType implements Comparable<CDOTransferType>
public static final Text UTF8 = text("UTF-8");
- public static final Set<CDOTransferType> STANDARD_TYPES = new HashSet<CDOTransferType>(Arrays.asList(UNKNOWN, FOLDER,
- MODEL, BINARY, UTF8));
-
public static final Map<String, CDOTransferType> REGISTRY = Collections.unmodifiableMap(MAP);
private CDOTransferType()

Back to the top