Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 130   Methods: 16
NCLOC: 91   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConfigurationServer.java 0% 0% 0% 0%
coverage
 1    /*
 2    * ConfigurationServer.java
 3    *
 4    * Created on 25. Januar 2004, 18:09
 5    */
 6   
 7    package org.jconfig.server;
 8   
 9    /**
 10    * This is the configuration server itself. It can either be started from the
 11    * command line like:
 12    * java -classpath jconfig.jar org.jconfig.server.ConfigurationServer -port {port} -docroot {directory}
 13    * or integrated into a JMX capable server.
 14    * If the port is not set then default port is 8234. The documentroot will be set to
 15    * the tmp-directory if not provided.
 16    *
 17    * @author Andreas Mecky andreasmecky@yahoo.de
 18    * @author Terry Dye terrydye@yahoo.com
 19    */
 20    public class ConfigurationServer implements ConfigurationServerMBean {
 21   
 22    private BaseServer server;
 23    private int port = 8234;
 24    private String documentRoot;
 25    private boolean daemon = false;
 26   
 27  0 public ConfigurationServer(int port,String documentRoot) {
 28  0 this.port = port;
 29  0 this.documentRoot = documentRoot;
 30  0 start();
 31    }
 32   
 33  0 public ConfigurationServer() {
 34    }
 35   
 36  0 public void shutdown() {
 37  0 if ( server != null ) {
 38  0 server.shutdown();
 39    }
 40    }
 41   
 42  0 public void start() {
 43  0 ServerContext serverContext = new ServerContext();
 44  0 serverContext.setDocumentRoot(documentRoot);
 45  0 server = new BaseServer(port, ConfigProtocolHandler.class,serverContext);
 46  0 server.setAsDaemon(daemon);
 47  0 server.start();
 48  0 System.out.println("Server started");
 49  0 System.out.println("Port:"+port);
 50  0 System.out.println("Documentroot:"+documentRoot);
 51    }
 52    /**
 53    * @param args the command line arguments
 54    */
 55  0 public static void main(String[] args) {
 56  0 ConfigurationServer cs = new ConfigurationServer();
 57  0 cs.setDocRootFromArgs(args);
 58  0 cs.setPortFromArgs(args);
 59  0 cs.startServer();
 60    }
 61   
 62  0 public String getDocumentRoot() {
 63  0 return documentRoot;
 64    }
 65   
 66  0 public int getPort() {
 67  0 return port;
 68    }
 69   
 70  0 public void setDocumentRoot(String docRoot) {
 71  0 this.documentRoot = docRoot;
 72    }
 73   
 74  0 public void setPort(int port) {
 75  0 this.port = port;
 76    }
 77   
 78  0 private void setDocRootFromArgs(String[] args) {
 79  0 String dr = getArgument(args,"-docroot");
 80  0 if ( dr != null ) {
 81  0 documentRoot = dr;
 82    }
 83    else {
 84  0 documentRoot = System.getProperty("java.io.tmpdir");
 85    }
 86    }
 87   
 88  0 private void setPortFromArgs(String[] args) {
 89  0 String myPort = getArgument(args,"-port");
 90  0 if ( myPort != null ) {
 91  0 try {
 92  0 port = Integer.parseInt(myPort);
 93    }
 94    catch (Exception e) {
 95   
 96    }
 97    }
 98    }
 99   
 100  0 private String getArgument(String[] args,String param) {
 101  0 String ret = null;
 102  0 for ( int i = 0; i < args.length;i++) {
 103  0 if ( args[i].equals(param)) {
 104  0 if ( (i+1) <= args.length ) {
 105  0 ret = args[i+1];
 106    }
 107    }
 108    }
 109  0 return ret;
 110    }
 111   
 112  0 public void startServer() {
 113  0 start();
 114    }
 115   
 116  0 public void stopServer() {
 117  0 shutdown();
 118    }
 119   
 120  0 public void setDaemon(boolean isDaemon) {
 121  0 daemon = isDaemon;
 122    }
 123   
 124  0 public void setStarted(boolean shouldStart) {
 125  0 if ( shouldStart ) {
 126  0 startServer();
 127    }
 128    }
 129   
 130    }