View | Details | Raw Unified | Return to bug 187811 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java (+83 lines)
Lines 13-18 Link Here
13
13
14
import java.io.File;
14
import java.io.File;
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.util.Collection;
17
import java.util.Collections;
16
18
17
import junit.framework.TestCase;
19
import junit.framework.TestCase;
18
20
Lines 25-31 Link Here
25
import org.eclipse.emf.ecore.EcorePackage;
27
import org.eclipse.emf.ecore.EcorePackage;
26
import org.eclipse.emf.ecore.resource.Resource;
28
import org.eclipse.emf.ecore.resource.Resource;
27
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
29
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
30
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
28
import org.eclipse.gmf.internal.common.migrate.MigrationConfig;
31
import org.eclipse.gmf.internal.common.migrate.MigrationConfig;
32
import org.eclipse.gmf.internal.common.migrate.MigrationHelper;
33
import org.eclipse.gmf.internal.common.migrate.MigrationHelperDelegate;
34
import org.eclipse.gmf.internal.common.migrate.MigrationResource2;
29
import org.eclipse.gmf.internal.common.migrate.MigrationUtil;
35
import org.eclipse.gmf.internal.common.migrate.MigrationUtil;
30
36
31
/**
37
/**
Lines 131-134 Link Here
131
			EPackage.Registry.INSTANCE.put(newNsURI, null);
137
			EPackage.Registry.INSTANCE.put(newNsURI, null);
132
		}
138
		}
133
	}
139
	}
140
141
	public void newTestRemovedAttribute() { //XXX: this test is turned off!
142
		final EObject testObject = newInstance();
143
		testObject.eSet(myAttrToRemove, "value");
144
145
		final String oldNsURI = getMetaModel().getNsURI();
146
		EPackage.Registry.INSTANCE.put(oldNsURI, getMetaModel());
147
		final String newNsURI = oldNsURI + "/2";
148
		EPackage.Registry.INSTANCE.put(newNsURI, getMetaModel());
149
150
		try {
151
			URI uri = null;
152
			try {
153
				uri = URI.createFileURI(File.createTempFile("removed", ".tests").getAbsolutePath());
154
				final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
155
				final Resource res = resourceSetImpl.createResource(uri);
156
				res.getContents().add(testObject);
157
				res.save(null);
158
				resourceSetImpl.getResources().remove(testObject);
159
			} catch (IOException ex) {
160
				fail(ex.toString());
161
			}
162
			// remove attr from metamodel
163
			myAttrToRemove.getEContainingClass().getEStructuralFeatures().remove(myAttrToRemove);
164
165
			// try to load mm
166
			try {
167
				new ResourceSetImpl().createResource(uri).load(null);
168
				fail("Load should fail because of missing meta-model attribute");
169
			} catch (IOException ex) {
170
				// expected
171
				assertNotNull(ex.getMessage());
172
				assertTrue(ex.getMessage().contains(myAttrToRemove.getName()));
173
			}
174
175
			EPackage.Registry.INSTANCE.put(oldNsURI, null);
176
177
			Resource.Factory factory = new ToolingResourceFactory() {
178
179
				@Override
180
				public Resource createResource(URI uri) {
181
					return new MigrationResource2(uri) {
182
						protected MigrationHelperDelegate createDelegate() {
183
							MigrationHelperDelegate delegate = new MigrationHelper.MigrationHelperDelegateImpl() {
184
								{
185
									registerDeletedAttributes(testObject.eClass(), myAttrToRemove.getName());
186
								}
187
							};
188
							return delegate;
189
						}
190
191
						protected Collection<String> getBackwardSupportedURIs() {
192
							return Collections.<String>singleton(oldNsURI);
193
						}
194
195
						@Override
196
						protected String getMetamodelNsURI() {
197
							return newNsURI;
198
						}
199
					};
200
				}
201
				
202
			};
203
			Resource migrated = MigrationUtil.migrateModel(factory, uri).getLoadedResource();
204
			assertNotNull(migrated);
205
			assertTrue(migrated.getErrors().isEmpty() && migrated.getWarnings().isEmpty());
206
			assertEquals(1, migrated.getContents().size());
207
			EObject migratedObj = migrated.getContents().get(0);
208
			assertEquals(testObject.eClass(), migratedObj.eClass());
209
		} finally {
210
			// clean-up, avoid any chances to affect other tests
211
			// XXX MigrationConfig should be cleaned as well.
212
			EPackage.Registry.INSTANCE.put(oldNsURI, null);
213
			EPackage.Registry.INSTANCE.put(newNsURI, null);
214
		}
215
	}
216
	
134
}
217
}
(-)src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java (-13 / +42 lines)
Lines 45-51 Link Here
45
45
46
		assertOnLoadModelMigrationSuccess(genmodelFileName);
46
		assertOnLoadModelMigrationSuccess(genmodelFileName);
47
47
48
		String gmfmapmodelFileName = "patch_138440.gmfmap"; //$NON-NLS-1$		
48
		String gmfmapmodelFileName = "patch_138440.gmfmap"; //$NON-NLS-1$
49
		Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
49
		Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
50
		assertTrue("expected IllegalArgumentException from metamodel EFactory", caughtMapException instanceof IllegalArgumentException); //$NON-NLS-1$
50
		assertTrue("expected IllegalArgumentException from metamodel EFactory", caughtMapException instanceof IllegalArgumentException); //$NON-NLS-1$
51
51
Lines 82-92 Link Here
82
	void assertOnLoadModelMigrationSuccess(String modelFileName) throws Exception {
82
	void assertOnLoadModelMigrationSuccess(String modelFileName) throws Exception {
83
		URI uri = createURI(modelFileName);
83
		URI uri = createURI(modelFileName);
84
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
84
		ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
85
		
85
		assertTrue("Migration warning load status expected", loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$
86
		assertTrue("Migration warning load status expected", loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$
86
87
		EList<Resource.Diagnostic> warnings = loadHelper.getLoadedResource().getWarnings();
87
		EList<Resource.Diagnostic> warnings = loadHelper.getLoadedResource().getWarnings();
88
		assertEquals("Single Warning diagnostic expected", 1, warnings.size()); //$NON-NLS-1$		
88
		assertEquals("Single Warning diagnostic expected", 1, warnings.size()); //$NON-NLS-1$		
89
		assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationUtil.MigrationDiagnostic); //$NON-NLS-1$
89
		assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationUtil.MigrationDiagnostic); //$NON-NLS-1$
90
		
90
		assertTrue(loadHelper.getLoadedResource().getErrors().isEmpty());
91
		assertTrue(loadHelper.getLoadedResource().getErrors().isEmpty());
91
	}
92
	}
92
93
Lines 108-124 Link Here
108
		return caughtException;
109
		return caughtException;
109
	}
110
	}
110
111
111
/*
112
	/*
112
GenDiagram
113
	GenDiagram
113
Removed attrs:
114
	Removed attrs:
114
attr String paletteProviderClassName;
115
	attr String paletteProviderClassName;
115
attr ProviderPriority paletteProviderPriority;
116
	attr ProviderPriority paletteProviderPriority;
116
attr String propertyProviderClassName;
117
	attr String propertyProviderClassName;
117
attr ProviderPriority propertyProviderPriority;
118
	attr ProviderPriority propertyProviderPriority;
118
attr String referenceConnectionEditPolicyClassName;
119
	attr String referenceConnectionEditPolicyClassName;
119
attr String externalNodeLabelHostLayoutEditPolicyClassName;
120
	attr String externalNodeLabelHostLayoutEditPolicyClassName;
120
attr String diagramFileCreatorClassName;
121
	attr String diagramFileCreatorClassName;
121
attr String preferenceInitializerClassName;
122
	attr String preferenceInitializerClassName;
122
	 */
123
	 */
123
	public void testGenDiagram() throws Exception {
124
	public void testGenDiagram() throws Exception {
124
		String genmodelFileName = "testGenDiagram.gmfgen"; //$NON-NLS-1$
125
		String genmodelFileName = "testGenDiagram.gmfgen"; //$NON-NLS-1$
Lines 129-134 Link Here
129
		assertOnLoadModelMigrationSuccess(genmodelFileName);
130
		assertOnLoadModelMigrationSuccess(genmodelFileName);
130
	}
131
	}
131
132
133
	/*
134
	FeatureLabelModelFacet 
135
	Removed refs:
136
	ref genmodel.GenFeature[1] metaFeature;
137
	 */
138
	public void testFeatureLabelModelFacet() throws Exception {
139
		String genmodelFileName = "testFeatureLabelModelFacet.gmfgen"; //$NON-NLS-1$
140
		
141
		Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
142
		assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$				
143
144
		assertOnLoadModelMigrationSuccess(genmodelFileName);
145
	}
146
147
//	/*
148
//	TypeLinkModelFacet 
149
//	Removed attrs:
150
//	attr String createCommandClassName;
151
//	 */
152
//	public void testTypeLinkModelFacet() throws Exception {
153
//		String genmodelFileName = "testTypeLinkModelFacet.gmfgen"; //$NON-NLS-1$
154
//		
155
//		Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
156
//		assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$				
157
//
158
//		assertOnLoadModelMigrationSuccess(genmodelFileName);
159
//	}
160
132
	public void testGenAuditRootDefaultAndNested() throws Exception {
161
	public void testGenAuditRootDefaultAndNested() throws Exception {
133
		String genmodelFileName = "testGenAuditRootDefaultAndNested.gmfgen"; //$NON-NLS-1$
162
		String genmodelFileName = "testGenAuditRootDefaultAndNested.gmfgen"; //$NON-NLS-1$
134
		
163
		
(-)models/migration/testTypeLinkModelFacet.gmfgen (+8 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmfgen:TypeLinkModelFacet xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:gmfgen="http://www.eclipse.org/gmf/2005/GenModel"
5
    createCommandClassName="CreateCommandClassName"/> 
6
    <modelElementSelector body="GenConstraintBody">
7
    </modelElementSelector>
8
</gmfgen:TypeLinkModelFacet>
(-)models/migration/testFeatureLabelModelFacet.gmfgen (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmfgen:FeatureLabelModelFacet xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:gmfgen="http://www.eclipse.org/gmf/2005/GenModel"> 
5
    <metaFeature name="DeletedFeature">
6
    </metaFeature>
7
</gmfgen:FeatureLabelModelFacet>
(-)plugin.xml (-1 / +1 lines)
Lines 14-20 Link Here
14
  </extension>
14
  </extension>
15
15
16
  <extension point="org.eclipse.emf.ecore.extension_parser">
16
  <extension point="org.eclipse.emf.ecore.extension_parser">
17
    <parser type="gmfgen" class="org.eclipse.gmf.internal.common.migrate.CompatibleToolResourceFactory$MigrateOnLoad" />
17
    <parser type="gmfgen" class="org.eclipse.gmf.internal.codegen.util.GMFGenResource$Factory" />
18
  </extension>
18
  </extension>
19
19
20
  <extension point="org.eclipse.team.core.fileTypes">
20
  <extension point="org.eclipse.team.core.fileTypes">
(-)src/org/eclipse/gmf/internal/codegen/util/GMFGenMigrationHelper.java (+127 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2007 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: Borland - initial API and implementation
10
 */
11
package org.eclipse.gmf.internal.codegen.util;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EReference;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.ecore.impl.EReferenceImpl;
20
import org.eclipse.gmf.codegen.gmfgen.GMFGenFactory;
21
import org.eclipse.gmf.codegen.gmfgen.GMFGenPackage;
22
import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer;
23
import org.eclipse.gmf.codegen.gmfgen.GenAuditRoot;
24
import org.eclipse.gmf.codegen.gmfgen.GenAuditRule;
25
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
26
import org.eclipse.gmf.internal.common.migrate.MigrationHelper;
27
28
public class GMFGenMigrationHelper extends MigrationHelper.MigrationHelperDelegateImpl {
29
	private EReference ourGenEditorGenerator_Audits;
30
	private EReference ourGenAuditContainer_ChildContainers;
31
	private EReference ourGenAuditContainer_Audits;
32
	
33
	public GMFGenMigrationHelper() {
34
	}
35
36
	public void init() {
37
		registerDeletedAttributes(GMFGenPackage.eINSTANCE.getEditorCandies(),
38
						"diagramFileCreatorClassName", //$NON-NLS-1$
39
						"preferenceInitializerClassName" //$NON-NLS-1$
40
		);
41
		registerDeletedAttributes(GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet(), "metaFeature"); //$NON-NLS-1$
42
		registerDeletedAttributes(GMFGenPackage.eINSTANCE.getProviderClassNames(), 
43
						"abstractParserClassName", //$NON-NLS-1$
44
						"structuralFeatureParserClassName", //$NON-NLS-1$
45
						"structuralFeaturesParserClassName", //$NON-NLS-1$
46
						"paletteProviderClassName", //$NON-NLS-1$
47
						"paletteProviderPriority", //$NON-NLS-1$
48
						"propertyProviderClassName", //$NON-NLS-1$
49
						"propertyProviderPriority" //$NON-NLS-1$
50
		);
51
		registerDeletedAttributes(GMFGenPackage.eINSTANCE.getEditPartCandies(), 
52
						"referenceConnectionEditPolicyClassName", //$NON-NLS-1$
53
						"externalNodeLabelHostLayoutEditPolicyClassName" //$NON-NLS-1$
54
		);
55
		registerDeletedAttributes(GMFGenPackage.eINSTANCE.getTypeLinkModelFacet(), "createCommandClassName"); //$NON-NLS-1$
56
57
		registerNarrowReferenceType(GMFGenPackage.eINSTANCE.getGenFeatureSeqInitializer_Initializers(),	GMFGenPackage.eINSTANCE.getGenFeatureValueSpec());
58
		{
59
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
60
			renamings.put("metaFeature", GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet_MetaFeatures()); //$NON-NLS-1$
61
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet(), renamings);
62
		}
63
		ourGenEditorGenerator_Audits = new EReferenceImpl() {};
64
		ourGenEditorGenerator_Audits.setName("audits"); //$NON-NLS-1$
65
		ourGenEditorGenerator_Audits.setEType(GMFGenPackage.eINSTANCE.getGenAuditContainer());
66
		ourGenEditorGenerator_Audits.setContainment(true);
67
		ourGenEditorGenerator_Audits.setLowerBound(0);
68
		ourGenEditorGenerator_Audits.setUpperBound(1);
69
		ourGenAuditContainer_ChildContainers = new EReferenceImpl() {};
70
		ourGenAuditContainer_ChildContainers.setName("childContainers"); //$NON-NLS-1$
71
		ourGenAuditContainer_ChildContainers.setEType(GMFGenPackage.eINSTANCE.getGenAuditContainer());
72
		ourGenAuditContainer_ChildContainers.setContainment(true);
73
		ourGenAuditContainer_ChildContainers.setLowerBound(0);
74
		ourGenAuditContainer_ChildContainers.setUpperBound(-1);
75
		ourGenAuditContainer_Audits = new EReferenceImpl() {};
76
		ourGenAuditContainer_Audits.setName("audits"); //$NON-NLS-1$
77
		ourGenAuditContainer_Audits.setEType(GMFGenPackage.eINSTANCE.getGenAuditRule());
78
		ourGenAuditContainer_Audits.setContainment(true);
79
		ourGenAuditContainer_Audits.setLowerBound(0);
80
		ourGenAuditContainer_Audits.setUpperBound(-1);
81
		{
82
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
83
			renamings.put(ourGenEditorGenerator_Audits.getName(), ourGenEditorGenerator_Audits);
84
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenEditorGenerator(), renamings);
85
		}
86
		{
87
			Map<String, EStructuralFeature> renamings = new HashMap<String, EStructuralFeature>();
88
			renamings.put(ourGenAuditContainer_Audits.getName(), ourGenAuditContainer_Audits);
89
			renamings.put(ourGenAuditContainer_ChildContainers.getName(), ourGenAuditContainer_ChildContainers);
90
			registerRenamedAttributes(GMFGenPackage.eINSTANCE.getGenAuditContainer(), renamings);
91
		}
92
		registerRenamedType("CompositeFeatureLabelModelFacet", GMFGenPackage.eINSTANCE.getFeatureLabelModelFacet()); //$NON-NLS-1$
93
	}
94
	
95
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
96
		if (ourGenEditorGenerator_Audits.equals(feature)) {
97
			GenEditorGenerator generator = (GenEditorGenerator) object;
98
			GenAuditContainer rootContainer = (GenAuditContainer) value;
99
			generator.setAudits(getOrCreateRoot(rootContainer));
100
		} else if (ourGenAuditContainer_ChildContainers.equals(feature)) {
101
			GenAuditContainer parent = (GenAuditContainer)object;
102
			GenAuditContainer container = (GenAuditContainer)value;
103
			container.getPath().addAll(parent.getPath());
104
			container.getPath().add(parent);
105
			getOrCreateRoot(parent).getCategories().add(container);
106
		} else if (ourGenAuditContainer_Audits.equals(feature)) {
107
			GenAuditContainer container = (GenAuditContainer)object;
108
			GenAuditRule rule = (GenAuditRule)value;
109
			rule.setCategory(container);
110
			getOrCreateRoot(container).getRules().add(rule);
111
		} else {
112
			// other cases are would be processed as defaults
113
			return super.setValue(object, feature, value, position);
114
		}
115
		return true;
116
	}
117
118
	private GenAuditRoot getOrCreateRoot(GenAuditContainer auditContainer) {
119
		GenAuditRoot result = auditContainer.getRoot();
120
		if (result == null) {
121
			result = GMFGenFactory.eINSTANCE.createGenAuditRoot();
122
			result.getCategories().add(auditContainer);
123
		}
124
		return result;
125
	}
126
127
}
(-)src/org/eclipse/gmf/internal/codegen/util/GMFGenResource.java (+58 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2007 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: Borland - initial API and implementation
10
 */
11
package org.eclipse.gmf.internal.codegen.util;
12
13
import java.util.Arrays;
14
import java.util.Collection;
15
16
import org.eclipse.emf.common.util.URI;
17
import org.eclipse.emf.ecore.resource.Resource;
18
import org.eclipse.gmf.codegen.gmfgen.GMFGenPackage;
19
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
20
import org.eclipse.gmf.internal.common.migrate.MigrationHelperDelegate;
21
import org.eclipse.gmf.internal.common.migrate.MigrationResource2;
22
23
public class GMFGenResource extends MigrationResource2 {
24
	private Collection<String> myBackwardSupportedURIs;
25
26
	public static class Factory extends ToolingResourceFactory {
27
		@Override
28
		public Resource createResource(URI uri) {
29
			return new GMFGenResource(uri);
30
		}
31
	}
32
33
	private GMFGenResource(URI uri) {
34
		super(uri);
35
	}
36
37
	@Override
38
	protected MigrationHelperDelegate createDelegate() {
39
		GMFGenMigrationHelper migrationHelper = new GMFGenMigrationHelper();
40
		migrationHelper.init();
41
		return migrationHelper;
42
	}
43
44
	@Override
45
	protected Collection<String> getBackwardSupportedURIs() {
46
		if (myBackwardSupportedURIs == null) {
47
			myBackwardSupportedURIs = Arrays.asList(new String[] {
48
					"http://www.eclipse.org/gmf/2005/GenModel", //$NON-NLS-1$
49
			});
50
		}
51
		return myBackwardSupportedURIs;
52
	}
53
54
	protected String getMetamodelNsURI() {
55
		return GMFGenPackage.eNS_URI;
56
	}
57
58
}
(-)plugin.xml (-1 / +1 lines)
Lines 14-20 Link Here
14
  </extension>
14
  </extension>
15
15
16
  <extension point="org.eclipse.emf.ecore.extension_parser">
16
  <extension point="org.eclipse.emf.ecore.extension_parser">
17
    <parser type="gmfmap" class="org.eclipse.gmf.internal.common.migrate.CompatibleToolResourceFactory$MigrateOnLoad" />
17
    <parser type="gmfmap" class="org.eclipse.gmf.mappings.util.GMFMapResource$Factory" />
18
  </extension>
18
  </extension>
19
19
20
  <extension point="org.eclipse.team.core.fileTypes">
20
  <extension point="org.eclipse.team.core.fileTypes">
(-)src/org/eclipse/gmf/mappings/util/GMFMapMigrationHelper.java (+62 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2007 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: Borland - initial API and implementation
10
 */
11
package org.eclipse.gmf.mappings.util;
12
13
import java.util.ArrayList;
14
import java.util.Collection;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.gmf.internal.common.migrate.MigrationHelper;
18
import org.eclipse.gmf.mappings.FeatureLabelMapping;
19
import org.eclipse.gmf.mappings.GMFMapPackage;
20
import org.eclipse.gmf.mappings.LabelMapping;
21
import org.eclipse.gmf.mappings.MappingEntry;
22
23
public class GMFMapMigrationHelper extends MigrationHelper.MigrationHelperDelegateImpl {
24
	private Collection<FeatureLabelMapping> myFeatureLabelMappings;
25
	
26
	protected GMFMapMigrationHelper() {
27
		super();
28
	}
29
30
	public void init() {
31
		registerNarrowReferenceType(GMFMapPackage.eINSTANCE.getFeatureSeqInitializer_Initializers(), GMFMapPackage.eINSTANCE.getFeatureValueSpec());
32
		registerNarrowReferenceType(GMFMapPackage.eINSTANCE.getMappingEntry_LabelMappings(), GMFMapPackage.eINSTANCE.getFeatureLabelMapping());
33
	}
34
35
	public void postProcess() {
36
		for (FeatureLabelMapping mapping : getSavedFeatureLabelMappings()) {
37
			if (mapping.getFeatures().isEmpty()) {
38
				MappingEntry entry = mapping.getMapEntry();
39
				entry.getLabelMappings().remove(mapping);
40
				LabelMapping newMapping = GMFMapPackage.eINSTANCE.getGMFMapFactory().createLabelMapping();
41
				newMapping.setDiagramLabel(mapping.getDiagramLabel());
42
				if (mapping.isReadOnly()) {
43
					newMapping.setReadOnly(true);
44
				}
45
				entry.getLabelMappings().add(newMapping);
46
			}
47
		}
48
	}
49
50
	public void processObject(EObject result) {
51
		if (result instanceof FeatureLabelMapping) {
52
			getSavedFeatureLabelMappings().add((FeatureLabelMapping) result);
53
		}
54
	}
55
	
56
	private Collection<FeatureLabelMapping> getSavedFeatureLabelMappings() {
57
		if (myFeatureLabelMappings == null) {
58
			myFeatureLabelMappings = new ArrayList<FeatureLabelMapping>();
59
		}
60
		return myFeatureLabelMappings;
61
	}
62
}
(-)src/org/eclipse/gmf/mappings/util/GMFMapResource.java (+59 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2007 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: Borland - initial API and implementation
10
 */
11
package org.eclipse.gmf.mappings.util;
12
13
import java.util.Arrays;
14
import java.util.Collection;
15
16
import org.eclipse.emf.common.util.URI;
17
import org.eclipse.emf.ecore.resource.Resource;
18
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
19
import org.eclipse.gmf.internal.common.migrate.MigrationHelperDelegate;
20
import org.eclipse.gmf.internal.common.migrate.MigrationResource2;
21
import org.eclipse.gmf.mappings.GMFMapPackage;
22
23
public class GMFMapResource extends MigrationResource2 {
24
	private Collection<String> myBackwardSupportedURIs;
25
	
26
	public static class Factory extends ToolingResourceFactory {
27
		@Override
28
		public Resource createResource(URI uri) {
29
			return new GMFMapResource(uri);
30
		}
31
	}
32
33
	private GMFMapResource(URI uri) {
34
		super(uri);
35
	}
36
37
	@Override
38
	protected MigrationHelperDelegate createDelegate() {
39
		GMFMapMigrationHelper migrationHelper = new GMFMapMigrationHelper();
40
		migrationHelper.init();
41
		return migrationHelper;
42
	}
43
44
	@Override
45
	protected Collection<String> getBackwardSupportedURIs() {
46
		if (myBackwardSupportedURIs == null) {
47
			myBackwardSupportedURIs = Arrays.asList(new String[] {
48
					"http://www.eclipse.org/gmf/2005/mappings", //$NON-NLS-1$
49
			});
50
		}
51
		return myBackwardSupportedURIs;
52
	}
53
54
	@Override
55
	protected String getMetamodelNsURI() {
56
		return GMFMapPackage.eNS_URI;
57
	}
58
59
}
(-)META-INF/MANIFEST.MF (-2 / +2 lines)
Lines 7-13 Link Here
7
Export-Package: org.eclipse.gmf.common,
7
Export-Package: org.eclipse.gmf.common,
8
 org.eclipse.gmf.common.codegen,
8
 org.eclipse.gmf.common.codegen,
9
 org.eclipse.gmf.internal.codegen.dispatch;x-friends:="org.eclipse.gmf.codegen,org.eclipse.gmf.graphdef.codegen,org.eclipse.gmf.codegen.lite",
9
 org.eclipse.gmf.internal.codegen.dispatch;x-friends:="org.eclipse.gmf.codegen,org.eclipse.gmf.graphdef.codegen,org.eclipse.gmf.codegen.lite",
10
 org.eclipse.gmf.internal.common;x-friends:="org.eclipse.gmf.codegen.edit,org.eclipse.gmf.graphdef.edit,org.eclipse.gmf.map.edit,org.eclipse.gmf.tooldef.edit,org.eclipse.gmf.bridge.trace,org.eclipse.gmf.bridge.ui,org.eclipse.gmf.bridge,org.eclipse.gmf.tests,org.eclipse.gmf.bridge.ui.dashboard,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.codegen.lite.ui",
10
 org.eclipse.gmf.internal.common;x-friends:="org.eclipse.gmf.codegen.edit,org.eclipse.gmf.graphdef.edit,org.eclipse.gmf.map.edit,org.eclipse.gmf.tooldef.edit,org.eclipse.gmf.bridge.trace,org.eclipse.gmf.bridge.ui,org.eclipse.gmf.bridge,org.eclipse.gmf.tests,org.eclipse.gmf.bridge.ui.dashboard,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.codegen.lite.ui,org.eclipse.gmf.codegen,org.eclipse.gmf.map",
11
 org.eclipse.gmf.internal.common.codegen;x-friends:="org.eclipse.gmf.codegen,org.eclipse.gmf.graphdef.codegen,org.eclipse.gmf.bridge,org.eclipse.gmf.codegen.lite,org.eclipse.gmf.tests,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.codegen.lite.ui,org.eclipse.gmf.tests.lite,org.eclipse.gmf.graphdef.codegen.ui",
11
 org.eclipse.gmf.internal.common.codegen;x-friends:="org.eclipse.gmf.codegen,org.eclipse.gmf.graphdef.codegen,org.eclipse.gmf.bridge,org.eclipse.gmf.codegen.lite,org.eclipse.gmf.tests,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.codegen.lite.ui,org.eclipse.gmf.tests.lite,org.eclipse.gmf.graphdef.codegen.ui",
12
 org.eclipse.gmf.internal.common.migrate;x-friends:="org.eclipse.gmf.codegen.ui,org.eclipse.gmf.tests,org.eclipse.gmf.codegen,org.eclipse.gmf.map,org.eclipse.gmf.bridge.ui",
12
 org.eclipse.gmf.internal.common.migrate;x-friends:="org.eclipse.gmf.codegen.ui,org.eclipse.gmf.tests,org.eclipse.gmf.codegen,org.eclipse.gmf.map,org.eclipse.gmf.bridge.ui",
13
 org.eclipse.gmf.internal.common.reconcile;x-friends:="org.eclipse.gmf.tests,org.eclipse.gmf.codegen,org.eclipse.gmf.bridge.ui",
13
 org.eclipse.gmf.internal.common.reconcile;x-friends:="org.eclipse.gmf.tests,org.eclipse.gmf.codegen,org.eclipse.gmf.bridge.ui",
Lines 16-22 Link Here
16
 org.eclipse.emf.common.ui;bundle-version="[2.3.0,3.0.0)",
16
 org.eclipse.emf.common.ui;bundle-version="[2.3.0,3.0.0)",
17
 org.eclipse.emf.codegen;bundle-version="[2.3.0,3.0.0)",
17
 org.eclipse.emf.codegen;bundle-version="[2.3.0,3.0.0)",
18
 org.eclipse.emf.codegen.ecore;bundle-version="[2.3.0,3.0.0)",
18
 org.eclipse.emf.codegen.ecore;bundle-version="[2.3.0,3.0.0)",
19
 org.eclipse.emf.ecore.xmi;bundle-version="[2.3.0,3.0.0)",
19
 org.eclipse.emf.ecore.xmi;bundle-version="[2.3.0,3.0.0)";visibility:=reexport,
20
 org.eclipse.core.resources;bundle-version="[3.3.0,4.0.0)";visibility:=reexport,
20
 org.eclipse.core.resources;bundle-version="[3.3.0,4.0.0)";visibility:=reexport,
21
 org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
21
 org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
22
 org.eclipse.ui.forms;bundle-version="[3.3.0,4.0.0)",
22
 org.eclipse.ui.forms;bundle-version="[3.3.0,4.0.0)",
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationUtil.java (-5 / +9 lines)
Lines 35-51 Link Here
35
	 * @return model-load-helper encapsulating the resource and its in-memory migrated contents.
35
	 * @return model-load-helper encapsulating the resource and its in-memory migrated contents.
36
	 */
36
	 */
37
	public static ModelLoadHelper migrateModel(URI modelResourceURI) {
37
	public static ModelLoadHelper migrateModel(URI modelResourceURI) {
38
		return migrateModel(new ToolingResourceFactory() {
39
			public Resource createResource(URI uri) {
40
				return new MigrationResource(uri);
41
			}
42
		}, modelResourceURI);
43
	}
44
45
	public static ModelLoadHelper migrateModel(final Resource.Factory factory, URI modelResourceURI) {
38
		if(modelResourceURI == null) {
46
		if(modelResourceURI == null) {
39
			throw new IllegalArgumentException("null resource uri"); //$NON-NLS-1$
47
			throw new IllegalArgumentException("null resource uri"); //$NON-NLS-1$
40
		}
48
		}
41
		ResourceSetImpl rset = new ResourceSetImpl();
49
		ResourceSetImpl rset = new ResourceSetImpl();
42
		rset.setResourceFactoryRegistry(new ResourceFactoryRegistryImpl() {			
50
		rset.setResourceFactoryRegistry(new ResourceFactoryRegistryImpl() {			
43
			public Factory getFactory(URI uri) {
51
			public Factory getFactory(URI uri) {
44
				return new ToolingResourceFactory() {
52
				return factory;
45
					public Resource createResource(URI uri) {
46
						return new MigrationResource(uri);
47
					}
48
				};
49
			}
53
			}
50
		});
54
		});
51
55
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationHelperDelegate.java (+34 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2007 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: Borland - initial API and implementation
10
 */
11
package org.eclipse.gmf.internal.common.migrate;
12
13
import org.eclipse.emf.ecore.EClass;
14
import org.eclipse.emf.ecore.EClassifier;
15
import org.eclipse.emf.ecore.EFactory;
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
19
public interface MigrationHelperDelegate {
20
	
21
	public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position);
22
	
23
	public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement);
24
	
25
	public EClassifier getType(EFactory factory, String typeName);
26
	
27
	public EClass getStructuralFeatureType(EStructuralFeature feature);
28
29
	public EObject createObject(EFactory factory, EClassifier type);
30
	
31
	public void postProcess();
32
33
	public void processObject(EObject result);
34
}
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationResource2.java (+89 lines)
Added Link Here
1
package org.eclipse.gmf.internal.common.migrate;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.util.Collection;
6
import java.util.Map;
7
8
import org.eclipse.emf.common.util.URI;
9
import org.eclipse.emf.ecore.EPackage;
10
import org.eclipse.emf.ecore.xmi.XMLHelper;
11
import org.eclipse.emf.ecore.xmi.XMLLoad;
12
import org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler;
13
import org.eclipse.emf.ecore.xmi.impl.XMILoadImpl;
14
import org.eclipse.gmf.internal.common.ToolingResourceFactory.ToolResource;
15
import org.xml.sax.helpers.DefaultHandler;
16
17
public abstract class MigrationResource2 extends ToolResource {
18
19
	private boolean isOldVersionDetected;
20
	
21
	protected MigrationResource2(URI uri) {
22
		super(uri);
23
	}
24
25
	public final void doLoad(InputStream inputStream, Map<?,?> options) throws IOException {
26
		try {
27
			isOldVersionDetected = false;
28
			super.doLoad(inputStream, options);
29
			handlePostLoad();
30
		} catch (IOException e) {
31
			handlePostLoadException(e);
32
			throw e;
33
		} catch (RuntimeException e) {
34
			handlePostLoadException(e);
35
			throw e;
36
		} finally {
37
			isOldVersionDetected = false;
38
		}
39
	}
40
41
	/*
42
	 * Create XMLLoad which handles old model migration at load-time 
43
	 * @see org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl#createXMLLoad()
44
	 */
45
	protected XMLLoad createXMLLoad() {
46
		return new XMILoadImpl(createXMLHelper()) {
47
48
			protected DefaultHandler makeDefaultHandler() {
49
				return new SAXXMIHandler(resource, helper, options) {
50
					protected EPackage getPackageForURI(String uriString) {
51
						if(!getMetamodelNsURI().equals(uriString) && 
52
								getBackwardSupportedURIs().contains(uriString)) {					
53
								handleOldVersionDetected();
54
								return super.getPackageForURI(getMetamodelNsURI());
55
						}
56
						return super.getPackageForURI(uriString);
57
					}
58
				};
59
			}
60
		};
61
	}
62
	
63
	private void handleOldVersionDetected() {
64
		isOldVersionDetected = true;
65
	}
66
	
67
	protected void handlePostLoad() {
68
		if (isOldVersionDetected) {
69
			// create warning only in case of old model loading
70
			Diagnostic diagnostic = MigrationUtil.createMessageDiagnostic(this, Messages.oldModelVersionLoadedMigrationRequired);
71
			getWarnings().add(0, diagnostic);
72
		}
73
	}
74
75
	protected void handlePostLoadException(Exception e) {
76
		Diagnostic diagnostic = MigrationUtil.createMessageDiagnostic(this, Messages.oldModelVersionLoadErrorMigrationMayBeRequired);
77
		getErrors().add(0, diagnostic);
78
	}
79
80
	protected XMLHelper createXMLHelper() {
81
		MigrationHelperDelegate delegate = createDelegate();
82
		assert delegate != null;
83
		return new MigrationHelper(this, delegate);
84
	}
85
86
	protected abstract String getMetamodelNsURI();
87
	protected abstract Collection<String> getBackwardSupportedURIs();
88
	protected abstract MigrationHelperDelegate createDelegate();
89
}
(-)src/org/eclipse/gmf/internal/common/migrate/MigrationHelper.java (+187 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2007 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: Borland - initial API and implementation
10
 */
11
package org.eclipse.gmf.internal.common.migrate;
12
13
import java.util.Arrays;
14
import java.util.Collection;
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.Map;
18
19
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EClassifier;
21
import org.eclipse.emf.ecore.EFactory;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.EReference;
24
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.emf.ecore.EcoreFactory;
26
import org.eclipse.emf.ecore.EcorePackage;
27
import org.eclipse.emf.ecore.xmi.XMLResource;
28
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
29
30
public class MigrationHelper extends XMIHelperImpl {
31
	private final MigrationHelperDelegate myDelegate;
32
33
	public MigrationHelper(XMLResource resource, MigrationHelperDelegate delegate) {
34
		super(resource);
35
		myDelegate = delegate;
36
		assert delegate != null;
37
	}
38
	
39
	public static class MigrationHelperDelegateImpl implements MigrationHelperDelegate {
40
41
		public MigrationHelperDelegateImpl() {
42
			super();
43
		}
44
45
		private static EStructuralFeature ourDeletedAttribute = EcoreFactory.eINSTANCE.createEAttribute();
46
		static {
47
			ourDeletedAttribute.setName("attributeIsDeleted"); //$NON-NLS-1$
48
			ourDeletedAttribute.setEType(EcorePackage.eINSTANCE.getEString());
49
		}
50
51
		private Map<EClassifier, Collection<String>> myDeletedAttributes = new HashMap<EClassifier, Collection<String>>();
52
		private Map<EReference, EClass> myarrowReferenceTypes = new HashMap<EReference, EClass>();
53
		private Map<EClass, Map<String, EStructuralFeature>> myRenamedAttributes = new HashMap<EClass, Map<String, EStructuralFeature>>();
54
		private Map<String, EClassifier> myRenamedTypes = new HashMap<String, EClassifier>();
55
		
56
		public void registerDeletedAttributes(EClassifier classifier, String... deletedAttrNames) {
57
			assert !myDeletedAttributes.containsKey(classifier);
58
			myDeletedAttributes.put(classifier, Arrays.asList(deletedAttrNames));
59
		}
60
		
61
		public void registerNarrowReferenceType(EReference reference, EClass concreteType) {
62
			myarrowReferenceTypes.put(reference, concreteType);
63
		}
64
		
65
		public void registerRenamedAttributes(EClass eClass, Map<String, EStructuralFeature> renamedAttributes) {
66
			myRenamedAttributes.put(eClass, renamedAttributes);
67
		}
68
		
69
		public void registerRenamedType(String oldTypeName, EClassifier newType) {
70
			myRenamedTypes.put(oldTypeName, newType);
71
		}
72
		
73
		public void registerRenamedAttribute(EClass eClass, String oldName, EStructuralFeature newStructuralFeature) {
74
			Map<String, EStructuralFeature> renamedAttributes = myRenamedAttributes.get(eClass);
75
			if (renamedAttributes == null) {
76
				renamedAttributes = new HashMap<String, EStructuralFeature>();
77
			}
78
			renamedAttributes.put(oldName, newStructuralFeature);
79
			registerRenamedAttributes(eClass, renamedAttributes);
80
		}
81
		
82
		public boolean isAttributeDeleted(EClass clazz, String name) {
83
			Collection<String> deletedAttributes = myDeletedAttributes.get(clazz);
84
			boolean result = deletedAttributes != null && deletedAttributes.contains(name);
85
			for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); !result && it.hasNext();) {
86
				EClass nextParent = it.next();
87
				result = isAttributeDeleted(nextParent, name);
88
			}
89
			return result;
90
		}
91
		
92
		public EClass getNarrowReferenceType(EStructuralFeature feature) {
93
			return myarrowReferenceTypes.get(feature);
94
		}
95
96
		public EStructuralFeature getRenamedFeatureFor(EClass clazz, String name) {
97
		    Map<String, EStructuralFeature> renamings = myRenamedAttributes.get(clazz);
98
			EStructuralFeature result = renamings != null ? renamings.get(name) : null;
99
			for (Iterator<EClass> it=clazz.getEAllSuperTypes().iterator(); result == null && it.hasNext();) {
100
				EClass nextParent = it.next();
101
				result = getRenamedFeatureFor(nextParent, name);
102
			}
103
			return result;
104
		}
105
106
		public EClassifier getRenamedType(String typeName) {
107
			return myRenamedTypes.get(typeName);
108
		}
109
110
		public EClass getStructuralFeatureType(EStructuralFeature feature) {
111
			return getNarrowReferenceType(feature);
112
		}
113
114
		public boolean setValue(EObject object, EStructuralFeature feature, Object value, int position) {
115
			return ourDeletedAttribute.equals(feature);
116
		}
117
118
		public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
119
			EStructuralFeature result = null;
120
			EStructuralFeature rename = null;
121
			if (isAttributeDeleted(eClass, name)) {
122
				result = ourDeletedAttribute;
123
			} else if ((rename = getRenamedFeatureFor(eClass, name)) != null) {
124
				result = rename;
125
			}
126
			return result;
127
		}
128
129
		public EClassifier getType(EFactory factory, String typeName) {
130
			EClassifier result = null;
131
			EClassifier type = getRenamedType(typeName);
132
			if (type != null) {
133
				result = type;
134
			}
135
			return result;
136
		}
137
138
		public EObject createObject(EFactory factory, EClassifier type) {
139
			return null;
140
		}
141
		
142
		public void postProcess() {
143
		}
144
145
		public void processObject(EObject result) {
146
		}
147
	}
148
149
	public EObject createObject(EFactory factory, EClassifier type) {
150
		EObject result = myDelegate.createObject(factory, type);
151
		if (result == null) {
152
			result = super.createObject(factory, type);
153
		}
154
		myDelegate.processObject(result);
155
		return result;
156
	}
157
158
	public void setValue(EObject object, EStructuralFeature feature, Object value, int position) {
159
		if (!myDelegate.setValue(object, feature, value, position)) {
160
			super.setValue(object, feature, value, position);
161
		}
162
	}
163
164
	public EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement) {
165
		EStructuralFeature result = myDelegate.getFeature(eClass, namespaceURI, name, isElement);
166
		if (result == null) {
167
			result = super.getFeature(eClass, namespaceURI, name);
168
		}
169
		EClass narrow = myDelegate.getStructuralFeatureType(result);
170
		if (narrow != null) {
171
			result.setEType(narrow);
172
		}
173
		return result;
174
	}
175
	
176
	public EClassifier getType(EFactory factory, String typeName) {
177
		EClassifier result = myDelegate.getType(factory, typeName);
178
		if (result == null) {
179
			result = super.getType(factory, typeName);
180
		}
181
		return result;
182
	}
183
184
	public void popContext() {
185
		myDelegate.postProcess();
186
	}
187
}

Return to bug 187811