summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-25 14:55:43 (EDT)
committerEike Stepper2007-07-25 14:55:43 (EDT)
commit8b91222a90e68e0b296cc6b39a6652cf058bb3b0 (patch)
tree42e7f794cdf56e97f94b889912805e9234813589
parentb7678d8f0563d9e5f530bc6fa64e5ae26683cdaa (diff)
downloadcdo-8b91222a90e68e0b296cc6b39a6652cf058bb3b0.zip
cdo-8b91222a90e68e0b296cc6b39a6652cf058bb3b0.tar.gz
cdo-8b91222a90e68e0b296cc6b39a6652cf058bb3b0.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java65
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java67
2 files changed, 81 insertions, 51 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 723d942..301934f 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
@@ -25,6 +25,7 @@ import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -55,6 +56,8 @@ 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.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
@@ -375,7 +378,8 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
{
CDOID resourceID = revision.getResourceID();
Resource.Internal resource = (Resource.Internal)view.lookupInstance(resourceID);
- ((BasicEObjectImpl)target).eSetResource(resource, null);
+ transferResourceToTarget((BasicEObjectImpl)target, resource);
+ // ((BasicEObjectImpl)target).eSetResource(resource, null);
}
else
{
@@ -426,6 +430,20 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
}
}
+ private void transferResourceToTarget(BasicEObjectImpl target, Resource.Internal resource)
+ {
+ Method method = ReflectUtil.getMethod(BasicEObjectImpl.class, "eSetDirectResource", Resource.Internal.class);
+
+ try
+ {
+ ReflectUtil.invokeMethod(method, target, resource);
+ }
+ catch (InvocationTargetException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
private Object getTargetValue(InternalEObject target, CDOFeatureImpl feature)
{
// Class<?> targetClass = target.getClass();
@@ -527,7 +545,7 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
int flagsMask = getEFlagMask(targetClass, flagName);
field = ReflectUtil.getField(targetClass, "eFlags");
- int flags = (Integer)getFiedValue(target, field);
+ int flags = (Integer)ReflectUtil.getValue(field, target);
boolean on = (Boolean)value;
if (on)
{
@@ -538,7 +556,7 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
flags &= ~flagsMask; // Remove EFlag
}
- setFiedValue(target, field, flags);
+ ReflectUtil.setValue(field, target, flags);
return;
}
}
@@ -548,46 +566,7 @@ public class CDOAdapterImpl extends AdapterImpl implements InternalCDOObject
throw new ImplementationError("Field not found: " + fieldName);
}
- setFiedValue(target, field, value);
- }
-
- private static Object getFiedValue(InternalEObject target, Field field)
- {
- if (!field.isAccessible())
- {
- field.setAccessible(true);
- }
-
- try
- {
- return field.get(target);
- }
- catch (IllegalAccessException ex)
- {
- throw new ImplementationError(ex);
- }
- }
-
- private static void setFiedValue(InternalEObject target, Field field, Object value)
- {
- if (!field.isAccessible())
- {
- field.setAccessible(true);
- }
-
- try
- {
- field.set(target, value);
- }
- catch (IllegalAccessException ex)
- {
- throw new ImplementationError(ex);
- }
- catch (RuntimeException ex)
- {
- ex.printStackTrace();
- throw ex;
- }
+ ReflectUtil.setValue(field, target, value);
}
private static int getEFlagMask(Class<?> targetClass, String flagName)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java
index c9e478c..aac1bb3 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ReflectUtil.java
@@ -56,20 +56,20 @@ public final class ReflectUtil
{
}
- public static Field getField(Class<?> c, String fieldName)
+ public static Method getMethod(Class<?> c, String methodName, Class... parameterTypes)
{
try
{
try
{
- return c.getDeclaredField(fieldName);
+ return c.getDeclaredMethod(methodName, parameterTypes);
}
- catch (NoSuchFieldException ex)
+ catch (NoSuchMethodException ex)
{
Class<?> superclass = c.getSuperclass();
if (superclass != null)
{
- return getField(superclass, fieldName);
+ return getMethod(superclass, methodName, parameterTypes);
}
return null;
@@ -85,20 +85,37 @@ public final class ReflectUtil
}
}
- public static Method getMethod(Class<?> c, String methodName, Class... parameterTypes)
+ public static Object invokeMethod(Method method, Object target, Object... arguments) throws InvocationTargetException
+ {
+ if (!method.isAccessible())
+ {
+ method.setAccessible(true);
+ }
+
+ try
+ {
+ return method.invoke(target, arguments);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new ImplementationError(ex);
+ }
+ }
+
+ public static Field getField(Class<?> c, String fieldName)
{
try
{
try
{
- return c.getDeclaredMethod(methodName, parameterTypes);
+ return c.getDeclaredField(fieldName);
}
- catch (NoSuchMethodException ex)
+ catch (NoSuchFieldException ex)
{
Class<?> superclass = c.getSuperclass();
if (superclass != null)
{
- return getMethod(superclass, methodName, parameterTypes);
+ return getField(superclass, fieldName);
}
return null;
@@ -114,6 +131,40 @@ public final class ReflectUtil
}
}
+ public static Object getValue(Field field, Object target)
+ {
+ if (!field.isAccessible())
+ {
+ field.setAccessible(true);
+ }
+
+ try
+ {
+ return field.get(target);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new ImplementationError(ex);
+ }
+ }
+
+ public static void setValue(Field field, Object target, Object value)
+ {
+ if (!field.isAccessible())
+ {
+ field.setAccessible(true);
+ }
+
+ try
+ {
+ field.set(target, value);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new ImplementationError(ex);
+ }
+ }
+
public static void printStackTrace(PrintStream out, StackTraceElement[] stackTrace)
{
for (int i = 2; i < stackTrace.length; i++)