blob: 964fd4c1a66ccaf0bbbad76503efe36939851e7d (
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*****************************************************************************
* Copyright (c) 2018 CEA LIST 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:
* Vincent LORENZO (CEA LIST) - Initial API and implementation
* Vincent LORENZO (CEA LIST) - Bug 535070
*****************************************************************************/
package org.eclipse.papyrus.emf.resources;
import java.io.IOException;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
/**
* @author Vincent LORENZO
* Abstract XMI Resource to extends for EMF model Resource. The goal is to provides the same options (save and load) for the Papyrus EMF models:
* <ul>
* <li>use ID, instead of position to reference element</li>
* <li>common formating rules (ignoring the options given by the editors)</li>
* <li>encoding : UTF-8</li>
* <li>default values are saved (allow to prevent troubles when default value changed)</li>
* <li>...</li>
* </ul>
*/
public abstract class AbstractEMFResource extends XMIResourceImpl {
/**
*
* Constructor.
*
* @param uri
*/
public AbstractEMFResource(final URI uri) {
super(uri);
}
/**
* @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#useUUIDs()
*
* @return
*/
@Override
protected boolean useUUIDs() {
return true;
}
/**
*
* @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#save(java.util.Map)
*
* @param options
* @throws IOException
*/
@Override
public final void save(Map<?, ?> options) throws IOException {
super.save(getDefaultSaveOptions());// we bypass the options argument to avoid changes between editors (ExpressionEditor, Ecore Sample Reflexive Editor and Ecore Editor
}
/**
* @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#getDefaultSaveOptions()
*
* @return
*/
@Override
public Map<Object, Object> getDefaultSaveOptions() {
if (null == this.defaultSaveOptions) {
super.getDefaultSaveOptions();// initialize the default save options
this.defaultSaveOptions.putAll(LoadAndSaveOptionsUtils.getSaveOptions());
}
return this.defaultSaveOptions;
}
/**
* @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#getDefaultLoadOptions()
*
* @return
*/
@Override
public Map<Object, Object> getDefaultLoadOptions() {
if (null == this.defaultLoadOptions) {
super.getDefaultLoadOptions(); // initialize the default load options
this.defaultLoadOptions.putAll(LoadAndSaveOptionsUtils.getLoadOptions());
}
return this.defaultLoadOptions;
}
/**
* @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#assignIDsWhileLoading()
*
* @return
*/
@Override
protected boolean assignIDsWhileLoading() {
//bug 535070
return false; // overridden to avoid to assign XMI_ID to element of previous configuration which are stilling use position to be saved
}
}
|