Changed FeatureValueProvider to have a helper to handle standard
EObject's too.
diff --git a/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/FeatureValueProvider.java b/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/FeatureValueProvider.java
index f1e40f4..8874f76 100644
--- a/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/FeatureValueProvider.java
+++ b/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/FeatureValueProvider.java
@@ -11,9 +11,12 @@
package org.eclipse.jem.internal.instantiation.base;
/*
* $RCSfile: FeatureValueProvider.java,v $
- * $Revision: 1.4 $ $Date: 2005/05/11 19:01:16 $
+ * $Revision: 1.5 $ $Date: 2005/05/12 22:17:05 $
*/
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
/**
@@ -24,6 +27,53 @@
* @since 1.1.0
*/
public interface FeatureValueProvider {
+
+ /**
+ * A helper class for FeatureValueProvider.
+ *
+ * @see FeatureValueProviderHelper#visitSetFeatures(EObject, Visitor)
+ *
+ * @since 1.1.0
+ */
+ public static class FeatureValueProviderHelper {
+
+ /**
+ * A helper to handle where the object may or may not be
+ * implement FeatureValueProvider. This way it can be a
+ * common access to do it.
+ *
+ * @param eobject
+ * @param visitor
+ * @return
+ *
+ * @since 1.1.0
+ */
+ public static Object visitSetFeatures(EObject eobject, Visitor visitor) {
+ FeatureValueProvider fvp;
+ try {
+ fvp = (FeatureValueProvider) eobject;
+ } catch (ClassCastException e) {
+ // Not a FeatureValueProvider, so do normal.
+ Iterator features = eobject.eClass().getEAllStructuralFeatures().iterator();
+ while(features.hasNext()){
+ EStructuralFeature sf = (EStructuralFeature)features.next();
+ if(eobject.eIsSet(sf)){
+ Object result = visitor.isSet(sf, eobject.eGet(sf));
+ if (result != null)
+ return result;
+ }
+ }
+ return null;
+ }
+ // We run it outside of the class cast block so in caise the visit itself
+ // throws a class cast, that one can go on out from here.
+ return fvp.visitSetFeatures(visitor);
+ }
+
+ private FeatureValueProviderHelper() {
+ }
+ }
+
/**
* The interface for the visiter callback.
*
@@ -47,5 +97,5 @@
* @param <code>null</code> if all settings visited, or the value returned from the visit (isSet) that returned a non-nullSe.
* @since 1.1.0
*/
- Object visitSetFeatures(Visitor aVisitor);
+ public Object visitSetFeatures(Visitor aVisitor);
}
diff --git a/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/IJavaObjectInstance.java b/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/IJavaObjectInstance.java
index 392377f..e8e2f9d 100644
--- a/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/IJavaObjectInstance.java
+++ b/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/IJavaObjectInstance.java
@@ -11,13 +11,13 @@
package org.eclipse.jem.internal.instantiation.base;
/*
* $RCSfile: IJavaObjectInstance.java,v $
- * $Revision: 1.4 $ $Date: 2005/02/15 22:36:09 $
+ * $Revision: 1.5 $ $Date: 2005/05/12 22:17:05 $
*/
/**
* Interface for java object instances.
*/
-public interface IJavaObjectInstance extends IJavaInstance {
+public interface IJavaObjectInstance extends IJavaInstance, FeatureValueProvider {
}
diff --git a/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/JavaObjectInstance.java b/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/JavaObjectInstance.java
index 002d477..8c9d9e0 100644
--- a/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/JavaObjectInstance.java
+++ b/plugins/org.eclipse.jem/javainst/org/eclipse/jem/internal/instantiation/base/JavaObjectInstance.java
@@ -11,7 +11,7 @@
package org.eclipse.jem.internal.instantiation.base;
/*
* $RCSfile: JavaObjectInstance.java,v $
- * $Revision: 1.14 $ $Date: 2005/05/11 19:01:16 $
+ * $Revision: 1.15 $ $Date: 2005/05/12 22:17:05 $
*/
import java.util.List;
@@ -30,7 +30,7 @@
* It should not be referenced directly, the IJavaObjectInstance interface should be
* used instead. It is public so that it can be subclassed.
*/
-public class JavaObjectInstance extends EObjectImpl implements IJavaObjectInstance , FeatureValueProvider {
+public class JavaObjectInstance extends EObjectImpl implements IJavaObjectInstance {
public JavaHelpers getJavaType(){
return (JavaHelpers) eClass();