summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-17 16:53:28 (EDT)
committerEike Stepper2007-07-17 16:53:28 (EDT)
commit1edfe35a59a4f30f7f76e31f8bb15560c2a1e0c8 (patch)
treea0a86057fa601e692d5ec14dbd82058804299f30
parentca5c83aa15abe52e0a2ff24a00d06fe50d7563f0 (diff)
downloadcdo-1edfe35a59a4f30f7f76e31f8bb15560c2a1e0c8.zip
cdo-1edfe35a59a4f30f7f76e31f8bb15560c2a1e0c8.tar.gz
cdo-1edfe35a59a4f30f7f76e31f8bb15560c2a1e0c8.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java13
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java179
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java6
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java42
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionPackageManager.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java17
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java (renamed from plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFUtil.java)376
13 files changed, 384 insertions, 277 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java
index 56532b4..f3b8f46 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.internal.server.RevisionManager;
import org.eclipse.emf.cdo.internal.server.bundle.OM;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
@@ -39,7 +40,7 @@ public class CommitTransactionIndication extends CDOServerIndication
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_REVISION, CommitTransactionIndication.class);
- private CDOPackageImpl[] newPackages;
+ private CDOPackage[] newPackages;
private CDORevisionImpl[] newResources;
@@ -65,7 +66,7 @@ public class CommitTransactionIndication extends CDOServerIndication
dirtyObjects = readDirtyObjects(in);
}
- private CDOPackageImpl[] readNewPackages(ExtendedDataInputStream in) throws IOException
+ private CDOPackage[] readNewPackages(ExtendedDataInputStream in) throws IOException
{
int size = in.readInt();
if (PROTOCOL.isEnabled())
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java
index 6e3b6ef..8cce108 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java
@@ -10,7 +10,6 @@
**************************************************************************/
package org.eclipse.emf.cdo.internal.server.protocol;
-import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.internal.server.Repository;
import org.eclipse.emf.cdo.internal.server.RepositoryManager;
import org.eclipse.emf.cdo.internal.server.RepositoryPackageManager;
@@ -18,6 +17,7 @@ import org.eclipse.emf.cdo.internal.server.Session;
import org.eclipse.emf.cdo.internal.server.SessionManager;
import org.eclipse.emf.cdo.internal.server.bundle.OM;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.RepositoryNotFoundException;
@@ -119,8 +119,8 @@ public class OpenSessionIndication extends IndicationWithResponse
private void writePackageURIs(ExtendedDataOutputStream out, RepositoryPackageManager packageManager)
throws IOException
{
- CDOPackageImpl[] packages = packageManager.getPackages();
- for (CDOPackageImpl p : packages)
+ CDOPackage[] packages = packageManager.getPackages();
+ for (CDOPackage p : packages)
{
if (!p.isSystem())
{
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
index 378ee18..4d4f964 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
@@ -36,7 +36,6 @@ import org.eclipse.emf.common.ui.viewer.IViewerProvider;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.resource.Resource;
@@ -63,7 +62,6 @@ import org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider;
import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper;
import org.eclipse.emf.edit.ui.util.EditUIUtil;
import org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage;
-import org.eclipse.emf.internal.cdo.util.EMFUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -2211,8 +2209,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
if (resource != null)
{
- EClass eClass = EMFUtil.getEClass(cdoClass);
- EObject object = EcoreUtil.create(eClass);
+ CDOObject object = view.newInstance(cdoClass);
resource.getContents().add(object);
}
}
diff --git a/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
index cfb886b..7ab59a5 100644
--- a/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
@@ -18,5 +18,6 @@ Export-Package: org.eclipse.emf.cdo;version="0.8.0",
org.eclipse.emf.internal.cdo.util;version="0.8.0"
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport,
+ org.eclipse.emf.ecore.xmi,
org.eclipse.emf.cdo.protocol;bundle-version="0.8.0";visibility:=reexport
Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
index 25ceecc..3435dd0 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.net4j.util.event.INotifier;
@@ -53,6 +54,8 @@ public interface CDOView extends INotifier
public CDOObject newInstance(EClass eClass);
+ public CDOObject newInstance(CDOClass cdoClass);
+
public CDORevision getRevision(CDOID id);
public boolean isDirty();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index 4557bf6..97f9107 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -27,14 +27,11 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.impl.EFactoryImpl;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
-import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import java.util.Map;
@@ -149,22 +146,12 @@ public final class CDOUtil
return URI.createURI(CDOProtocolConstants.PROTOCOL_NAME + ":" + path);
}
- public static void prepareEPackage(EPackage ePackage)
- {
- EFactory factory = ePackage.getEFactoryInstance();
- if (factory == null || factory.getClass() == EFactoryImpl.class)
- {
- ePackage.setEFactoryInstance(new CDOFactoryImpl(ePackage));
- }
- }
-
public static EPackage createEPackage(String name, String nsPrefix, String nsURI)
{
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName(name);
ePackage.setNsPrefix(nsPrefix);
ePackage.setNsURI(nsURI);
- prepareEPackage(ePackage);
return ePackage;
}
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
new file mode 100644
index 0000000..9e3bca5
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
@@ -0,0 +1,179 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 Eike Stepper, Germany.
+ * 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.util;
+
+import org.eclipse.net4j.util.ReflectUtil;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+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.internal.cdo.bundle.OM;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * @author Eike Stepper
+ */
+public final class EMFUtil
+{
+ private EMFUtil()
+ {
+ }
+
+ public static List<EClass> getPersistentClasses(EPackage ePackage)
+ {
+ List<EClass> result = new ArrayList();
+ for (EClassifier classifier : ePackage.getEClassifiers())
+ {
+ if (classifier instanceof EClass)
+ {
+ result.add((EClass)classifier);
+ }
+ }
+
+ return result;
+ }
+
+ public static List<EStructuralFeature> getPersistentFeatures(EList<EStructuralFeature> eFeatues)
+ {
+ List<EStructuralFeature> result = new ArrayList();
+ for (EStructuralFeature feature : eFeatues)
+ {
+ if (!feature.isTransient())
+ {
+ result.add(feature);
+ }
+ }
+
+ return result;
+ }
+
+ public static boolean isDynamicPackage(EPackage ePackage)
+ {
+ return ePackage.getClass() == EPackageImpl.class;
+ }
+
+ public static boolean isMany(EStructuralFeature eFeature)
+ {
+ return eFeature.isMany();
+ }
+
+ public static boolean isReference(EStructuralFeature eFeature)
+ {
+ return eFeature instanceof EReference;
+ }
+
+ public static boolean isContainment(EStructuralFeature eFeature)
+ {
+ if (isReference(eFeature))
+ {
+ EReference ref = (EReference)eFeature;
+ return ref.isContainment();
+ }
+
+ return false;
+ }
+
+ /**
+ * TODO Remove when EMF has fixed this
+ */
+ public static void fixEClassifiers(EPackageImpl ePackage)
+ {
+ try
+ {
+ Method method = EPackageImpl.class.getDeclaredMethod("fixEClassifiers", ReflectUtil.NO_PARAMETERS);
+ if (!method.isAccessible())
+ {
+ method.setAccessible(true);
+ }
+
+ method.invoke(ePackage, ReflectUtil.NO_ARGUMENTS);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
+ // public static List<Change> analyzeListDifferences(CDORevisionImpl
+ // oldRevision,
+ // CDORevisionImpl newRevision, CDOFeatureImpl feature)
+ // {
+ // if (!feature.isMany())
+ // {
+ // throw new IllegalArgumentException("Feature is not many: " + feature);
+ // }
+ //
+ // final List<Object> oldList = (List)oldRevision.getValue(feature);
+ // final List newList = (List)newRevision.getValue(feature);
+ // final List<Change> changes = new ArrayList(0);
+ //
+ // new ECollections.ListDifferenceAnalyzer()
+ // {
+ // @Override
+ // protected void add(List<Object> oldList, Object newObject, int index)
+ // {
+ // changes.add(new AddChange(newObject, index));
+ // }
+ //
+ // @Override
+ // protected void remove(List<?> oldList, int index)
+ // {
+ // changes.add(new RemoveChange(index));
+ // }
+ //
+ // @Override
+ // protected void move(List<?> oldList, int index, int toIndex)
+ // {
+ // changes.add(new MoveChange(index, toIndex));
+ // }
+ // }.createListChanges(oldList, newList);
+ //
+ // return changes;
+ // }
+ //
+ // /**
+ // * @author Eike Stepper
+ // */
+ // public static class MoveChange implements FeatureChange
+ // {
+ // public MoveChange(int index, int toIndex)
+ // {
+ // }
+ // }
+ //
+ // /**
+ // * @author Eike Stepper
+ // */
+ // public static class RemoveChange implements FeatureChange
+ // {
+ // public RemoveChange(int index)
+ // {
+ // }
+ // }
+ //
+ // /**
+ // * @author Eike Stepper
+ // */
+ // public static class AddChange implements FeatureChange
+ // {
+ // public AddChange(Object newObject, int index)
+ // {
+ // }
+ // }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index eff2d2d..aa169ae 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -30,7 +30,7 @@ import org.eclipse.emf.ecore.impl.EStoreEObjectImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Internal;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.util.EMFUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
/**
* @author Eike Stepper
@@ -63,7 +63,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements CDOObject
}
CDOSessionPackageManager packageManager = view.getSession().getPackageManager();
- return EMFUtil.getCDOClass(eClass(), packageManager);
+ return ModelUtil.getCDOClass(eClass(), packageManager);
}
public CDOID cdoID()
@@ -235,7 +235,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements CDOObject
private void finalizeRevisionFeature(CDOViewImpl view, CDORevisionImpl revision, int i, Object setting,
EStructuralFeature eFeature)
{
- CDOFeatureImpl cdoFeature = EMFUtil.getCDOFeature(eFeature, cdoView().getSession().getPackageManager());
+ CDOFeatureImpl cdoFeature = ModelUtil.getCDOFeature(eFeature, cdoView().getSession().getPackageManager());
if (TRACER.isEnabled())
{
TRACER.format("Finalizing feature {0}", cdoFeature);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
index da79d10..af7e98e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
@@ -12,18 +12,15 @@ package org.eclipse.emf.internal.cdo;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.util.CDOPackageRegistry;
-
-import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.emf.cdo.util.EMFUtil;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.util.EMFUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
-import java.lang.reflect.Method;
import java.util.Map;
/**
@@ -62,13 +59,12 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
public Object put(String key, Object value)
{
EPackage ePackage = (EPackage)value;
- if (isDynamicPackage(ePackage))
+ if (EMFUtil.isDynamicPackage(ePackage))
{
EPackageImpl copy = (EPackageImpl)EcoreUtil.copy(ePackage);
- copy.setEFactoryInstance(createCDOFactory(copy));
- fixEClassifiers(copy);
+ ModelUtil.prepareEPackage(copy);
- CDOPackageImpl cdoPackage = EMFUtil.getCDOPackage(copy, session.getPackageManager());
+ CDOPackageImpl cdoPackage = ModelUtil.getCDOPackage(copy, session.getPackageManager());
cdoPackage.setPersistent(false);
ePackage = copy;
@@ -87,32 +83,4 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
{
throw new UnsupportedOperationException();
}
-
- protected CDOFactoryImpl createCDOFactory(EPackage ePackage)
- {
- return new CDOFactoryImpl(ePackage);
- }
-
- private static boolean isDynamicPackage(EPackage ePackage)
- {
- return ePackage.getClass() == EPackageImpl.class;
- }
-
- private static void fixEClassifiers(EPackageImpl ePackage)
- {
- try
- {
- Method method = EPackageImpl.class.getDeclaredMethod("fixEClassifiers", ReflectUtil.NO_PARAMETERS);
- if (!method.isAccessible())
- {
- method.setAccessible(true);
- }
-
- method.invoke(ePackage, ReflectUtil.NO_ARGUMENTS);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- }
}
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 17e916e..a762801 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
@@ -15,7 +15,7 @@ import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageManagerImpl;
import org.eclipse.emf.cdo.protocol.util.TransportException;
import org.eclipse.emf.internal.cdo.protocol.LoadPackageRequest;
-import org.eclipse.emf.internal.cdo.util.EMFUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
import java.util.Collection;
@@ -29,7 +29,7 @@ public class CDOSessionPackageManager extends CDOPackageManagerImpl
public CDOSessionPackageManager(CDOSessionImpl session)
{
this.session = session;
- EMFUtil.addModelInfos(this);
+ ModelUtil.addModelInfos(this);
}
public CDOSessionImpl getSession()
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
index 8822eeb..79b5512 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
@@ -26,7 +26,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.InternalEObject.EStore;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.util.EMFUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
/**
* @author Eike Stepper
@@ -420,7 +420,7 @@ public final class CDOStore implements EStore
}
CDOPackageManagerImpl packageManager = view.getSession().getPackageManager();
- return EMFUtil.getCDOFeature(eFeature, packageManager);
+ return ModelUtil.getCDOFeature(eFeature, packageManager);
}
private static CDORevisionImpl getRevisionForReading(CDOObjectImpl cdoObject)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 0cc8856..28e174a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.CDOViewResourcesEvent;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.EresourceFactory;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
@@ -42,7 +43,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
-import org.eclipse.emf.internal.cdo.util.EMFUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
import java.text.MessageFormat;
import java.util.Date;
@@ -198,7 +199,12 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
public CDOObjectImpl newInstance(CDOClass cdoClass)
{
- EClass eClass = EMFUtil.getEClass(cdoClass);
+ EClass eClass = ModelUtil.getEClass((CDOClassImpl)cdoClass, session.getPackageRegistry());
+ if (eClass == null)
+ {
+ throw new IllegalStateException("No EClass for " + cdoClass);
+ }
+
return newInstance(eClass);
}
@@ -220,11 +226,6 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
return lastLookupObject;
}
- // if (TRACER.isEnabled())
- // {
- // TRACER.format("Looking up object {0}", id);
- // }
-
lastLookupID = id;
lastLookupObject = objects.get(id);
if (lastLookupObject == null)
@@ -504,7 +505,7 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
}
CDORevisionImpl revision = getRevision(id);
- CDOClass cdoClass = revision.getCDOClass();
+ CDOClassImpl cdoClass = revision.getCDOClass();
CDOID resourceID = revision.getResourceID();
CDOObjectImpl object = newInstance(cdoClass);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
index dedddce..6c98bc2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
@@ -21,90 +21,33 @@ import org.eclipse.emf.cdo.internal.protocol.model.CDOTypeImpl;
import org.eclipse.emf.cdo.internal.protocol.model.core.CDOCorePackageImpl;
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.protocol.model.CDOClass;
-import org.eclipse.emf.cdo.protocol.model.CDOFeature;
-import org.eclipse.emf.cdo.protocol.model.CDOPackage;
-import org.eclipse.emf.cdo.protocol.util.ImplementationError;
+import org.eclipse.emf.cdo.util.EMFUtil;
+
+import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
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.util.ArrayList;
-import java.util.List;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
/**
* @author Eike Stepper
*/
-public final class EMFUtil
+public final class ModelUtil
{
- private EMFUtil()
- {
- }
-
- public static CDOClassRefImpl createClassRef(EClassifier classifier)
- {
- if (classifier instanceof EClass)
- {
- String packageURI = classifier.getEPackage().getNsURI();
- int classifierID = classifier.getClassifierID();
- return new CDOClassRefImpl(packageURI, classifierID);
- }
-
- return null;
- }
-
- public static List<EClass> getPersistentClasses(EPackage ePackage)
+ private ModelUtil()
{
- List<EClass> result = new ArrayList();
- for (EClassifier classifier : ePackage.getEClassifiers())
- {
- if (classifier instanceof EClass)
- {
- result.add((EClass)classifier);
- }
- }
-
- return result;
- }
-
- public static List<EStructuralFeature> getPersistentFeatures(EList<EStructuralFeature> eFeatues)
- {
- List<EStructuralFeature> result = new ArrayList();
- for (EStructuralFeature feature : eFeatues)
- {
- if (!feature.isTransient())
- {
- result.add(feature);
- }
- }
-
- return result;
- }
-
- public static boolean isMany(EStructuralFeature eFeature)
- {
- return eFeature.isMany();
- }
-
- public static boolean isReference(EStructuralFeature eFeature)
- {
- return eFeature instanceof EReference;
- }
-
- public static boolean isContainment(EStructuralFeature eFeature)
- {
- if (isReference(eFeature))
- {
- EReference ref = (EReference)eFeature;
- return ref.isContainment();
- }
-
- return false;
}
public static CDOTypeImpl getCDOType(EStructuralFeature eFeature)
@@ -150,7 +93,7 @@ public final class EMFUtil
CDOPackageImpl cdoPackage = packageManager.lookupPackage(packageURI);
if (cdoPackage == null)
{
- cdoPackage = convertPackage(ePackage, packageManager);
+ cdoPackage = createCDOPackage(ePackage, packageManager);
packageManager.addPackage(cdoPackage);
}
@@ -169,67 +112,46 @@ public final class EMFUtil
return cdoClass.lookupFeature(eFeature.getFeatureID());
}
- public static EPackage getEPackage(CDOPackage cdoPackage)
+ private static CDOPackageImpl createCDOPackage(EPackage ePackage, CDOPackageManagerImpl packageManager)
{
- return (EPackage)cdoPackage.getClientInfo();
- }
-
- public static EClass getEClass(CDOClass cdoClass)
- {
- return (EClass)cdoClass.getClientInfo();
- }
-
- public static EStructuralFeature getEFeature(CDOFeature cdoFeature)
- {
- return (EStructuralFeature)cdoFeature.getClientInfo();
- }
-
- public static void addModelInfos(CDOPackageManagerImpl packageManager)
- {
- // Ecore
- CDOCorePackageImpl corePackage = packageManager.getCDOCorePackage();
- corePackage.setClientInfo(EcorePackage.eINSTANCE);
- corePackage.getCDOObjectClass().setClientInfo(EcorePackage.eINSTANCE.getEObject());
-
- // Eresource
- CDOResourcePackageImpl resourcePackage = packageManager.getCDOResourcePackage();
- resourcePackage.setClientInfo(EresourcePackage.eINSTANCE);
- CDOResourceClassImpl resourceClass = resourcePackage.getCDOResourceClass();
- resourceClass.setClientInfo(EresourcePackage.eINSTANCE.getCDOResource());
- resourceClass.getCDOContentsFeature().setClientInfo(EresourcePackage.eINSTANCE.getCDOResource_Contents());
- resourceClass.getCDOPathFeature().setClientInfo(EresourcePackage.eINSTANCE.getCDOResource_Path());
- }
-
- public static void removeModelInfos(CDOPackageManagerImpl packageManager)
- {
- // Ecore
- CDOCorePackageImpl corePackage = packageManager.getCDOCorePackage();
- corePackage.setClientInfo(null);
- corePackage.getCDOObjectClass().setClientInfo(null);
+ String ecore = null;
+ if (EMFUtil.isDynamicPackage(ePackage))
+ {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ XMIResource resource = new XMIResourceImpl();
+ resource.getContents().add(ePackage);
- // Eresource
- CDOResourcePackageImpl resourcePackage = packageManager.getCDOResourcePackage();
- resourcePackage.setClientInfo(null);
- CDOResourceClassImpl resourceClass = resourcePackage.getCDOResourceClass();
- resourceClass.setClientInfo(null);
- resourceClass.getCDOContentsFeature().setClientInfo(null);
- resourceClass.getCDOPathFeature().setClientInfo(null);
- }
+ try
+ {
+ resource.save(stream, null);
+ ecore = stream.toString();
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ resource.getContents().clear();
+ }
+ }
- private static CDOPackageImpl convertPackage(EPackage ePackage, CDOPackageManagerImpl packageManager)
- {
- CDOPackageImpl cdoPackage = new CDOPackageImpl(packageManager, ePackage.getNsURI(), ePackage.getName());
+ CDOPackageImpl cdoPackage = new CDOPackageImpl(packageManager, ePackage.getNsURI(), ePackage.getName(), ecore);
cdoPackage.setClientInfo(ePackage);
- for (EClass eClass : getPersistentClasses(ePackage))
+ for (EClass eClass : EMFUtil.getPersistentClasses(ePackage))
{
- CDOClassImpl cdoClass = convertClass(cdoPackage, eClass, packageManager);
+ CDOClassImpl cdoClass = createCDOClass(cdoPackage, eClass, packageManager);
cdoPackage.addClass(cdoClass);
}
return cdoPackage;
}
- private static CDOClassImpl convertClass(CDOPackageImpl containingPackage, EClass eClass,
+ private static CDOClassImpl createCDOClass(CDOPackageImpl containingPackage, EClass eClass,
CDOPackageManagerImpl packageManager)
{
CDOClassImpl cdoClass = new CDOClassImpl(containingPackage, eClass.getClassifierID(), eClass.getName(), eClass
@@ -242,9 +164,9 @@ public final class EMFUtil
// cdoClass.addSuperType(classRef);
// }
- for (EStructuralFeature eFeature : getPersistentFeatures(eClass.getEStructuralFeatures()))
+ for (EStructuralFeature eFeature : EMFUtil.getPersistentFeatures(eClass.getEStructuralFeatures()))
{
- CDOFeatureImpl cdoFeature = convertFeature(cdoClass, eFeature, packageManager);
+ CDOFeatureImpl cdoFeature = createCDOFeature(cdoClass, eFeature, packageManager);
cdoClass.addFeature(cdoFeature);
}
@@ -253,137 +175,185 @@ public final class EMFUtil
return cdoClass;
}
- private static CDOFeatureImpl convertFeature(CDOClassImpl containingClass, EStructuralFeature eFeature,
+ private static CDOFeatureImpl createCDOFeature(CDOClassImpl containingClass, EStructuralFeature eFeature,
CDOPackageManagerImpl packageManager)
{
- CDOFeatureImpl cdoFeature = isReference(eFeature) ? convertReference(containingClass, eFeature, packageManager)
- : convertAttribute(containingClass, eFeature);
+ CDOFeatureImpl cdoFeature = EMFUtil.isReference(eFeature) ? createCDOReference(containingClass, eFeature, packageManager)
+ : createCDOAttribute(containingClass, eFeature);
cdoFeature.setClientInfo(eFeature);
return cdoFeature;
}
- private static CDOFeatureImpl convertReference(CDOClassImpl containingClass, EStructuralFeature eFeature,
+ private static CDOFeatureImpl createCDOReference(CDOClassImpl containingClass, EStructuralFeature eFeature,
CDOPackageManagerImpl packageManager)
{
int featureID = eFeature.getFeatureID();
String name = eFeature.getName();
CDOClassRefImpl classRef = createClassRef(eFeature.getEType());
boolean many = eFeature.isMany();
- boolean containment = isContainment(eFeature);
+ boolean containment = EMFUtil.isContainment(eFeature);
return new CDOFeatureImpl(containingClass, featureID, name, new CDOClassProxy(classRef, packageManager), many,
containment);
}
- private static CDOFeatureImpl convertAttribute(CDOClassImpl containingClass, EStructuralFeature eFeature)
+ private static CDOFeatureImpl createCDOAttribute(CDOClassImpl containingClass, EStructuralFeature eFeature)
{
int featureID = eFeature.getFeatureID();
String name = eFeature.getName();
CDOTypeImpl type = getCDOType(eFeature);
- boolean many = isMany(eFeature);
+ boolean many = EMFUtil.isMany(eFeature);
return new CDOFeatureImpl(containingClass, featureID, name, type, many);
}
- private static void initAllSuperTypes(CDOClassImpl cdoClass, CDOPackageManagerImpl packageManager)
+ public static EPackage getEPackage(CDOPackageImpl cdoPackage, CDOPackageRegistryImpl packageRegistry)
{
- EClass eClass = getEClass(cdoClass);
- EList<EClass> eClasses = eClass.getEAllSuperTypes();
- CDOClassImpl[] allSuperTypes = new CDOClassImpl[eClasses.size()];
+ EPackage ePackage = (EPackage)cdoPackage.getClientInfo();
+ if (ePackage == null)
+ {
+ ePackage = createEPackage(cdoPackage);
+ packageRegistry.internalPut(ePackage.getNsURI(), ePackage);
+ cdoPackage.setClientInfo(ePackage);
+ }
+
+ return ePackage;
+ }
- int i = 0;
- for (EClass superEClass : eClasses)
+ public static EClass getEClass(CDOClassImpl cdoClass, CDOPackageRegistryImpl packageRegistry)
+ {
+ EClass eClass = (EClass)cdoClass.getClientInfo();
+ if (eClass == null)
{
- CDOClassImpl superType = getCDOClass(superEClass, packageManager);
- allSuperTypes[i++] = superType;
+ EPackage ePackage = getEPackage(cdoClass.getContainingPackage(), packageRegistry);
+ eClass = (EClass)ePackage.getEClassifier(cdoClass.getName());
+ cdoClass.setClientInfo(eClass);
}
- cdoClass.setAllSuperTypes(allSuperTypes);
+ return eClass;
}
- private static void initAllFeatures(CDOClassImpl cdoClass, CDOPackageManagerImpl packageManager)
+ public static EStructuralFeature getEFeature(CDOFeatureImpl cdoFeature, CDOPackageRegistryImpl packageRegistry)
{
- EClass eClass = getEClass(cdoClass);
- List<EStructuralFeature> eFeatures = getPersistentFeatures(eClass.getEAllStructuralFeatures());
- CDOFeatureImpl[] allFeatures = new CDOFeatureImpl[eFeatures.size()];
+ EStructuralFeature eFeature = (EStructuralFeature)cdoFeature.getClientInfo();
+ if (eFeature == null)
+ {
+ EClass eClass = getEClass(cdoFeature.getContainingClass(), packageRegistry);
+ eFeature = eClass.getEStructuralFeature(cdoFeature.getFeatureID());
+ cdoFeature.setClientInfo(eFeature);
+ }
+
+ return eFeature;
+ }
+
+ private static EPackage createEPackage(CDOPackageImpl cdoPackage)
+ {
+ byte[] ecore = cdoPackage.getEcore().getBytes();// TODO Use ASCII charset?
+ ByteArrayInputStream stream = new ByteArrayInputStream(ecore);
+ XMIResource resource = new XMIResourceImpl();
- int i = 0;
- for (EStructuralFeature eFeature : eFeatures)
+ try
{
- CDOFeatureImpl cdoFeature = getCDOFeature(eFeature, packageManager);
- if (cdoFeature.getFeatureID() != i)
- {
- throw new ImplementationError("Wrong featureID: " + cdoFeature);
- }
+ 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);
+ }
+ }
+
+ public static void prepareEPackage(EPackageImpl ePackage)
+ {
+ ePackage.setEFactoryInstance(new CDOFactoryImpl(ePackage));
+ EMFUtil.fixEClassifiers(ePackage);
+ }
- allFeatures[i++] = cdoFeature;
+ public static CDOClassRefImpl createClassRef(EClassifier classifier)
+ {
+ if (classifier instanceof EClass)
+ {
+ String packageURI = classifier.getEPackage().getNsURI();
+ int classifierID = classifier.getClassifierID();
+ return new CDOClassRefImpl(packageURI, classifierID);
}
- cdoClass.setAllFeatures(allFeatures);
+ return null;
}
- // public static List<Change> analyzeListDifferences(CDORevisionImpl
- // oldRevision,
- // CDORevisionImpl newRevision, CDOFeatureImpl feature)
- // {
- // if (!feature.isMany())
+ public static void addModelInfos(CDOPackageManagerImpl packageManager)
+ {
+ // Ecore
+ CDOCorePackageImpl corePackage = packageManager.getCDOCorePackage();
+ corePackage.setClientInfo(EcorePackage.eINSTANCE);
+ corePackage.getCDOObjectClass().setClientInfo(EcorePackage.eINSTANCE.getEObject());
+
+ // Eresource
+ CDOResourcePackageImpl resourcePackage = packageManager.getCDOResourcePackage();
+ resourcePackage.setClientInfo(EresourcePackage.eINSTANCE);
+ CDOResourceClassImpl resourceClass = resourcePackage.getCDOResourceClass();
+ resourceClass.setClientInfo(EresourcePackage.eINSTANCE.getCDOResource());
+ resourceClass.getCDOContentsFeature().setClientInfo(EresourcePackage.eINSTANCE.getCDOResource_Contents());
+ resourceClass.getCDOPathFeature().setClientInfo(EresourcePackage.eINSTANCE.getCDOResource_Path());
+ }
+
+ public static void removeModelInfos(CDOPackageManagerImpl packageManager)
+ {
+ // Ecore
+ CDOCorePackageImpl corePackage = packageManager.getCDOCorePackage();
+ corePackage.setClientInfo(null);
+ corePackage.getCDOObjectClass().setClientInfo(null);
+
+ // Eresource
+ CDOResourcePackageImpl resourcePackage = packageManager.getCDOResourcePackage();
+ resourcePackage.setClientInfo(null);
+ CDOResourceClassImpl resourceClass = resourcePackage.getCDOResourceClass();
+ resourceClass.setClientInfo(null);
+ resourceClass.getCDOContentsFeature().setClientInfo(null);
+ resourceClass.getCDOPathFeature().setClientInfo(null);
+ }
+
+ // private static void initAllSuperTypes(CDOClassImpl cdoClass,
+ // CDOPackageManagerImpl packageManager)
// {
- // throw new IllegalArgumentException("Feature is not many: " + feature);
- // }
+ // EClass eClass = getEClass(cdoClass);
+ // EList<EClass> eClasses = eClass.getEAllSuperTypes();
+ // CDOClassImpl[] allSuperTypes = new CDOClassImpl[eClasses.size()];
//
- // final List<Object> oldList = (List)oldRevision.getValue(feature);
- // final List newList = (List)newRevision.getValue(feature);
- // final List<Change> changes = new ArrayList(0);
- //
- // new ECollections.ListDifferenceAnalyzer()
- // {
- // @Override
- // protected void add(List<Object> oldList, Object newObject, int index)
+ // int i = 0;
+ // for (EClass superEClass : eClasses)
// {
- // changes.add(new AddChange(newObject, index));
+ // CDOClassImpl superType = getCDOClass(superEClass, packageManager);
+ // allSuperTypes[i++] = superType;
// }
//
- // @Override
- // protected void remove(List<?> oldList, int index)
- // {
- // changes.add(new RemoveChange(index));
+ // cdoClass.setAllSuperTypes(allSuperTypes);
// }
- //
- // @Override
- // protected void move(List<?> oldList, int index, int toIndex)
+
+ // private static void initAllFeatures(CDOClassImpl cdoClass,
+ // CDOPackageManagerImpl packageManager)
// {
- // changes.add(new MoveChange(index, toIndex));
- // }
- // }.createListChanges(oldList, newList);
- //
- // return changes;
- // }
+ // EClass eClass = getEClass(cdoClass);
+ // List<EStructuralFeature> eFeatures =
+ // getPersistentFeatures(eClass.getEAllStructuralFeatures());
+ // CDOFeatureImpl[] allFeatures = new CDOFeatureImpl[eFeatures.size()];
//
- // /**
- // * @author Eike Stepper
- // */
- // public static class MoveChange implements FeatureChange
+ // int i = 0;
+ // for (EStructuralFeature eFeature : eFeatures)
// {
- // public MoveChange(int index, int toIndex)
+ // CDOFeatureImpl cdoFeature = getCDOFeature(eFeature, packageManager);
+ // if (cdoFeature.getFeatureID() != i)
// {
- // }
+ // throw new ImplementationError("Wrong featureID: " + cdoFeature);
// }
//
- // /**
- // * @author Eike Stepper
- // */
- // public static class RemoveChange implements FeatureChange
- // {
- // public RemoveChange(int index)
- // {
- // }
+ // allFeatures[i++] = cdoFeature;
// }
//
- // /**
- // * @author Eike Stepper
- // */
- // public static class AddChange implements FeatureChange
- // {
- // public AddChange(Object newObject, int index)
- // {
- // }
+ // cdoClass.setAllFeatures(allFeatures);
// }
}