01: package net.sf.crispy.impl.local;
02:
03: import java.util.Hashtable;
04: import java.util.Map;
05:
06: import net.sf.crispy.impl.MiniServer;
07: import net.sf.crispy.util.Util;
08:
09: import org.apache.commons.logging.Log;
10: import org.apache.commons.logging.LogFactory;
11:
12: /**
13: * Simulate a server for local Java Object access.
14: *
15: * @author Linke
16: *
17: */
18: public class MiniLocalObjectServer implements MiniServer {
19:
20: protected static final Log log = LogFactory
21: .getLog(MiniLocalObjectServer.class);
22:
23: private static Map serviceRegistry = new Hashtable();
24:
25: public void addService(String pvServiceInterface,
26: String pvServiceObject) {
27: try {
28: Object lvServiceObject = Util.createObject(pvServiceObject);
29: Class clazzInterface = Class.forName(pvServiceInterface);
30: addService(clazzInterface, lvServiceObject);
31: } catch (Exception e) {
32: if (log.isDebugEnabled()) {
33: log.debug("The service-interface: "
34: + pvServiceInterface + " or the service-impl:"
35: + pvServiceObject + " can't added.", e);
36: }
37: }
38: }
39:
40: public void addService(Class pvInterface, Object pvServiceObject) {
41: serviceRegistry.put(pvInterface, pvServiceObject);
42: }
43:
44: public static Object getServiceByInterface(Class pvInterface) {
45: return serviceRegistry.get(pvInterface);
46: }
47:
48: public static void removeService(Class pvInterface) {
49: serviceRegistry.remove(pvInterface);
50: }
51:
52: public void start() {
53: }
54:
55: public void stop() {
56: serviceRegistry.clear();
57: }
58:
59: }
|