package net.sf.crispy.impl.local;
import java.util.Hashtable;
import java.util.Map;
import net.sf.crispy.impl.MiniServer;
import net.sf.crispy.util.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Simulate a server for local Java Object access.
*
* @author Linke
*
*/
public class MiniLocalObjectServer implements MiniServer {
protected static final Log log = LogFactory.getLog (MiniLocalObjectServer.class);
private static Map serviceRegistry = new Hashtable();
public void addService (String pvServiceInterface, String pvServiceObject) {
try {
Object lvServiceObject = Util.createObject(pvServiceObject);
Class clazzInterface = Class.forName(pvServiceInterface);
addService(clazzInterface, lvServiceObject);
} catch (Exception e) {
if (log.isDebugEnabled()) { log.debug("The service-interface: "
+ pvServiceInterface + " or the service-impl:" + pvServiceObject
+ " can't added." , e); }
}
}
public void addService (Class pvInterface, Object pvServiceObject) {
serviceRegistry.put(pvInterface, pvServiceObject);
}
public static Object getServiceByInterface (Class pvInterface) {
return serviceRegistry.get(pvInterface);
}
public static void removeService(Class pvInterface) {
serviceRegistry.remove(pvInterface);
}
public void start() { }
public void stop() {
serviceRegistry.clear();
}
}
|