Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java60
1 files changed, 58 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
index 91a6778b62..b55a0a6215 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Simon McDuff - http://bugs.eclipse.org/246705
**************************************************************************/
package org.eclipse.emf.internal.cdo.util;
@@ -28,7 +29,9 @@ import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import java.lang.reflect.Method;
@@ -92,6 +95,12 @@ public final class FSMUtil
return state == CDOState.TRANSIENT || state == CDOState.PREPARED;
}
+ public static boolean isNew(CDOObject object)
+ {
+ CDOState state = object.cdoState();
+ return state == CDOState.NEW;
+ }
+
/**
* @param view
* Only needed if object is a meta instance.
@@ -157,9 +166,51 @@ public final class FSMUtil
return null;
}
- public static Iterator<InternalCDOObject> iterator(Collection<?> instances, final CDOViewImpl view)
+ /**
+ * Similar to {@link EcoreUtil#getAllProperContents(Resource, boolean)} except gives only one depth
+ */
+ public static Iterator<InternalCDOObject> getProperContents(final InternalCDOObject object)
+ {
+ final boolean isResource = object instanceof Resource;
+ final CDOView cdoView = object.cdoView();
+ final Iterator<EObject> delegate = object.eContents().iterator();
+
+ return new Iterator<InternalCDOObject>()
+ {
+ private Object next;
+
+ public boolean hasNext()
+ {
+ while (delegate.hasNext())
+ {
+ InternalEObject eObject = (InternalEObject)delegate.next();
+
+ if (isResource || eObject.eDirectResource() == null)
+ {
+ next = adapt(eObject, cdoView);
+ if (next instanceof InternalCDOObject)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public InternalCDOObject next()
+ {
+ return (InternalCDOObject)next;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public static Iterator<InternalCDOObject> iterator(final Iterator<?> delegate, final CDOViewImpl view)
{
- final Iterator<?> delegate = instances.iterator();
return new Iterator<InternalCDOObject>()
{
private Object next;
@@ -189,4 +240,9 @@ public final class FSMUtil
}
};
}
+
+ public static Iterator<InternalCDOObject> iterator(Collection<?> instances, final CDOViewImpl view)
+ {
+ return iterator(instances.iterator(), view);
+ }
}

Back to the top