Lines 11-73
Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.gmf.runtime.emf.core.internal.resources; |
12 |
package org.eclipse.gmf.runtime.emf.core.internal.resources; |
13 |
|
13 |
|
14 |
import org.eclipse.emf.common.notify.Adapter; |
|
|
15 |
import org.eclipse.emf.common.notify.Notification; |
16 |
import org.eclipse.emf.common.notify.NotificationChain; |
17 |
import org.eclipse.emf.common.util.URI; |
14 |
import org.eclipse.emf.common.util.URI; |
18 |
import org.eclipse.emf.ecore.EObject; |
|
|
19 |
import org.eclipse.emf.ecore.EStructuralFeature; |
20 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
21 |
import org.eclipse.emf.ecore.xmi.XMLHelper; |
15 |
import org.eclipse.emf.ecore.xmi.XMLHelper; |
22 |
import org.eclipse.emf.ecore.xmi.XMLLoad; |
16 |
import org.eclipse.emf.ecore.xmi.XMLLoad; |
23 |
import org.eclipse.emf.ecore.xmi.XMLSave; |
|
|
24 |
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; |
25 |
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl; |
26 |
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants; |
27 |
import org.eclipse.gmf.runtime.emf.core.internal.util.Util; |
28 |
|
17 |
|
29 |
/** |
18 |
/** |
30 |
* Custom implementation of an XMIResource. |
19 |
* Custom implementation of an XMIResource. |
31 |
* |
20 |
* |
32 |
* @author rafikj |
21 |
* @author rafikj |
|
|
22 |
* |
23 |
* @deprecated Use the {@link org.eclipse.gmf.runtime.emf.core.resources.GMFResource} |
24 |
* class, instead |
33 |
*/ |
25 |
*/ |
34 |
public class GMFResource |
26 |
public class GMFResource |
35 |
extends XMIResourceImpl { |
27 |
extends org.eclipse.gmf.runtime.emf.core.resources.GMFResource { |
36 |
|
|
|
37 |
/** |
38 |
* Use this option to abort loading a resource immediately when an error occurs. |
39 |
* The default is <code>Boolean.FALSE</code> unless set to <code>Boolean.TRUE</code> explicitly. |
40 |
*/ |
41 |
public static final String OPTION_ABORT_ON_ERROR = "ABORT_ON_ERROR"; //$NON-NLS-1$ |
42 |
|
43 |
private boolean useIDAttributes = false; |
44 |
|
28 |
|
45 |
/** |
29 |
/** |
46 |
* Constructor. |
30 |
* Constructor. |
47 |
*/ |
31 |
*/ |
48 |
public GMFResource(URI uri) { |
32 |
public GMFResource(URI uri) { |
49 |
|
|
|
50 |
super(uri); |
33 |
super(uri); |
51 |
|
|
|
52 |
setTrackingModification(true); |
53 |
} |
54 |
|
55 |
protected boolean useUUIDs() { |
56 |
return true; |
57 |
} |
58 |
|
59 |
/** |
60 |
* Should we use ID attribute? |
61 |
*/ |
62 |
public void setUseIDAttributes(boolean b) { |
63 |
useIDAttributes = b; |
64 |
} |
65 |
|
66 |
/** |
67 |
* Should we use ID attribute? |
68 |
*/ |
69 |
protected boolean useIDAttributes() { |
70 |
return useIDAttributes; |
71 |
} |
34 |
} |
72 |
|
35 |
|
73 |
protected XMLHelper createXMLHelper() { |
36 |
protected XMLHelper createXMLHelper() { |
Lines 77-197
Link Here
|
77 |
protected XMLLoad createXMLLoad() { |
40 |
protected XMLLoad createXMLLoad() { |
78 |
return new GMFLoad(createXMLHelper()); |
41 |
return new GMFLoad(createXMLHelper()); |
79 |
} |
42 |
} |
80 |
|
|
|
81 |
protected XMLSave createXMLSave() { |
82 |
return new XMISaveImpl(createXMLHelper()); |
83 |
} |
84 |
|
85 |
/** |
86 |
* @see org.eclipse.emf.ecore.resource.Resource#getEObject(java.lang.String) |
87 |
*/ |
88 |
public EObject getEObject(String uriFragment) { |
89 |
|
90 |
int index = uriFragment.indexOf(EMFCoreConstants.FRAGMENT_SEPARATOR); |
91 |
|
92 |
if (index != -1) |
93 |
uriFragment = uriFragment.substring(0, index); |
94 |
|
95 |
return super.getEObject(uriFragment); |
96 |
} |
97 |
|
98 |
/** |
99 |
* Get the saved ID of an EObject. |
100 |
*/ |
101 |
public static String getSavedID(EObject eObject) { |
102 |
return (String) DETACHED_EOBJECT_TO_ID_MAP.get(eObject); |
103 |
} |
104 |
|
105 |
/** |
106 |
* @see org.eclipse.emf.ecore.resource.Resource#setURI(org.eclipse.emf.common.util.URI) |
107 |
*/ |
108 |
public void setURI(URI uri) { |
109 |
|
110 |
if (getResourceSet() != null) { |
111 |
setRawURI(Util.denormalizeURI(uri, getResourceSet())); |
112 |
} |
113 |
} |
114 |
|
115 |
public NotificationChain basicSetResourceSet(ResourceSet rset, NotificationChain notifications) { |
116 |
// when I am added to a new resource set, my optimally denormalized URI |
117 |
// may change according to its different URI converter |
118 |
if (rset != null) { |
119 |
setURI(getURI()); |
120 |
} |
121 |
|
122 |
return super.basicSetResourceSet(rset, notifications); |
123 |
} |
124 |
|
125 |
/** |
126 |
* Set the URI of the resource without processing it. |
127 |
*/ |
128 |
public void setRawURI(URI uri) { |
129 |
|
130 |
URI oldURI = getURI(); |
131 |
|
132 |
if ((uri == oldURI) || ((uri != null) && (uri.equals(oldURI)))) |
133 |
return; |
134 |
|
135 |
super.setURI(uri); |
136 |
} |
137 |
|
138 |
/** |
139 |
* The inherited implementation creates an adapter that <em>always</em> sets |
140 |
* the modified state. We prefer to check, first, whether the resource |
141 |
* is already modified so that we don't generate redundant notifications. |
142 |
* Moreover, we additionally set modified state only for changes that are |
143 |
* in non-transient features of objects contained (recursively) by |
144 |
* non-transient references. |
145 |
*/ |
146 |
protected Adapter createModificationTrackingAdapter() { |
147 |
return new ModificationTrackingAdapter() { |
148 |
public void notifyChanged(Notification notification) { |
149 |
if (!isModified() && !isTransient( |
150 |
notification.getNotifier(), notification.getFeature())) { |
151 |
|
152 |
super.notifyChanged(notification); |
153 |
} |
154 |
} |
155 |
|
156 |
/** |
157 |
* Check if the feature or one of the notifier's containers is |
158 |
* transient. |
159 |
* |
160 |
* @param notifier a notifier |
161 |
* @param feature the feature that changed |
162 |
* |
163 |
* @return <code>true</code> if the feature is transient or if the |
164 |
* notifier or any of its ancestors is contained by a transient |
165 |
* reference; <code>false</code>, otherwise |
166 |
*/ |
167 |
private boolean isTransient(Object notifier, Object feature) { |
168 |
if (feature instanceof EStructuralFeature) { |
169 |
if (((EStructuralFeature) feature).isTransient()) |
170 |
return true; |
171 |
else |
172 |
// calling isTransient could be a lengthy operation. |
173 |
// It is safe to cast because the adapter is only |
174 |
// attached to EObjects, not to the resource |
175 |
return isTransient((EObject) notifier); |
176 |
} |
177 |
return false; |
178 |
} |
179 |
|
180 |
/** |
181 |
* Is object transient? |
182 |
*/ |
183 |
private boolean isTransient(EObject eObject) { |
184 |
EStructuralFeature containmentFeature = eObject.eContainmentFeature(); |
185 |
while (containmentFeature != null) { |
186 |
if (containmentFeature.isTransient()) |
187 |
return true; |
188 |
eObject = eObject.eContainer(); |
189 |
if (eObject != null) |
190 |
containmentFeature = eObject.eContainmentFeature(); |
191 |
else |
192 |
break; |
193 |
} |
194 |
return false; |
195 |
}}; |
196 |
} |
197 |
} |
43 |
} |