Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-03-21 17:50:26 +0000
committerEike Stepper2012-03-21 17:50:26 +0000
commitd637f145c13224dd858db50b1a31f944768786a5 (patch)
tree3c5dc1a79fce7945fcc313ff77ead272056d0137 /plugins/org.eclipse.emf.cdo
parent67c7c58ed35ad91a20add4b484f4f3d832fed3cc (diff)
downloadcdo-d637f145c13224dd858db50b1a31f944768786a5.tar.gz
cdo-d637f145c13224dd858db50b1a31f944768786a5.tar.xz
cdo-d637f145c13224dd858db50b1a31f944768786a5.zip
[374962] Make CDOStaleReferencePolicy.PROXY robust for eAdapters() calls
https://bugs.eclipse.org/bugs/show_bug.cgi?id=374962
Diffstat (limited to 'plugins/org.eclipse.emf.cdo')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java228
1 files changed, 117 insertions, 111 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java
index 6d1c9dcf35..4522a758e3 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java
@@ -1,111 +1,117 @@
-/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.view;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.ObjectNotFoundException;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-/**
- * Specifies a policy on how to deal with stale references.
- *
- * @author Simon McDuff
- * @since 3.0
- */
-public interface CDOStaleReferencePolicy
-{
- /**
- * A default stale reference policy. It will throw an exception each time.
- */
- public static final CDOStaleReferencePolicy EXCEPTION = new CDOStaleReferencePolicy()
- {
- public Object processStaleReference(EObject source, EStructuralFeature feature, int index, CDOID target)
- {
- throw new ObjectNotFoundException(target);
- }
-
- @Override
- public String toString()
- {
- return Messages.getString("CDOStaleReferencePolicy.0"); //$NON-NLS-1$
- }
- };
-
- /**
- * Returns a proxy object with the appropriate EClass. The proxy object supports the {@link InternalEObject#eClass()
- * eClass()} and {@link InternalEObject#eIsProxy() eIsProxy()} methods. For all invocations to other methods the proxy
- * object throws an {@link ObjectNotFoundException}. The receiver can use {@link CDOUtil#isStaleObject(Object)} to
- * detect proxy objects.
- */
- public static final CDOStaleReferencePolicy PROXY = new CDOStaleReferencePolicy()
- {
- public Object processStaleReference(EObject source, final EStructuralFeature feature, int index, final CDOID target)
- {
- final EClassifier type = feature.getEType();
- InvocationHandler handler = new InvocationHandler()
- {
- public Object invoke(Object arg0, Method arg1, Object[] arg2) throws Throwable
- {
- if (arg1.getName().equals("eIsProxy")) //$NON-NLS-1$
- {
- return false;
- }
-
- if (arg1.getName().equals("eClass")) //$NON-NLS-1$
- {
- return type;
- }
-
- throw new ObjectNotFoundException(target);
- }
- };
-
- Class<?> instanceClass = type.getInstanceClass();
- Class<?>[] interfaces = null;
-
- // Be sure to have only interface
- if (instanceClass.isInterface())
- {
- interfaces = new Class<?>[] { instanceClass, InternalEObject.class, CDOStaleObject.class };
- }
- else
- {
- interfaces = new Class<?>[] { InternalEObject.class, CDOStaleObject.class };
- }
-
- return Proxy.newProxyInstance(instanceClass.getClassLoader(), interfaces, handler);
- }
-
- @Override
- public String toString()
- {
- return Messages.getString("CDOStaleReferencePolicy.1"); //$NON-NLS-1$
- }
- };
-
- /**
- * Returns an object that we want to return to the caller (clients). Exception thrown will be received by the caller
- * (clients).
- */
- public Object processStaleReference(EObject source, EStructuralFeature feature, int index, CDOID target);
-}
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.view;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.ObjectNotFoundException;
+
+import org.eclipse.emf.internal.cdo.messages.Messages;
+
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.InternalEObject;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * Specifies a policy on how to deal with stale references.
+ *
+ * @author Simon McDuff
+ * @since 3.0
+ */
+public interface CDOStaleReferencePolicy
+{
+ /**
+ * A default stale reference policy. It will throw an exception each time.
+ */
+ public static final CDOStaleReferencePolicy EXCEPTION = new CDOStaleReferencePolicy()
+ {
+ public Object processStaleReference(EObject source, EStructuralFeature feature, int index, CDOID target)
+ {
+ throw new ObjectNotFoundException(target);
+ }
+
+ @Override
+ public String toString()
+ {
+ return Messages.getString("CDOStaleReferencePolicy.0"); //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * Returns a proxy object with the appropriate EClass. The proxy object supports the {@link InternalEObject#eClass()
+ * eClass()} and {@link InternalEObject#eIsProxy() eIsProxy()} methods. For all invocations to other methods the proxy
+ * object throws an {@link ObjectNotFoundException}. The receiver can use {@link CDOUtil#isStaleObject(Object)} to
+ * detect proxy objects.
+ */
+ public static final CDOStaleReferencePolicy PROXY = new CDOStaleReferencePolicy()
+ {
+ public Object processStaleReference(final EObject source, final EStructuralFeature feature, int index,
+ final CDOID target)
+ {
+ final EClassifier type = feature.getEType();
+ InvocationHandler handler = new InvocationHandler()
+ {
+ public Object invoke(Object arg0, Method arg1, Object[] arg2) throws Throwable
+ {
+ if (arg1.getName().equals("eIsProxy")) //$NON-NLS-1$
+ {
+ return false;
+ }
+
+ if (arg1.getName().equals("eClass")) //$NON-NLS-1$
+ {
+ return type;
+ }
+
+ if (arg1.getName().equals("eAdapters")) //$NON-NLS-1$
+ {
+ return source.eAdapters();
+ }
+
+ throw new ObjectNotFoundException(target);
+ }
+ };
+
+ Class<?> instanceClass = type.getInstanceClass();
+ Class<?>[] interfaces = null;
+
+ // Be sure to have only interface
+ if (instanceClass.isInterface())
+ {
+ interfaces = new Class<?>[] { instanceClass, InternalEObject.class, CDOStaleObject.class };
+ }
+ else
+ {
+ interfaces = new Class<?>[] { InternalEObject.class, CDOStaleObject.class };
+ }
+
+ return Proxy.newProxyInstance(instanceClass.getClassLoader(), interfaces, handler);
+ }
+
+ @Override
+ public String toString()
+ {
+ return Messages.getString("CDOStaleReferencePolicy.1"); //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * Returns an object that we want to return to the caller (clients). Exception thrown will be received by the caller
+ * (clients).
+ */
+ public Object processStaleReference(EObject source, EStructuralFeature feature, int index, CDOID target);
+}

Back to the top