Skip to main content
summaryrefslogtreecommitdiffstats
blob: 99bb364267180cebd7bd48b73fe93b934a879687 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006 Springsite BV (The Netherlands) and others
 * 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:
 *   Martin Taal
 * </copyright>
 *
 * $Id: GMFNotationAction.java,v 1.3 2007/01/30 10:51:50 mtaal Exp $
 */

package org.eclipse.emf.teneo.test.emf.sample;

import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.StoreTestException;
import org.eclipse.emf.teneo.test.stores.TestStore;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.example.mindmap.MindmapPackage;

/**
 * Tests persisting of gmf diagram.
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.3 $ 
*/
public class GMFNotationAction extends AbstractTestAction {
	
	/** Constructor */
	public GMFNotationAction() {
		super(new EPackage[] {EcorePackage.eINSTANCE, NotationPackage.eINSTANCE, MindmapPackage.eINSTANCE});
	}

	/* (non-Javadoc)
	 * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
	 */
	public Properties getExtraConfigurationProperties() {
		final Properties props = new Properties();
		//props.setProperty(PersistenceOptions.USE_MAPPING_FILE, "true");
		return props;
	}

	/** Reads the library model and persists it. */
	public void doAction(TestStore store) {
		store.disableDrop();
		
		final URL mindmapURL = getClass().getResource("default.mindmap");
		final URI mindmapURI = URI.createURI(mindmapURL.toString());
		final URL diagramURL = getClass().getResource("default.mmd");
		final URI diagramURI = URI.createURI(diagramURL.toString());
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mmd", new XMIResourceFactoryImpl());
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mindmap", new XMIResourceFactoryImpl());
		final ResourceSet rs = new ResourceSetImpl();
		final XMIResource mindmapResource = (XMIResource)rs.createResource(mindmapURI);
		final XMIResource diagramResource = (XMIResource)rs.createResource(diagramURI);
		try {
			// default load options.
			final HashMap loadOptions = new HashMap();
			loadOptions.putAll(mindmapResource.getDefaultLoadOptions());
			//loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
			loadOptions.put(XMIResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE);
			mindmapResource.load(loadOptions);
			diagramResource.load(loadOptions);
			store.beginTransaction();
			for (Iterator it = mindmapResource.getContents().iterator(); it.hasNext();) {
				store.store(it.next());
			}
			for (Iterator it = diagramResource.getContents().iterator(); it.hasNext();) {
				store.store(it.next());
			}
			store.commitTransaction();
		} catch (Exception e) {
			throw new StoreTestException("Exception", e);
		}
	
	}
}

Back to the top