aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/terminal/web/AjaxApplicationManager.java
blob: dae70dc88f5a2f57486ad7b2c3cee4e16a01b01c (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
/* *************************************************************************
 
 IT Mill Toolkit 

 Development of Browser User Interfaces Made Easy

 Copyright (C) 2000-2006 IT Mill Ltd
 
 *************************************************************************

 This product is distributed under commercial license that can be found
 from the product package on license.pdf. Use of this product might 
 require purchasing a commercial license from IT Mill Ltd. For guidelines 
 on usage, see licensing-guidelines.html

 *************************************************************************
 
 For more information, contact:
 
 IT Mill Ltd                           phone: +358 2 4802 7180
 Ruukinkatu 2-4                        fax:   +358 2 4802 7181
 20540, Turku                          email:  info@itmill.com
 Finland                               company www: www.itmill.com
 
 Primary source for information and releases: www.itmill.com

 ********************************************************************** */

package com.itmill.toolkit.terminal.web;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itmill.toolkit.Application;
import com.itmill.toolkit.Application.WindowAttachEvent;
import com.itmill.toolkit.Application.WindowDetachEvent;
import com.itmill.toolkit.terminal.DownloadStream;
import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.terminal.Paintable;
import com.itmill.toolkit.terminal.URIHandler;
import com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent;
import com.itmill.toolkit.ui.Component;
import com.itmill.toolkit.ui.FrameWindow;
import com.itmill.toolkit.ui.Window;

/**
 * Application manager processes changes and paints for single application
 * instance.
 * 
 * @author IT Mill Ltd.
 * @version
 * @VERSION@
 * @since 3.1
 */
public class AjaxApplicationManager implements
		Paintable.RepaintRequestListener, Application.WindowAttachListener,
		Application.WindowDetachListener {

	private static String GET_PARAM_REPAINT_ALL = "repaintAll";

	private static int DEFAULT_BUFFER_SIZE = 32 * 1024;

	private static int MAX_BUFFER_SIZE = 64 * 1024;

	private WeakHashMap applicationToVariableMapMap = new WeakHashMap();

	private HashSet dirtyPaintabletSet = new HashSet();

	// TODO THIS TEMPORARY HACK IS ONLY HERE TO MAKE GWT DEVEL EASIER
    static WeakHashMap paintableIdMap = new WeakHashMap();

	private int idSequence = 0;

	private Application application;

	private Set removedWindows = new HashSet();

	private PaintTarget paintTarget;

	public AjaxApplicationManager(Application application) {
		this.application = application;
	}

	/**
	 * 
	 * @return
	 */
	private AjaxVariableMap getVariableMap() {
		AjaxVariableMap vm = (AjaxVariableMap) applicationToVariableMapMap
				.get(application);
		if (vm == null) {
			vm = new AjaxVariableMap();
			applicationToVariableMapMap.put(application, vm);
		}
		return vm;
	}

	/**
	 * 
	 * 
	 */
	public void takeControl() {
		application.addListener((Application.WindowAttachListener) this);
		application.addListener((Application.WindowDetachListener) this);

	}

	/**
	 * 
	 * 
	 */
	public void releaseControl() {
		application.removeListener((Application.WindowAttachListener) this);
		application.removeListener((Application.WindowDetachListener) this);
	}

	
	public void handleUidlRequest(HttpServletRequest request,
			HttpServletResponse response, ThemeSource themeSource) throws IOException {
		handleUidlRequest(request,
				response, themeSource, false); 
		
	}

	
	/**
	 * 
	 * @param request
	 *            the HTTP Request.
	 * @param response
	 *            the HTTP Response.
	 * @throws IOException
	 *             if the writing failed due to input/output error.
	 */
	public void handleUidlRequest(HttpServletRequest request,
			HttpServletResponse response, ThemeSource themeSource, boolean isJson) 
		throws IOException {

		// repaint requested or sesssion has timed out and new one is created
		boolean repaintAll = (request.getParameter(GET_PARAM_REPAINT_ALL) != null)
				|| request.getSession().isNew();

		OutputStream out = response.getOutputStream();
		PrintWriter outWriter = new PrintWriter(new BufferedWriter(
				new OutputStreamWriter(out, "UTF-8")));
		
		outWriter.print(")/*{"); // some dirt to prevent cross site scripting vulnerabilities

		try {

			// Is this a download request from application
			DownloadStream download = null;

			// The rest of the process is synchronized with the application
			// in order to guarantee that no parallel variable handling is
			// made
			synchronized (application) {

				// Change all variables based on request parameters
				Map unhandledParameters = getVariableMap().handleVariables(
						request, application);

				// Handles the URI if the application is still running
				if (application.isRunning())
					download = handleURI(application, request, response);

				// If this is not a download request
				if (download == null) {

					// Finds the window within the application
					Window window = null;
					if (application.isRunning())
						window = getApplicationWindow(request, application);

					// Handles the unhandled parameters if the application is
					// still running
					if (window != null && unhandledParameters != null
							&& !unhandledParameters.isEmpty())
						window.handleParameters(unhandledParameters);

					// Removes application if it has stopped
					if (!application.isRunning()) {
						endApplication(request, response, application);
						return;
					}

					// Returns if no window found
					if (window == null)
						return;

					// Sets the response type
					response.setContentType("application/json; charset=UTF-8");
					outWriter.print("\"changes\":[");
					
					paintTarget = new AjaxJsonPaintTarget(getVariableMap(), 
							this, outWriter);

					// Paints components
					Set paintables;
					if (repaintAll) {
						paintables = new LinkedHashSet();
						paintables.add(window);

						// Adds all non-native windows
						for (Iterator i = window.getApplication().getWindows()
								.iterator(); i.hasNext();) {
							Window w = (Window) i.next();
							if (!"native".equals(w.getStyle()) && w != window)
								paintables.add(w);
						}
					} else
						paintables = getDirtyComponents();
					if (paintables != null) {

						// Creates "working copy" of the current state.
						List currentPaintables = new ArrayList(paintables);

						// Sorts the paintable so that parent windows
						// are always painted before child windows
						Collections.sort(currentPaintables, new Comparator() {

							public int compare(Object o1, Object o2) {

								// If first argumement is now window
								// the second is "smaller" if it is.
								if (!(o1 instanceof Window)) {
									return (o2 instanceof Window) ? 1 : 0;
								}

								// Now, if second is not window the
								// first is smaller.
								if (!(o2 instanceof Window)) {
									return -1;
								}

								// Both are windows.
								String n1 = ((Window) o1).getName();
								String n2 = ((Window) o2).getName();
								if (o1 instanceof FrameWindow) {
									if (((FrameWindow) o1).getFrameset()
											.getFrame(n2) != null) {
										return -1;
									} else if (!(o2 instanceof FrameWindow)) {
										return -1;
									}
								}
								if (o2 instanceof FrameWindow) {
									if (((FrameWindow) o2).getFrameset()
											.getFrame(n1) != null) {
										return 1;
									} else if (!(o1 instanceof FrameWindow)) {
										return 1;
									}
								}

								return 0;
							}
						});

						for (Iterator i = currentPaintables.iterator(); i
								.hasNext();) {
							Paintable p = (Paintable) i.next();

							// TODO CLEAN
							if (p instanceof Window) {
								Window w = (Window) p;
								if (w.getTerminal() == null)
									w.setTerminal(application.getMainWindow()
											.getTerminal());
							}

							paintTarget.startTag("change");
							paintTarget.addAttribute("format", "uidl");
							String pid = getPaintableId(p);
							paintTarget.addAttribute("pid", pid);

							// Track paints to identify empty paints
							((AjaxPaintTarget) paintTarget).setTrackPaints(true);
							p.paint(paintTarget);

							// If no paints add attribute empty
							if (((AjaxPaintTarget) paintTarget).getNumberOfPaints() <= 0) {
								paintTarget.addAttribute("visible", false);
							}
							paintTarget.endTag("change");
							paintablePainted(p);
						}
					}

					((AjaxPaintTarget) paintTarget).close();
					outWriter.print("]"); // close changes


					// Render the removed windows
					// TODO refactor commented area to send some meta instructions to close window
//					Set removed = new HashSet(getRemovedWindows());
//					if (removed.size() > 0) {
//						for (Iterator i = removed.iterator(); i.hasNext();) {
//							Window w = (Window) i.next();
//							paintTarget.startTag("change");
//							paintTarget.addAttribute("format", "uidl");
//							String pid = getPaintableId(w);
//							paintTarget.addAttribute("pid", pid);
//							paintTarget.addAttribute("windowname", w.getName());
//							paintTarget.addAttribute("visible", false);
//							paintTarget.endTag("change");
//							removedWindowNotified(w);
//
//						}
//					}


					
                	outWriter.print(", meta : {");
                	boolean metaOpen = false;

					
                    // .. or initializion (first uidl-request)
                    if(application.ajaxInit()) {
                    	outWriter.print("\"appInit\":true");
                    }
                    // add meta instruction for client to set focus if it is set
                    Paintable f = (Paintable) application.consumeFocus();
                    if(f != null) {
                    	if(metaOpen)
                    		outWriter.append(",");
                    	outWriter.write("\"focus\":\""+ getPaintableId(f) +"\"");
                    }
                	outWriter.print("}");

                    // Precache custom layouts
                	// TODO Rewrite this to print to outWriter a custom json attribute. Don't use paintTarget !!
                    // TODO Does not support theme-get param or different themes in different windows -> Allways preload layouts with the theme specified by the applications
//                    String themeName = application.getTheme() != null ? application.getTheme() : ApplicationServlet.DEFAULT_THEME;
//                    // TODO We should only precache the layouts that are not cached already
//                    for (Iterator i=((AjaxPaintTarget) paintTarget).getPreCachedResources().iterator(); i.hasNext();) {
//                    	String resource = (String) i.next();
//                    	InputStream is = null;
//                    	try {
//                			is = themeSource.getResource(themeName + "/" +  resource);
//                		} catch (ThemeSource.ThemeException e) {
//                			Log.info(e.getMessage());
//                		}
//                    	if (is != null) {
//                    		paintTarget.startTag("precache");
//                    		paintTarget.addAttribute("resource", resource);
//                    		StringBuffer layout = new StringBuffer();
//
//                    		try {
//                        		InputStreamReader r = new InputStreamReader(is);
//                    				char[] buffer = new char[20000];
//                    				int charsRead = 0;
//                    				while ((charsRead = r.read(buffer)) > 0)
//                    					layout.append(buffer, 0, charsRead);
//                    				r.close();
//                    		} catch (java.io.IOException e) {
//                    			Log.info("Resource transfer failed:  " + request.getRequestURI()
//                    					+ ". (" + e.getMessage() + ")");
//                    		}
//                    		paintTarget.addCharacterData(layout.toString());
//                    		paintTarget.endTag("precache");
//                    	}
//                    }
                	outWriter.flush();
                    outWriter.close();
					out.flush();
				} else {

					// For download request, transfer the downloaded data
					handleDownload(download, request, response);
				}
			}

			out.flush();
			out.close();

		} catch (Throwable e) {
			// Writes the error report to client
			OutputStreamWriter w = new OutputStreamWriter(out);
			PrintWriter err = new PrintWriter(w);
			err
					.write("<html><head><title>Application Internal Error</title></head><body>");
			err.write("<h1>" + e.toString() + "</h1><pre>\n");
			e.printStackTrace(new PrintWriter(err));
			err.write("\n</pre></body></html>");
			err.close();
		} finally {

		}

	}

	/**
	 * Gets the existing application or create a new one. Get a window within an
	 * application based on the requested URI.
	 * 
	 * @param request
	 *            the HTTP Request.
	 * @param application
	 *            the Application to query for window.
	 * @return Window mathing the given URI or null if not found.
	 * @throws ServletException
	 *             if an exception has occurred that interferes with the
	 *             servlet's normal operation.
	 */
	private Window getApplicationWindow(HttpServletRequest request,
			Application application) throws ServletException {

		Window window = null;

		// Find the window where the request is handled
		String path = request.getPathInfo();

		// Main window as the URI is empty
		if (path == null || path.length() == 0 || path.equals("/"))
			window = application.getMainWindow();

		// Try to search by window name
		else {
			String windowName = null;
			if (path.charAt(0) == '/')
				path = path.substring(1);
			int index = path.indexOf('/');
			if (index < 0) {
				windowName = path;
				path = "";
			} else {
				windowName = path.substring(0, index);
				path = path.substring(index + 1);
			}
			window = application.getWindow(windowName);

			// By default, we use main window
			if (window == null)
				window = application.getMainWindow();
		}

		return window;
	}

	/**
	 * Handles the requested URI. An application can add handlers to do special
	 * processing, when a certain URI is requested. The handlers are invoked
	 * before any windows URIs are processed and if a DownloadStream is returned
	 * it is sent to the client.
	 * 
	 * @param application
	 *            the Application owning the URI.
	 * @param request
	 *            the HTTP request instance.
	 * @param response
	 *            the HTTP response to write to.
	 * @return boolean <code>true</code> if the request was handled and
	 *         further processing should be suppressed, otherwise
	 *         <code>false</code>.
	 * @see com.itmill.toolkit.terminal.URIHandler
	 */
	private DownloadStream handleURI(Application application,
			HttpServletRequest request, HttpServletResponse response) {

		String uri = request.getPathInfo();

		// If no URI is available
		if (uri == null || uri.length() == 0 || uri.equals("/"))
			return null;

		// Remove the leading /
		while (uri.startsWith("/") && uri.length() > 0)
			uri = uri.substring(1);

		// Handle the uri
		DownloadStream stream = null;
		try {
			stream = application.handleURI(application.getURL(), uri);
		} catch (Throwable t) {
			application.terminalError(new URIHandlerErrorImpl(application, t));
		}

		return stream;
	}

	/**
	 * Handles the requested URI. An application can add handlers to do special
	 * processing, when a certain URI is requested. The handlers are invoked
	 * before any windows URIs are processed and if a DownloadStream is returned
	 * it is sent to the client.
	 * 
	 * @param stream
	 *            the downloadable stream.
	 * 
	 * @param request
	 *            the HTTP request instance.
	 * @param response
	 *            the HTTP response to write to.
	 * 
	 * @see com.itmill.toolkit.terminal.URIHandler
	 */
	private void handleDownload(DownloadStream stream,
			HttpServletRequest request, HttpServletResponse response) {

		// Download from given stream
		InputStream data = stream.getStream();
		if (data != null) {

			// Sets content type
			response.setContentType(stream.getContentType());

			// Sets cache headers
			long cacheTime = stream.getCacheTime();
			if (cacheTime <= 0) {
				response.setHeader("Cache-Control", "no-cache");
				response.setHeader("Pragma", "no-cache");
				response.setDateHeader("Expires", 0);
			} else {
				response.setHeader("Cache-Control", "max-age=" + cacheTime
						/ 1000);
				response.setDateHeader("Expires", System.currentTimeMillis()
						+ cacheTime);
				response.setHeader("Pragma", "cache"); // Required to apply
				// caching in some
				// Tomcats
			}

			// Copy download stream parameters directly
			// to HTTP headers.
			Iterator i = stream.getParameterNames();
			if (i != null) {
				while (i.hasNext()) {
					String param = (String) i.next();
					response.setHeader((String) param, stream
							.getParameter(param));
				}
			}

			int bufferSize = stream.getBufferSize();
			if (bufferSize <= 0 || bufferSize > MAX_BUFFER_SIZE)
				bufferSize = DEFAULT_BUFFER_SIZE;
			byte[] buffer = new byte[bufferSize];
			int bytesRead = 0;

			try {
				OutputStream out = response.getOutputStream();

				while ((bytesRead = data.read(buffer)) > 0) {
					out.write(buffer, 0, bytesRead);
					out.flush();
				}
				out.close();
			} catch (IOException ignored) {
			}

		}

	}

	/**
	 * Ends the Application.
	 * 
	 * @param request
	 *            the HTTP request instance.
	 * @param response
	 *            the HTTP response to write to.
	 * @param application
	 *            the Application to end.
	 * @throws IOException
	 *             if the writing failed due to input/output error.
	 */
	private void endApplication(HttpServletRequest request,
			HttpServletResponse response, Application application)
			throws IOException {

		String logoutUrl = application.getLogoutURL();
		if (logoutUrl == null)
			logoutUrl = application.getURL().toString();
		// clients JS app is still running, send a special xml file to
		// tell client that application is quit and where to point browser now
		// Set the response type
		response.setContentType("application/xml; charset=UTF-8");
		ServletOutputStream out = response.getOutputStream();
		out.println("<redirect url=\"" + logoutUrl + "\">");
		out.println("</redirect>");
	}

	/**
	 * Gets the Paintable Id.
	 * 
	 * @param paintable
	 * @return the paintable Id.
	 */
	public synchronized String getPaintableId(Paintable paintable) {

		String id = (String) paintableIdMap.get(paintable);
		if (id == null) {
			id = "PID" + Integer.toString(idSequence++);
			paintableIdMap.put(paintable, id);
		}

		return id;
	}

	/**
	 * 
	 * @return
	 */
	public synchronized Set getDirtyComponents() {

		// Remove unnecessary repaints from the list
		Object[] paintables = dirtyPaintabletSet.toArray();
		for (int i = 0; i < paintables.length; i++) {
			if (paintables[i] instanceof Component) {
				Component c = (Component) paintables[i];

				// Check if any of the parents of c already exist in the list
				Component p = c.getParent();
				while (p != null) {
					if (dirtyPaintabletSet.contains(p)) {

						// Remove component c from the dirty paintables as its
						// parent is also dirty
						dirtyPaintabletSet.remove(c);
						p = null;
					} else
						p = p.getParent();
				}
			}
		}

		return Collections.unmodifiableSet(dirtyPaintabletSet);
	}

	/**
	 * Clears the Dirty Components.
	 * 
	 */
	public synchronized void clearDirtyComponents() {
		dirtyPaintabletSet.clear();
	}

	/**
	 * @see com.itmill.toolkit.terminal.Paintable.RepaintRequestListener#repaintRequested(com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent)
	 */
	public void repaintRequested(RepaintRequestEvent event) {
		Paintable p = event.getPaintable();
		dirtyPaintabletSet.add(p);

		// For FrameWindows we mark all frames (windows) dirty
		if (p instanceof FrameWindow) {
			FrameWindow fw = (FrameWindow) p;
			repaintFrameset(fw.getFrameset());
		}
	}

	/**
	 * Recursively request repaint for all frames in frameset.
	 * 
	 * @param fs
	 *            the Framewindow.Frameset.
	 */
	private void repaintFrameset(FrameWindow.Frameset fs) {
		List frames = fs.getFrames();
		for (Iterator i = frames.iterator(); i.hasNext();) {
			FrameWindow.Frame f = (FrameWindow.Frame) i.next();
			if (f instanceof FrameWindow.Frameset) {
				repaintFrameset((FrameWindow.Frameset) f);
			} else {
				Window w = f.getWindow();
				if (w != null) {
					w.requestRepaint();
				}
			}
		}
	}

	/**
	 * 
	 * @param p
	 */
	public void paintablePainted(Paintable p) {
		dirtyPaintabletSet.remove(p);
		p.requestRepaintRequests();
	}

	/**
	 * 
	 * @param paintable
	 * @return
	 */
	public boolean isDirty(Paintable paintable) {
		return (dirtyPaintabletSet.contains(paintable));
	}

	/**
	 * @see com.itmill.toolkit.Application.WindowAttachListener#windowAttached(com.itmill.toolkit.Application.WindowAttachEvent)
	 */
	public void windowAttached(WindowAttachEvent event) {
		event.getWindow().addListener(this);
		dirtyPaintabletSet.add(event.getWindow());
	}

	/**
	 * @see com.itmill.toolkit.Application.WindowDetachListener#windowDetached(com.itmill.toolkit.Application.WindowDetachEvent)
	 */
	public void windowDetached(WindowDetachEvent event) {
		event.getWindow().removeListener(this);
		// Notify client of the close operation
		removedWindows.add(event.getWindow());
	}

	/**
	 * 
	 * @return
	 */
	public synchronized Set getRemovedWindows() {
		return Collections.unmodifiableSet(removedWindows);

	}

	/**
	 * 
	 * @param w
	 */
	private void removedWindowNotified(Window w) {
		this.removedWindows.remove(w);
	}

	/**
	 * Implementation of URIHandler.ErrorEvent interface.
	 */
	public class URIHandlerErrorImpl implements URIHandler.ErrorEvent {

		private URIHandler owner;

		private Throwable throwable;

		/**
		 * 
		 * @param owner
		 * @param throwable
		 */
		private URIHandlerErrorImpl(URIHandler owner, Throwable throwable) {
			this.owner = owner;
			this.throwable = throwable;
		}

		/**
		 * @see com.itmill.toolkit.terminal.Terminal.ErrorEvent#getThrowable()
		 */
		public Throwable getThrowable() {
			return this.throwable;
		}

		/**
		 * @see com.itmill.toolkit.terminal.URIHandler.ErrorEvent#getURIHandler()
		 */
		public URIHandler getURIHandler() {
			return this.owner;
		}
	}
}