1 package org.apache.turbine.services.jsonrpc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.CharArrayWriter;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpSession;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.turbine.services.TurbineBaseService;
30
31 import com.metaparadigm.jsonrpc.JSONRPCBridge;
32
33 /***
34 * This is a service that will respond to JSON-RPC calls.
35 *
36 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
37 * @version $Id$
38 */
39 public class TurbineJsonRpcService
40 extends TurbineBaseService
41 implements JsonRpcService
42 {
43 /*** Log. */
44 private static Log log = LogFactory.getLog(TurbineJsonRpcService.class);
45
46 /*** The key used to store the bridge in the session. */
47 public static final String JSON_BRIDGE_KEY = "JSONRPCBridge";
48 /***
49 * The debug option for the bridge can be enabled by enabling debug level
50 * logging for this class.
51 */
52 private static final boolean DEBUG = log.isDebugEnabled();
53
54 public Object processCall(CharArrayWriter cdata,
55 JSONRPCBridge json_bridge, HttpServletRequest request)
56 {
57 return JSONProcessor.processCall(cdata, json_bridge, request);
58 }
59
60 public void registerObjectGlobal(String key, Object value)
61 {
62 JSONRPCBridge.getGlobalBridge().setDebug(DEBUG);
63 JSONRPCBridge.getGlobalBridge().registerObject(key, value);
64 }
65
66 public void registerObject(HttpSession session, String key, Object value)
67 {
68 JSONRPCBridge json_bridge = getBridge(session);
69 json_bridge.setDebug(DEBUG);
70 json_bridge.registerObject(key, value);
71 }
72
73 public JSONRPCBridge getBridge(HttpSession session)
74 {
75 JSONRPCBridge json_bridge = (JSONRPCBridge) session.getAttribute(JSON_BRIDGE_KEY);
76 if (json_bridge == null)
77 {
78 json_bridge = new JSONRPCBridge();
79 session.setAttribute(JSON_BRIDGE_KEY, json_bridge);
80 }
81 return json_bridge;
82 }
83
84 public void clearBridge(HttpSession session)
85 {
86 session.removeAttribute(JSON_BRIDGE_KEY);
87 }
88
89
90 /***
91 // * Initialize the JsonRpcService.
92 // *
93 // * @throws InitializationException Something went wrong in the init stage.
94 // */
95
96
97
98
99
100
101 /***
102 // * Shuts down this service, stopping running threads.
103 // */
104
105
106
107
108
109 }