001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: JMSConfiguration.java 1206 2006-09-23 03:51:32Z fling $
023: */
024: package com.bostechcorp.cbesb.runtime.component.jms;
025:
026: import java.io.File;
027: import java.io.FileInputStream;
028: import java.io.FileOutputStream;
029: import java.io.IOException;
030: import java.util.Properties;
031:
032: import com.bostechcorp.cbesb.common.util.ErrorUtil;
033:
034: /**
035: * @author fling
036: *
037: */
038: public class JMSConfiguration implements JMSConfigurationMBean {
039:
040: public final static String CONFIG_FILE = "component.properties";
041:
042: // You only need this if you have some configuration value needed to be read
043: // from a properties file or from JMX console
044: // I use a sample properties call jmxSampleConfigAttr with a default value
045: // of "foo"
046: // private String jmxSampleConfigAttr = "foo";
047:
048: private String rootDir;
049:
050: private String userName;
051:
052: private String password;
053:
054: private String awaitTimeout;
055:
056: private String replyTimeout;
057:
058: private String jndiInitialContextFactory;
059:
060: private String jndiProviderUrl;
061:
062: private String jndiConnectionFactoryName;
063:
064: private Properties properties = new Properties();
065:
066: // /**
067: // * @return the jmxSampleConfigAttr
068: // */
069: // public String getJmxSampleConfigAttr() {
070: // return jmxSampleConfigAttr;
071: // }
072: //
073: // /**
074: // * @param jmxSampleConfigAttr
075: // * the jmxSampleConfigAttr to set
076: // */
077: // public void setJmxSampleConfigAttr(String jmxSampleConfigAttr) {
078: // this.jmxSampleConfigAttr = jmxSampleConfigAttr;
079: // save();
080: // }
081:
082: public String getRootDir() {
083: return rootDir;
084: }
085:
086: public void setRootDir(String rootDir) {
087: this .rootDir = rootDir;
088: }
089:
090: public String getUserName() {
091: return userName;
092: }
093:
094: public void setUserName(String userName) {
095: this .userName = userName;
096: save();
097: }
098:
099: public String getPassword() {
100: return password;
101: }
102:
103: public void setPassword(String password) {
104: this .password = password;
105: save();
106: }
107:
108: public String getAwaitTimeout() {
109: return awaitTimeout;
110: }
111:
112: public void setAwaitTimeout(String awaitTimeout) {
113: this .awaitTimeout = awaitTimeout;
114: save();
115: }
116:
117: public String getReplyTimeout() {
118: return replyTimeout;
119: }
120:
121: public void setReplyTimeout(String replyTimeout) {
122: this .replyTimeout = replyTimeout;
123: save();
124: }
125:
126: public String getJndiConnectionFactoryName() {
127: return jndiConnectionFactoryName;
128: }
129:
130: public void setJndiConnectionFactoryName(
131: String jndiConnectionFactoryName) {
132: this .jndiConnectionFactoryName = jndiConnectionFactoryName;
133: save();
134: }
135:
136: public String getJndiInitialContextFactory() {
137: return jndiInitialContextFactory;
138: }
139:
140: public void setJndiInitialContextFactory(
141: String jndiInitialContextFactory) {
142: this .jndiInitialContextFactory = jndiInitialContextFactory;
143: save();
144: }
145:
146: public String getJndiProviderUrl() {
147: return jndiProviderUrl;
148: }
149:
150: public void setJndiProviderUrl(String jndiProviderUrl) {
151: this .jndiProviderUrl = jndiProviderUrl;
152: save();
153: }
154:
155: /**
156: * @return Returns the connectionFactory.
157: */
158:
159: public void save() {
160: // properties.setProperty("jmxSampleConfigAttr", jmxSampleConfigAttr);
161: properties.setProperty("userName", userName);
162: properties.setProperty("password", password);
163: properties.setProperty("awaitTimeout", awaitTimeout);
164: properties.setProperty("replyTimeout", replyTimeout);
165: properties.setProperty("jndiInitialContextFactory",
166: jndiInitialContextFactory);
167: properties.setProperty("jndiProviderUrl", jndiProviderUrl);
168: properties.setProperty("jndiName", jndiConnectionFactoryName);
169:
170: if (rootDir != null) {
171: File f = new File(rootDir, CONFIG_FILE);
172: try {
173: this .properties.store(new FileOutputStream(f), null);
174: } catch (Exception e) {
175:
176: ErrorUtil.printError(
177: "Could not store component configuration ", e);
178: throw new RuntimeException(
179: "Could not store component configuration", e);
180: }
181: }
182: }
183:
184: public boolean load() {
185:
186: if (rootDir == null) {
187: return false;
188: }
189: File f = new File(rootDir, CONFIG_FILE);
190: if (!f.exists()) {
191: return false;
192: }
193: try {
194: properties.load(new FileInputStream(f));
195: } catch (IOException e) {
196:
197: ErrorUtil.printError(
198: "Could not load component configuration ", e);
199: throw new RuntimeException(
200: "Could not load component configuration", e);
201: }
202:
203: if (properties.getProperty("UserID") != null) {
204: userName = properties.getProperty("UserID");
205: }
206: if (properties.getProperty("Password") != null) {
207: password = properties.getProperty("Password");
208: }
209: if (properties.getProperty("AwaitTimeout") != null) {
210: awaitTimeout = properties.getProperty("AwaitTimeout");
211: }
212: if (properties.getProperty("ReplyTimeout") != null) {
213: replyTimeout = properties.getProperty("ReplyTimeout");
214: }
215: if (properties.getProperty("jndiInitialContextFactory") != null) {
216: jndiInitialContextFactory = properties
217: .getProperty("jndiInitialContextFactory");
218: }
219: if (properties.getProperty("jndiProviderUrl") != null) {
220: jndiProviderUrl = properties.getProperty("jndiProviderUrl");
221: }
222: if (properties.getProperty("jndiConnectionFactoryName") != null) {
223: jndiConnectionFactoryName = properties
224: .getProperty("jndiConnectionFactoryName");
225: }
226: // if (properties.getProperty("jmxSampleConfigAttr") != null) {
227: // jmxSampleConfigAttr = properties.getProperty("jmxSampleConfigAttr");
228: // }
229:
230: return true;
231: }
232: }
|