Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2009-05-07 03:54:13 -0400
committerEike Stepper2009-05-07 03:54:13 -0400
commitcaee5708555502d1e162eb336a4684a4a05786ac (patch)
treec8d7946beed533a023120c1d08bee7748daf5a1d
parentb882ed3d43cf05ad46d11130594a4fde75162975 (diff)
downloadcdo-caee5708555502d1e162eb336a4684a4a05786ac.tar.gz
cdo-caee5708555502d1e162eb336a4684a4a05786ac.tar.xz
cdo-caee5708555502d1e162eb336a4684a4a05786ac.zip
[247226] Transparently support legacy models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247226
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/UMLTest.launch19
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/UMLTest.java85
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java24
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/ModelUtil.java59
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java37
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java91
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java73
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java45
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java63
13 files changed, 324 insertions, 203 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
index ec939d5c1e..592e2fed85 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
@@ -4,7 +4,7 @@
* 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
* Victor Roldan Betancort - maintenance
@@ -54,6 +54,18 @@ public final class EMFUtil
{
}
+ public static EPackage getGeneratedEPackage(EPackage ePackage)
+ {
+ String packageURI = ePackage.getNsURI();
+ if (packageURI.equals(EcorePackage.eINSTANCE.getNsURI()))
+ {
+ return EcorePackage.eINSTANCE;
+ }
+
+ EPackage.Registry registry = EPackage.Registry.INSTANCE;
+ return registry.getEPackage(packageURI);
+ }
+
public static Map.Entry<String, Object>[] getSortedRegistryEntries(EPackage.Registry packageRegistry)
{
Set<Map.Entry<String, Object>> entries = packageRegistry.entrySet();
diff --git a/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
index 089d6834b6..75f79d5b1e 100644
--- a/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.tests/META-INF/MANIFEST.MF
@@ -24,7 +24,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.cdo.tests.model4interfaces;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.tests.model5;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.defs;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
- org.junit;bundle-version="[3.8.0,4.0.0)";visibility:=reexport
+ org.junit;bundle-version="[3.8.0,4.0.0)";visibility:=reexport,
+ org.eclipse.uml2.uml;bundle-version="[3.0.0,4.0.0)";resolution:=optional
Export-Package: base;version="2.0.0",
base.impl;version="2.0.0",
base.util;version="2.0.0",
diff --git a/plugins/org.eclipse.emf.cdo.tests/UMLTest.launch b/plugins/org.eclipse.emf.cdo.tests/UMLTest.launch
new file mode 100644
index 0000000000..fbd3d5b385
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/UMLTest.launch
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/UMLTest.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.UMLTest"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
index e94ea7b52d..adb01fd345 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
@@ -21,6 +21,7 @@ import org.eclipse.emf.cdo.tests.model2.SpecialPurchaseOrder;
import org.eclipse.emf.cdo.tests.model2.Task;
import org.eclipse.emf.cdo.tests.model2.TaskContainer;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -554,6 +555,8 @@ public class ContainmentTest extends AbstractCDOTest
schoolPackage.setNsPrefix("elv");
schoolPackage.setNsURI("http:///www.elver.org/School");
schoolPackage.getEClassifiers().add(schoolBookEClass);
+
+ CDOUtil.prepareDynamicEPackage(schoolPackage);
return schoolPackage;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
index 36b7873fdd..e4ba8bada7 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
@@ -4,7 +4,7 @@
* 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
*/
@@ -30,8 +30,7 @@ import org.eclipse.emf.cdo.tests.model3.Model3Package;
import org.eclipse.emf.cdo.tests.model3.subpackage.Class2;
import org.eclipse.emf.cdo.tests.model3.subpackage.SubpackageFactory;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
-
-import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
+import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
@@ -307,7 +306,7 @@ public class PackageRegistryTest extends AbstractCDOTest
c.setName("DClass");
p.getEClassifiers().add(c);
- CDOFactoryImpl.prepareDynamicEPackage(p);
+ CDOUtil.prepareDynamicEPackage(p);
EPackage.Registry.INSTANCE.put(nsURI, p);
CDOSession session = openSession();
@@ -355,9 +354,9 @@ public class PackageRegistryTest extends AbstractCDOTest
transaction.commit();
session.close();
- fail("Expected: UnsupportedOperationException: Legacy models not supported");
+ fail("Expected: IllegalArgumentException: Use CDOFactory to create dynamic object");
}
- catch (UnsupportedOperationException success)
+ catch (IllegalArgumentException success)
{
// SUCCESS
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/UMLTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/UMLTest.java
new file mode 100644
index 0000000000..fa45e24c06
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/UMLTest.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2004 - 2009 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.tests;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.emf.internal.cdo.CDOLegacyWrapper;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.UMLFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class UMLTest extends AbstractCDOTest
+{
+ public void testCommit() throws Exception
+ {
+ Class umlClass = UMLFactory.eINSTANCE.createClass();
+ umlClass.setName("TestClass");
+ umlClass.setIsAbstract(false);
+ // TODO umlClass.setVisibility(VisibilityKind.PUBLIC_LITERAL);
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/test1");
+ resource.getContents().add(umlClass);
+ transaction.commit();
+
+ CDOObject cdoClass = CDOUtil.getCDOObject(umlClass);
+ assertEquals(false, CDOLegacyWrapper.isLegacyProxy(cdoClass));
+ assertEquals(CDOState.CLEAN, cdoClass.cdoState());
+ assertEquals(CDOState.CLEAN, resource.cdoState());
+ session.close();
+ }
+
+ public void testLoad() throws Exception
+ {
+ {
+ Class umlClass = UMLFactory.eINSTANCE.createClass();
+ umlClass.setName("TestClass");
+ umlClass.setIsAbstract(false);
+ // TODO umlClass.setVisibility(VisibilityKind.PUBLIC_LITERAL);
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/test1");
+ resource.getContents().add(umlClass);
+ transaction.commit();
+ session.close();
+ }
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getResource("/test1");
+ EList<EObject> contents = resource.getContents();
+
+ Class umlClass = (Class)contents.get(0);
+ CDOObject cdoClass = CDOUtil.getCDOObject(umlClass);
+ assertEquals(false, CDOLegacyWrapper.isLegacyProxy(cdoClass));
+ assertEquals(CDOState.CLEAN, cdoClass.cdoState());
+ assertEquals(CDOState.CLEAN, resource.cdoState());
+
+ String name = umlClass.getName();
+ assertEquals("Mr. Hook", name);
+ assertEquals(CDOState.CLEAN, cdoClass.cdoState());
+ session.close();
+ }
+}
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 c3132a47f1..89790f7ec5 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
@@ -26,6 +26,7 @@ import org.eclipse.emf.cdo.view.CDORevisionPrefetchingPolicy;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.cdo.view.CDOViewSet;
+import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
import org.eclipse.emf.internal.cdo.CDOStateMachine;
import org.eclipse.emf.internal.cdo.session.CDOCollectionLoadingPolicyImpl;
import org.eclipse.emf.internal.cdo.transaction.CDOXATransactionImpl;
@@ -40,6 +41,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
import org.eclipse.emf.ecore.resource.Resource;
@@ -61,6 +63,24 @@ public final class CDOUtil
/**
* @since 2.0
*/
+ public static boolean prepareDynamicEPackage(EPackage startPackage)
+ {
+ if (CDOFactoryImpl.prepareDynamicEPackage(startPackage))
+ {
+ for (EPackage subPackage : startPackage.getESubpackages())
+ {
+ prepareDynamicEPackage(subPackage);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @since 2.0
+ */
public static CDOSessionConfiguration createSessionConfiguration()
{
// TODO Remove before release
@@ -196,9 +216,7 @@ public final class CDOUtil
return (CDOObject)object;
}
- // TODO LEGACY
- throw new UnsupportedOperationException();
- // return (CDOObject)FSMUtil.getLegacyWrapper((InternalEObject)object);
+ return FSMUtil.adaptLegacy((InternalEObject)object);
}
/**
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/ModelUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/ModelUtil.java
deleted file mode 100644
index 6fa8919f1d..0000000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/ModelUtil.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 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
- * Simon McDuff - maintenance
- */
-package org.eclipse.emf.cdo.util;
-
-import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
-
-import org.eclipse.net4j.util.ObjectUtil;
-
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.ecore.impl.EPackageImpl;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public final class ModelUtil
-{
- private ModelUtil()
- {
- }
-
- public static EPackage getGeneratedEPackage(EPackage ePackage)
- {
- String packageURI = ePackage.getNsURI();
- if (packageURI.equals(EcorePackage.eINSTANCE.getNsURI()))
- {
- return EcorePackage.eINSTANCE;
- }
-
- EPackage.Registry registry = EPackage.Registry.INSTANCE;
- return registry.getEPackage(packageURI);
- }
-
- public static EPackageImpl prepareDynamicEPackage(EPackageImpl ePackage, String nsURI)
- {
- CDOFactoryImpl.prepareDynamicEPackage(ePackage);
- EPackageImpl result = ObjectUtil.equals(ePackage.getNsURI(), nsURI) ? ePackage : null;
- for (EPackage subPackage : ePackage.getESubpackages())
- {
- EPackageImpl p = prepareDynamicEPackage((EPackageImpl)subPackage, nsURI);
- if (p != null && result == null)
- {
- result = p;
- }
- }
-
- return result;
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java
index 33a22f7620..fb4783a60d 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java
@@ -24,9 +24,9 @@ import java.util.List;
*/
public final class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Internal
{
- public CDOLegacyAdapter(InternalEObject instance)
+ public CDOLegacyAdapter()
{
- super(instance);
+ super(null);
}
public void setTarget(Notifier newTarget)
@@ -49,59 +49,58 @@ public final class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.
public boolean isAdapterForType(Object type)
{
- return true;
+ return type == CDOLegacyAdapter.class;
}
- public void notifyChanged(Notification notification)
+ public void notifyChanged(Notification msg)
{
- switch (notification.getEventType())
+ CDOStore store = view.getStore();
+ EStructuralFeature feature = (EStructuralFeature)msg.getFeature();
+ switch (msg.getEventType())
{
case Notification.SET:
- view.getStore().set(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition(),
- notification.getNewValue());
+ store.set(instance, feature, msg.getPosition(), msg.getNewValue());
break;
case Notification.UNSET:
- view.getStore().unset(instance, (EStructuralFeature)notification.getFeature());
+ store.unset(instance, feature);
break;
case Notification.MOVE:
// TODO Is that correct?
- view.getStore().move(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition(),
- (Integer)notification.getOldValue());
+ store.move(instance, feature, msg.getPosition(), (Integer)msg.getOldValue());
break;
case Notification.ADD:
- view.getStore().add(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition(),
- notification.getNewValue());
+ store.add(instance, feature, msg.getPosition(), msg.getNewValue());
break;
case Notification.ADD_MANY:
{
- int pos = notification.getPosition();
+ int pos = msg.getPosition();
@SuppressWarnings("unchecked")
- List<Object> list = (List<Object>)notification.getNewValue();
+ List<Object> list = (List<Object>)msg.getNewValue();
for (Object object : list)
{
// TODO Is that correct?
- view.getStore().add(instance, (EStructuralFeature)notification.getFeature(), pos++, object);
+ store.add(instance, feature, pos++, object);
}
}
break;
case Notification.REMOVE:
- view.getStore().remove(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition());
+ store.remove(instance, feature, msg.getPosition());
break;
case Notification.REMOVE_MANY:
{
- int pos = notification.getPosition();
+ int pos = msg.getPosition();
@SuppressWarnings("unchecked")
- List<Object> list = (List<Object>)notification.getOldValue();
+ List<Object> list = (List<Object>)msg.getOldValue();
for (int i = 0; i < list.size(); i++)
{
- view.getStore().remove(instance, (EStructuralFeature)notification.getFeature(), pos);
+ store.remove(instance, feature, pos);
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
index a9d322825b..a2a072e587 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
@@ -17,13 +17,11 @@ import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.common.model.GenUtil;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.session.CDORevisionManagerImpl;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.net4j.util.ImplementationError;
@@ -56,7 +54,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.Iterator;
import java.util.List;
/**
@@ -150,17 +147,17 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
public void cdoInternalPreCommit()
{
- instanceToRevision();
- if (cdoState() == CDOState.DIRTY) // NEW is handled in PrepareTransition
- {
- CDORevisionManagerImpl revisionManager = (CDORevisionManagerImpl)cdoView().getSession().getRevisionManager();
- InternalCDORevision originRevision = revisionManager.getRevisionByVersion(revision.getID(),
- CDORevision.UNCHUNKED, revision.getVersion() - 1, false);
- CDORevisionDelta delta = revision.compare(originRevision);
-
- // TODO LEGACY Consider to gather the deltas on the fly with noremal EMF change notifications
- cdoView().toTransaction().registerRevisionDelta(delta);
- }
+ // instanceToRevision();
+ // if (cdoState() == CDOState.DIRTY) // NEW is handled in PrepareTransition
+ // {
+ // CDORevisionManagerImpl revisionManager = (CDORevisionManagerImpl)cdoView().getSession().getRevisionManager();
+ // InternalCDORevision originRevision = revisionManager.getRevisionByVersion(revision.getID(),
+ // CDORevision.UNCHUNKED, revision.getVersion() - 1, false);
+ // CDORevisionDelta delta = revision.compare(originRevision);
+ //
+ // // TODO LEGACY Consider to gather the deltas on the fly with noremal EMF change notifications
+ // cdoView().toTransaction().registerRevisionDelta(delta);
+ // }
}
public void cdoInternalPreLoad()
@@ -245,38 +242,39 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
protected void instanceToRevisionFeature(EStructuralFeature feature, CDOPackageRegistry packageRegistry)
{
Object instanceValue = getInstanceValue(instance, feature, packageRegistry);
- if (feature.isMany())
- {
- List<Object> revisionList = revision.getList(feature); // TODO lazy?
- revisionList.clear();
-
- if (instanceValue != null)
- {
- InternalEList<?> instanceList = (InternalEList<?>)instanceValue;
- if (!instanceList.isEmpty())
- {
- for (Iterator<?> it = instanceList.basicIterator(); it.hasNext();)
- {
- Object instanceElement = it.next();
- if (instanceElement != null && feature instanceof EReference)
- {
- instanceElement = view.convertObjectToID(instanceElement);
- }
-
- revisionList.add(instanceElement);
- }
- }
- }
- }
- else
- {
- if (instanceValue != null && feature instanceof EReference)
- {
- instanceValue = view.convertObjectToID(instanceValue);
- }
-
- revision.setValue(feature, instanceValue);
- }
+ CDOObjectImpl.instanceToRevisionFeature(view, revision, feature, instanceValue);
+ // if (feature.isMany())
+ // {
+ // List<Object> revisionList = revision.getList(feature); // TODO lazy?
+ // revisionList.clear();
+ //
+ // if (instanceValue != null)
+ // {
+ // InternalEList<?> instanceList = (InternalEList<?>)instanceValue;
+ // if (!instanceList.isEmpty())
+ // {
+ // for (Iterator<?> it = instanceList.basicIterator(); it.hasNext();)
+ // {
+ // Object instanceElement = it.next();
+ // if (instanceElement != null && feature instanceof EReference)
+ // {
+ // instanceElement = view.convertObjectToID(instanceElement);
+ // }
+ //
+ // revisionList.add(instanceElement);
+ // }
+ // }
+ // }
+ // }
+ // else
+ // {
+ // if (instanceValue != null && feature instanceof EReference)
+ // {
+ // instanceValue = view.convertObjectToID(instanceValue);
+ // }
+ //
+ // revision.setValue(feature, instanceValue);
+ // }
}
/**
@@ -731,5 +729,4 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
throw new UnsupportedOperationException(method.getName());
}
}
-
}
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 82ca7821c0..6e60859328 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
@@ -322,7 +322,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- populateRevisionFeature(view, revision, eFeature, eSettings, i);
+ instanceToRevisionFeature(view, revision, eFeature, eSettings, i);
}
}
@@ -368,7 +368,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- depopulateRevisionFeature(view, revision, eFeature, eSettings, i);
+ revisionToInstanceFeature(view, revision, eFeature, eSettings, i);
}
}
}
@@ -915,39 +915,14 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return cdoView().getStore();
}
- @SuppressWarnings("unchecked")
- private void populateRevisionFeature(InternalCDOView view, InternalCDORevision revision, EStructuralFeature feature,
- Object[] eSettings, int i)
+ private void instanceToRevisionFeature(InternalCDOView view, InternalCDORevision revision,
+ EStructuralFeature feature, Object[] eSettings, int i)
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Populating feature {0}", feature); //$NON-NLS-1$
- }
-
Object setting = cdoBasicSettings() != null ? cdoSettings()[i] : null;
- CDOStore cdoStore = cdoStore();
-
- if (feature.isMany())
- {
- if (setting != null)
- {
- int index = 0;
- EList<Object> list = (EList<Object>)setting;
- for (Object value : list)
- {
- value = cdoStore.convertToCDO(cdoView(), feature, value);
- revision.add(feature, index++, value);
- }
- }
- }
- else
- {
- setting = cdoStore.convertToCDO(cdoView(), feature, setting);
- revision.set(feature, 0, setting);
- }
+ instanceToRevisionFeature(view, revision, feature, setting);
}
- private void depopulateRevisionFeature(InternalCDOView view, InternalCDORevision revision,
+ private void revisionToInstanceFeature(InternalCDOView view, InternalCDORevision revision,
EStructuralFeature eFeature, Object[] eSettings, int i)
{
if (TRACER.isEnabled())
@@ -991,7 +966,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
* Adjust the reference ONLY if the opposite reference used CDOID. This is true ONLY if the state of <cdo>this</code>
* was not {@link CDOState#NEW}.
*/
- @SuppressWarnings("unchecked")
private void adjustOppositeReference(InternalEObject object, EReference feature)
{
if (object != null)
@@ -1022,6 +996,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
// We should not trigger events. But we have no choice :-(.
if (feature.isMany())
{
+ @SuppressWarnings("unchecked")
InternalEList<Object> list = (InternalEList<Object>)object.eGet(feature);
int index = list.indexOf(this);
if (index != -1)
@@ -1045,6 +1020,40 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
/**
+ * @since 2.0
+ */
+ public static void instanceToRevisionFeature(InternalCDOView view, InternalCDORevision revision,
+ EStructuralFeature feature, Object setting)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Populating feature {0}", feature); //$NON-NLS-1$
+ }
+
+ CDOStore cdoStore = view.getStore();
+
+ if (feature.isMany())
+ {
+ if (setting != null)
+ {
+ int index = 0;
+ @SuppressWarnings("unchecked")
+ EList<Object> list = (EList<Object>)setting;
+ for (Object value : list)
+ {
+ value = cdoStore.convertToCDO(view, feature, value);
+ revision.add(feature, index++, value);
+ }
+ }
+ }
+ else
+ {
+ setting = cdoStore.convertToCDO(view, feature, setting);
+ revision.set(feature, 0, setting);
+ }
+ }
+
+ /**
* @author Simon McDuff
* @since 2.0
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
index 18df3f6163..7083bbf96b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
@@ -21,15 +21,21 @@ import org.eclipse.emf.cdo.util.InvalidObjectException;
import org.eclipse.emf.cdo.util.ObjectNotFoundException;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.internal.cdo.CDOLegacyAdapter;
import org.eclipse.emf.internal.cdo.CDOLegacyWrapper;
import org.eclipse.emf.internal.cdo.CDOMetaWrapper;
import org.eclipse.emf.internal.cdo.CDOStateMachine;
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
@@ -73,8 +79,24 @@ public final class FSMUtil
public static boolean isMeta(Object object)
{
- return object instanceof EModelElement || object instanceof EGenericType
- || object instanceof org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
+ if (object instanceof EModelElement || object instanceof EGenericType)
+ {
+ EClass eClass = ((EObject)object).eClass();
+ if (eClass == null)
+ {
+ return false;
+ }
+
+ EPackage ePackage = eClass.getEPackage();
+ if (ePackage == null)
+ {
+ return false;
+ }
+
+ return ePackage.getNsURI() == EcorePackage.eNS_URI;
+ }
+
+ return object instanceof org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
}
public static boolean isWatchable(Object obj)
@@ -153,8 +175,21 @@ public final class FSMUtil
*/
public static InternalCDOObject adaptLegacy(InternalEObject object)
{
- // TODO LEGACY
- throw new UnsupportedOperationException(Messages.getString("FSMUtil.3")); //$NON-NLS-1$
+ if (object.getClass() == DynamicEObjectImpl.class)
+ {
+ throw new IllegalArgumentException("Use CDOFactory to create dynamic object: " + object);
+ }
+
+ EList<Adapter> adapters = object.eAdapters();
+ CDOLegacyAdapter adapter = (CDOLegacyAdapter)EcoreUtil.getAdapter(adapters, CDOLegacyAdapter.class);
+ if (adapter == null)
+ {
+ adapter = new CDOLegacyAdapter();
+ adapters.add(adapter);
+ }
+
+ return adapter;
+
// EList<InternalEObject.EReadListener> readListeners = object.eReadListeners();
// CDOLegacyWrapper wrapper = getLegacyWrapper(readListeners);
// if (wrapper == null)
@@ -168,6 +203,7 @@ public final class FSMUtil
// return wrapper;
}
+ @Deprecated
public static CDOLegacyWrapper getLegacyWrapper(EList<?> listeners)
{
for (Object listener : listeners)
@@ -185,6 +221,7 @@ public final class FSMUtil
* IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support is only enabled for
* EMF with fixed bug #247130. These compile errors do not affect native models!
*/
+ @Deprecated
public static Object getLegacyWrapper(InternalEObject object)
{
// TODO LEGACY
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index aff42b181e..d7b0fb13a2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -939,41 +939,42 @@ public class CDOViewImpl extends Lifecycle implements InternalCDOView
return potentialObject;
}
- if (potentialObject instanceof InternalEObject && !(potentialObject instanceof InternalCDOObject))
- {
- // TODO LEGACY
- // try
- // {
- // InternalEObject eObject = (InternalEObject)potentialObject;
- // Object legacyListener = FSMUtil.getLegacyWrapper(eObject);
- // if (legacyListener != null)
- // {
- // potentialObject = legacyListener;
- // }
- // }
- // catch (Throwable ex)
- // {
- // OM.LOG.warn(ex);
- // }
- }
-
- if (potentialObject instanceof InternalCDOObject)
- {
- InternalCDOObject object = (InternalCDOObject)potentialObject;
- boolean newOrTransient = FSMUtil.isTransient(object) || FSMUtil.isNew(object);
- if (!(onlyPersistedID && newOrTransient))
- {
- CDOView view = object.cdoView();
- if (view == this)
+ if (potentialObject instanceof InternalEObject)
+ {
+ if (potentialObject instanceof InternalCDOObject)
+ {
+ InternalCDOObject object = (InternalCDOObject)potentialObject;
+ boolean newOrTransient = FSMUtil.isTransient(object) || FSMUtil.isNew(object);
+ if (!(onlyPersistedID && newOrTransient))
{
- return object.cdoID();
- }
+ CDOView view = object.cdoView();
+ if (view == this)
+ {
+ return object.cdoID();
+ }
- if (view != null && view.getSession() == getSession())
- {
- return object.cdoID();
+ if (view != null && view.getSession() == getSession())
+ {
+ return object.cdoID();
+ }
}
}
+ else
+ {
+ // try
+ // {
+ // InternalEObject eObject = (InternalEObject)potentialObject;
+ // InternalCDOObject cdoObject = FSMUtil.adaptLegacy(eObject);
+ // if (cdoObject != null)
+ // {
+ // potentialObject = cdoObject;
+ // }
+ // }
+ // catch (Throwable ex)
+ // {
+ // OM.LOG.warn(ex);
+ // }
+ }
}
return potentialObject;

Back to the top