Clover coverage report - CRISPY - 1.1.1
Coverage timestamp: Mi Nov 15 2006 13:09:46 CET
file stats: LOC: 129   Methods: 11
NCLOC: 89   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MiniXmlRpcServer.java 100% 93,3% 100% 95,3%
coverage coverage
 1    /*
 2    * Created on 20.04.2005 from Linke
 3    *
 4    */
 5    package net.sf.crispy.impl.xmlrpc;
 6   
 7    import java.util.Hashtable;
 8    import java.util.Map;
 9   
 10    import net.sf.crispy.impl.MiniServer;
 11    import net.sf.crispy.util.Util;
 12   
 13    import org.apache.commons.logging.Log;
 14    import org.apache.commons.logging.LogFactory;
 15    import org.apache.xmlrpc.WebServer;
 16    import org.apache.xmlrpc.XmlRpc;
 17   
 18   
 19    /**
 20    * Mini web server for XML-RPC to answer to XML-RPC client requests.
 21    *
 22    * @author Linke
 23    * Mini_WebServer
 24    */
 25    public class MiniXmlRpcServer extends WebServer implements MiniServer {
 26   
 27    public static final int DEFAULT_PORT = 9090;
 28   
 29    protected static final Log log = LogFactory.getLog (MiniXmlRpcServer.class);
 30    protected Integer port = Integer.valueOf(Integer.toString(DEFAULT_PORT));
 31    private String nullValue = null;
 32   
 33  2 public final void setNullValue (String pvNullValue) {
 34  2 nullValue = pvNullValue;
 35    }
 36  15 public final String getNullValue() {
 37  15 return nullValue;
 38    }
 39   
 40  4 private final void init() {
 41   
 42  0 try { addDefaultHandlers(); } catch (Exception e) { e.printStackTrace(); }
 43  4 Map lvMapService = new Hashtable();
 44  4 addHandler(XmlRpcAdminService.class.getName(), new XmlRpcConvertHandler(new XmlRpcAdminServiceImpl(this.xmlrpc, lvMapService, getNullValue()), getNullValue()));
 45    }
 46   
 47  1 public MiniXmlRpcServer() {
 48  1 super(DEFAULT_PORT);
 49  1 init();
 50    }
 51   
 52  1 public MiniXmlRpcServer(String pvNullValue) {
 53  1 super(DEFAULT_PORT);
 54  1 setNullValue(pvNullValue);
 55  1 init();
 56    }
 57   
 58  1 public MiniXmlRpcServer(int pvPort) {
 59  1 super(pvPort);
 60  1 port = Integer.valueOf(Integer.toString(pvPort));
 61  1 init();
 62    }
 63   
 64  1 public MiniXmlRpcServer(int pvPort, String pvNullValue) {
 65  1 super(pvPort);
 66  1 port = Integer.valueOf(Integer.toString(pvPort));
 67  1 setNullValue(pvNullValue);
 68  1 init();
 69    }
 70   
 71  1 public Integer getPort() { return port; }
 72   
 73  6 public void addService (String pvServiceInterface, String pvServiceObject) {
 74  6 try {
 75  6 Object lvServiceObject = Util.createObject(pvServiceObject);
 76  5 addService(pvServiceInterface, lvServiceObject);
 77    } catch (Exception e) {
 78    if (log.isDebugEnabled()) { log.debug("Can'nt addService: " + pvServiceInterface
 79    + " with implementation: " + pvServiceObject, e); }
 80    }
 81    }
 82   
 83  6 public void addService(String pvServiceInterface, Object pvServiceImpl) {
 84  6 addHandler(pvServiceInterface, new XmlRpcConvertHandler(pvServiceImpl, getNullValue()));
 85    }
 86   
 87    /**
 88    * @see org.apache.xmlrpc.WebServer#start()
 89    */
 90  4 public void start() {
 91  4 try {
 92  4 boolean isPortFree = Util.isPortFree(port.intValue());
 93  4 if (isPortFree == true) {
 94  3 super.start();
 95    }
 96  4 log.debug("MiniXmlRpcServer is started!");
 97    } catch (Exception e) {
 98  0 log.warn("Excption by start MiniXmlRpcServer.", e);
 99    }
 100    }
 101   
 102    /**
 103    * @see org.apache.xmlrpc.WebServer#shutdown()
 104    */
 105    public void stop() {
 106    shutdown();
 107    }
 108   
 109    public static void main(String[] argv)
 110    {
 111    int p = determinePort(argv, 8080);
 112    // XmlRpc.setDebug (true);
 113    XmlRpc.setKeepAlive(true);
 114    MiniXmlRpcServer webserver = new MiniXmlRpcServer(p);
 115   
 116    try
 117    {
 118    webserver.start();
 119    }
 120    catch (Exception e)
 121    {
 122    System.err.println("Error running web server");
 123    e.printStackTrace();
 124    System.exit(1);
 125    }
 126    }
 127   
 128   
 129    }