01: package com.xoetrope.service.php;
02:
03: import java.awt.Frame;
04: import javax.swing.JOptionPane;
05: import net.xoetrope.optional.service.ServiceContext;
06: import net.xoetrope.optional.service.ServiceProxy;
07: import net.xoetrope.optional.service.ServiceProxyArgs;
08: import net.xoetrope.optional.service.ServiceProxyException;
09: import net.xoetrope.optional.service.XRouteManager;
10: import net.xoetrope.xui.XProject;
11: import net.xoetrope.xui.XProjectManager;
12:
13: /**
14: *
15: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
16: * the GNU Public License (GPL), please see license.txt for more details. If
17: * you make commercial use of this software you must purchase a commercial
18: * license from Xoetrope.</p>
19: * <p> $Revision: 1.7 $</p>
20: */
21: public class SessionManger extends ServiceProxy {
22: private String sessionKey;
23: private final String INVALID_SESSION = "INVALID_SESSION";
24:
25: /**
26: * The owner project and the context in which this object operates.
27: */
28: protected XProject currentProject = XProjectManager
29: .getCurrentProject();
30:
31: /**
32: * The overloaded call for the ServiceProxy
33: * @param method the name of the service
34: * @param context the context object of the service call
35: */
36: public Object call(String method, ServiceContext context)
37: throws ServiceProxyException {
38: Object res = null;
39: ServiceProxyArgs args = context.getArgs();
40:
41: boolean client = (side == XRouteManager.CLIENT_SIDE);
42:
43: if (client) {
44: /*
45: * Pass the current session key to the server, call the next proxy. If
46: * there was an error on the server show the error message otherwise store
47: * the session key for future calls.
48: * Syntax for PHPSessionID...
49: * PHPSESSID=789ec62424e5865edf3ceec4f0976bdf
50: */
51: args.setPassParam("PHPSESSID", sessionKey);
52: res = nextProxy.call(method, context);
53: String Error = (String) args.getPassParam("Error");
54: if (Error != null)
55: showErrorMessage();
56:
57: sessionKey = (String) args.getPassParam("sessionkey");
58: }
59: return res;
60: }
61:
62: /**
63: * If there is a problem with the session show a message on the client.
64: */
65: private void showErrorMessage() {
66: Frame fra = currentProject.getAppFrame();
67: JOptionPane dlg = new JOptionPane();
68: dlg.showMessageDialog(fra,
69: "You session has expired... Please log on again!");
70: }
71: }
|