1 45 46 package org.openejb.loader; 47 48 import java.util.Properties ; 49 import java.util.HashMap ; 50 51 import org.openejb.util.FileUtils; 52 53 63 public class SystemInstance { 64 65 private final long startTime = System.currentTimeMillis(); 66 private final Properties properties; 67 private final FileUtils home; 68 private final FileUtils base; 69 private final ClassLoader classLoader; 70 private final HashMap components; 71 private final ClassPath classPath; 72 73 private SystemInstance(Properties properties) throws Exception { 74 this.components = new HashMap (); 75 this.properties = new Properties (); 76 this.properties.putAll(System.getProperties()); 77 this.properties.putAll(properties); 78 79 this.home = new FileUtils("openejb.home", "user.dir", this.properties); 80 this.base = new FileUtils("openejb.base", "openejb.home", this.properties); 81 this.classPath = ClassPathFactory.createClassPath(this.properties.getProperty("openejb.loader", "context")); 82 this.classLoader = classPath.getClassLoader(); 83 84 86 this.properties.setProperty("openejb.home", home.getDirectory().getCanonicalPath()); 87 this.properties.setProperty("openejb.base", base.getDirectory().getCanonicalPath()); 88 } 89 90 91 public long getStartTime() { 92 return startTime; 93 } 94 95 public Properties getProperties() { 96 return properties; 97 } 98 99 public String getProperty(String key) { 100 return properties.getProperty(key); 101 } 102 103 public String getProperty(String key, String defaultValue) { 104 return properties.getProperty(key, defaultValue); 105 } 106 107 public Object setProperty(String key, String value) { 108 return properties.setProperty(key, value); 109 } 110 111 public FileUtils getHome() { 112 return home; 113 } 114 115 public FileUtils getBase() { 116 return base; 117 } 118 119 public ClassPath getClassPath() { 120 return classPath; 121 } 122 123 public ClassLoader getClassLoader() { 124 return classLoader; 125 } 126 127 public Object getObject(String name) { 128 return components.get(name); 129 } 130 131 public Object setObject(String name, Object value) { 132 return components.put(name, value); 133 } 134 135 139 private static SystemInstance system; 140 static { 141 try { 142 system = new SystemInstance(System.getProperties()); 143 } catch (Exception e) { 144 throw new RuntimeException ("Failed to create default instance of SystemInstance",e); 145 } 146 } 147 private static boolean initialized; 148 public static void init(Properties properties) throws Exception { 149 if (initialized) return; 150 system = new SystemInstance(properties); 151 initialized = true; 152 } 153 154 public static SystemInstance get(){ 155 return system; 156 } 157 158 } 159 | Popular Tags |