KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > taskman > NestingTestTask


1 package org.sapia.taskman;
2
3 /**
4  * @author Yanick Duchesne 1-May-2003
5  */

6 public class NestingTestTask extends TestTask {
7   private static int _currentCount;
8   private static int _totalCount;
9   private boolean _asynchronous;
10   private TestTask _tt;
11
12   /**
13    * Constructor for NestingTestTask.
14    */

15   public NestingTestTask(boolean async) {
16     super();
17     _asynchronous = async;
18   }
19
20   public NestingTestTask(boolean async, int count) {
21     super();
22     _asynchronous = async;
23     _totalCount = count;
24   }
25
26   static void reset() {
27     _currentCount = 0;
28     _totalCount = 0;
29   }
30
31   /**
32    * @see org.sapia.taskman.Task#exec(TaskContext)
33    */

34   public void exec(TaskContext ctx) {
35     super.execCount++;
36     
37     if(((TxTaskOutput) ctx.getTaskOutput()).internalOutput() instanceof TestTaskOutput) {
38       ((TestTaskOutput) ((TxTaskOutput) ctx.getTaskOutput()).internalOutput())
39           .inc();
40     }
41
42     if(_currentCount == 0) {
43       ctx.exportVal("name", "value");
44     } else {
45       if(ctx.importVal("name") == null) {
46         throw new IllegalStateException JavaDoc("Value not in context");
47       }
48     }
49
50     if(!_asynchronous) {
51       if(_totalCount > 0) {
52         if(_currentCount >= _totalCount) {
53           ctx.execSyncNestedTask("nested", _tt = new TestTask());
54         } else {
55           _currentCount++;
56           ctx.execSyncNestedTask("nested", _tt = new NestingTestTask(false));
57         }
58
59         TaskOutput out = ctx.getTaskOutput();
60
61         if(out instanceof TestTaskOutput) {
62           if(((TestTaskOutput) out).closed()) {
63             throw new IllegalStateException JavaDoc("Task output should not be closed");
64           }
65         }
66       } else {
67         ctx.execSyncNestedTask("nested", _tt = new TestTask());
68       }
69     } else {
70       if(_totalCount > 0) {
71         if(_currentCount >= _totalCount) {
72           ctx.execAsyncNestedTask("nested", _tt = new TestTask());
73         } else {
74           _currentCount++;
75           ctx.execAsyncNestedTask("nested", _tt = new NestingTestTask(true));
76         }
77       } else {
78         ctx.execAsyncNestedTask("nested", _tt = new TestTask());
79       }
80     }
81   }
82
83   boolean executed() {
84     return (_tt != null) && (_tt.execCount > 0);
85   }
86 }
87
Popular Tags