1 package net.sf.crispy.impl.local;
2
3 import java.util.Hashtable;
4 import java.util.Map;
5
6 import net.sf.crispy.impl.MiniServer;
7 import net.sf.crispy.util.Util;
8
9 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.getLog (MiniLocalObjectServer.class);
21
22 private static Map serviceRegistry = new Hashtable();
23
24 public void addService (String pvServiceInterface, String pvServiceObject) {
25 try {
26 Object lvServiceObject = Util.createObject(pvServiceObject);
27 Class clazzInterface = Class.forName(pvServiceInterface);
28 addService(clazzInterface, lvServiceObject);
29 } catch (Exception e) {
30 if (log.isDebugEnabled()) { log.debug("The service-interface: "
31 + pvServiceInterface + " or the service-impl:" + pvServiceObject
32 + " can't added." , e); }
33 }
34 }
35
36 public void addService (Class pvInterface, Object pvServiceObject) {
37 serviceRegistry.put(pvInterface, pvServiceObject);
38 }
39
40 public static Object getServiceByInterface (Class pvInterface) {
41 return serviceRegistry.get(pvInterface);
42 }
43
44 public static void removeService(Class pvInterface) {
45 serviceRegistry.remove(pvInterface);
46 }
47
48 public void start() { }
49
50 public void stop() {
51 serviceRegistry.clear();
52 }
53
54 }