summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-19 10:01:24 (EDT)
committerEike Stepper2007-07-19 10:01:24 (EDT)
commita74c23d4204e29c4ca3999be746664c16e26ad60 (patch)
tree0fdf68a645f330f5be9512d10d496e6f0b6cae86
parentf620e5a291067eb4996647f7ab837b339fb02e18 (diff)
downloadcdo-a74c23d4204e29c4ca3999be746664c16e26ad60.zip
cdo-a74c23d4204e29c4ca3999be746664c16e26ad60.tar.gz
cdo-a74c23d4204e29c4ca3999be746664c16e26ad60.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java151
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java54
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java1
3 files changed, 147 insertions, 59 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java
index c29c860..adb06e8 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java
@@ -39,6 +39,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.internal.cdo.bundle.OM;
import java.lang.reflect.Field;
@@ -60,6 +61,7 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
public CDOObjectAdapter()
{
+ state = CDOState.TRANSIENT;
}
@Override
@@ -71,7 +73,7 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
@Override
public boolean isAdapterForType(Object type)
{
- return type instanceof InternalEObject;
+ return type == CDOObjectAdapter.class;
}
@Override
@@ -178,7 +180,65 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
}
this.revision = (CDORevisionImpl)revision;
- transferRevisionToTarget();
+ transferTargetToRevision();
+ }
+
+ public void cdoInternalSetView(CDOView view)
+ {
+ // Do nothing since target will never be a CDOResource
+ }
+
+ public void cdoInternalSetResource(CDOResource resource)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Setting resource: {0}", resource);
+ }
+
+ this.resource = (CDOResourceImpl)resource;
+ }
+
+ public void cdoInternalFinalizeRevision()
+ {
+ // InternalEObject target = getTarget();
+ // EObject eContainer = target.eContainer();
+ // int eContainerFeatureID = target.eContainerFeatureID();
+ // // Setting setting = target.eSetting(null);
+ // CDOObjectImpl.finalizeCDORevision(this, eContainer, eContainerFeatureID,
+ // null);
+ }
+
+ public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
+ {
+ // TODO Implement method CDOObjectAdapter.cdoInternalDynamicFeature()
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ private void transferTargetToRevision()
+ {
+ InternalEObject target = getTarget();
+ CDOViewImpl view = (CDOViewImpl)cdoView();
+
+ CDOClassImpl cdoClass = revision.getCDOClass();
+ System.out.println("TRANSFER " + cdoClass);
+
+ CDOFeatureImpl[] features = cdoClass.getAllFeatures();
+ for (int i = 0; i < features.length; i++)
+ {
+ CDOFeatureImpl feature = features[i];
+ Object value = revision.getValue(feature);
+ if (feature.isMany())
+ {
+ EList list = (EList)getTargetValue(target, feature);
+ dumpSetting(feature, list);
+ }
+ else
+ {
+ value = view.convertToObject(value);
+ dumpSetting(feature, value);
+ setTargetValue(target, feature, value);
+ }
+ }
}
private void transferRevisionToTarget()
@@ -196,18 +256,42 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
Object value = revision.getValue(feature);
if (feature.isMany())
{
- Field field = getField(target.getClass(), feature.getName());
- System.out.println(field.getType().getName() + " --> " + field);
+ EList list = (EList)getTargetValue(target, feature);
+ dumpSetting(feature, list);
}
else
{
value = view.convertToObject(value);
- transferValueToTarget(target, feature, value);
+ dumpSetting(feature, value);
+ setTargetValue(target, feature, value);
}
}
}
- private static void transferValueToTarget(InternalEObject target, CDOFeatureImpl feature, Object value)
+ private void dumpSetting(CDOFeatureImpl feature, Object value)
+ {
+ System.out.println(feature.getName() + " --> " + (value == null ? "null" : value.getClass().getName()));
+ }
+
+ private static Object getTargetValue(InternalEObject target, CDOFeatureImpl feature)
+ {
+ Field field = getField(target.getClass(), feature.getName());
+ if (!field.isAccessible())
+ {
+ field.setAccessible(true);
+ }
+
+ try
+ {
+ return field.get(target);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new ImplementationError(ex);
+ }
+ }
+
+ private static void setTargetValue(InternalEObject target, CDOFeatureImpl feature, Object value)
{
Field field = getField(target.getClass(), feature.getName());
if (!field.isAccessible())
@@ -229,17 +313,20 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
{
try
{
- Field field = c.getDeclaredField(fieldName);
- if (field == null)
+ try
+ {
+ return c.getDeclaredField(fieldName);
+ }
+ catch (NoSuchFieldException ex)
{
Class<?> superclass = c.getSuperclass();
if (superclass != null)
{
- field = getField(superclass, fieldName);
+ return getField(superclass, fieldName);
}
- }
- return field;
+ throw new NoSuchFieldException(fieldName);
+ }
}
catch (RuntimeException ex)
{
@@ -251,35 +338,6 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
}
}
- public void cdoInternalSetView(CDOView view)
- {
- // Do nothing since target will never be a CDOResource
- }
-
- public void cdoInternalSetResource(CDOResource resource)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting resource: {0}", resource);
- }
-
- this.resource = (CDOResourceImpl)resource;
- }
-
- public void cdoInternalFinalizeRevision()
- {
- CDOObjectImpl.finalizeCDORevision(this, null, 0, null);
-
- // TODO Implement method CDOObjectAdapter.cdoInternalFinalizeRevision()
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
- {
- // TODO Implement method CDOObjectAdapter.cdoInternalDynamicFeature()
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
public EList<Adapter> eAdapters()
{
return getTarget().eAdapters();
@@ -502,4 +560,17 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
{
return getTarget().eURIFragmentSegment(feature, object);
}
+
+ public static CDOObjectAdapter getFor(InternalEObject eObject)
+ {
+ EList<Adapter> adapters = eObject.eAdapters();
+ CDOObjectAdapter adapter = (CDOObjectAdapter)EcoreUtil.getAdapter(adapters, CDOObjectAdapter.class);
+ if (adapter == null)
+ {
+ adapter = new CDOObjectAdapter();
+ adapters.add(adapter);
+ }
+
+ return adapter;
+ }
}
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 4f791bf..879892e 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
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageManagerImpl;
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.net4j.internal.util.om.trace.ContextTracer;
@@ -41,7 +42,7 @@ public final class CDOStore implements EStore
public InternalEObject getContainer(InternalEObject eObject)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
if (TRACER.isEnabled())
{
TRACER.format("getContainer({0})", cdoObject);
@@ -54,7 +55,7 @@ public final class CDOStore implements EStore
public int getContainingFeatureID(InternalEObject eObject)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
if (TRACER.isEnabled())
{
TRACER.format("getContainingFeatureID({0})", cdoObject);
@@ -66,7 +67,7 @@ public final class CDOStore implements EStore
public void setContainer(InternalEObject eObject, InternalEObject newContainer, int newContainerFeatureID)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
if (TRACER.isEnabled())
{
TRACER.format("setContainer({0}, {1}, {2})", cdoObject, newContainer, newContainerFeatureID);
@@ -86,7 +87,7 @@ public final class CDOStore implements EStore
public Object get(InternalEObject eObject, EStructuralFeature eFeature, int index)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -105,7 +106,7 @@ public final class CDOStore implements EStore
public boolean isSet(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -118,7 +119,7 @@ public final class CDOStore implements EStore
public int size(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -131,7 +132,7 @@ public final class CDOStore implements EStore
public boolean isEmpty(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -144,7 +145,7 @@ public final class CDOStore implements EStore
public boolean contains(InternalEObject eObject, EStructuralFeature eFeature, Object value)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -162,7 +163,7 @@ public final class CDOStore implements EStore
public int indexOf(InternalEObject eObject, EStructuralFeature eFeature, Object value)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -180,7 +181,7 @@ public final class CDOStore implements EStore
public int lastIndexOf(InternalEObject eObject, EStructuralFeature eFeature, Object value)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -198,7 +199,7 @@ public final class CDOStore implements EStore
public int hashCode(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -211,7 +212,7 @@ public final class CDOStore implements EStore
public Object[] toArray(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -239,7 +240,7 @@ public final class CDOStore implements EStore
public Object set(InternalEObject eObject, EStructuralFeature eFeature, int index, Object value)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -268,7 +269,7 @@ public final class CDOStore implements EStore
public void unset(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -281,7 +282,7 @@ public final class CDOStore implements EStore
public void add(InternalEObject eObject, EStructuralFeature eFeature, int index, Object value)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -304,7 +305,7 @@ public final class CDOStore implements EStore
public Object remove(InternalEObject eObject, EStructuralFeature eFeature, int index)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -323,7 +324,7 @@ public final class CDOStore implements EStore
public void clear(InternalEObject eObject, EStructuralFeature eFeature)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -336,7 +337,7 @@ public final class CDOStore implements EStore
public Object move(InternalEObject eObject, EStructuralFeature eFeature, int target, int source)
{
- InternalCDOObject cdoObject = (InternalCDOObject)eObject;
+ InternalCDOObject cdoObject = getCDOObject(eObject);
CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
if (TRACER.isEnabled())
{
@@ -364,6 +365,21 @@ public final class CDOStore implements EStore
return "PersistentStore";
}
+ private static InternalCDOObject getCDOObject(Object object)
+ {
+ if (object instanceof InternalCDOObject)
+ {
+ return (InternalCDOObject)object;
+ }
+
+ if (object instanceof InternalEObject)
+ {
+ return CDOObjectAdapter.getFor((InternalEObject)object);
+ }
+
+ throw new ImplementationError("Neither InternalCDOObject nor InternalEObject: " + object.getClass().getName());
+ }
+
private static CDOFeatureImpl getCDOFeature(InternalCDOObject cdoObject, EStructuralFeature eFeature)
{
CDOViewImpl view = (CDOViewImpl)cdoObject.cdoView();
@@ -402,7 +418,7 @@ public final class CDOStore implements EStore
private static void handleContainmentAdd(InternalCDOObject cdoObject, CDOFeatureImpl cdoFeature, Object value)
{
InternalCDOObject container = cdoObject;
- InternalCDOObject contained = (InternalCDOObject)value;
+ InternalCDOObject contained = getCDOObject(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 74a06a3..5f9f521 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
@@ -103,6 +103,7 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
}
catch (ClassCastException ex)
{
+ ex.printStackTrace();
throw new IllegalStateException("Dangling reference: " + object);
}
}