1 17 package org.apache.servicemix.jms; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.util.Properties ; 24 25 import javax.jms.ConnectionFactory ; 26 27 import org.apache.servicemix.jbi.security.auth.AuthenticationService; 28 import org.apache.servicemix.jbi.security.keystore.KeystoreManager; 29 30 34 public class JmsConfiguration implements JmsConfigurationMBean { 35 36 public final static String CONFIG_FILE = "component.properties"; 37 38 private String rootDir; 39 private Properties properties = new Properties (); 40 private String userName; 41 private String password; 42 private String jndiInitialContextFactory; 43 private String jndiProviderUrl; 44 private String jndiConnectionFactoryName; 45 private String processorName = "multiplexing"; 46 private transient ConnectionFactory connectionFactory; 47 private transient KeystoreManager keystoreManager; 48 private transient AuthenticationService authenticationService; 49 50 53 private String authenticationServiceName = "java:comp/env/smx/AuthenticationService"; 54 55 58 private String keystoreManagerName = "java:comp/env/smx/KeystoreManager"; 59 60 61 64 public String getRootDir() { 65 return rootDir; 66 } 67 68 71 public void setRootDir(String rootDir) { 72 this.rootDir = rootDir; 73 } 74 75 78 public AuthenticationService getAuthenticationService() { 79 return authenticationService; 80 } 81 84 public void setAuthenticationService(AuthenticationService authenticationService) { 85 this.authenticationService = authenticationService; 86 } 87 90 public String getAuthenticationServiceName() { 91 return authenticationServiceName; 92 } 93 96 public void setAuthenticationServiceName(String authenticationServiceName) { 97 this.authenticationServiceName = authenticationServiceName; 98 } 99 102 public KeystoreManager getKeystoreManager() { 103 return keystoreManager; 104 } 105 108 public void setKeystoreManager(KeystoreManager keystoreManager) { 109 this.keystoreManager = keystoreManager; 110 save(); 111 } 112 115 public String getKeystoreManagerName() { 116 return keystoreManagerName; 117 } 118 121 public void setKeystoreManagerName(String keystoreManagerName) { 122 this.keystoreManagerName = keystoreManagerName; 123 save(); 124 } 125 128 public String getPassword() { 129 return password; 130 } 131 134 public void setPassword(String password) { 135 this.password = password; 136 save(); 137 } 138 141 public String getUserName() { 142 return userName; 143 } 144 147 public void setUserName(String userName) { 148 this.userName = userName; 149 save(); 150 } 151 154 public String getJndiConnectionFactoryName() { 155 return jndiConnectionFactoryName; 156 } 157 160 public void setJndiConnectionFactoryName(String jndiName) { 161 this.jndiConnectionFactoryName = jndiName; 162 save(); 163 } 164 167 public String getJndiInitialContextFactory() { 168 return jndiInitialContextFactory; 169 } 170 173 public void setJndiInitialContextFactory(String jndiInitialContextFactory) { 174 this.jndiInitialContextFactory = jndiInitialContextFactory; 175 save(); 176 } 177 180 public String getJndiProviderUrl() { 181 return jndiProviderUrl; 182 } 183 186 public void setJndiProviderUrl(String jndiProviderUrl) { 187 this.jndiProviderUrl = jndiProviderUrl; 188 save(); 189 } 190 193 public String getProcessorName() { 194 return processorName; 195 } 196 199 public void setProcessorName(String processorName) { 200 this.processorName = processorName; 201 save(); 202 } 203 206 public ConnectionFactory getConnectionFactory() { 207 return connectionFactory; 208 } 209 213 public void setConnectionFactory(ConnectionFactory connectionFactory) { 214 this.connectionFactory = connectionFactory; 215 } 216 217 218 public void save() { 219 properties.setProperty("userName", userName); 220 properties.setProperty("password", password); 221 properties.setProperty("jndiInitialContextFactory", jndiInitialContextFactory); 222 properties.setProperty("jndiProviderUrl", jndiProviderUrl); 223 properties.setProperty("jndiName", jndiConnectionFactoryName); 224 properties.setProperty("processorName", processorName); 225 properties.setProperty("keystoreManagerName", keystoreManagerName); 226 properties.setProperty("authenticationServiceName", authenticationServiceName); 227 if (rootDir != null) { 228 File f = new File (rootDir, CONFIG_FILE); 229 try { 230 this.properties.store(new FileOutputStream (f), null); 231 } catch (Exception e) { 232 throw new RuntimeException ("Could not store component configuration", e); 233 } 234 } 235 } 236 237 public boolean load() { 238 if (rootDir == null) { 239 return false; 240 } 241 File f = new File (rootDir, CONFIG_FILE); 242 if (!f.exists()) { 243 return false; 244 } 245 try { 246 properties.load(new FileInputStream (f)); 247 } catch (IOException e) { 248 throw new RuntimeException ("Could not load component configuration", e); 249 } 250 if (properties.getProperty("userName") != null) { 251 userName = properties.getProperty("userName"); 252 } 253 if (properties.getProperty("password") != null) { 254 password = properties.getProperty("password"); 255 } 256 if (properties.getProperty("jndiInitialContextFactory") != null) { 257 jndiInitialContextFactory = properties.getProperty("jndiInitialContextFactory"); 258 } 259 if (properties.getProperty("jndiProviderUrl") != null) { 260 jndiProviderUrl = properties.getProperty("jndiProviderUrl"); 261 } 262 if (properties.getProperty("jndiName") != null) { 263 jndiConnectionFactoryName = properties.getProperty("jndiName"); 264 } 265 if (properties.getProperty("processorName") != null) { 266 processorName = properties.getProperty("processorName"); 267 } 268 if (properties.getProperty("keystoreManagerName") != null) { 269 keystoreManagerName = properties.getProperty("keystoreManagerName"); 270 } 271 if (properties.getProperty("authenticationServiceName") != null) { 272 authenticationServiceName = properties.getProperty("authenticationServiceName"); 273 } 274 return true; 275 } 276 } 277 | Popular Tags |