1 31 package org.objectweb.proactive.core.config; 32 33 import org.apache.log4j.ConsoleAppender; 34 import org.apache.log4j.Level; 35 import org.apache.log4j.Logger; 36 import org.apache.log4j.PatternLayout; 37 38 import org.objectweb.proactive.core.config.xml.MasterFileHandler; 39 40 import java.util.HashMap ; 41 import java.util.Iterator ; 42 43 44 public class ProActiveConfiguration { 45 protected HashMap loadedProperties; 47 protected HashMap addedProperties; 48 protected static ProActiveConfiguration singleton; 49 protected static boolean isLoaded = false; 50 51 private ProActiveConfiguration() { 52 this.loadedProperties = new HashMap (); 53 this.addedProperties = new HashMap (); 54 } 56 57 protected static synchronized void createConfiguration() { 58 if (ProActiveConfiguration.singleton == null) { 59 ProActiveConfiguration.singleton = new ProActiveConfiguration(); 60 } 61 } 62 63 71 public static void load() { 72 if (!isLoaded) { 73 String filename = null; 74 if (System.getProperty("proactive.configuration") != null) { 75 filename = System.getProperty("proactive.configuration"); 76 } else { 77 filename = ProActiveConfiguration.class.getResource( 81 "ProActiveConfiguration.xml").toString(); 82 } 83 84 ProActiveConfiguration.load(filename); 89 isLoaded = true; 90 } 91 } 92 93 97 public static void load(String filename) { 98 if (!isLoaded) { 99 MasterFileHandler.createMasterFileHandler(filename, 100 ProActiveConfiguration.getConfiguration()); 101 ProActiveConfiguration.getConfiguration().addProperties(); 102 isLoaded = true; 103 } 104 } 105 106 public synchronized static ProActiveConfiguration getConfiguration() { 107 if (ProActiveConfiguration.singleton == null) { 108 ProActiveConfiguration.createConfiguration(); 109 } 110 return singleton; 111 } 112 113 118 public void propertyFound(String name, String value) { 119 this.loadedProperties.put(name, value); 120 } 121 122 125 public void addProperties() { 126 Iterator it = loadedProperties.keySet().iterator(); 128 String name = null; 129 String value = null; 130 while (it.hasNext()) { 131 name = (String ) it.next(); 132 value = (String ) this.loadedProperties.get(name); 133 setProperty(name, value); 134 } 135 loadDefaultProperties(); 136 } 137 138 141 public void dumpLoadedProperties() { 142 Iterator it = loadedProperties.keySet().iterator(); 143 while (it.hasNext()) { 144 String name = (String ) it.next(); 145 146 } 149 } 150 151 155 public void dumpAddedProperties() { 156 Iterator it = addedProperties.keySet().iterator(); 157 while (it.hasNext()) { 158 String name = (String ) it.next(); 159 160 } 163 } 164 165 public static String getLocationServerClass() { 166 return System.getProperty("proactive.locationserver"); 167 } 168 169 public static String getLocationServerRmi() { 170 return System.getProperties().getProperty("proactive.locationserver.rmi"); 171 } 172 173 public static String getACState() { 174 return System.getProperty("proactive.future.ac"); 175 } 176 177 public static String getSchemaValidationState() { 178 return System.getProperty("schema.validation"); 179 } 180 181 201 204 private void loadDefaultProperties() { 205 setProperty("proactive.communication.protocol", "rmi"); 206 setProperty("proactive.future.ac", "enable"); 207 setProperty("schema.validation", "disable"); 208 if (System.getProperty("log4j.configuration") == null) { 209 loadLogger(); 210 } 211 } 212 213 216 private void loadLogger() { 217 Logger logger = Logger.getLogger("org.objectweb.proactive"); 220 logger.setAdditivity(false); 221 logger.setLevel(Level.INFO); 222 logger.addAppender(new ConsoleAppender(new PatternLayout())); 223 } 224 225 private void setProperty(String name, String value) { 226 if (System.getProperty(name) == null) { 227 System.setProperty(name, value); 228 this.addedProperties.put(name, value); 229 } 230 } 231 } 232 | Popular Tags |