01: package com.xoetrope.service;
02:
03: import java.util.Hashtable;
04: import net.xoetrope.optional.service.ServiceContext;
05: import net.xoetrope.optional.service.ServiceProxy;
06: import net.xoetrope.optional.service.ServiceProxyException;
07:
08: /**
09: * Adds a wrapper capable of holding mutable state. Simply calls the next proxy
10: *
11: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
12: * the GNU Public License (GPL), please see license.txt for more details. If
13: * you make commercial use of this software you must purchase a commercial
14: * license from Xoetrope.</p>
15: * <p> $Revision: 1.8 $</p>
16: */
17: public class XServiceProxyState extends ServiceProxy {
18: private Hashtable states;
19:
20: /** Creates a new instance of XServiceProxyState */
21: public XServiceProxyState() {
22: }
23:
24: /**
25: * Calls the next proxy and does nothing more
26: * Services should place data
27: * they wish to return in the ServiceContext. The RETURN_PARAM is the default
28: * location for a single return value.
29: * @return the status of the service call
30: * @param context The ServiceContext contain pass and return parameters
31: * @param method the name of the service being called
32: * @throws net.xoetrope.optional.service.ServiceProxyException Throw an exception if there is a problem with the call
33: */
34: public Object call(String method, ServiceContext serviceContext)
35: throws ServiceProxyException {
36: return callNextProxy(method, serviceContext, null);
37: }
38:
39: /**
40: * Get a state value held by this proxy
41: * @param key the name by which teh storage is referenced
42: * @return the stored value or null if no value was available
43: */
44: public Object getState(String key) {
45: if (states != null)
46: return states.get(key);
47:
48: return null;
49: }
50:
51: /**
52: * Set a value to be held by this instance.
53: * @param key the name by which teh storage is referenced
54: * @param value the value to store
55: */
56: public void setState(String key, Object value) {
57: if (states == null)
58: states = new Hashtable();
59:
60: states.put(key, value);
61: }
62: }
|