1 package org.sapia.taskman; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 23 public class TaskContext { 24 private TaskOutput _out; 25 private TaskManager _mgr; 26 private Map _context = new HashMap (); 27 private TaskmanTransaction _tx; 28 29 37 protected TaskContext(TaskOutput out, TaskManager mgr) { 38 _out = out; 39 _mgr = mgr; 40 } 41 42 47 public TaskOutput getTaskOutput() { 48 return _out; 49 } 50 51 61 public TaskContext exportVal(Object key, Object value) { 62 _context.put(key, value); 63 64 return this; 65 } 66 67 76 public Object importVal(Object key) { 77 return _context.get(key); 78 } 79 80 88 public void execSyncNestedTask(String name, Task t) { 89 _mgr.execSyncTask(name, t, this); 90 _out.setTaskName(name); 91 } 92 93 106 public void execAsyncNestedTask(String name, Task t) { 107 _mgr.execAsyncTask(name, t, this); 108 } 109 110 127 public void execSyncNestedTask(String name, Class taskClass, TaskContext ctx) 128 throws IllegalAccessException , InstantiationException { 129 execSyncNestedTask(name, (Task) taskClass.newInstance()); 130 } 131 132 139 public void execTaskFor(TaskDescriptor desc) { 140 _mgr.execTaskFor(desc); 141 } 142 143 147 public boolean isInTransaction() { 148 return _tx != null; 149 } 150 151 157 void setTaskOutput(TaskOutput out) { 158 _out = out; 159 } 160 161 167 void copyVals(Map vals) { 168 if(vals != null) { 169 _context.putAll(vals); 170 } 171 } 172 173 178 Map getVals() { 179 return _context; 180 } 181 182 void setTransaction(TaskmanTransaction tx) { 183 _tx = tx; 184 } 185 186 TaskmanTransaction getTransaction() { 187 return _tx; 188 } 189 } 190 | Popular Tags |