summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-23 02:39:09 (EDT)
committerEike Stepper2007-07-23 02:39:09 (EDT)
commit581c02fe6a27774fdb57d511525ca1c6393e362d (patch)
tree74d839cfd8da5a4ed1f2d1d3f3e867b872ac4955
parentf6ebd3881d9c6db6eca0f5f4fb5e091ee31dae9f (diff)
downloadcdo-581c02fe6a27774fdb57d511525ca1c6393e362d.zip
cdo-581c02fe6a27774fdb57d511525ca1c6393e362d.tar.gz
cdo-581c02fe6a27774fdb57d511525ca1c6393e362d.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java34
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaImpl.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java98
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java91
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java39
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java105
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TreeTraversal.java72
11 files changed, 208 insertions, 246 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java
index 45b18cf..3cad9a1 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java
@@ -33,6 +33,4 @@ public interface CDOObject extends EObject
public CDOResource cdoResource();
public CDORevision cdoRevision();
-
- public boolean cdoTransient();
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 7b3e145..cd16954 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -33,6 +33,7 @@ import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.internal.cdo.CDOObjectImpl;
import org.eclipse.emf.internal.cdo.CDOViewImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.util.FSMUtil;
import java.io.IOException;
import java.io.InputStream;
@@ -159,7 +160,7 @@ public class CDOResourceImpl extends CDOObjectImpl implements CDOResource
*/
public EList<EObject> getContents()
{
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
EList<EObject> transientContents = (EList<EObject>)eSettings[EresourcePackage.CDO_RESOURCE__CONTENTS];
if (transientContents == null)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java
index 5eb6d18..2d1319b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java
@@ -149,11 +149,6 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
return CDOObjectImpl.getCDOView(this);
}
- public boolean cdoTransient()
- {
- return CDOObjectImpl.isCDOTransient(this);
- }
-
public void cdoInternalSetID(CDOID id)
{
if (id == null)
@@ -212,6 +207,11 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
transferTargetToRevision();
}
+ public InternalEObject cdoInternalInstance()
+ {
+ return getTarget();
+ }
+
public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
{
// TODO Implement method CDOAdapterImpl.cdoInternalDynamicFeature()
@@ -296,12 +296,6 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
}
}
- private void transferRevisionToTarget()
- {
- // TODO Implement method CDOAdapterImpl.transferRevisionToTarget()
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
private static Object getTargetValue(InternalEObject target, CDOFeatureImpl feature, CDOViewImpl view)
{
Class<?> targetClass = target.getClass();
@@ -388,24 +382,6 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
}
}
- private static void setTargetValue(InternalEObject target, CDOFeatureImpl feature, Object value)
- {
- Field field = getField(target.getClass(), feature.getName());
- if (!field.isAccessible())
- {
- field.setAccessible(true);
- }
-
- try
- {
- field.set(target, value);
- }
- catch (IllegalAccessException ex)
- {
- throw new ImplementationError(ex);
- }
- }
-
private static Field getField(Class<?> c, String fieldName)
{
try
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaImpl.java
index e07984e..98ba97d 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaImpl.java
@@ -122,6 +122,11 @@ public class CDOMetaImpl implements InternalCDOObject
throw new UnsupportedOperationException();
}
+ public InternalEObject cdoInternalInstance()
+ {
+ return metaInstance;
+ }
+
public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
{
// TODO Implement method CDOMetaImpl.enclosing_method()
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 2b75123..a30b77a 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
@@ -10,7 +10,6 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo;
-import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResource;
@@ -27,13 +26,13 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
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.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
/**
@@ -93,11 +92,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return resource;
}
- public boolean cdoTransient()
- {
- return isCDOTransient(this);
- }
-
public void cdoInternalSetID(CDOID id)
{
if (id == null)
@@ -161,54 +155,42 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public void cdoInternalFinalizeRevision()
{
- // TODO Inline
- finalizeCDORevision(this, eContainer, eContainerFeatureID, eSettings);
- }
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Finalizing revision for {0}", this);
+ }
- public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
- {
- return eDynamicFeature(dynamicFeatureID);
- }
+ CDOViewImpl view = cdoView();
+ revision.setVersion(1);
+ revision.setContainerID(eContainer == null ? CDOID.NULL : ((CDOObjectImpl)eContainer).cdoID());
+ revision.setContainingFeature(eContainerFeatureID);
- @Deprecated
- void initializeContainer(InternalEObject container, EStructuralFeature eContainingFeature)
- {
- eContainer = container;
- CDORevisionImpl revision = cdoRevision();
- if (eContainer != null)
+ if (eSettings != null)
{
- if (revision != null)
+ EClass eClass = eClass();
+ for (int i = 0; i < eClass.getFeatureCount(); i++)
{
- if (eContainer instanceof CDOObject && !(eContainer instanceof CDOResource))
- {
- revision.setContainerID(((CDOObject)eContainer).cdoID());
- }
- else
+ Object setting = eSettings[i];
+ if (setting != null)
{
- revision.setContainerID(CDOID.NULL);
+ EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
+ if (!eFeature.isTransient())
+ {
+ finalizeRevisionFeature(view, revision, i, setting, eFeature, eSettings);
+ }
}
}
+ }
+ }
- if (eContainingFeature instanceof EReference)
- {
- EReference eContainingReference = (EReference)eContainingFeature;
- EReference eOpposite = eContainingReference.getEOpposite();
- if (eOpposite != null)
- {
- eContainerFeatureID = eClass().getFeatureID(eOpposite);
- return;
- }
- }
+ public InternalEObject cdoInternalInstance()
+ {
+ return this;
+ }
- eContainerFeatureID = EOPPOSITE_FEATURE_BASE - eContainer.eClass().getFeatureID(eContainingFeature);
- }
- else
- {
- if (revision != null)
- {
- revision.setContainerID(CDOID.NULL);
- }
- }
+ public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
+ {
+ return eDynamicFeature(dynamicFeatureID);
}
@Override
@@ -239,7 +221,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public Object dynamicGet(int dynamicFeatureID)
{
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
if (eSettings == null)
{
@@ -256,7 +238,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public boolean eIsSet(EStructuralFeature feature)
{
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
// TODO What about defaultValues != null?
if (eSettings == null)
@@ -274,7 +256,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public void dynamicSet(int dynamicFeatureID, Object value)
{
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
eSettings(); // Important to create eSettings array if necessary
eSettings[dynamicFeatureID] = value;
@@ -289,7 +271,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public void dynamicUnset(int dynamicFeatureID)
{
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
if (eSettings != null)
{
@@ -307,7 +289,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public InternalEObject eInternalContainer()
{
InternalEObject container;
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
container = eContainer;
}
@@ -328,7 +310,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public int eContainerFeatureID()
{
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
return eContainerFeatureID;
}
@@ -345,7 +327,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
TRACER.format("Setting container: {0}, featureID={1}", newContainer, newContainerFeatureID);
}
- if (cdoTransient())
+ if (FSMUtil.isTransient(this))
{
eContainer = newContainer;
eContainerFeatureID = newContainerFeatureID;
@@ -393,16 +375,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return resource != null ? (CDOViewImpl)cdoObject.cdoResource().cdoView() : null;
}
- static boolean isCDOTransient(InternalCDOObject cdoObject)
- {
- final CDOState cdoState = cdoObject.cdoState();
- return cdoState == CDOState.TRANSIENT || cdoState == CDOState.PREPARED_ATTACH;
- }
-
- /**
- * TODO Inline
- */
- @Deprecated
static void finalizeCDORevision(InternalCDOObject cdoObject, EObject eContainer, int eContainerFeatureID,
Object[] eSettings)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
index f87e965..8694acd 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
@@ -5,7 +5,6 @@ import org.eclipse.emf.cdo.eresource.CDOResource;
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.util.ImplementationError;
import org.eclipse.emf.cdo.protocol.util.TransportException;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.ServerException;
@@ -14,30 +13,17 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.fsm.FiniteStateMachine;
import org.eclipse.net4j.util.fsm.ITransition;
-import org.eclipse.emf.common.notify.Adapter;
-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.InternalEObject;
-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.ResourceIDRequest;
+import org.eclipse.emf.internal.cdo.util.FSMUtil;
+import java.util.Iterator;
import java.util.Map;
/**
* @author Eike Stepper
*/
-enum CDOEvent
-{
- ATTACH, DETACH, READ, WRITE, COMMIT, ROLLBACK, INVALIDATE, FINALIZE_ATTACH
-}
-
-/**
- * @author Eike Stepper
- */
public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent, InternalCDOObject>
{
// @Singleton
@@ -120,11 +106,13 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
data.view = view;
// TRANSIENT --> PREPARED_ATTACH
- if (TRACER.isEnabled()) TRACER.format("ATTACH: {0} --> {1}", object, view);
+ if (TRACER.isEnabled())
+ TRACER.format("ATTACH: {0} --> {1}", object, view);
process(object, CDOEvent.ATTACH, data);
// PREPARED_ATTACH --> NEW
- if (TRACER.isEnabled()) TRACER.format("FINALIZE_ATTACH: {0} --> {1}", object, view);
+ if (TRACER.isEnabled())
+ TRACER.format("FINALIZE_ATTACH: {0} --> {1}", object, view);
process(object, CDOEvent.FINALIZE_ATTACH, data);
}
@@ -136,62 +124,39 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
public void read(InternalCDOObject object)
{
- if (TRACER.isEnabled()) TRACER.format("READ: {0}", object);
+ if (TRACER.isEnabled())
+ TRACER.format("READ: {0}", object);
process(object, CDOEvent.READ, null);
}
public void write(InternalCDOObject object)
{
- if (TRACER.isEnabled()) TRACER.format("WRITE: {0}", object);
+ if (TRACER.isEnabled())
+ TRACER.format("WRITE: {0}", object);
process(object, CDOEvent.WRITE, null);
}
public void invalidate(InternalCDOObject object, long timeStamp)
{
- if (TRACER.isEnabled()) TRACER.format("INVALIDATE: {0}", object);
+ if (TRACER.isEnabled())
+ TRACER.format("INVALIDATE: {0}", object);
process(object, CDOEvent.INVALIDATE, timeStamp);
}
public void commit(InternalCDOObject object, CommitTransactionResult result)
{
- if (TRACER.isEnabled()) TRACER.format("COMMIT: {0}", object);
+ if (TRACER.isEnabled())
+ TRACER.format("COMMIT: {0}", object);
process(object, CDOEvent.COMMIT, result);
}
public void rollback(InternalCDOObject object)
{
- if (TRACER.isEnabled()) TRACER.format("ROLLBACK: {0}", object);
+ if (TRACER.isEnabled())
+ TRACER.format("ROLLBACK: {0}", object);
process(object, CDOEvent.ROLLBACK, null);
}
- public static InternalCDOObject adapt(Object object)
- {
- if (object instanceof InternalCDOObject)
- {
- return (InternalCDOObject)object;
- }
-
- if (object instanceof EModelElement || object instanceof EGenericType)
- {
- return new CDOMetaImpl((InternalEObject)object);
- }
-
- if (object instanceof InternalEObject)
- {
- EList<Adapter> adapters = ((InternalEObject)object).eAdapters();
- CDOAdapterImpl adapter = (CDOAdapterImpl)EcoreUtil.getAdapter(adapters, CDOAdapterImpl.class);
- if (adapter == null)
- {
- adapter = new CDOAdapterImpl();
- adapters.add(adapter);
- }
-
- return adapter;
- }
-
- throw new ImplementationError("Neither InternalCDOObject nor InternalEObject: " + object.getClass().getName());
- }
-
@Override
protected CDOState getState(InternalCDOObject object)
{
@@ -235,11 +200,11 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
data.view.registerObject(object);
transaction.registerNew(object);
- // Prepare content tree
- for (EObject content : object.eContents())
+ // Attach content tree
+ for (Iterator it = FSMUtil.iterator(object.eContents()); it.hasNext();)
{
- InternalCDOObject objectOrAdapter = adapt(content);
- INSTANCE.process(objectOrAdapter, CDOEvent.ATTACH, data);
+ InternalCDOObject content = (InternalCDOObject)it.next();
+ INSTANCE.process(content, CDOEvent.ATTACH, data);
}
}
}
@@ -255,11 +220,11 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
object.cdoInternalFinalizeRevision();
object.cdoInternalSetState(CDOState.NEW);
- // Prepare content tree
- for (EObject content : object.eContents())
+ // Finalize content tree
+ for (Iterator it = FSMUtil.iterator(object.eContents()); it.hasNext();)
{
- InternalCDOObject objectOrAdapter = adapt(content);
- INSTANCE.process(objectOrAdapter, CDOEvent.FINALIZE_ATTACH, null);
+ InternalCDOObject content = (InternalCDOObject)it.next();
+ INSTANCE.process(content, CDOEvent.FINALIZE_ATTACH, null);
}
}
}
@@ -411,3 +376,11 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
}
}
}
+
+/**
+ * @author Eike Stepper
+ */
+enum CDOEvent
+{
+ ATTACH, DETACH, READ, WRITE, COMMIT, ROLLBACK, INVALIDATE, FINALIZE_ATTACH
+}
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 1fb1b85..ffbbf9d 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
@@ -22,6 +22,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.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
/**
@@ -40,7 +41,7 @@ public final class CDOStore implements EStore
public void setContainer(InternalEObject eObject, InternalEObject newContainer, int newContainerFeatureID)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
if (TRACER.isEnabled())
{
TRACER.format("setContainer({0}, {1}, {2})", cdoObject, newContainer, newContainerFeatureID);
@@ -55,7 +56,7 @@ public final class CDOStore implements EStore
public InternalEObject getContainer(InternalEObject eObject)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
if (TRACER.isEnabled())
{
TRACER.format("getContainer({0})", cdoObject);
@@ -68,7 +69,7 @@ public final class CDOStore implements EStore
public int getContainingFeatureID(InternalEObject eObject)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
if (TRACER.isEnabled())
{
TRACER.format("getContainingFeatureID({0})", cdoObject);
@@ -85,7 +86,7 @@ public final class CDOStore implements EStore
public Object get(InternalEObject eObject, EStructuralFeature eFeature, int index)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -104,7 +105,7 @@ public final class CDOStore implements EStore
public boolean isSet(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -117,7 +118,7 @@ public final class CDOStore implements EStore
public int size(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -130,7 +131,7 @@ public final class CDOStore implements EStore
public boolean isEmpty(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -143,7 +144,7 @@ public final class CDOStore implements EStore
public boolean contains(InternalEObject eObject, EStructuralFeature eFeature, Object value)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -161,7 +162,7 @@ public final class CDOStore implements EStore
public int indexOf(InternalEObject eObject, EStructuralFeature eFeature, Object value)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -179,7 +180,7 @@ public final class CDOStore implements EStore
public int lastIndexOf(InternalEObject eObject, EStructuralFeature eFeature, Object value)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -197,7 +198,7 @@ public final class CDOStore implements EStore
public int hashCode(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -210,7 +211,7 @@ public final class CDOStore implements EStore
public Object[] toArray(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -238,7 +239,7 @@ public final class CDOStore implements EStore
public Object set(InternalEObject eObject, EStructuralFeature eFeature, int index, Object value)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -267,7 +268,7 @@ public final class CDOStore implements EStore
public void unset(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -280,7 +281,7 @@ public final class CDOStore implements EStore
public void add(InternalEObject eObject, EStructuralFeature eFeature, int index, Object value)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -303,7 +304,7 @@ public final class CDOStore implements EStore
public Object remove(InternalEObject eObject, EStructuralFeature eFeature, int index)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -322,7 +323,7 @@ public final class CDOStore implements EStore
public void clear(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -335,7 +336,7 @@ public final class CDOStore implements EStore
public Object move(InternalEObject eObject, EStructuralFeature eFeature, int target, int source)
{
- InternalCDOObject cdoObject = CDOStateMachine.adapt(eObject);
+ InternalCDOObject cdoObject = FSMUtil.adapt(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -401,7 +402,7 @@ public final class CDOStore implements EStore
private static void handleContainmentAdd(InternalCDOObject cdoObject, CDOFeatureImpl cdoFeature, Object value)
{
InternalCDOObject container = cdoObject;
- InternalCDOObject contained = CDOStateMachine.adapt(value);
+ InternalCDOObject contained = FSMUtil.adapt(value);
CDOViewImpl containerView = (CDOViewImpl)container.cdoView();
CDOViewImpl containedView = (CDOViewImpl)contained.cdoView();
if (containedView != containerView)
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 9746dcc..e66e9eb 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
@@ -42,6 +42,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
+import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
import java.text.MessageFormat;
@@ -296,7 +297,7 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
return id;
}
- InternalCDOObject adapter = CDOStateMachine.adapt(eObject);
+ InternalCDOObject adapter = FSMUtil.adapt(eObject);
potentialObject = adapter;
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java
index 6ff9ee3..2643279 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java
@@ -37,5 +37,7 @@ public interface InternalCDOObject extends CDOObject, InternalEObject
public void cdoInternalFinalizeRevision();
+ public InternalEObject cdoInternalInstance();
+
public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID);
}
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
new file mode 100644
index 0000000..6a6b764
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
@@ -0,0 +1,105 @@
+/***************************************************************************
+ * 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.internal.cdo.util;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
+import org.eclipse.emf.cdo.protocol.util.ImplementationError;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EGenericType;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.internal.cdo.CDOAdapterImpl;
+import org.eclipse.emf.internal.cdo.CDOMetaImpl;
+import org.eclipse.emf.internal.cdo.InternalCDOObject;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author Eike Stepper
+ */
+public final class FSMUtil
+{
+ private FSMUtil()
+ {
+ }
+
+ public static boolean isTransient(CDOObject object)
+ {
+ CDOState state = object.cdoState();
+ return state == CDOState.TRANSIENT || state == CDOState.PREPARED_ATTACH;
+ }
+
+ public static InternalCDOObject adapt(Object object)
+ {
+ if (object instanceof InternalCDOObject)
+ {
+ return (InternalCDOObject)object;
+ }
+
+ if (object instanceof EModelElement || object instanceof EGenericType)
+ {
+ return new CDOMetaImpl((InternalEObject)object);
+ }
+
+ if (object instanceof InternalEObject)
+ {
+ EList<Adapter> adapters = ((InternalEObject)object).eAdapters();
+ CDOAdapterImpl adapter = (CDOAdapterImpl)EcoreUtil.getAdapter(adapters, CDOAdapterImpl.class);
+ if (adapter == null)
+ {
+ adapter = new CDOAdapterImpl();
+ adapters.add(adapter);
+ }
+
+ return adapter;
+ }
+
+ throw new ImplementationError("Neither InternalCDOObject nor InternalEObject: " + object.getClass().getName());
+ }
+
+ public static Iterator<InternalCDOObject> iterator(Collection instances)
+ {
+ final Iterator delegate = instances.iterator();
+ return new Iterator<InternalCDOObject>()
+ {
+ private Object next;
+
+ public boolean hasNext()
+ {
+ while (delegate.hasNext())
+ {
+ next = adapt(delegate.next());
+ if (next instanceof InternalCDOObject)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public InternalCDOObject next()
+ {
+ return (InternalCDOObject)next;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TreeTraversal.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TreeTraversal.java
deleted file mode 100644
index 7c1087e..0000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TreeTraversal.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.eclipse.emf.internal.cdo.util;
-
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.internal.cdo.InternalCDOObject;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-@Deprecated
-public class TreeTraversal
-{
- private InternalCDOObject root;
-
- private List<InternalCDOObject> objects = new ArrayList(0);
-
- public TreeTraversal(InternalCDOObject root)
- {
- this.root = root;
- collectContents();
- }
-
- public InternalCDOObject getRoot()
- {
- return root;
- }
-
- public List<InternalCDOObject> getObjects()
- {
- return objects;
- }
-
- public void traverseTopDown(final ObjectHandler handler)
- {
- for (int i = 0; i < objects.size(); i++)
- {
- handler.handleObject(objects.get(i));
- }
- }
-
- public void traverseBottomUp(final ObjectHandler handler)
- {
- for (int i = objects.size() - 1; i >= 0; i--)
- {
- handler.handleObject(objects.get(i));
- }
- }
-
- private void collectContents()
- {
- objects.add(root);
- for (TreeIterator<EObject> it = root.eAllContents(); it.hasNext();)
- {
- Object content = it.next();
- if (content instanceof InternalCDOObject)
- {
- objects.add(((InternalCDOObject)content));
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public interface ObjectHandler
- {
- public void handleObject(final InternalCDOObject object);
- }
-} \ No newline at end of file