01: package net.sf.crispy.server;
02:
03: import java.util.Hashtable;
04: import java.util.Map;
05:
06: import net.sf.crispy.impl.ServiceManager;
07: import net.sf.crispy.util.Util;
08:
09: /**
10: *
11: * Container for the service implementation. This is a mapping from service-interface to the service-implementation.
12: * The service instance exist once. They must be Thread safe.
13: *
14: * @author Linke
15: *
16: * @since 1.1.0
17: */
18: public class SingleServiceContainerImpl implements
19: SingleServiceContainer {
20:
21: private Map services = new Hashtable();
22:
23: /**
24: * see net.sf.crispy.server.SingleServiceContainer#addService(java.lang.String, java.lang.Object)
25: */
26: public void addService(String pvServiceInterfaceName,
27: Object pvServiceImpl) {
28: services.put(pvServiceInterfaceName, pvServiceImpl);
29: }
30:
31: /**
32: * @see net.sf.crispy.server.SingleServiceContainer#addService(java.lang.String, java.lang.String)
33: */
34: public void addService(String pvServiceInterfaceName,
35: String pvServiceImplName) {
36: try {
37: Object lvServiceImpl = Util.createObject(pvServiceImplName);
38: addService(pvServiceInterfaceName, lvServiceImpl);
39: } catch (Exception e) {
40: if (ServiceManager.DEBUG_MODE_ON) {
41: e.printStackTrace();
42: }
43: }
44: }
45:
46: /**
47: * @see net.sf.crispy.server.SingleServiceContainer#removeService(java.lang.String)
48: */
49: public void removeService(String pvServiceInterfaceName) {
50: services.remove(pvServiceInterfaceName);
51: }
52:
53: /**
54: * @see net.sf.crispy.server.SingleServiceContainer#getService(java.lang.String)
55: */
56: public Object getService(String pvServiceInterfaceName) {
57: return services.get(pvServiceInterfaceName);
58: }
59:
60: /**
61: * @see net.sf.crispy.server.SingleServiceContainer#getServiceSize()
62: */
63: public int getServiceSize() {
64: return services.size();
65: }
66:
67: }
|