summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-18 01:49:28 (EDT)
committerEike Stepper2007-07-18 01:49:28 (EDT)
commit4cc41dda30145912557fadbaec378c6a266763b0 (patch)
treec2d92adc0937b8dff99d8c2c88d4181718024079
parent1a1018aa60f6fcc9821316ee6ac27d3bb538b287 (diff)
downloadcdo-4cc41dda30145912557fadbaec378c6a266763b0.zip
cdo-4cc41dda30145912557fadbaec378c6a266763b0.tar.gz
cdo-4cc41dda30145912557fadbaec378c6a266763b0.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryPackageManager.java7
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java52
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManager.java9
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java62
4 files changed, 77 insertions, 53 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryPackageManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryPackageManager.java
index 1167783..46c7864 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryPackageManager.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryPackageManager.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.internal.server;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageManagerImpl;
+import org.eclipse.emf.cdo.protocol.util.ImplementationError;
/**
* @author Eike Stepper
@@ -36,4 +37,10 @@ public class RepositoryPackageManager extends CDOPackageManagerImpl
// TODO Implement method RepositoryPackageManager.resolve()
throw new UnsupportedOperationException("Not yet implemented");
}
+
+ @Override
+ protected String provideEcore(CDOPackageImpl cdoPackage)
+ {
+ throw new ImplementationError("No generated model on server side");
+ }
}
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 4fa0dcf..37100eb 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
@@ -11,6 +11,7 @@
package org.eclipse.emf.cdo.util;
import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
@@ -19,8 +20,13 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EPackageImpl;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +36,8 @@ import java.util.List;
*/
public final class EMFUtil
{
+ private static final String ECORE_ENCODING = "ASCII";
+
private EMFUtil()
{
}
@@ -88,6 +96,50 @@ public final class EMFUtil
return false;
}
+ public static EPackage ePackageFromString(String ecore)
+ {
+ try
+ {
+ ByteArrayInputStream stream = new ByteArrayInputStream(ecore.getBytes(ECORE_ENCODING));
+ XMIResource resource = new XMIResourceImpl();
+ resource.load(stream, null);
+ return (EPackage)resource.getContents().get(0);
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
+ public static String ePackageToString(EPackage ePackage)
+ {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ XMIResource resource = new XMIResourceImpl();
+
+ try
+ {
+ resource.getContents().add(ePackage);
+ resource.save(stream, null);
+ return stream.toString(ECORE_ENCODING);
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ resource.getContents().clear();
+ }
+ }
+
/**
* TODO Remove when EMF has fixed this
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManager.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManager.java
index a762801..1f7e97b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManager.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManager.java
@@ -13,7 +13,9 @@ package org.eclipse.emf.internal.cdo;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageManagerImpl;
import org.eclipse.emf.cdo.protocol.util.TransportException;
+import org.eclipse.emf.cdo.util.EMFUtil;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.internal.cdo.protocol.LoadPackageRequest;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
@@ -62,4 +64,11 @@ public class CDOSessionPackageManager extends CDOPackageManagerImpl
throw new TransportException(ex);
}
}
+
+ @Override
+ protected String provideEcore(CDOPackageImpl cdoPackage)
+ {
+ EPackage ePackage = ModelUtil.getEPackage(cdoPackage, session.getPackageRegistry());
+ return EMFUtil.ePackageToString(ePackage);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
index 625ade4..d4b2344 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
@@ -23,8 +23,6 @@ import org.eclipse.emf.cdo.internal.protocol.model.resource.CDOResourceClassImpl
import org.eclipse.emf.cdo.internal.protocol.model.resource.CDOResourcePackageImpl;
import org.eclipse.emf.cdo.util.EMFUtil;
-import org.eclipse.net4j.util.io.IORuntimeException;
-
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
@@ -32,15 +30,9 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.impl.EPackageImpl;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
import org.eclipse.emf.internal.cdo.CDOPackageRegistryImpl;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
/**
* @author Eike Stepper
*/
@@ -114,33 +106,12 @@ public final class ModelUtil
private static CDOPackageImpl createCDOPackage(EPackage ePackage, CDOPackageManagerImpl packageManager)
{
- String ecore = null;
- if (EMFUtil.isDynamicEPackage(ePackage))
- {
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- XMIResource resource = new XMIResourceImpl();
- resource.getContents().add(ePackage);
-
- try
- {
- resource.save(stream, null);
- ecore = stream.toString();
- }
- catch (RuntimeException ex)
- {
- throw ex;
- }
- catch (IOException ex)
- {
- throw new IORuntimeException(ex);
- }
- finally
- {
- resource.getContents().clear();
- }
- }
+ String packageURI = ePackage.getNsURI();
+ String name = ePackage.getName();
+ boolean dynamic = EMFUtil.isDynamicEPackage(ePackage);
+ String ecore = dynamic ? EMFUtil.ePackageToString(ePackage) : null;
- CDOPackageImpl cdoPackage = new CDOPackageImpl(packageManager, ePackage.getNsURI(), ePackage.getName(), ecore);
+ CDOPackageImpl cdoPackage = new CDOPackageImpl(packageManager, packageURI, name, ecore, dynamic);
cdoPackage.setClientInfo(ePackage);
for (EClass eClass : EMFUtil.getPersistentClasses(ePackage))
{
@@ -246,25 +217,10 @@ public final class ModelUtil
private static EPackage createEPackage(CDOPackageImpl cdoPackage)
{
- byte[] ecore = cdoPackage.getEcore().getBytes();// TODO Use ASCII charset?
- ByteArrayInputStream stream = new ByteArrayInputStream(ecore);
- XMIResource resource = new XMIResourceImpl();
-
- try
- {
- resource.load(stream, null);
- EPackageImpl ePackage = (EPackageImpl)resource.getContents().get(0);
- prepareEPackage(ePackage);
- return ePackage;
- }
- catch (RuntimeException ex)
- {
- throw ex;
- }
- catch (IOException ex)
- {
- throw new IORuntimeException(ex);
- }
+ String ecore = cdoPackage.getEcore();
+ EPackageImpl ePackage = (EPackageImpl)EMFUtil.ePackageFromString(ecore);
+ prepareEPackage(ePackage);
+ return ePackage;
}
public static void prepareEPackage(EPackageImpl ePackage)