1
2
3
4
5
6 package net.kwfgrid.gwui.servlets;
7
8 import net.kwfgrid.gworkflowdl.structure.*;
9 import net.kwfgrid.gworkflowdl.protocol.*;
10 import net.kwfgrid.gworkflowdl.protocol.client.*;
11 import net.kwfgrid.gworkflowdl.protocol.service.IStructureService;
12 import net.kwfgrid.gworkflowdl.protocol.xupdate.*;
13 import net.kwfgrid.gwui.GWUI;
14
15 import org.apache.log4j.Logger;
16
17 import java.rmi.RemoteException;
18
19 /***
20 Implementation of <code>IStructureService</code> to be used in servlets which need to modify
21 a workflow structure. The implementation automatically initializes the protocol layer
22 of GWorkflowDL. Singleton pattern.
23 */
24 public class ServletStructureServiceStub implements IStructureService {
25 private static Logger logger = Logger.getLogger(ServletStructureServiceStub.class);
26
27 private static ServletStructureServiceStub _instance = null;
28
29 public synchronized static ServletStructureServiceStub getInstance() {
30 if (_instance == null) {
31 initialize();
32 }
33 return _instance;
34 }
35
36 /***
37 Initialize the protocol layer.
38 */
39 public synchronized static void initialize() {
40 if (_instance == null) {
41 logger.info("Initializing GWorkflowDL protocol layer...");
42
43 _instance = new ServletStructureServiceStub();
44 IMethodCallStrategy defaults = new DefaultMethodCallStrategy();
45 IMethodCallStrategy protocol = new DefaultClientDelegate(_instance);
46 IModificationHandler handler = new XUModificationHandler();
47 IMethodCallEncoder encoder = new XUMethodCallEncoder();
48 Protocol.setDefaultMethodCallStrategy(defaults);
49 Protocol.setProtocolMethodCallStrategy(protocol);
50 Protocol.setModificationHandler(handler);
51 Protocol.setMethodCallEncoder(encoder);
52
53 Creator creator = new ClientCreator(new DefaultCreator());
54 Factory.setCreator(creator);
55
56 logger.info("Initializing GWorkflowDL protocol layer done.");
57 }
58 }
59
60 private ServletStructureServiceStub() {
61
62 }
63
64 /***
65 Commit a modification of the workflow structure to the server.
66 Implementation of <code>IStructureService</code>.
67 */
68 public int commitModification(String structureid, int clientversion, String modification)
69 throws IllegalModificationException, IncompatibleVersionsException, RemoteException {
70 IStructureService service = null;
71 try {
72 service = GWUI.getInstance().getIStructureService();
73 } catch (Exception e) {
74 throw new RemoteException("No GWES available for workflow "+structureid+": "+e, e);
75 }
76 if (service == null)
77 throw new RemoteException("No GWES available for workflow "+structureid+".");
78 return service.commitModification(structureid, clientversion, modification);
79 }
80
81 /***
82 Get all pending modificications of the workflow structure from the server.
83 Implementation of <code>IStructureService</code>.
84 */
85 public String[][] getModificationsForUpdate(String structureid, int clientversion)
86 throws RemoteException {
87 IStructureService service = null;
88 try {
89 service = GWUI.getInstance().getIStructureService();
90 } catch (Exception e) {
91 throw new RemoteException("No GWES available for workflow "+structureid+": "+e, e);
92 }
93 if (service == null)
94 throw new RemoteException("No GWES available for workflow "+structureid+".");
95 return service.getModificationsForUpdate(structureid, clientversion);
96 }
97 }