View Javadoc

1   package net.sf.crispy.server;
2   
3   import java.util.Hashtable;
4   import java.util.Map;
5   
6   import net.sf.crispy.impl.ServiceManager;
7   import net.sf.crispy.util.Util;
8   
9   /**
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 SingleServiceContainer {
19  
20  	private Map services = new Hashtable();
21  	
22  
23  	/**
24  	 * see net.sf.crispy.server.SingleServiceContainer#addService(java.lang.String, java.lang.Object)
25  	 */
26  	public void addService(String pvServiceInterfaceName, Object pvServiceImpl) {
27  		services.put(pvServiceInterfaceName, pvServiceImpl);
28  	}
29  
30  	/**
31  	 * @see net.sf.crispy.server.SingleServiceContainer#addService(java.lang.String, java.lang.String)
32  	 */
33  	public void addService(String pvServiceInterfaceName, String pvServiceImplName) {
34  		try {
35  			Object lvServiceImpl = Util.createObject(pvServiceImplName);
36  			addService(pvServiceInterfaceName, lvServiceImpl);
37  		} catch (Exception e) {
38  			if (ServiceManager.DEBUG_MODE_ON) {
39  				e.printStackTrace();
40  			}
41  		}
42  	}
43  
44  	/**
45  	 * @see net.sf.crispy.server.SingleServiceContainer#removeService(java.lang.String)
46  	 */
47  	public void removeService(String pvServiceInterfaceName) {
48  		services.remove(pvServiceInterfaceName);
49  	}
50  
51  	/**
52  	 * @see net.sf.crispy.server.SingleServiceContainer#getService(java.lang.String)
53  	 */
54  	public Object getService(String pvServiceInterfaceName) {
55  		return services.get(pvServiceInterfaceName);
56  	}
57  
58  	/**
59  	 * @see net.sf.crispy.server.SingleServiceContainer#getServiceSize()
60  	 */
61  	public int getServiceSize() {
62  		return services.size();
63  	}
64  
65  }