01: package org.uispec4j.interception.handlers;
02:
03: import org.uispec4j.Window;
04: import org.uispec4j.utils.ExceptionContainer;
05:
06: public class NewThreadInterceptionHandlerDecorator extends
07: AbstractInterceptionHandlerDecorator {
08:
09: private ExceptionContainer exceptionContainer = new ExceptionContainer();
10: private Thread handlerThread;
11:
12: public NewThreadInterceptionHandlerDecorator(
13: InterceptionHandler innerHandler) {
14: super (innerHandler);
15: }
16:
17: public void process(final Window window) {
18: handlerThread = new Thread() {
19: public void run() {
20: try {
21: NewThreadInterceptionHandlerDecorator.super
22: .process(window);
23: } catch (Throwable e) {
24: exceptionContainer.set(e);
25: }
26: }
27: };
28: handlerThread.setName(handlerThread.getName()
29: + " [NewThreadHandler]");
30: handlerThread.start();
31: }
32:
33: public void complete() {
34: join();
35: exceptionContainer.rethrowIfNeeded();
36: }
37:
38: public void join() {
39: if (handlerThread != null) {
40: try {
41: handlerThread.join();
42: handlerThread = null;
43: } catch (InterruptedException e) {
44: throw new RuntimeException(e);
45: }
46: }
47: }
48: }
|