KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jms > JmsConfiguration


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jms;
18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import javax.jms.ConnectionFactory JavaDoc;
26
27 import org.apache.servicemix.jbi.security.auth.AuthenticationService;
28 import org.apache.servicemix.jbi.security.keystore.KeystoreManager;
29
30 /**
31  * @author gnodet
32  *
33  */

34 public class JmsConfiguration implements JmsConfigurationMBean {
35
36     public final static String JavaDoc CONFIG_FILE = "component.properties";
37     
38     private String JavaDoc rootDir;
39     private Properties JavaDoc properties = new Properties JavaDoc();
40     private String JavaDoc userName;
41     private String JavaDoc password;
42     private String JavaDoc jndiInitialContextFactory;
43     private String JavaDoc jndiProviderUrl;
44     private String JavaDoc jndiConnectionFactoryName;
45     private String JavaDoc processorName = "multiplexing";
46     private transient ConnectionFactory JavaDoc connectionFactory;
47     private transient KeystoreManager keystoreManager;
48     private transient AuthenticationService authenticationService;
49     
50     /**
51      * The JNDI name of the AuthenticationService object
52      */

53     private String JavaDoc authenticationServiceName = "java:comp/env/smx/AuthenticationService";
54     
55     /**
56      * The JNDI name of the KeystoreManager object
57      */

58     private String JavaDoc keystoreManagerName = "java:comp/env/smx/KeystoreManager";
59
60     
61     /**
62      * @return Returns the rootDir.
63      */

64     public String JavaDoc getRootDir() {
65         return rootDir;
66     }
67
68     /**
69      * @param rootDir The rootDir to set.
70      */

71     public void setRootDir(String JavaDoc rootDir) {
72         this.rootDir = rootDir;
73     }
74
75     /**
76      * @return the authenticationService
77      */

78     public AuthenticationService getAuthenticationService() {
79         return authenticationService;
80     }
81     /**
82      * @param authenticationService the authenticationService to set
83      */

84     public void setAuthenticationService(AuthenticationService authenticationService) {
85         this.authenticationService = authenticationService;
86     }
87     /**
88      * @return the authenticationServiceName
89      */

90     public String JavaDoc getAuthenticationServiceName() {
91         return authenticationServiceName;
92     }
93     /**
94      * @param authenticationServiceName the authenticationServiceName to set
95      */

96     public void setAuthenticationServiceName(String JavaDoc authenticationServiceName) {
97         this.authenticationServiceName = authenticationServiceName;
98     }
99     /**
100      * @return the keystoreManager
101      */

102     public KeystoreManager getKeystoreManager() {
103         return keystoreManager;
104     }
105     /**
106      * @param keystoreManager the keystoreManager to set
107      */

108     public void setKeystoreManager(KeystoreManager keystoreManager) {
109         this.keystoreManager = keystoreManager;
110         save();
111     }
112     /**
113      * @return the keystoreManagerName
114      */

115     public String JavaDoc getKeystoreManagerName() {
116         return keystoreManagerName;
117     }
118     /**
119      * @param keystoreManagerName the keystoreManagerName to set
120      */

121     public void setKeystoreManagerName(String JavaDoc keystoreManagerName) {
122         this.keystoreManagerName = keystoreManagerName;
123         save();
124     }
125     /**
126      * @return Returns the password.
127      */

128     public String JavaDoc getPassword() {
129         return password;
130     }
131     /**
132      * @param password The password to set.
133      */

134     public void setPassword(String JavaDoc password) {
135         this.password = password;
136         save();
137     }
138     /**
139      * @return Returns the userName.
140      */

141     public String JavaDoc getUserName() {
142         return userName;
143     }
144     /**
145      * @param userName The userName to set.
146      */

147     public void setUserName(String JavaDoc userName) {
148         this.userName = userName;
149         save();
150     }
151     /**
152      * @return Returns the jndiName.
153      */

154     public String JavaDoc getJndiConnectionFactoryName() {
155         return jndiConnectionFactoryName;
156     }
157     /**
158      * @param jndiName The jndiName to set.
159      */

160     public void setJndiConnectionFactoryName(String JavaDoc jndiName) {
161         this.jndiConnectionFactoryName = jndiName;
162         save();
163     }
164     /**
165      * @return Returns the jndiInitialContextFactory.
166      */

167     public String JavaDoc getJndiInitialContextFactory() {
168         return jndiInitialContextFactory;
169     }
170     /**
171      * @param jndiInitialContextFactory The jndiInitialContextFactory to set.
172      */

173     public void setJndiInitialContextFactory(String JavaDoc jndiInitialContextFactory) {
174         this.jndiInitialContextFactory = jndiInitialContextFactory;
175         save();
176     }
177     /**
178      * @return Returns the jndiProviderUrl.
179      */

180     public String JavaDoc getJndiProviderUrl() {
181         return jndiProviderUrl;
182     }
183     /**
184      * @param jndiProviderUrl The jndiProviderUrl to set.
185      */

186     public void setJndiProviderUrl(String JavaDoc jndiProviderUrl) {
187         this.jndiProviderUrl = jndiProviderUrl;
188         save();
189     }
190     /**
191      * @return Returns the processorName.
192      */

193     public String JavaDoc getProcessorName() {
194         return processorName;
195     }
196     /**
197      * @param processorName The processorName to set.
198      */

199     public void setProcessorName(String JavaDoc processorName) {
200         this.processorName = processorName;
201         save();
202     }
203     /**
204      * @return Returns the connectionFactory.
205      */

206     public ConnectionFactory JavaDoc getConnectionFactory() {
207         return connectionFactory;
208     }
209     /**
210      * Default ConnectionFactory to use in a spring configuration.
211      * @param connectionFactory the connectionFactory to set.
212      */

213     public void setConnectionFactory(ConnectionFactory JavaDoc 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 JavaDoc f = new File JavaDoc(rootDir, CONFIG_FILE);
229             try {
230                 this.properties.store(new FileOutputStream JavaDoc(f), null);
231             } catch (Exception JavaDoc e) {
232                 throw new RuntimeException JavaDoc("Could not store component configuration", e);
233             }
234         }
235     }
236     
237     public boolean load() {
238         if (rootDir == null) {
239             return false;
240         }
241         File JavaDoc f = new File JavaDoc(rootDir, CONFIG_FILE);
242         if (!f.exists()) {
243             return false;
244         }
245         try {
246             properties.load(new FileInputStream JavaDoc(f));
247         } catch (IOException JavaDoc e) {
248             throw new RuntimeException JavaDoc("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