View | Details | Raw Unified | Return to bug 137063
Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/GMFResource.java (-158 / +4 lines)
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
}
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/PathmapManager.java (-3 / +17 lines)
Lines 52-57 Link Here
52
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
52
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
53
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
53
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
54
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
54
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
55
import org.eclipse.gmf.runtime.emf.core.resources.GMFResource;
56
import org.eclipse.gmf.runtime.emf.core.resources.IPathmapManager;
55
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
57
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
56
import org.osgi.framework.Bundle;
58
import org.osgi.framework.Bundle;
57
import org.osgi.service.prefs.BackingStoreException;
59
import org.osgi.service.prefs.BackingStoreException;
Lines 61-67 Link Here
61
 * 
63
 * 
62
 * @author rafikj
64
 * @author rafikj
63
 */
65
 */
64
public class PathmapManager extends AdapterImpl {
66
public class PathmapManager extends AdapterImpl implements IPathmapManager {
65
	// path maps can be defined using an extension point: Pathmaps
67
	// path maps can be defined using an extension point: Pathmaps
66
	//  or by referencing an eclipse path variable
68
	//  or by referencing an eclipse path variable
67
	//  or by adding a pathmap manually
69
	//  or by adding a pathmap manually
Lines 200-206 Link Here
200
	public static void removePathVariableReference(String pathVariable) {
202
	public static void removePathVariableReference(String pathVariable) {
201
		if (referencedPathVariablesList.contains(pathVariable)) {
203
		if (referencedPathVariablesList.contains(pathVariable)) {
202
			referencedPathVariablesList.remove(pathVariable);
204
			referencedPathVariablesList.remove(pathVariable);
203
			removePathVariable(pathVariable);
205
			unsetPathVariable(pathVariable);
204
		}
206
		}
205
	}
207
	}
206
	
208
	
Lines 305-314 Link Here
305
		}
307
		}
306
	}
308
	}
307
309
310
	public IStatus addPathVariable(String name, String value) {
311
		setPathVariable(name, value);
312
		
313
		return Status.OK_STATUS; // TODO: report accurate status
314
	}
315
	
308
	/**
316
	/**
309
	 * Remove a pathmap variable.
317
	 * Remove a pathmap variable.
310
	 */
318
	 */
311
	public static void removePathVariable(String var) {
319
	public static void unsetPathVariable(String var) {
312
		PATH_MAP.remove(var);
320
		PATH_MAP.remove(var);
313
321
314
		for (Iterator i = allInstances().iterator(); i.hasNext();) {
322
		for (Iterator i = allInstances().iterator(); i.hasNext();) {
Lines 316-321 Link Here
316
		}
324
		}
317
	}
325
	}
318
	
326
	
327
	public IStatus removePathVariable(String name) {
328
		unsetPathVariable(name);
329
		
330
		return Status.OK_STATUS; // TODO: report accurate status
331
	}
332
	
319
	/**
333
	/**
320
	 * Obtains the resource set for which I manage the path mappings.
334
	 * Obtains the resource set for which I manage the path mappings.
321
	 * 
335
	 * 
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/GMFHandler.java (-113 / +5 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-47 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 java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
14
import java.util.Map;
17
15
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EFactory;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EPackage;
22
import org.eclipse.emf.ecore.EStructuralFeature;
23
import org.eclipse.emf.ecore.InternalEObject;
24
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
26
import org.eclipse.emf.ecore.xmi.XMIException;
27
import org.eclipse.emf.ecore.xmi.XMLHelper;
16
import org.eclipse.emf.ecore.xmi.XMLHelper;
28
import org.eclipse.emf.ecore.xmi.XMLResource;
17
import org.eclipse.emf.ecore.xmi.XMLResource;
29
import org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler;
30
import org.eclipse.emf.ecore.xml.type.AnyType;
31
import org.eclipse.gmf.runtime.emf.core.internal.exceptions.AbortResourceLoadException;
32
18
33
/**
19
/**
34
 * The SAX handler for MSL resources. Updates demand-created packages with their
20
 * The SAX handler for MSL resources. Updates demand-created packages with their
35
 * namespace prefixes and schema locations.
21
 * namespace prefixes and schema locations.
36
 * 
22
 * 
37
 * @author khussey
23
 * @author khussey
24
 * 
25
 * @deprecated Use the {@link org.eclipse.gmf.runtime.emf.core.resources.GMFHandler}
26
 *     class, instead
38
 */
27
 */
39
public class GMFHandler
28
public class GMFHandler
40
	extends SAXXMIHandler {
29
	extends org.eclipse.gmf.runtime.emf.core.resources.GMFHandler {
41
42
	protected final Map urisToProxies;
43
	
44
	protected boolean abortOnError;
45
30
46
	/**
31
	/**
47
	 * Constructs a new MSL handler for the specified resource with the
32
	 * Constructs a new MSL handler for the specified resource with the
Lines 56-153 Link Here
56
	 */
41
	 */
57
	public GMFHandler(XMLResource xmiResource, XMLHelper helper, Map options) {
42
	public GMFHandler(XMLResource xmiResource, XMLHelper helper, Map options) {
58
		super(xmiResource, helper, options);
43
		super(xmiResource, helper, options);
59
60
		urisToProxies = new HashMap();
61
		if (Boolean.TRUE.equals(options.get(GMFResource.OPTION_ABORT_ON_ERROR))) {
62
			abortOnError = true;
63
		}
64
	}
65
66
	/**
67
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#endDocument()
68
	 */
69
	public void endDocument() {
70
		super.endDocument();
71
72
		if (null != extendedMetaData) {
73
74
			for (Iterator demandedPackages = extendedMetaData
75
				.demandedPackages().iterator(); demandedPackages.hasNext();) {
76
77
				EPackage ePackage = (EPackage) demandedPackages.next();
78
				String nsURI = ePackage.getNsURI();
79
80
				if (null != nsURI) {
81
82
					if (null != urisToLocations) {
83
						URI locationURI = (URI) urisToLocations.get(nsURI);
84
85
						if (null != locationURI) {
86
							// set the schema location
87
							Resource resource = new ResourceImpl();
88
							resource.setURI(locationURI);
89
							resource.getContents().add(ePackage);
90
						}
91
					}
92
93
					for (Iterator entries = helper.getPrefixToNamespaceMap()
94
						.iterator(); entries.hasNext();) {
95
96
						Map.Entry entry = (Map.Entry) entries.next();
97
98
						if (nsURI.equals(entry.getValue())) {
99
							// set the namespace prefix
100
							ePackage.setNsPrefix((String) entry.getKey());
101
						}
102
					}
103
				}
104
			}
105
		}
106
	}
107
108
	/**
109
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#validateCreateObjectFromFactory(org.eclipse.emf.ecore.EFactory,
110
	 *      java.lang.String, org.eclipse.emf.ecore.EObject,
111
	 *      org.eclipse.emf.ecore.EStructuralFeature)
112
	 */
113
	protected EObject validateCreateObjectFromFactory(EFactory factory,
114
			String typeName, EObject newObject, EStructuralFeature feature) {
115
116
		if (!(objects.peek() instanceof AnyType) && null != newObject
117
			&& newObject.eIsProxy() && !sameDocumentProxies.contains(newObject)) {
118
119
			URI proxyURI = ((InternalEObject) newObject).eProxyURI();
120
121
			Map typeNamesToProxies = (Map) urisToProxies.get(proxyURI);
122
123
			if (null == typeNamesToProxies) {
124
				urisToProxies.put(proxyURI, typeNamesToProxies = new HashMap());
125
			}
126
127
			EObject proxy = (EObject) typeNamesToProxies.get(typeName);
128
129
			if (null == proxy) {
130
				typeNamesToProxies.put(typeName, proxy = newObject);
131
			}
132
133
			// canonicalize proxies
134
			newObject = proxy;
135
		}
136
137
		return super.validateCreateObjectFromFactory(factory, typeName,
138
			newObject, feature);
139
	}
140
141
	/**
142
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#error(org.eclipse.emf.ecore.xmi.XMIException)
143
	 */
144
	public void error(XMIException e) {
145
		super.error(e);
146
		if (abortOnError) {
147
			if (e.getWrappedException() != null) {
148
				throw new AbortResourceLoadException(e.getWrappedException());
149
			}
150
			throw new AbortResourceLoadException(e);
151
		}
152
	}
44
	}
153
}
45
}
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/GMFHelper.java (-23 / +5 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-29 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.util.URI;
15
import org.eclipse.emf.ecore.xmi.XMLResource;
14
import org.eclipse.emf.ecore.xmi.XMLResource;
16
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
17
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
18
15
19
/**
16
/**
20
 * This class changes the behavior of the default XMIHelper so that references
17
 * This class changes the behavior of the default XMIHelper so that references
21
 * between projects are not deresolved.
18
 * between projects are not deresolved.
22
 * 
19
 * 
23
 * @author rafikj
20
 * @author rafikj
21
 * 
22
 * @deprecated Use the {@link org.eclipse.gmf.runtime.emf.core.resources.GMFHelper}
23
 *     class, instead
24
 */
24
 */
25
public class GMFHelper
25
public class GMFHelper
26
	extends XMIHelperImpl {
26
	extends org.eclipse.gmf.runtime.emf.core.resources.GMFHelper {
27
27
28
	/**
28
	/**
29
	 * Constructor.
29
	 * Constructor.
Lines 31-52 Link Here
31
	public GMFHelper(XMLResource resource) {
31
	public GMFHelper(XMLResource resource) {
32
		super(resource);
32
		super(resource);
33
	}
33
	}
34
35
	/**
36
	 * @see org.eclipse.emf.ecore.xmi.XMLHelper#deresolve(org.eclipse.emf.common.util.URI)
37
	 */
38
	public URI deresolve(URI uri) {
39
40
		// if this both target and container are within a platform resource and
41
		// projects
42
		// or plugins are different then do not deresolve.
43
		if (((EMFCoreConstants.PLATFORM_SCHEME.equals(uri.scheme())) && (EMFCoreConstants.PLATFORM_SCHEME
44
			.equals(resourceURI.scheme())))
45
			&& ((uri.segmentCount() > 2) && (resourceURI.segmentCount() > 2))
46
			&& ((!uri.segments()[0].equals(resourceURI.segments()[0])) || (!uri
47
				.segments()[1].equals(resourceURI.segments()[1]))))
48
			return uri;
49
50
		return super.deresolve(uri);
51
	}
52
}
34
}
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/GMFLoad.java (-30 / +5 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-27 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 java.io.IOException;
15
import java.io.InputStream;
16
import java.util.Map;
17
18
import org.eclipse.emf.ecore.resource.Resource;
19
import org.eclipse.emf.ecore.xmi.UnresolvedReferenceException;
20
import org.eclipse.emf.ecore.xmi.XMLHelper;
14
import org.eclipse.emf.ecore.xmi.XMLHelper;
21
import org.eclipse.emf.ecore.xmi.XMLResource;
22
import org.eclipse.emf.ecore.xmi.impl.SAXWrapper;
15
import org.eclipse.emf.ecore.xmi.impl.SAXWrapper;
23
import org.eclipse.emf.ecore.xmi.impl.XMILoadImpl;
24
import org.eclipse.gmf.runtime.emf.core.internal.exceptions.AbortResourceLoadException;
25
import org.xml.sax.helpers.DefaultHandler;
16
import org.xml.sax.helpers.DefaultHandler;
26
17
27
/**
18
/**
Lines 29-37 Link Here
29
 * UnresolvedReferenceExceptions are not thrown back.
20
 * UnresolvedReferenceExceptions are not thrown back.
30
 * 
21
 * 
31
 * @author rafikj
22
 * @author rafikj
23
 * 
24
 * @deprecated Use the {@link org.eclipse.gmf.runtime.emf.core.resources.GMFLoad}
25
 *     class, instead
32
 */
26
 */
33
public class GMFLoad
27
public class GMFLoad
34
	extends XMILoadImpl {
28
	extends org.eclipse.gmf.runtime.emf.core.resources.GMFLoad {
35
29
36
	/**
30
	/**
37
	 * Constructor.
31
	 * Constructor.
Lines 41-65 Link Here
41
	}
35
	}
42
36
43
	/**
37
	/**
44
	 * @see org.eclipse.emf.ecore.xmi.XMLLoad#load(org.eclipse.emf.ecore.xmi.XMLResource,
45
	 *      java.io.InputStream, java.util.Map)
46
	 */
47
	public void load(XMLResource r, InputStream s, Map o)
48
		throws IOException {
49
50
		try {
51
52
			super.load(r, s, o);
53
54
		} catch (Resource.IOWrappedException e) {
55
			if (!(e.getWrappedException() instanceof UnresolvedReferenceException))
56
				throw e;
57
		} catch (AbortResourceLoadException arle) {
58
			throw new Resource.IOWrappedException((Exception)arle.getCause());
59
		}
60
	}
61
62
	/**
63
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl#makeDefaultHandler()
38
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl#makeDefaultHandler()
64
	 */
39
	 */
65
	protected DefaultHandler makeDefaultHandler() {
40
	protected DefaultHandler makeDefaultHandler() {
(-)src/org/eclipse/gmf/runtime/emf/core/resources/IResourceHelper.java (-2 lines)
Lines 14-21 Link Here
14
import org.eclipse.emf.common.notify.Adapter;
14
import org.eclipse.emf.common.notify.Adapter;
15
import org.eclipse.emf.ecore.EClass;
15
import org.eclipse.emf.ecore.EClass;
16
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.resource.Resource;
18
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
19
17
20
18
21
/**
19
/**
(-)src/org/eclipse/gmf/runtime/emf/core/resources/package.html (-2 / +11 lines)
Lines 4-10 Link Here
4
<!--
4
<!--
5
5
6
/******************************************************************************
6
/******************************************************************************
7
 * Copyright (c) 2005 IBM Corporation and others.
7
 * Copyright (c) 2005, 2006 IBM Corporation and others.
8
 * All rights reserved. This program and the accompanying materials
8
 * All rights reserved. This program and the accompanying materials
9
 * are made available under the terms of the Eclipse Public License v1.0
9
 * are made available under the terms of the Eclipse Public License v1.0
10
 * which accompanies this distribution, and is available at
10
 * which accompanies this distribution, and is available at
Lines 28-37 Link Here
28
creates GMF resources.  It is not intended to be used by client code, but to
28
creates GMF resources.  It is not intended to be used by client code, but to
29
be referenced on the EMF <tt>org.eclipse.emf.ecore.extension_parser</tt>
29
be referenced on the EMF <tt>org.eclipse.emf.ecore.extension_parser</tt>
30
extension point to associate the client application's file extension with the
30
extension point to associate the client application's file extension with the
31
resource factory.
31
resource factory.  Associated with this factory is the
32
{@link org.eclipse.gmf.runtime.emf.core.resources.GMFResource} class which is
33
GMF's custom resource implementation, supporting path map URIs and automatic
34
URI denormalization and modification tracking.
35
</p>
36
<p>
37
This package also defines a {@link org.eclipse.gmf.runtime.emf.core.resources.PathmapManager}
38
class which has static API methods for managing path map variables, in particular
39
for defining path maps statically for your plug-in's resources.
32
</p>
40
</p>
33
41
34
@see org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory
42
@see org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory
43
@see org.eclipse.gmf.runtime.emf.core.resources.PathmapManager
35
44
36
@canBeSeenBy %partners
45
@canBeSeenBy %partners
37
46
(-)src/org/eclipse/gmf/runtime/emf/core/resources/GMFResourceFactory.java (-1 lines)
Lines 20-26 Link Here
20
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
20
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
21
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
21
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
22
22
23
import org.eclipse.gmf.runtime.emf.core.internal.resources.GMFResource;
24
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
23
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
25
24
26
/**
25
/**
(-)src/org/eclipse/gmf/runtime/emf/core/resources/IExtendedResourceFactory.java (-1 lines)
Lines 12-18 Link Here
12
package org.eclipse.gmf.runtime.emf.core.resources;
12
package org.eclipse.gmf.runtime.emf.core.resources;
13
13
14
import org.eclipse.emf.ecore.EObject;
14
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.emf.transaction.TransactionalEditingDomain;
15
import org.eclipse.emf.transaction.TransactionalEditingDomain;
17
16
18
17
(-)src/org/eclipse/gmf/runtime/emf/core/internal/exceptions/AbortResourceLoadException.java (-3 / +7 lines)
Lines 17-24 Link Here
17
 * abort loading at any time.
17
 * abort loading at any time.
18
 * 
18
 * 
19
 * @author Christian Vogt (cvogt)
19
 * @author Christian Vogt (cvogt)
20
 * 
21
 * @deprecated Use the {@link org.eclipse.gmf.runtime.emf.core.resources.AbortResourceLoadException}
22
 *     exception, instead.
20
 */
23
 */
21
public class AbortResourceLoadException extends RuntimeException {
24
public class AbortResourceLoadException extends org.eclipse.gmf.runtime.emf.core.resources.AbortResourceLoadException {
25
26
	private static final long serialVersionUID = 1317448650831196205L;
22
27
23
	/**
28
	/**
24
	 * Initializes me without any details.
29
	 * Initializes me without any details.
Lines 44-50 Link Here
44
	 *            the cause of this exception.
49
	 *            the cause of this exception.
45
	 */
50
	 */
46
	public AbortResourceLoadException(Throwable cause) {
51
	public AbortResourceLoadException(Throwable cause) {
47
		super(null == cause ? null
52
		super(cause);
48
			: cause.toString(), cause);
49
	}
53
	}
50
}
54
}
(-)src/org/eclipse/gmf/runtime/emf/core/clipboard/CopyingResource.java (-1 / +1 lines)
Lines 35-41 Link Here
35
import org.eclipse.gmf.runtime.common.core.util.Trace;
35
import org.eclipse.gmf.runtime.common.core.util.Trace;
36
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
36
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
37
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
37
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
38
import org.eclipse.gmf.runtime.emf.core.internal.resources.GMFResource;
38
import org.eclipse.gmf.runtime.emf.core.resources.GMFResource;
39
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
39
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
40
import org.eclipse.gmf.runtime.emf.core.internal.util.Util;
40
import org.eclipse.gmf.runtime.emf.core.internal.util.Util;
41
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
41
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
(-)src/org/eclipse/gmf/runtime/emf/core/resources/GMFHelper.java (+52 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.resources;
13
14
import org.eclipse.emf.common.util.URI;
15
import org.eclipse.emf.ecore.xmi.XMLResource;
16
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
17
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
18
19
/**
20
 * This class changes the behavior of the default XMIHelper so that references
21
 * between projects are not deresolved.
22
 * 
23
 * @author rafikj
24
 */
25
public class GMFHelper
26
	extends XMIHelperImpl {
27
28
	/**
29
	 * Constructor.
30
	 */
31
	public GMFHelper(XMLResource resource) {
32
		super(resource);
33
	}
34
35
	/**
36
	 * @see org.eclipse.emf.ecore.xmi.XMLHelper#deresolve(org.eclipse.emf.common.util.URI)
37
	 */
38
	public URI deresolve(URI uri) {
39
40
		// if this both target and container are within a platform resource and
41
		// projects
42
		// or plugins are different then do not deresolve.
43
		if (((EMFCoreConstants.PLATFORM_SCHEME.equals(uri.scheme())) && (EMFCoreConstants.PLATFORM_SCHEME
44
			.equals(resourceURI.scheme())))
45
			&& ((uri.segmentCount() > 2) && (resourceURI.segmentCount() > 2))
46
			&& ((!uri.segments()[0].equals(resourceURI.segments()[0])) || (!uri
47
				.segments()[1].equals(resourceURI.segments()[1]))))
48
			return uri;
49
50
		return super.deresolve(uri);
51
	}
52
}
(-)src/org/eclipse/gmf/runtime/emf/core/resources/GMFResource.java (+197 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2004-2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.resources;
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;
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;
22
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
29
/**
30
 * Custom implementation of an XMIResource.
31
 * 
32
 * @author rafikj
33
 */
34
public class GMFResource
35
	extends XMIResourceImpl {
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
	
45
	/**
46
	 * Constructor.
47
	 */
48
	public GMFResource(URI uri) {
49
50
		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
	}
72
73
	protected XMLHelper createXMLHelper() {
74
		return new GMFHelper(this);
75
	}
76
77
	protected XMLLoad createXMLLoad() {
78
		return new GMFLoad(createXMLHelper());
79
	}
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
}
(-)src/org/eclipse/gmf/runtime/emf/core/resources/AbortResourceLoadException.java (+52 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.resources;
13
14
/**
15
 * This exception is intended to be thrown during Resource load when an
16
 * error occurs. This RuntimeException wrapper is required in order to
17
 * abort loading at any time.
18
 * 
19
 * @author Christian Vogt (cvogt)
20
 */
21
public class AbortResourceLoadException extends RuntimeException {
22
23
	private static final long serialVersionUID = -5621491416138595586L;
24
25
	/**
26
	 * Initializes me without any details.
27
	 */
28
	public AbortResourceLoadException() {
29
		super();
30
	}
31
32
	/**
33
	 * Initializes me with a useful message.
34
	 * 
35
	 * @param message
36
	 *            a message
37
	 */
38
	public AbortResourceLoadException(String message) {
39
		super(message);
40
	}
41
42
	/**
43
	 * Initializes me with a cause.
44
	 * 
45
	 * @param cause
46
	 *            the cause of this exception.
47
	 */
48
	public AbortResourceLoadException(Throwable cause) {
49
		super(null == cause ? null
50
			: cause.toString(), cause);
51
	}
52
}
(-)src/org/eclipse/gmf/runtime/emf/core/resources/GMFLoad.java (+67 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.resources;
13
14
import java.io.IOException;
15
import java.io.InputStream;
16
import java.util.Map;
17
18
import org.eclipse.emf.ecore.resource.Resource;
19
import org.eclipse.emf.ecore.xmi.UnresolvedReferenceException;
20
import org.eclipse.emf.ecore.xmi.XMLHelper;
21
import org.eclipse.emf.ecore.xmi.XMLResource;
22
import org.eclipse.emf.ecore.xmi.impl.SAXWrapper;
23
import org.eclipse.emf.ecore.xmi.impl.XMILoadImpl;
24
import org.xml.sax.helpers.DefaultHandler;
25
26
/**
27
 * This class changes the behavior of the default XMILoader so that
28
 * UnresolvedReferenceExceptions are not thrown back.
29
 * 
30
 * @author rafikj
31
 */
32
public class GMFLoad
33
	extends XMILoadImpl {
34
35
	/**
36
	 * Constructor.
37
	 */
38
	public GMFLoad(XMLHelper helper) {
39
		super(helper);
40
	}
41
42
	/**
43
	 * @see org.eclipse.emf.ecore.xmi.XMLLoad#load(org.eclipse.emf.ecore.xmi.XMLResource,
44
	 *      java.io.InputStream, java.util.Map)
45
	 */
46
	public void load(XMLResource r, InputStream s, Map o)
47
		throws IOException {
48
49
		try {
50
51
			super.load(r, s, o);
52
53
		} catch (Resource.IOWrappedException e) {
54
			if (!(e.getWrappedException() instanceof UnresolvedReferenceException))
55
				throw e;
56
		} catch (AbortResourceLoadException arle) {
57
			throw new Resource.IOWrappedException((Exception)arle.getCause());
58
		}
59
	}
60
61
	/**
62
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl#makeDefaultHandler()
63
	 */
64
	protected DefaultHandler makeDefaultHandler() {
65
		return new SAXWrapper(new GMFHandler(resource, helper, options));
66
	}
67
}
(-)src/org/eclipse/gmf/runtime/emf/core/resources/GMFHandler.java (+152 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.resources;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EFactory;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EPackage;
22
import org.eclipse.emf.ecore.EStructuralFeature;
23
import org.eclipse.emf.ecore.InternalEObject;
24
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
26
import org.eclipse.emf.ecore.xmi.XMIException;
27
import org.eclipse.emf.ecore.xmi.XMLHelper;
28
import org.eclipse.emf.ecore.xmi.XMLResource;
29
import org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler;
30
import org.eclipse.emf.ecore.xml.type.AnyType;
31
32
/**
33
 * The SAX handler for MSL resources. Updates demand-created packages with their
34
 * namespace prefixes and schema locations.
35
 * 
36
 * @author khussey
37
 */
38
public class GMFHandler
39
	extends SAXXMIHandler {
40
41
	protected final Map urisToProxies;
42
	
43
	protected boolean abortOnError;
44
45
	/**
46
	 * Constructs a new MSL handler for the specified resource with the
47
	 * specified helper and options.
48
	 * 
49
	 * @param xmiResource
50
	 *            The resource for the new handler.
51
	 * @param helper
52
	 *            The helper for the new handler.
53
	 * @param options
54
	 *            The load options for the new handler.
55
	 */
56
	public GMFHandler(XMLResource xmiResource, XMLHelper helper, Map options) {
57
		super(xmiResource, helper, options);
58
59
		urisToProxies = new HashMap();
60
		if (Boolean.TRUE.equals(options.get(GMFResource.OPTION_ABORT_ON_ERROR))) {
61
			abortOnError = true;
62
		}
63
	}
64
65
	/**
66
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#endDocument()
67
	 */
68
	public void endDocument() {
69
		super.endDocument();
70
71
		if (null != extendedMetaData) {
72
73
			for (Iterator demandedPackages = extendedMetaData
74
				.demandedPackages().iterator(); demandedPackages.hasNext();) {
75
76
				EPackage ePackage = (EPackage) demandedPackages.next();
77
				String nsURI = ePackage.getNsURI();
78
79
				if (null != nsURI) {
80
81
					if (null != urisToLocations) {
82
						URI locationURI = (URI) urisToLocations.get(nsURI);
83
84
						if (null != locationURI) {
85
							// set the schema location
86
							Resource resource = new ResourceImpl();
87
							resource.setURI(locationURI);
88
							resource.getContents().add(ePackage);
89
						}
90
					}
91
92
					for (Iterator entries = helper.getPrefixToNamespaceMap()
93
						.iterator(); entries.hasNext();) {
94
95
						Map.Entry entry = (Map.Entry) entries.next();
96
97
						if (nsURI.equals(entry.getValue())) {
98
							// set the namespace prefix
99
							ePackage.setNsPrefix((String) entry.getKey());
100
						}
101
					}
102
				}
103
			}
104
		}
105
	}
106
107
	/**
108
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#validateCreateObjectFromFactory(org.eclipse.emf.ecore.EFactory,
109
	 *      java.lang.String, org.eclipse.emf.ecore.EObject,
110
	 *      org.eclipse.emf.ecore.EStructuralFeature)
111
	 */
112
	protected EObject validateCreateObjectFromFactory(EFactory factory,
113
			String typeName, EObject newObject, EStructuralFeature feature) {
114
115
		if (!(objects.peek() instanceof AnyType) && null != newObject
116
			&& newObject.eIsProxy() && !sameDocumentProxies.contains(newObject)) {
117
118
			URI proxyURI = ((InternalEObject) newObject).eProxyURI();
119
120
			Map typeNamesToProxies = (Map) urisToProxies.get(proxyURI);
121
122
			if (null == typeNamesToProxies) {
123
				urisToProxies.put(proxyURI, typeNamesToProxies = new HashMap());
124
			}
125
126
			EObject proxy = (EObject) typeNamesToProxies.get(typeName);
127
128
			if (null == proxy) {
129
				typeNamesToProxies.put(typeName, proxy = newObject);
130
			}
131
132
			// canonicalize proxies
133
			newObject = proxy;
134
		}
135
136
		return super.validateCreateObjectFromFactory(factory, typeName,
137
			newObject, feature);
138
	}
139
140
	/**
141
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#error(org.eclipse.emf.ecore.xmi.XMIException)
142
	 */
143
	public void error(XMIException e) {
144
		super.error(e);
145
		if (abortOnError) {
146
			if (e.getWrappedException() != null) {
147
				throw new AbortResourceLoadException(e.getWrappedException());
148
			}
149
			throw new AbortResourceLoadException(e);
150
		}
151
	}
152
}
(-)src/org/eclipse/gmf/runtime/emf/core/resources/IPathmapManager.java (+55 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2002, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.resources;
13
14
import org.eclipse.core.runtime.IStatus;
15
16
/**
17
 * Specification of an object that manages URI mappings (path variables) for
18
 * the <code>pathmap</code> URI scheme on an editing domain's resource set.
19
 * 
20
 * @author rafikj
21
 */
22
public interface IPathmapManager {
23
	
24
	/**
25
	 * Set the value of a path variable.
26
	 * 
27
	 * @param name the path variable name
28
	 * @param value the path variable value (a file URI)
29
	 * 
30
	 * @return a status indicating success (OK) or failure (ERROR) to set the
31
	 *     path variable.  In case of error, the status message provides a
32
	 *     user-friendly explanation of the reason 
33
	 */
34
	IStatus addPathVariable(String name, String value);
35
	
36
	/**
37
	 * Removes a path variable and its value.
38
	 * 
39
	 * @param name the path variable name
40
	 * 
41
	 * @return a status indicating success (OK) or failure (ERROR) to remove the
42
	 *     path variable.  In case of error, the status message provides a
43
	 *     user-friendly explanation of the reason 
44
	 */
45
	IStatus removePathVariable(String name);
46
47
	/**
48
	 * Queries the current value of a path variable.
49
	 * 
50
	 * @param name the path variable name
51
	 * @return the path variable value (a URI) or an empty string if
52
	 *    the specified variable is undefined
53
	 */
54
	String getPathVariable(String name);
55
}

Return to bug 137063