Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-24 06:38:08 +0000
committerEike Stepper2007-07-24 06:38:08 +0000
commitbb3bdf5dd43806174460d9f83fb0db38dfe4b5e4 (patch)
treed61bf5f08b0a1dd305379aed39abc70fa519654e
parenteb193d4a5b41d5de155c00a985436214ab5619dd (diff)
downloadcdo-bb3bdf5dd43806174460d9f83fb0db38dfe4b5e4.tar.gz
cdo-bb3bdf5dd43806174460d9f83fb0db38dfe4b5e4.tar.xz
cdo-bb3bdf5dd43806174460d9f83fb0db38dfe4b5e4.zip
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java180
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java296
2 files changed, 402 insertions, 74 deletions
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 f98960d44c..57128aaa1f 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
@@ -50,8 +50,10 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.util.GenUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
@@ -90,8 +92,21 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
@Override
public void notifyChanged(Notification msg)
{
- // TODO Implement method CDOAdapterImpl.notifyChanged()
- throw new UnsupportedOperationException("Not yet implemented");
+ if (msg.getEventType() == Notification.RESOLVE)
+ {
+ return;
+ }
+
+ if (msg.getNotifier() instanceof InternalEObject)
+ {
+ InternalEObject notifier = (InternalEObject)msg.getNotifier();
+ if (!notifier.eIsProxy())
+ {
+ System.out.println(msg);
+ // TODO Implement method CDOAdapterImpl.notifyChanged()
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+ }
}
@Override
@@ -180,7 +195,7 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
{
if (!target.eIsProxy())
{
- URI uri = URI.createURI(CDOProtocolConstants.PROTOCOL_NAME + ":" + id);
+ URI uri = URI.createURI(CDOProtocolConstants.PROTOCOL_NAME + ":proxy#" + id);
target.eSetProxyURI(uri);
}
}
@@ -316,17 +331,24 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
if (feature.isMany())
{
InternalEList targetList = (InternalEList)getTargetValue(target, feature);
- targetList.clear(); // XXX Notifications?
-
- List revisionList = (List)value;
- for (Object revisionElement : revisionList)
+ if (targetList != null)
{
- if (feature.isReference())
+ while (!targetList.isEmpty())
{
- revisionElement = view.convertIDToObject(revisionElement);
+ Object toBeRemoved = targetList.basicGet(0);
+ targetList.basicRemove(toBeRemoved, null);
}
- targetList.basicAdd(revisionElement, null);
+ List revisionList = (List)value;
+ for (Object toBeAdded : revisionList)
+ {
+ if (feature.isReference())
+ {
+ toBeAdded = view.convertIDToObject(toBeAdded);
+ }
+
+ targetList.basicAdd(toBeAdded, null);
+ }
}
}
else
@@ -343,53 +365,65 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
private Object getTargetValue(InternalEObject target, CDOFeatureImpl feature)
{
- Class<?> targetClass = target.getClass();
- String featureName = feature.getName();
- String fieldName = featureName;// XXX safeName()
- Field field = getField(targetClass, fieldName);
- if (field == null && feature.getType() == CDOType.BOOLEAN)
- {
- if (targetClass.isAssignableFrom(EAttributeImpl.class) || targetClass.isAssignableFrom(EClassImpl.class)
- || targetClass.isAssignableFrom(EDataTypeImpl.class) || targetClass.isAssignableFrom(EReferenceImpl.class)
- || targetClass.isAssignableFrom(EStructuralFeatureImpl.class)
- || targetClass.isAssignableFrom(ETypedElementImpl.class))
- {
- // *******************************************
- // ID_EFLAG = 1 << 15;
- // *******************************************
- // ABSTRACT_EFLAG = 1 << 8;
- // INTERFACE_EFLAG = 1 << 9;
- // *******************************************
- // SERIALIZABLE_EFLAG = 1 << 8;
- // *******************************************
- // CONTAINMENT_EFLAG = 1 << 15;
- // RESOLVE_PROXIES_EFLAG = 1 << 16;
- // *******************************************
- // CHANGEABLE_EFLAG = 1 << 10;
- // VOLATILE_EFLAG = 1 << 11;
- // TRANSIENT_EFLAG = 1 << 12;
- // UNSETTABLE_EFLAG = 1 << 13;
- // DERIVED_EFLAG = 1 << 14;
- // *******************************************
- // ORDERED_EFLAG = 1 << 8;
- // UNIQUE_EFLAG = 1 << 9;
- // *******************************************
-
- String flagName = GenUtil.getUpperFeatureName(featureName) + "_EFLAG";
- int flagsMask = getEFlagMask(targetClass, flagName);
-
- field = getField(targetClass, "eFlags");
- int value = (Integer)getFiedValue(target, field);
- return new Boolean((value & flagsMask) != 0);
- }
- }
-
- if (field == null)
- {
- throw new ImplementationError("Field not found: " + fieldName);
- }
-
- return getFiedValue(target, field);
+ // Class<?> targetClass = target.getClass();
+ // String featureName = feature.getName();
+ EStructuralFeature eFeature = ModelUtil.getEFeature(feature, cdoView().getSession().getPackageRegistry());
+ Object value = target.eGet(eFeature);
+ return value;
+
+ // // TODO BOOLEAN_OBJECT?
+ // String methodName = GenUtil.getFeatureGetterName(featureName,
+ // feature.getType() == CDOType.BOOLEAN);
+ // Method method = getMethod(targetClass, methodName,
+ // ReflectUtil.NO_PARAMETERS);
+ //
+ // String fieldName = featureName;// XXX safeName()
+ // Field field = getField(targetClass, fieldName);
+ // if (field == null && feature.getType() == CDOType.BOOLEAN)
+ // {
+ // if (targetClass.isAssignableFrom(EAttributeImpl.class) ||
+ // targetClass.isAssignableFrom(EClassImpl.class)
+ // || targetClass.isAssignableFrom(EDataTypeImpl.class) ||
+ // targetClass.isAssignableFrom(EReferenceImpl.class)
+ // || targetClass.isAssignableFrom(EStructuralFeatureImpl.class)
+ // || targetClass.isAssignableFrom(ETypedElementImpl.class))
+ // {
+ // // *******************************************
+ // // ID_EFLAG = 1 << 15;
+ // // *******************************************
+ // // ABSTRACT_EFLAG = 1 << 8;
+ // // INTERFACE_EFLAG = 1 << 9;
+ // // *******************************************
+ // // SERIALIZABLE_EFLAG = 1 << 8;
+ // // *******************************************
+ // // CONTAINMENT_EFLAG = 1 << 15;
+ // // RESOLVE_PROXIES_EFLAG = 1 << 16;
+ // // *******************************************
+ // // CHANGEABLE_EFLAG = 1 << 10;
+ // // VOLATILE_EFLAG = 1 << 11;
+ // // TRANSIENT_EFLAG = 1 << 12;
+ // // UNSETTABLE_EFLAG = 1 << 13;
+ // // DERIVED_EFLAG = 1 << 14;
+ // // *******************************************
+ // // ORDERED_EFLAG = 1 << 8;
+ // // UNIQUE_EFLAG = 1 << 9;
+ // // *******************************************
+ //
+ // String flagName = GenUtil.getFeatureUpperName(featureName) + "_EFLAG";
+ // int flagsMask = getEFlagMask(targetClass, flagName);
+ //
+ // field = getField(targetClass, "eFlags");
+ // int value = (Integer)getFiedValue(target, field);
+ // return new Boolean((value & flagsMask) != 0);
+ // }
+ // }
+ //
+ // if (field == null)
+ // {
+ // throw new ImplementationError("Field not found: " + fieldName);
+ // }
+ //
+ // return getFiedValue(target, field);
}
private void setTargetValue(InternalEObject target, CDOFeatureImpl feature, Object value)
@@ -426,7 +460,7 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
// UNIQUE_EFLAG = 1 << 9;
// *******************************************
- String flagName = GenUtil.getUpperFeatureName(featureName) + "_EFLAG";
+ String flagName = GenUtil.getFeatureUpperName(featureName) + "_EFLAG";
int flagsMask = getEFlagMask(targetClass, flagName);
field = getField(targetClass, "eFlags");
@@ -442,6 +476,7 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
}
setFiedValue(target, field, flags);
+ return;
}
}
@@ -534,6 +569,35 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
}
}
+ private static Method getMethod(Class<?> c, String methodName, Class... parameterTypes)
+ {
+ try
+ {
+ try
+ {
+ return c.getDeclaredMethod(methodName, parameterTypes);
+ }
+ catch (NoSuchMethodException ex)
+ {
+ Class<?> superclass = c.getSuperclass();
+ if (superclass != null)
+ {
+ return getMethod(superclass, methodName, parameterTypes);
+ }
+
+ return null;
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new ImplementationError(ex);
+ }
+ }
+
public EList<Adapter> eAdapters()
{
return getTarget().eAdapters();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
index 340e5739fa..676c113d47 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
@@ -34,10 +34,16 @@ import org.eclipse.net4j.util.event.EventUtil;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
@@ -45,6 +51,9 @@ import org.eclipse.emf.internal.cdo.protocol.CDOClientProtocol;
import org.eclipse.emf.internal.cdo.protocol.OpenSessionRequest;
import org.eclipse.emf.internal.cdo.protocol.OpenSessionResult;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
@@ -57,7 +66,6 @@ import java.util.Set;
*/
public class CDOSessionImpl extends Lifecycle implements CDOSession
{
- @SuppressWarnings("unused")
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SESSION, CDOSessionImpl.class);
private static final long INITIAL_TEMPORARY_ID = -1L;
@@ -177,8 +185,9 @@ public class CDOSessionImpl extends Lifecycle implements CDOSession
public CDOTransactionImpl openTransaction(ResourceSet resourceSet)
{
- prepare(resourceSet);
- return (CDOTransactionImpl)attach(resourceSet, new CDOTransactionImpl(++lastViewID, this));
+ CDOTransactionImpl transaction = new CDOTransactionImpl(++lastViewID, this);
+ attach(resourceSet, transaction);
+ return transaction;
}
public CDOTransactionImpl openTransaction()
@@ -188,8 +197,9 @@ public class CDOSessionImpl extends Lifecycle implements CDOSession
public CDOViewImpl openView(ResourceSet resourceSet)
{
- prepare(resourceSet);
- return attach(resourceSet, new CDOViewImpl(++lastViewID, this));
+ CDOViewImpl view = new CDOViewImpl(++lastViewID, this);
+ attach(resourceSet, view);
+ return view;
}
public CDOViewImpl openView()
@@ -199,8 +209,9 @@ public class CDOSessionImpl extends Lifecycle implements CDOSession
public CDOAuditImpl openAudit(ResourceSet resourceSet, long timeStamp)
{
- prepare(resourceSet);
- return (CDOAuditImpl)attach(resourceSet, new CDOAuditImpl(++lastViewID, this, timeStamp));
+ CDOAuditImpl audit = new CDOAuditImpl(++lastViewID, this, timeStamp);
+ attach(resourceSet, audit);
+ return audit;
}
public CDOAuditImpl openAudit(long timeStamp)
@@ -365,28 +376,30 @@ public class CDOSessionImpl extends Lifecycle implements CDOSession
return new ResourceSetImpl();
}
- private void prepare(ResourceSet resourceSet)
+ private void attach(ResourceSet resourceSet, CDOViewImpl view)
{
- CDOView view = CDOUtil.getView(resourceSet);
- if (view != null)
+ if (CDOUtil.getView(resourceSet) != null)
{
- throw new IllegalStateException("CDO view already open: " + view);
+ throw new IllegalStateException("CDO view already open");
}
resourceSet.setPackageRegistry(new EPackageRegistryImpl(packageRegistry));
CDOUtil.prepareResourceSet(resourceSet);
- }
- private CDOViewImpl attach(ResourceSet resourceSet, CDOViewImpl view)
- {
+ Map<URI, Resource> resourceMap = null;
+ if (resourceSet instanceof ResourceSetImpl)
+ {
+ ResourceSetImpl rs = (ResourceSetImpl)resourceSet;
+ resourceMap = rs.getURIResourceMap();
+ rs.setURIResourceMap(new ProxyResolverURIResourceMap(view, resourceMap));
+ }
+
synchronized (views)
{
resourceSet.eAdapters().add(view);
views.put(resourceSet, view);
fireEvent(new ViewsEvent(view, IContainerDelta.Kind.ADDED));
}
-
- return view;
}
/**
@@ -456,4 +469,255 @@ public class CDOSessionImpl extends Lifecycle implements CDOSession
return "CDOSessionInvalidationEvent" + dirtyOIDs;
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class ProxyResolverURIResourceMap implements Map<URI, Resource>
+ {
+ private Map<URI, Resource> delegate;
+
+ private Resource proxyResolverResource;
+
+ public ProxyResolverURIResourceMap(CDOViewImpl view, Map<URI, Resource> delegate)
+ {
+ if (delegate == null)
+ {
+ delegate = new HashMap(); // TODO Cleanup of this lookup cache?
+ }
+
+ this.delegate = delegate;
+ proxyResolverResource = new ProxyResolverResource(view);
+ }
+
+ public Resource get(Object key)
+ {
+ if (key instanceof URI)
+ {
+ URI uri = (URI)key;
+ String scheme = uri.scheme();
+ if ("cdo".equals(scheme))
+ {
+ String opaquePart = uri.opaquePart();
+ if ("proxy".equals(opaquePart))
+ {
+ return proxyResolverResource;
+ }
+ }
+ }
+
+ return delegate.get(key);
+ }
+
+ public void clear()
+ {
+ delegate.clear();
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return delegate.containsKey(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return delegate.containsValue(value);
+ }
+
+ public Set<Entry<URI, Resource>> entrySet()
+ {
+ return delegate.entrySet();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ return delegate.equals(o);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean isEmpty()
+ {
+ return delegate.isEmpty();
+ }
+
+ public Set<URI> keySet()
+ {
+ return delegate.keySet();
+ }
+
+ public Resource put(URI key, Resource value)
+ {
+ return delegate.put(key, value);
+ }
+
+ public void putAll(Map<? extends URI, ? extends Resource> t)
+ {
+ delegate.putAll(t);
+ }
+
+ public Resource remove(Object key)
+ {
+ return delegate.remove(key);
+ }
+
+ public int size()
+ {
+ return delegate.size();
+ }
+
+ public Collection<Resource> values()
+ {
+ return delegate.values();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class ProxyResolverResource implements Resource
+ {
+ private CDOViewImpl view;
+
+ public ProxyResolverResource(CDOViewImpl view)
+ {
+ this.view = view;
+ }
+
+ /*
+ * Called by {@link ResourceSetImpl#getResource(URI, boolean)}
+ */
+ public boolean isLoaded()
+ {
+ return true;
+ }
+
+ /*
+ * Called by {@link ResourceSetImpl#getEObject(URI, boolean)}
+ */
+ public EObject getEObject(String uriFragment)
+ {
+ CDOID id = CDOIDImpl.create(Long.parseLong(uriFragment));
+ InternalCDOObject object = view.lookupInstance(id);
+ if (object instanceof CDOAdapterImpl)
+ {
+ CDOAdapterImpl adapter = (CDOAdapterImpl)object;
+ System.out.println("RESOLVING");
+ adapter.cdoInternalResolveRevision();
+ return adapter.getTarget();
+ }
+
+ return null;
+ }
+
+ public TreeIterator<EObject> getAllContents()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public EList<EObject> getContents()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public EList<Diagnostic> getErrors()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ResourceSet getResourceSet()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public URI getURI()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getURIFragment(EObject object)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public EList<Diagnostic> getWarnings()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isModified()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isTrackingModification()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void load(Map<?, ?> options) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void load(InputStream inputStream, Map<?, ?> options) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void save(Map<?, ?> options) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void save(OutputStream outputStream, Map<?, ?> options) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setModified(boolean isModified)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setTrackingModification(boolean isTrackingModification)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setURI(URI uri)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void unload()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public EList<Adapter> eAdapters()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean eDeliver()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void eNotify(Notification notification)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void eSetDeliver(boolean deliver)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
}

Back to the top