Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2007-05-18 18:44:52 -0400
committeratikhomirov2007-05-18 18:44:52 -0400
commit2bc0a85bb21b2d2cf4a869dfa3a05f244e7db3f7 (patch)
treedf0e4d9ca0dab107de97b571253a7db9cfaeb211
parent38724968f4f6a00c5d066dd4077fc4ed43534988 (diff)
downloadorg.eclipse.gmf-tooling-2bc0a85bb21b2d2cf4a869dfa3a05f244e7db3f7.tar.gz
org.eclipse.gmf-tooling-2bc0a85bb21b2d2cf4a869dfa3a05f244e7db3f7.tar.xz
org.eclipse.gmf-tooling-2bc0a85bb21b2d2cf4a869dfa3a05f244e7db3f7.zip
do not process up-to-date versions of the model, consult delegate only when old version was detected;
moved base delegate impl out from helper class
-rw-r--r--plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java143
-rw-r--r--plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegateImpl.java137
2 files changed, 163 insertions, 117 deletions
diff --git a/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java b/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java
index 69a0f8045..d15671a8e 100644
--- a/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java
+++ b/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java
@@ -10,20 +10,12 @@
*/
package org.eclipse.gmf.internal.common.migrate;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.impl.EReferenceImpl;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
@@ -32,124 +24,23 @@ public class MigrationHelper extends XMIHelperImpl {
private final MigrationHelperDelegate myDelegate;
private EStructuralFeature mySavedFeature;
private EReferenceImpl myFakeFeatureWithNarrowType;
+ private boolean myIsDelegateDisabled = true;
public MigrationHelper(XMLResource resource, MigrationHelperDelegate delegate) {
super(resource);
assert delegate != null;
myDelegate = delegate;
}
-
- public static class MigrationHelperDelegateImpl implements MigrationHelperDelegate {
-
- public MigrationHelperDelegateImpl() {
- super();
- }
-
- private static EStructuralFeature ourDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
- static {
- ourDeletedAttribute.setName("attributeIsDeleted"); //$NON-NLS-1$
- ourDeletedAttribute.setEType(EcorePackage.eINSTANCE.getEString());
- }
-
- private Map<EClassifier, Collection<String>> myDeletedAttributes = new HashMap<EClassifier, Collection<String>>();
- private Map<EReference, EClass> myNarrowReferenceTypes = new HashMap<EReference, EClass>();
- private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
- private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
-
- public void registerDeletedAttributes(EClassifier classifier, String... deletedAttrNames) {
- assert !myDeletedAttributes.containsKey(classifier);
- myDeletedAttributes.put(classifier, Arrays.asList(deletedAttrNames));
- }
-
- public void registerNarrowReferenceType(EReference reference, EClass concreteType) {
- myNarrowReferenceTypes.put(reference, concreteType);
- }
-
- public void registerRenamedAttributes(EClass eClass, Map<String, EStructuralFeature> renamedAttributes) {
- myRenamedAttributes.put(eClass, renamedAttributes);
- }
-
- public void registerRenamedType(String oldTypeName, EClassifier newType) {
- myRenamedTypes.put(oldTypeName, newType);
- }
-
- public void registerRenamedAttribute(EClass eClass, String oldName, EStructuralFeature newStructuralFeature) {
- Map<String, EStructuralFeature> renamedAttributes = myRenamedAttributes.get(eClass);
- if (renamedAttributes == null) {
- renamedAttributes = new HashMap<String, EStructuralFeature>();
- }
- renamedAttributes.put(oldName, newStructuralFeature);
- registerRenamedAttributes(eClass, renamedAttributes);
- }
-
- public boolean isAttributeDeleted(EClass clazz, String name) {
- Collection<String> deletedAttributes = myDeletedAttributes.get(clazz);
- boolean result = deletedAttributes != null && deletedAttributes.contains(name);
- for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); !result && it.hasNext();) {
- EClass nextParent = it.next();
- result = isAttributeDeleted(nextParent, name);
- }
- return result;
- }
-
- public EClass getNarrowReferenceType(EStructuralFeature feature) {
- return myNarrowReferenceTypes.get(feature);
- }
- public EStructuralFeature getRenamedFeatureFor(EClass clazz, String name) {
- Map<String, EStructuralFeature> renamings = myRenamedAttributes.get(clazz);
- EStructuralFeature result = renamings != null ? renamings.get(name) : null;
- for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); result == null && it.hasNext();) {
- EClass nextParent = it.next();
- result = getRenamedFeatureFor(nextParent, name);
- }
- return result;
- }
-
- public EClassifier getRenamedType(String typeName) {
- return myRenamedTypes.get(typeName);
- }
-
- public EClass getStructuralFeatureType(EStructuralFeature feature) {
- return getNarrowReferenceType(feature);
- }
-
- public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
- return ourDeletedAttribute.equals(feature);
- }
-
- public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
- EStructuralFeature result = null;
- EStructuralFeature rename = null;
- if (isAttributeDeleted(eClass, name)) {
- result = ourDeletedAttribute;
- } else if ((rename = getRenamedFeatureFor(eClass, name)) != null) {
- result = rename;
- }
- return result;
- }
-
- public EClassifier getType(EFactory factory, String typeName) {
- EClassifier result = null;
- EClassifier type = getRenamedType(typeName);
- if (type != null) {
- result = type;
- }
- return result;
- }
-
- public EObject createObject(EFactory factory, EClassifier type) {
- return null;
- }
-
- public void postProcess() {
- }
-
- public void processObject(EObject result) {
- }
+ void enableDelegate(boolean enabled) {
+ myIsDelegateDisabled = !enabled;
}
+ @Override
public EObject createObject(EFactory factory, EClassifier type) {
+ if (myIsDelegateDisabled) {
+ return super.createObject(factory, type);
+ }
EObject result = myDelegate.createObject(factory, type);
if (result == null) {
result = super.createObject(factory, type);
@@ -158,7 +49,12 @@ public class MigrationHelper extends XMIHelperImpl {
return result;
}
+ @Override
public void setValue(EObject object, EStructuralFeature feature, Object value, int position) {
+ if (myIsDelegateDisabled) {
+ super.setValue(object, feature, value, position);
+ return;
+ }
if (feature != null && feature.equals(myFakeFeatureWithNarrowType)) {
feature = mySavedFeature;
}
@@ -167,10 +63,14 @@ public class MigrationHelper extends XMIHelperImpl {
}
}
+ @Override
public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
+ if (myIsDelegateDisabled) {
+ return super.getFeature(eClass, namespaceURI, name, isElement);
+ }
EStructuralFeature result = myDelegate.getFeature(eClass, namespaceURI, name, isElement);
if (result == null) {
- result = super.getFeature(eClass, namespaceURI, name);
+ result = super.getFeature(eClass, namespaceURI, name, isElement);
}
EClass narrow = myDelegate.getStructuralFeatureType(result);
if (narrow != null) {
@@ -183,7 +83,11 @@ public class MigrationHelper extends XMIHelperImpl {
return result;
}
+ @Override
public EClassifier getType(EFactory factory, String typeName) {
+ if (myIsDelegateDisabled) {
+ return super.getType(factory, typeName);
+ }
EClassifier result = myDelegate.getType(factory, typeName);
if (result == null) {
result = super.getType(factory, typeName);
@@ -191,7 +95,12 @@ public class MigrationHelper extends XMIHelperImpl {
return result;
}
+ @Override
public void popContext() {
+ super.popContext();
+ if (myIsDelegateDisabled) {
+ return;
+ }
myDelegate.postProcess();
}
}
diff --git a/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegateImpl.java b/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegateImpl.java
new file mode 100644
index 000000000..ba5b0f310
--- /dev/null
+++ b/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegateImpl.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2007 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.common.migrate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+
+public class MigrationHelperDelegateImpl implements MigrationHelperDelegate {
+
+ public MigrationHelperDelegateImpl() {
+ super();
+ }
+
+ private static EStructuralFeature ourDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
+ static {
+ ourDeletedAttribute.setName("attributeIsDeleted"); //$NON-NLS-1$
+ ourDeletedAttribute.setEType(EcorePackage.eINSTANCE.getEString());
+ }
+
+ private Map<EClassifier, Collection<String>> myDeletedAttributes = new HashMap<EClassifier, Collection<String>>();
+ private Map<EReference, EClass> myNarrowReferenceTypes = new HashMap<EReference, EClass>();
+ private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
+ private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
+
+ public void registerDeletedAttributes(EClassifier classifier, String... deletedAttrNames) {
+ assert !myDeletedAttributes.containsKey(classifier);
+ myDeletedAttributes.put(classifier, Arrays.asList(deletedAttrNames));
+ }
+
+ public void registerNarrowReferenceType(EReference reference, EClass concreteType) {
+ myNarrowReferenceTypes.put(reference, concreteType);
+ }
+
+ public void registerRenamedAttributes(EClass eClass, Map<String, EStructuralFeature> renamedAttributes) {
+ myRenamedAttributes.put(eClass, renamedAttributes);
+ }
+
+ public void registerRenamedType(String oldTypeName, EClassifier newType) {
+ myRenamedTypes.put(oldTypeName, newType);
+ }
+
+ public void registerRenamedAttribute(EClass eClass, String oldName, EStructuralFeature newStructuralFeature) {
+ Map<String, EStructuralFeature> renamedAttributes = myRenamedAttributes.get(eClass);
+ if (renamedAttributes == null) {
+ renamedAttributes = new HashMap<String, EStructuralFeature>();
+ }
+ renamedAttributes.put(oldName, newStructuralFeature);
+ registerRenamedAttributes(eClass, renamedAttributes);
+ }
+
+ public boolean isAttributeDeleted(EClass clazz, String name) {
+ Collection<String> deletedAttributes = myDeletedAttributes.get(clazz);
+ boolean result = deletedAttributes != null && deletedAttributes.contains(name);
+ for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); !result && it.hasNext();) {
+ EClass nextParent = it.next();
+ result = isAttributeDeleted(nextParent, name);
+ }
+ return result;
+ }
+
+ public EClass getNarrowReferenceType(EStructuralFeature feature) {
+ return myNarrowReferenceTypes.get(feature);
+ }
+
+ public EStructuralFeature getRenamedFeatureFor(EClass clazz, String name) {
+ Map<String, EStructuralFeature> renamings = myRenamedAttributes.get(clazz);
+ EStructuralFeature result = renamings != null ? renamings.get(name) : null;
+ for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); result == null && it.hasNext();) {
+ EClass nextParent = it.next();
+ result = getRenamedFeatureFor(nextParent, name);
+ }
+ return result;
+ }
+
+ public EClassifier getRenamedType(String typeName) {
+ return myRenamedTypes.get(typeName);
+ }
+
+ public EClass getStructuralFeatureType(EStructuralFeature feature) {
+ return getNarrowReferenceType(feature);
+ }
+
+ public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
+ return ourDeletedAttribute.equals(feature);
+ }
+
+ public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
+ EStructuralFeature result = null;
+ EStructuralFeature rename = null;
+ if (isAttributeDeleted(eClass, name)) {
+ result = ourDeletedAttribute;
+ } else if ((rename = getRenamedFeatureFor(eClass, name)) != null) {
+ result = rename;
+ }
+ return result;
+ }
+
+ public EClassifier getType(EFactory factory, String typeName) {
+ EClassifier result = null;
+ EClassifier type = getRenamedType(typeName);
+ if (type != null) {
+ result = type;
+ }
+ return result;
+ }
+
+ public EObject createObject(EFactory factory, EClassifier type) {
+ return null;
+ }
+
+ public void postProcess() {
+ }
+
+ public void processObject(EObject result) {
+ }
+} \ No newline at end of file

Back to the top