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

Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/emf/core/edit/MEditingDomain.java (-55 lines)
Lines 259-319 Link Here
259
			EClass rootEClass, int options);
259
			EClass rootEClass, int options);
260
260
261
	/**
261
	/**
262
	 * Loads a resource from a given file.
263
	 * 
264
	 * @param fileNameURI
265
	 *            The resource's file path.
266
	 * @return The loaded resource.
267
	 * 
268
	 * @deprecated Use the
269
	 *    {@link org.eclipse.emf.ecore.resource.ResourceSet#getResource(URI, boolean)}
270
	 *    API or, if it does not already existin in the resource set,
271
	 *    {@link org.eclipse.emf.ecore.resource.ResourceSet#createResource(URI) create}
272
	 *    it and then {@link org.eclipse.emf.ecore.resource.Resource#load(Map)} it.
273
	 */
274
	public abstract Resource loadResource(String fileNameURI);
275
276
	/**
277
	 * Loads a resource from a given file.
278
	 * 
279
	 * @param fileNameURI
280
	 *            The resource's file path.
281
	 * @param options
282
	 *            The load options. This is a bit mask of values from
283
	 *            <code>MResourceOption</code>.
284
	 * @return The loaded resource.
285
	 * 
286
	 * @deprecated Use the
287
	 *    {@link org.eclipse.emf.ecore.resource.ResourceSet#getResource(URI, boolean)}
288
	 *    API or, if it does not already existin in the resource set,
289
	 *    {@link org.eclipse.emf.ecore.resource.ResourceSet#createResource(URI) create}
290
	 *    it and then {@link org.eclipse.emf.ecore.resource.Resource#load(Map)} it.
291
	 */
292
	public abstract Resource loadResource(String fileNameURI, int options);
293
	
294
	/**
295
	 * Loads a resource with a given file path from the given input stream using
296
	 * the given load options.
297
	 * 
298
	 * @param fileNameURI
299
	 *            The resource's file path.
300
	 * @param options
301
	 *            The load options. This is a bit mask of values from
302
	 *            <code>MResourceOption</code>.
303
	 * @param inputStream
304
	 *            The input stream from which to load the resource's contents.
305
	 * @return The loaded resource.
306
	 * 
307
	 * @deprecated Use the
308
	 *    {@link org.eclipse.emf.ecore.resource.ResourceSet#getResource(URI, boolean)}
309
	 *    API or, if it does not already existin in the resource set,
310
	 *    {@link org.eclipse.emf.ecore.resource.ResourceSet#createResource(URI) create}
311
	 *    it and then {@link org.eclipse.emf.ecore.resource.Resource#load(InputStream, Map)} it.
312
	 */
313
	public abstract Resource loadResource(String fileNameURI, int options,
314
			InputStream inputStream);
315
316
	/**
317
	 * Loads an unloaded resource. It is the responsibility of callers to catch
262
	 * Loads an unloaded resource. It is the responsibility of callers to catch
318
	 *  any exceptions that will be thrown as a result of the resource being loaded
263
	 *  any exceptions that will be thrown as a result of the resource being loaded
319
	 *  with errors. Note that the state of the resource could be loaded (ie. it could
264
	 *  with errors. Note that the state of the resource could be loaded (ie. it could
(-)src/org/eclipse/gmf/runtime/emf/core/internal/notifications/MSLEventBroker.java (-9 / +22 lines)
Lines 126-131 Link Here
126
	 * Runs the runnable instance without sending events.
126
	 * Runs the runnable instance without sending events.
127
	 */
127
	 */
128
	public Object runSilent(MRunnable runnable) {
128
	public Object runSilent(MRunnable runnable) {
129
129
		return runWithOptions(runnable, MRunOption.SILENT);
130
		return runWithOptions(runnable, MRunOption.SILENT);
130
	}
131
	}
131
132
Lines 133-138 Link Here
133
	 * Runs the runnable instance without semantic procedures.
134
	 * Runs the runnable instance without semantic procedures.
134
	 */
135
	 */
135
	public Object runWithNoSemProcs(MRunnable runnable) {
136
	public Object runWithNoSemProcs(MRunnable runnable) {
137
136
		return runWithOptions(runnable, MRunOption.NO_SEM_PROCS);
138
		return runWithOptions(runnable, MRunOption.NO_SEM_PROCS);
137
	}
139
	}
138
140
Lines 140-145 Link Here
140
	 * Runs the runnable instance without validation.
142
	 * Runs the runnable instance without validation.
141
	 */
143
	 */
142
	public Object runUnvalidated(MRunnable runnable) {
144
	public Object runUnvalidated(MRunnable runnable) {
145
143
		return runWithOptions(runnable, MRunOption.UNVALIDATED);
146
		return runWithOptions(runnable, MRunOption.UNVALIDATED);
144
	}
147
	}
145
148
Lines 151-156 Link Here
151
	 * @see MRunOption
154
	 * @see MRunOption
152
	 */
155
	 */
153
	public Object runWithOptions(MRunnable runnable, int options) {
156
	public Object runWithOptions(MRunnable runnable, int options) {
157
154
		Object result = null;
158
		Object result = null;
155
159
156
		Object previousNoNotifications = null;
160
		Object previousNoNotifications = null;
Lines 245-250 Link Here
245
	 * Adds a new event to the pending list of events.
249
	 * Adds a new event to the pending list of events.
246
	 */
250
	 */
247
	public void addEvent(Notification event) {
251
	public void addEvent(Notification event) {
252
248
		notifyMetaModel(event);
253
		notifyMetaModel(event);
249
254
250
		if (domain.isUndoInProgress())
255
		if (domain.isUndoInProgress())
Lines 258-264 Link Here
258
	 * Checks if event is undo event.
263
	 * Checks if event is undo event.
259
	 */
264
	 */
260
	public boolean isUndoEvent(Notification event) {
265
	public boolean isUndoEvent(Notification event) {
266
261
		Boolean isUndo = (Boolean) undoRedoEvents.get(event);
267
		Boolean isUndo = (Boolean) undoRedoEvents.get(event);
268
262
		return (isUndo != null) && (isUndo.booleanValue());
269
		return (isUndo != null) && (isUndo.booleanValue());
263
	}
270
	}
264
271
Lines 266-272 Link Here
266
	 * Checks if event is redo event.
273
	 * Checks if event is redo event.
267
	 */
274
	 */
268
	public boolean isRedoEvent(Notification event) {
275
	public boolean isRedoEvent(Notification event) {
276
269
		Boolean isUndo = (Boolean) undoRedoEvents.get(event);
277
		Boolean isUndo = (Boolean) undoRedoEvents.get(event);
278
270
		return (isUndo != null) && (!isUndo.booleanValue());
279
		return (isUndo != null) && (!isUndo.booleanValue());
271
	}
280
	}
272
281
Lines 274-280 Link Here
274
	 * Notify the meta-model about the modification.
283
	 * Notify the meta-model about the modification.
275
	 */
284
	 */
276
	public void notifyMetaModel(Notification event) {
285
	public void notifyMetaModel(Notification event) {
286
277
		if (sendEventsToMetaModel) {
287
		if (sendEventsToMetaModel) {
288
278
			Object notifier = event.getNotifier();
289
			Object notifier = event.getNotifier();
279
290
280
			if (((domain.isWriteInProgress()) || (domain
291
			if (((domain.isWriteInProgress()) || (domain
Lines 303-308 Link Here
303
	 * Fires events.
314
	 * Fires events.
304
	 */
315
	 */
305
	private void fireEvents(List events) {
316
	private void fireEvents(List events) {
317
306
		if (events.isEmpty())
318
		if (events.isEmpty())
307
			return;
319
			return;
308
320
Lines 323-329 Link Here
323
			//  consuming and save the time of extracting the single Notification from the list.
335
			//  consuming and save the time of extracting the single Notification from the list.
324
			Notification singleEvent = (Notification)events.get(0);
336
			Notification singleEvent = (Notification)events.get(0);
325
			
337
			
326
			for (Iterator iter = allListeners.iterator(); iter.hasNext();) {
338
		for (Iterator iter = allListeners.iterator(); iter.hasNext();) {
327
				MListener listener = (MListener)iter.next();
339
				MListener listener = (MListener)iter.next();
328
				fireSingleEvent(listener, singleEvent, events);
340
				fireSingleEvent(listener, singleEvent, events);
329
			}
341
			}
Lines 333-345 Link Here
333
			//  only have two lists occupying memory that are the same size rather
345
			//  only have two lists occupying memory that are the same size rather
334
			//  than allocating lists of different sizes for each listener.
346
			//  than allocating lists of different sizes for each listener.
335
			List listenerEventCache = new ArrayList(events.size());
347
			List listenerEventCache = new ArrayList(events.size());
336
			
348
337
			for (Iterator iter = allListeners.iterator(); iter.hasNext();) {
349
			for (Iterator iter = allListeners.iterator(); iter.hasNext();) {
338
				MListener listener = (MListener)iter.next();
350
				MListener listener = (MListener)iter.next();
339
				fireEvents(listener, events, listenerEventCache);
351
				fireEvents(listener, events, listenerEventCache);
340
			}
341
		}
352
		}
342
	}
353
	}
354
	}
343
	
355
	
344
	private boolean shouldSuppressUnbatchedResourceEvent(List events) {
356
	private boolean shouldSuppressUnbatchedResourceEvent(List events) {
345
		boolean result = false;
357
		boolean result = false;
Lines 349-359 Link Here
349
			
361
			
350
			if (notification.getNotifier() instanceof Resource) {
362
			if (notification.getNotifier() instanceof Resource) {
351
				if (notification.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
363
				if (notification.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
352
					Resource res = (Resource) notification.getNotifier();
364
					result = !notification.getNewBooleanValue() && !(notification instanceof MSLResourceListener.UnloadNotification);
353
					
354
					result = notification.getNewBooleanValue()?
355
						domain.getResouceListener().loadedWithErrors(res) :
356
						!(notification instanceof MSLResourceListener.UnloadNotification);
357
				}
365
				}
358
			}
366
			}
359
		}
367
		}
Lines 367-372 Link Here
367
	 *  the returned list is garbage collected.
375
	 *  the returned list is garbage collected.
368
	 */
376
	 */
369
	private List getAllListeners() {
377
	private List getAllListeners() {
378
370
		List allListeners = new ArrayList(listeners.size()
379
		List allListeners = new ArrayList(listeners.size()
371
			+ universalListeners.size() + semProcProviders.size());
380
			+ universalListeners.size() + semProcProviders.size());
372
381
Lines 397-402 Link Here
397
			Iterator j = events.iterator();
406
			Iterator j = events.iterator();
398
407
399
			while (j.hasNext()) {
408
			while (j.hasNext()) {
409
400
				Notification event = (Notification) j.next();
410
				Notification event = (Notification) j.next();
401
411
402
				if (filter.matches(event))
412
				if (filter.matches(event))
Lines 408-415 Link Here
408
			return;
418
			return;
409
419
410
		try {
420
		try {
421
411
			listener.onEvent(eventsToSend);
422
			listener.onEvent(eventsToSend);
423
412
		} catch (Exception e) {
424
		} catch (Exception e) {
425
413
			// this is a bad listener so remove it so the next
426
			// this is a bad listener so remove it so the next
414
			// listeners can get their events.
427
			// listeners can get their events.
415
			// bugzilla110334: Do not remove listener as it will cause
428
			// bugzilla110334: Do not remove listener as it will cause
Lines 437-443 Link Here
437
		if (!filter.matches(event)) {
450
		if (!filter.matches(event)) {
438
			return;
451
			return;
439
		}
452
		}
440
453
		
441
		try {
454
		try {
442
			listener.onEvent(eventsToSend);
455
			listener.onEvent(eventsToSend);
443
		} catch (Exception e) {
456
		} catch (Exception e) {
(-)src/org/eclipse/gmf/runtime/emf/core/internal/notifications/MSLResourceListener.java (-76 / +8 lines)
Lines 69-90 Link Here
69
69
70
	private Map unloadedResourcesRoot = new HashMap();
70
	private Map unloadedResourcesRoot = new HashMap();
71
	
71
	
72
	// TODO Remove this tracking of resources with errors in the next iteration.
73
	/*
74
	 * This map is here to keep track of which resources were
75
	 *  loaded with errors. For now we are not going to be propagating
76
	 *  any events associated with loading/unloaded these resources.
77
	 *  In the next iteration we will propagate all of these events
78
	 *  and listeners will be required to verify whether the resource
79
	 *  loaded with errors or not.
80
	 *  
81
	 *  Look at MEditingDomain.loadResource, MEditingDomain.unloadResource
82
	 *   and IDemuxedMListener.handleResourceLoadedEvent for more details.
83
	 *   
84
	 *  cmcgee
85
	 */
86
	private Map resourcesWithErrors = new WeakHashMap();
87
	
88
	/**
72
	/**
89
	 * Constructor.
73
	 * Constructor.
90
	 */
74
	 */
Lines 154-189 Link Here
154
					boolean oldBooleanValue = notification.getOldBooleanValue();
138
					boolean oldBooleanValue = notification.getOldBooleanValue();
155
139
156
					if (newBooleanValue && !oldBooleanValue) {
140
					if (newBooleanValue && !oldBooleanValue) {
157
158
						loadedResources.put(notifier, Boolean.TRUE);
141
						loadedResources.put(notifier, Boolean.TRUE);
159
142
160
						MSLUtil.postProcessResource(notifier);
143
						MSLUtil.postProcessResource(notifier);
161
						
162
						// TODO Remove this check for errors in the next iteration.
163
						// If the resource loaded with errors, place it into a special
164
						//  map indicating that it was loaded with errors so that we
165
						//  do not propagate any automated unload events. This is going
166
						//  to change in the next iteration where we will propagate all
167
						//  resource-level events.
168
						//
169
						// cmcgee
170
						//
171
						if (notifier.getErrors().size() > 0) {
172
							// remove the notification that we got from the
173
							//    current transaction
174
							InternalTransaction tx = domain.getActiveTransaction();
175
							if (tx != null) {
176
								tx.getNotifications().remove(notification);
177
							}
178
							
179
							resourcesWithErrors.put(notifier, Boolean.TRUE);
180
						} else {
181
							resourcesWithErrors.remove(notifier);
182
183
							// forward event to broker.
184
							domain.getEventBroker().addEvent(notification);
185
						}
186
						return;
187
					} else if (!newBooleanValue && oldBooleanValue
144
					} else if (!newBooleanValue && oldBooleanValue
188
							&& !(notification instanceof UnloadNotification)) {
145
							&& !(notification instanceof UnloadNotification)) {
189
146
Lines 199-226 Link Here
199
						UnloadNotification unloadNotification = new UnloadNotification(root, notification);
156
						UnloadNotification unloadNotification = new UnloadNotification(root, notification);
200
						unloadedResourcesRoot.remove(notifier);
157
						unloadedResourcesRoot.remove(notifier);
201
						
158
						
202
						// TODO Remove this check for resources with errors in the next iteration.
159
						// remove the notification that we got from the
203
						// We will be checking whether this resource was one that
160
						//    current transaction
204
						//  loaded with errors in it. If this is the case then we
161
						InternalTransaction tx = domain.getActiveTransaction();
205
						//  do not propagate the event. This is going to change in the
162
						if (tx != null) {
206
						//  next iteration.
163
							tx.getNotifications().remove(notification);
207
						//
208
						// cmcgee
209
						//
210
						if (!resourcesWithErrors.containsKey(notifier)) {
211
							// remove the notification that we got from the
212
							//    current transaction
213
							InternalTransaction tx = domain.getActiveTransaction();
214
							if (tx != null) {
215
								tx.getNotifications().remove(notification);
216
							}
217
							
218
							// and send this one in its place
219
							domain.sendNotification(unloadNotification);
220
						} else {
221
							resourcesWithErrors.remove(notifier);
222
						}
164
						}
223
						
165
						
166
						// and send this one in its place
167
						domain.sendNotification(unloadNotification);
168
						
224
						return;
169
						return;
225
					}
170
					}
226
				}
171
				}
Lines 255-271 Link Here
255
		else
200
		else
256
			loadedResources.remove(resource);
201
			loadedResources.remove(resource);
257
	}
202
	}
258
	
259
	/**
260
	 * Was the resource loaded with errors (and, therefore, the load event
261
	 * should not be propagated to listeners)?
262
	 * 
263
	 * @param resource a resource
264
	 * @return <code>true</code> if it was loaded with errors;
265
	 *    <code>false</code>, otherwise
266
	 */
267
	public boolean loadedWithErrors(Resource resource) {
268
		return resourcesWithErrors.containsKey(resource)
269
			|| !resource.getErrors().isEmpty();
270
	}
271
}
203
}
(-)src/org/eclipse/gmf/runtime/emf/core/internal/domain/MSLEditingDomain.java (-3 lines)
Lines 692-700 Link Here
692
				resource.load(inputStream, loadOptions);
692
				resource.load(inputStream, loadOptions);
693
693
694
		} catch (Exception e) {
694
		} catch (Exception e) {
695
			// TODO In the next iteration, we will no longer be automatically unloading a resource if there are errors.
696
			resource.unload();
697
			
698
			RuntimeException newE = null;
695
			RuntimeException newE = null;
699
696
700
			if (e instanceof MSLRuntimeException)
697
			if (e instanceof MSLRuntimeException)
(-)src/org/eclipse/gmf/runtime/emf/core/util/ResourceUtil.java (-54 lines)
Lines 211-233 Link Here
211
		return MEditingDomain.INSTANCE
211
		return MEditingDomain.INSTANCE
212
			.createResource(path, rootEClass, options);
212
			.createResource(path, rootEClass, options);
213
	}
213
	}
214
215
	/**
216
	 * Loads a resource from a given file.
217
	 * 
218
	 * @param path
219
	 *            The resource's file path.
220
	 * @param options
221
	 *            The load options. This is a bit mask of values from
222
	 *            <code>MResourceOption</code>.
223
	 * @return The loaded resource.
224
	 * 
225
	 * @deprecated Create or get an existing resource in the resource set
226
	 *     and {@link org.eclipse.emf.ecore.resource.Resource#load(Map) load} it.
227
	 */
228
	public static Resource load(String path, int options) {
229
		return MEditingDomain.INSTANCE.loadResource(path, options);
230
	}
231
	
214
	
232
	/**
215
	/**
233
	 * Produces a resource for a given file path and with the provided
216
	 * Produces a resource for a given file path and with the provided
Lines 254-281 Link Here
254
	}
237
	}
255
238
256
	/**
239
	/**
257
	 * Loads a resource with a given file path from the given input stream using
258
	 * the given load options.
259
	 * 
260
	 * @param path
261
	 *            The resource's file path.
262
	 * @param options
263
	 *            The load options. This is a bit mask of values from
264
	 *            <code>MResourceOption</code>.
265
	 * @param inputStream
266
	 *            The input stream from which to load the resource's contents.
267
	 * @return The loaded resource.
268
	 * 
269
	 * @deprecated Create or get an existing resource in the resource set
270
	 *     and {@link org.eclipse.emf.ecore.resource.Resource#load(InputStream, Map) load}
271
	 *     it.
272
	 */
273
	public static Resource load(String path, int options,
274
			InputStream inputStream) {
275
		return MEditingDomain.INSTANCE.loadResource(path, options, inputStream);
276
	}
277
278
	/**
279
	 * Loads an unloaded resource. It is the client's responsibility
240
	 * Loads an unloaded resource. It is the client's responsibility
280
	 *  to catch any exceptions that are thrown because of the loading
241
	 *  to catch any exceptions that are thrown because of the loading
281
	 *  of the resource. Also, once a resource is loaded, it could have
242
	 *  of the resource. Also, once a resource is loaded, it could have
Lines 411-431 Link Here
411
	}
372
	}
412
373
413
	/**
374
	/**
414
	 * Loads a resource from a given file.
415
	 * 
416
	 * @param path
417
	 *            The resource's file path.
418
	 * @return The loaded resource.
419
	 * 
420
	 * @deprecated Create or get an existing resource from the resource set,
421
	 *     by the required file URI, and
422
	 *     {@link org.eclipse.emf.ecore.resource.Resource#load(Map) load} it.
423
	 */
424
	public static Resource load(String path) {
425
		return MEditingDomain.INSTANCE.loadResource(path);
426
	}
427
428
	/**
429
	 * Loads an unloaded resource. It is the client's responsibility
375
	 * Loads an unloaded resource. It is the client's responsibility
430
	 *  to catch any exceptions that are thrown because of the loading
376
	 *  to catch any exceptions that are thrown because of the loading
431
	 *  of the resource. Also, once a resource is loaded, it could have
377
	 *  of the resource. Also, once a resource is loaded, it could have
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/listener/MListenerTest.java (-2 / +1 lines)
Lines 43-49 Link Here
43
	}
43
	}
44
	
44
	
45
	public void testResourceLoadEventsWhenError() {
45
	public void testResourceLoadEventsWhenError() {
46
		// TODO Change this test case come the next iteration when we change the behaviour of resource load
47
		MEditingDomain domain = MEditingDomain.createNewDomain();
46
		MEditingDomain domain = MEditingDomain.createNewDomain();
48
		
47
		
49
		final boolean[] results = new boolean[2];
48
		final boolean[] results = new boolean[2];
Lines 71-77 Link Here
71
			// Ignore this exception.
70
			// Ignore this exception.
72
		}
71
		}
73
		
72
		
74
		assertTrue(results[0]);
73
		assertFalse(results[0]);
75
		assertTrue(results[1]);
74
		assertTrue(results[1]);
76
	}
75
	}
77
}
76
}
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/domain/MSLEditingDomainTestCase.java (-2 / +1 lines)
Lines 88-94 Link Here
88
			assertTrue(true);
88
			assertTrue(true);
89
		}
89
		}
90
		
90
		
91
		// TODO Change this line when we turn off automatic unloading of resources during load.
91
		assertTrue(r.isLoaded());
92
		assertFalse(r.isLoaded());
93
	}
92
	}
94
}
93
}

Return to bug 115700