1
2
3
4
5
6 package net.kwfgrid.gworkflowdl.protocol;
7
8 import net.kwfgrid.gworkflowdl.protocol.calls.IMethodCall;
9 import net.kwfgrid.gworkflowdl.protocol.calls.MethodCallException;
10 import net.kwfgrid.gworkflowdl.protocol.structure.IStructureTask;
11
12 import java.util.List;
13
14 /***
15 Extension of the default method call strategy that invokes the methods of the <code>IStructureListenerExt</code> interface.
16 */
17 public class DefaultMethodCallStrategyExt extends AbstractMethodCallStrategyExt {
18 public Object execute(IMethodCall call) throws MethodCallException {
19 Object ret = null;
20 IStructureTask tasks[] = null;
21
22 synchronized(call.getTarget().getStructureLock()) {
23 fireBeginModifications(call.getTarget());
24
25 try {
26 ret = call.execute();
27 } catch (Exception x) {
28 fireException(call.getTarget(), x);
29 MethodCallException mcx = new MethodCallException(x);
30 throw mcx;
31 }
32
33 fireEndModifications(call.getTarget());
34
35 List queue = call.getTarget().getTaskQueue();
36 tasks = (IStructureTask[])queue.toArray(new IStructureTask[queue.size()]);
37 queue.clear();
38 }
39
40 try {
41 for (int i=0; i<tasks.length; i++) {
42 tasks[i].run();
43 }
44 } catch (Exception x) {
45 throw new MethodCallException("Could not execute inner method call.", x);
46 }
47
48 return ret;
49 }
50 }