1 25 package org.objectweb.carol.util.configuration; 26 27 import java.util.Enumeration ; 28 import java.util.Properties ; 29 30 import javax.naming.Context ; 31 32 38 public class ServerConfiguration { 39 40 43 private Properties properties = null; 44 45 48 private boolean startNS = false; 49 50 53 private boolean startJNDI = false; 54 55 58 private boolean startRMI = false; 59 60 65 protected ServerConfiguration(Properties properties) throws ConfigurationException { 66 this.properties = properties; 67 if (properties == null) { 68 throw new ConfigurationException("Cannot build a server configuration withotu properties"); 69 } 70 71 startNS = getBooleanValue(CarolDefaultValues.START_NS_KEY); 73 startRMI = getBooleanValue(CarolDefaultValues.START_RMI_KEY); 74 startJNDI = getBooleanValue(CarolDefaultValues.START_JNDI_KEY); 75 76 Properties jvmProperties = new Properties (); 77 if (startRMI) { 78 jvmProperties.setProperty("javax.rmi.CORBA.PortableRemoteObjectClass", CarolDefaultValues.MULTI_PROD); 79 } 80 81 if (startJNDI) { 82 jvmProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, CarolDefaultValues.MULTI_JNDI); 83 } 84 85 String protocols = properties.getProperty(CarolDefaultValues.PROTOCOLS_KEY); 86 boolean isMultiProtocols = false; 87 if (protocols != null) { 88 isMultiProtocols = (protocols.split(",").length > 1); 89 } 90 91 92 93 String jndiPrefix = CarolDefaultValues.CAROL_PREFIX + "." + CarolDefaultValues.JNDI_PREFIX; 94 String multiJvmPrefix = CarolDefaultValues.MULTI_RMI_PREFIX + "." + CarolDefaultValues.CAROL_PREFIX + "." + "jvm"; 95 String singleJvmPrefix = CarolDefaultValues.CAROL_PREFIX + "." + CarolDefaultValues.JVM_PREFIX; 96 for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { 97 String key = (String ) e.nextElement(); 98 if (key.startsWith(jndiPrefix)) { 100 jvmProperties.setProperty(key.substring(jndiPrefix.length() + 1), properties.getProperty(key)); 101 } 102 103 if (key.startsWith(multiJvmPrefix) && isMultiProtocols) { 105 String newKey = key.substring(multiJvmPrefix.length() + 1); 107 jvmProperties.setProperty(newKey, ""); 108 } 109 110 if (key.startsWith(singleJvmPrefix)) { 112 String newKey = key.substring(singleJvmPrefix.length() + 1); 114 jvmProperties.setProperty(newKey, properties.getProperty(key)); 115 } 116 117 } 118 119 120 for (Enumeration e = jvmProperties.propertyNames(); e.hasMoreElements();) { 122 String key = (String ) e.nextElement(); 123 String value = jvmProperties.getProperty(key); 124 System.setProperty(key, value); 125 if (TraceCarol.isDebugCarol()) { 126 TraceCarol.debugCarol("Set the JVM property '" + key + "' with the value '" + value + "'."); 127 } 128 } 129 130 } 131 132 138 protected boolean getBooleanValue(String key) throws ConfigurationException { 139 String s = properties.getProperty(key); 141 if (s == null) { 142 throw new ConfigurationException("Property '" + key 143 + "' was not found in the properties object of the protocol, properties are :'" + properties + "'"); 144 } 145 return new Boolean (s.trim()).booleanValue(); 146 } 147 148 151 public boolean isStartingJNDI() { 152 return startJNDI; 153 } 154 155 158 public boolean isStartingNS() { 159 return startNS; 160 } 161 162 165 public boolean isStartingRMI() { 166 return startRMI; 167 } 168 169 } 170 | Popular Tags |