summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-04 12:22:16 (EDT)
committerEike Stepper2007-08-04 12:22:16 (EDT)
commit3d821b073e11ef92c14d7aa0c9acbcfda8fa7dd6 (patch)
tree40d0f263f684b0383ce7a0e01775c0ca34a9084f
parenta589a2d364ab789f87913267335fcff87ee86cd5 (diff)
downloadcdo-3d821b073e11ef92c14d7aa0c9acbcfda8fa7dd6.zip
cdo-3d821b073e11ef92c14d7aa0c9acbcfda8fa7dd6.tar.gz
cdo-3d821b073e11ef92c14d7aa0c9acbcfda8fa7dd6.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java76
1 files changed, 67 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
index 1e5ad62..04acc42 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.impl.EClassifierImpl;
import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.eclipse.emf.ecore.resource.Resource;
@@ -30,6 +31,7 @@ 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.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
@@ -51,29 +53,75 @@ public final class EMFUtil
{
}
- public static EObject loadXMI(String fileName)
+ public static ResourceSet newResourceSet(Resource.Factory resourceFactory)
{
- return loadXMI(fileName, EPackage.Registry.INSTANCE);
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", resourceFactory);
+ return resourceSet;
}
- public static EObject loadXMI(String fileName, EPackage.Registry packageRegistry)
+ public static ResourceSet newXMIResourceSet(EPackage... ePackages)
{
- ResourceSet resourceSet = new ResourceSetImpl();
- resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
+ ResourceSet resourceSet = newResourceSet(new XMIResourceFactoryImpl());
+ if (ePackages != null && ePackages.length != 0)
+ {
+ Registry packageRegistry = resourceSet.getPackageRegistry();
+ for (EPackage ePackage : ePackages)
+ {
+ packageRegistry.put(ePackage.getNsURI(), ePackage);
+ }
+ }
+
+ return resourceSet;
+ }
+
+ public static ResourceSet newEcoreResourceSet(EPackage.Registry packageRegistry)
+ {
+ ResourceSet resourceSet = newResourceSet(new EcoreResourceFactoryImpl());
resourceSet.setPackageRegistry(packageRegistry);
+ return resourceSet;
+ }
+ public static ResourceSet newEcoreResourceSet()
+ {
+ return newEcoreResourceSet(EPackage.Registry.INSTANCE);
+ }
+
+ public static EObject load(String fileName, ResourceSet resourceSet)
+ {
Resource resource = resourceSet.getResource(URI.createFileURI(fileName), true);
return resource.getContents().get(0);
}
- public static void saveXMI(String fileName, EObject root)
+ public static EObject loadXMI(String fileName, EPackage... ePackages)
{
- ResourceSet resourceSet = new ResourceSetImpl();
- resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
- Resource resource = resourceSet.createResource(URI.createFileURI(fileName));
+ ResourceSet resourceSet = newXMIResourceSet(ePackages);
+ return load(fileName, resourceSet);
+ }
+ public static EObject loadXMI(String fileName, EPackage.Registry packageRegistry)
+ {
+ ResourceSet resourceSet = newXMIResourceSet();
+ resourceSet.setPackageRegistry(packageRegistry);
+ return load(fileName, resourceSet);
+ }
+
+ public static EObject loadEcore(String fileName, EPackage.Registry packageRegistry)
+ {
+ return load(fileName, newEcoreResourceSet(packageRegistry));
+ }
+
+ public static EObject loadEcore(String fileName)
+ {
+ return load(fileName, newEcoreResourceSet());
+ }
+
+ public static void save(String fileName, EObject root, ResourceSet resourceSet)
+ {
+ Resource resource = resourceSet.createResource(URI.createFileURI(fileName));
EObject copy = EcoreUtil.copy(root);
resource.getContents().add(copy);
+
try
{
resource.save(null);
@@ -84,6 +132,16 @@ public final class EMFUtil
}
}
+ public static void saveXMI(String fileName, EObject root)
+ {
+ save(fileName, root, newXMIResourceSet());
+ }
+
+ public static void saveEcore(String fileName, EObject root)
+ {
+ save(fileName, root, newEcoreResourceSet());
+ }
+
public static int countAllContents(EObject eObject)
{
int count = 0;