1 25 package org.objectweb.carol.util.configuration; 26 27 import java.util.Properties ; 28 29 import javax.rmi.CORBA.PortableRemoteObjectDelegate ; 30 31 32 42 public class Protocol { 43 44 47 private String name = null; 48 49 52 private Properties properties = null; 53 54 57 private PortableRemoteObjectDelegate portableRemoteObjectDelegate = null; 58 59 62 private String portableRemoteObjectClassName = null; 63 64 67 private String initialContextFactoryClassName = null; 68 69 73 private String registryClassName = null; 74 75 78 private String interceptorNamePrefix = null; 79 80 86 protected String getValue(String key) throws ConfigurationException { 87 String s = properties.getProperty(key); 89 if (s == null) { 90 throw new ConfigurationException("Property '" + key + "' was not found in the properties object of the protocol, properties are :'" + properties + "'"); 91 } 92 return s; 93 } 94 95 96 102 public Protocol(String name, Properties properties) throws ConfigurationException { 103 if (name == null || "".equals(name)) { 104 throw new ConfigurationException("Cannot build a protocol with null or empty name"); 105 } 106 this.name = name; 107 108 if (properties == null) { 109 throw new ConfigurationException("Cannot build a new protocol without properties"); 110 } 111 this.properties = properties; 112 113 String prefixProtocol = CarolDefaultValues.CAROL_PREFIX + "." + name + "."; 114 115 portableRemoteObjectClassName = getValue(prefixProtocol + CarolDefaultValues.PRO_PREFIX); 117 118 this.initialContextFactoryClassName = getValue(prefixProtocol + CarolDefaultValues.FACTORY_PREFIX); 120 121 this.registryClassName = getValue(prefixProtocol + CarolDefaultValues.NS_PREFIX); 123 124 125 interceptorNamePrefix = properties.getProperty(CarolDefaultValues.CAROL_PREFIX + "." + name + "." 127 + CarolDefaultValues.INTERCEPTOR_PKGS_PREFIX); 128 129 String interceptorValues = properties.getProperty(CarolDefaultValues.CAROL_PREFIX + "." + name + "." 130 + CarolDefaultValues.INTERCEPTOR_VALUES_PREFIX); 131 132 if ((interceptorNamePrefix != null) && (interceptorValues != null)) { 134 String [] values = interceptorValues.split(","); 136 for (int s = 0; s < values.length; s++) { 137 String value = values[s]; 138 addInterceptor(value); 139 } 140 } 141 142 143 } 144 145 149 public void addInterceptor(String interceptorInitializer) { 150 System.setProperty(interceptorNamePrefix + "." + interceptorInitializer, ""); 151 if (TraceCarol.isDebugCarol()) { 152 TraceCarol.debugCarol("Setting interceptor " + interceptorNamePrefix + "." + interceptorInitializer + "/"); 153 } 154 } 155 156 157 160 public String getInitialContextFactoryClassName() { 161 return initialContextFactoryClassName; 162 } 163 164 167 public String getRegistryClassName() { 168 return registryClassName; 169 } 170 171 172 175 public PortableRemoteObjectDelegate getPortableRemoteObject() { 176 if (portableRemoteObjectDelegate != null) { 177 return portableRemoteObjectDelegate; 178 } 179 try { 180 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(portableRemoteObjectClassName); 181 portableRemoteObjectDelegate = (PortableRemoteObjectDelegate ) clazz.newInstance(); 182 } catch (Exception e) { 183 IllegalStateException newEx = new IllegalStateException ("Cannot build PortableRemoteObjectDelegate class '" + portableRemoteObjectClassName + "'"); 184 newEx.initCause(e); 185 throw newEx; 186 } 187 188 return portableRemoteObjectDelegate; 189 } 190 191 192 195 public String getName() { 196 return name; 197 } 198 199 200 } 201 | Popular Tags |