Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-19 22:10:22 +0000
committerEike Stepper2007-07-19 22:10:22 +0000
commit49a10ec0b9f8c478fd7942b7ddcac4fd1bdde271 (patch)
tree3b87f255da7360eeedf8539c5d0d940bfdd7515e
parentff11efee7dead8e18b07dd8516cc660cc2dbdb74 (diff)
downloadcdo-49a10ec0b9f8c478fd7942b7ddcac4fd1bdde271.tar.gz
cdo-49a10ec0b9f8c478fd7942b7ddcac4fd1bdde271.tar.xz
cdo-49a10ec0b9f8c478fd7942b7ddcac4fd1bdde271.zip
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java136
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java13
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/GenUtil.java143
3 files changed, 256 insertions, 36 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java
index 552a5ef551..492b4ab69e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectAdapter.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOType;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.cdo.protocol.util.ImplementationError;
@@ -39,9 +40,16 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.impl.EAttributeImpl;
+import org.eclipse.emf.ecore.impl.EClassImpl;
+import org.eclipse.emf.ecore.impl.EDataTypeImpl;
+import org.eclipse.emf.ecore.impl.EReferenceImpl;
+import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
+import org.eclipse.emf.ecore.impl.ETypedElementImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.util.GenUtil;
import java.lang.reflect.Field;
import java.util.List;
@@ -227,7 +235,7 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
CDOViewImpl view = (CDOViewImpl)cdoView();
CDOClassImpl cdoClass = revision.getCDOClass();
- System.out.println("TRANSFER " + cdoClass);
+ System.out.println("TRANSFER " + cdoClass.getName());
CDOFeatureImpl[] features = cdoClass.getAllFeatures();
for (int i = 0; i < features.length; i++)
@@ -235,30 +243,46 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
CDOFeatureImpl feature = features[i];
System.out.println("FEATURE " + feature);
- Object targetValue = getTargetValue(target, feature);
+ Object targetValue = getTargetValue(target, feature, view);
if (feature.isMany())
{
List revisionList = revision.getList(feature);
revisionList.clear();
- BasicEList targetList = (BasicEList)targetValue;
- Object[] data = targetList.data();
- if (data != null)
+ if (targetValue instanceof BasicEList)
{
- for (Object targetElement : data)
+ BasicEList targetList = (BasicEList)targetValue;
+ if (targetList != null)
{
- if (feature.isReference())
+ Object[] data = targetList.data();
+ if (data != null)
{
- targetElement = view.convertToID(targetElement);
+ for (int j = 0; j < targetList.size(); j++)
+ {
+ Object targetElement = data[j];
+ if (targetElement != null && feature.isReference())
+ {
+ targetElement = view.convertToID(targetElement);
+ }
+
+ revisionList.add(targetElement);
+ }
}
-
- revisionList.add(targetElement);
}
}
+ else
+ {
+ if (targetValue != null && feature.isReference())
+ {
+ targetValue = view.convertToID(targetValue);
+ }
+
+ revisionList.add(targetValue);
+ }
}
else
{
- if (feature.isReference())
+ if (targetValue != null && feature.isReference())
{
targetValue = view.convertToID(targetValue);
}
@@ -270,39 +294,81 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
private void transferRevisionToTarget()
{
- InternalEObject target = getTarget();
- CDOViewImpl view = (CDOViewImpl)cdoView();
-
- CDOClassImpl cdoClass = revision.getCDOClass();
- System.out.println("TRANSFER " + cdoClass);
+ // TODO Implement method CDOObjectAdapter.transferRevisionToTarget()
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
- CDOFeatureImpl[] features = cdoClass.getAllFeatures();
- for (int i = 0; i < features.length; i++)
+ private static Object getTargetValue(InternalEObject target, CDOFeatureImpl feature, CDOViewImpl view)
+ {
+ 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)
{
- CDOFeatureImpl feature = features[i];
- Object value = revision.getValue(feature);
- if (feature.isMany())
- {
- EList list = (EList)getTargetValue(target, feature);
- dumpSetting(feature, list);
- }
- else
+ 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))
{
- value = view.convertToObject(value);
- dumpSetting(feature, value);
- setTargetValue(target, feature, value);
+ // *******************************************
+ // 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);
}
- private void dumpSetting(CDOFeatureImpl feature, Object value)
+ private static Object getFiedValue(InternalEObject target, Field field)
{
- System.out.println(feature.getName() + " --> " + (value == null ? "null" : value.getClass().getName()));
+ if (!field.isAccessible())
+ {
+ field.setAccessible(true);
+ }
+
+ try
+ {
+ return field.get(target);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new ImplementationError(ex);
+ }
}
- private static Object getTargetValue(InternalEObject target, CDOFeatureImpl feature)
+ private static int getEFlagMask(Class<?> targetClass, String flagName)
{
- Field field = getField(target.getClass(), feature.getName());
+ Field field = getField(targetClass, flagName);
if (!field.isAccessible())
{
field.setAccessible(true);
@@ -310,7 +376,7 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
try
{
- return field.get(target);
+ return (Integer)field.get(null);
}
catch (IllegalAccessException ex)
{
@@ -352,7 +418,7 @@ public class CDOObjectAdapter extends AdapterImpl implements InternalCDOObject
return getField(superclass, fieldName);
}
- throw new NoSuchFieldException(fieldName);
+ return null;
}
}
catch (RuntimeException ex)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 82a112b021..c3fe4b08e1 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -94,7 +94,13 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
{
try
{
- CDOID id = (CDOID)CDOViewImpl.this.convertToID(object);
+ Object converted = CDOViewImpl.this.convertToID(object);
+ if (!(converted instanceof CDOID))
+ {
+ System.out.println(object);
+ }
+
+ CDOID id = (CDOID)converted;
if (TRACER.isEnabled())
{
TRACER.format("Converted dangling reference: {0} --> {1}", object, id);
@@ -309,6 +315,11 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
public Object convertToID(Object potentialObject)
{
+ if (potentialObject == null)
+ {
+ throw new ImplementationError();
+ }
+
if (!(potentialObject instanceof InternalCDOObject))
{
if (potentialObject instanceof InternalEObject)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/GenUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/GenUtil.java
new file mode 100644
index 0000000000..7eba0fe998
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/GenUtil.java
@@ -0,0 +1,143 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public final class GenUtil
+{
+ private GenUtil()
+ {
+ }
+
+ public static String getUpperFeatureName(String featureName)
+ {
+ return format(featureName, '_', null, false, true).toUpperCase();
+ }
+
+ /**
+ * Formats a name by parsing it into words separated by underscores and/or
+ * mixed-casing and then recombining them using the specified separator. A
+ * prefix can also be given to be recognized as a separate word or to be
+ * trimmed. Leading underscores can be ignored or can cause a leading
+ * separator to be prepended.
+ *
+ * @since 2.2
+ */
+ public static String format(String name, char separator, String prefix, boolean includePrefix,
+ boolean includeLeadingSeparator)
+ {
+ String leadingSeparators = includeLeadingSeparator ? getLeadingSeparators(name, '_') : null;
+ if (leadingSeparators != null)
+ {
+ name = name.substring(leadingSeparators.length());
+ }
+
+ List<String> parsedName = new ArrayList<String>();
+ if (prefix != null && name.startsWith(prefix) && name.length() > prefix.length()
+ && Character.isUpperCase(name.charAt(prefix.length())))
+ {
+ name = name.substring(prefix.length());
+ if (includePrefix)
+ {
+ parsedName = parseName(prefix, '_');
+ }
+ }
+
+ if (name.length() != 0)
+ parsedName.addAll(parseName(name, '_'));
+
+ StringBuilder result = new StringBuilder();
+
+ for (Iterator<String> nameIter = parsedName.iterator(); nameIter.hasNext();)
+ {
+ String nameComponent = nameIter.next();
+ result.append(nameComponent);
+
+ if (nameIter.hasNext() && nameComponent.length() > 1)
+ {
+ result.append(separator);
+ }
+ }
+
+ if (result.length() == 0 && prefix != null)
+ {
+ result.append(prefix);
+ }
+ return leadingSeparators != null ? "_" + result.toString() : result.toString();
+ }
+
+ /**
+ * This method breaks sourceName into words delimited by separator and/or
+ * mixed-case naming.
+ */
+ public static List<String> parseName(String sourceName, char separator)
+ {
+ List<String> result = new ArrayList<String>();
+ if (sourceName != null)
+ {
+ StringBuilder currentWord = new StringBuilder();
+ boolean lastIsLower = false;
+ for (int index = 0, length = sourceName.length(); index < length; ++index)
+ {
+ char curChar = sourceName.charAt(index);
+ if (Character.isUpperCase(curChar) || !lastIsLower && Character.isDigit(curChar) || curChar == separator)
+ {
+ if (lastIsLower && currentWord.length() > 1 || curChar == separator && currentWord.length() > 0)
+ {
+ result.add(currentWord.toString());
+ currentWord = new StringBuilder();
+ }
+ lastIsLower = false;
+ }
+ else
+ {
+ if (!lastIsLower)
+ {
+ int currentWordLength = currentWord.length();
+ if (currentWordLength > 1)
+ {
+ char lastChar = currentWord.charAt(--currentWordLength);
+ currentWord.setLength(currentWordLength);
+ result.add(currentWord.toString());
+ currentWord = new StringBuilder();
+ currentWord.append(lastChar);
+ }
+ }
+ lastIsLower = true;
+ }
+
+ if (curChar != separator)
+ {
+ currentWord.append(curChar);
+ }
+ }
+
+ result.add(currentWord.toString());
+ }
+ return result;
+ }
+
+ private static String getLeadingSeparators(String name, char separator)
+ {
+ int i = 0;
+ for (int len = name.length(); i < len && name.charAt(i) == separator; i++)
+ {
+ // the for loop's condition finds the separator
+ }
+ return i != 0 ? name.substring(0, i) : null;
+ }
+}

Back to the top