1 package com.quadcap.server; 2 3 40 41 import java.io.BufferedInputStream ; 42 import java.io.FileInputStream ; 43 import java.io.FileReader ; 44 45 import java.util.HashMap ; 46 import java.util.Iterator ; 47 import java.util.Properties ; 48 49 import org.xml.sax.InputSource ; 50 51 import com.quadcap.util.ConfigString; 52 import com.quadcap.util.Debug; 53 54 59 public class ServiceContainer { 60 static HashMap services = new HashMap (); 61 62 65 public ServiceContainer() {} 66 67 74 public void addService(String serviceName, String serviceClass, 75 Properties serviceProps) 76 throws Exception  77 { 78 Class sc = Class.forName(serviceClass); 79 Service service = (Service)sc.newInstance(); 80 Debug.println(0, "Starting service: " + serviceName + ", config = " + 81 serviceProps + ", service = " + service); 82 serviceProps.put("service.name", serviceName); 83 service.init(this, serviceProps); 84 services.put(serviceName, service); 85 } 86 87 90 public void init(String configFile) throws Exception { 91 ServerConfigParser p = new ServerConfigParser(this); 92 p.parse(configFile); 93 } 94 95 100 public static Service getService(String name) { 101 return (Service)services.get(name); 102 } 103 104 107 public Iterator serviceNames() { 108 return services.keySet().iterator(); 109 } 110 111 114 public static void main(String [] args) { 115 try { 116 ServiceContainer c = new ServiceContainer(); 117 ConfigString cs = ConfigString.find("server.config", "server.xml"); 118 c.init(cs.toString()); 119 } catch (Exception e) { 120 Debug.print(e); 121 } 122 } 123 } 124
| Popular Tags
|