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
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) 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
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: *
023: * $Id: FtpConfiguration.java 6628 2007-04-11 01:10:16Z zjin $
024: */
025: package com.bostechcorp.cbesb.runtime.component.ftp;
026:
027: import java.io.File;
028: import java.io.FileInputStream;
029: import java.io.FileOutputStream;
030: import java.io.IOException;
031: import java.util.Properties;
032:
033: import com.bostechcorp.cbesb.common.util.ErrorUtil;
034:
035: /**
036: * @author j.zhang
037: * @version 1.0.0
038: */
039: public class FtpConfiguration implements FtpConfigurationMBean {
040:
041: public final static String CONFIG_FILE = "component.properties";
042:
043: private Properties properties = new Properties();
044:
045: // private String jmxSampleConfigAttr = "foo";
046:
047: private String rootDir;
048:
049: /**
050: * User name to login to input FTP server for Input endpoint.
051: */
052: private String inputUser;
053:
054: /**
055: * Password for the above user id to login to input FTP server.
056: */
057: private String inputPassword;
058:
059: /**
060: * User name to login to reply FTP server for input endpoint.
061: */
062: private String replyUser;
063:
064: /**
065: * Password for the above user id to login to reply FTP server for input endpoint.
066: */
067: private String replyPassword;
068:
069: /**
070: * User name to login to output FTP server for output endpoint.
071: */
072: private String ouputUser;
073:
074: /**
075: * Password for the above user id to login to output FTP server for ouput endpoint.
076: */
077: private String outputPassword;
078:
079: // /* (non-Javadoc)
080: // * @see com.bostechcorp.cbesb.runtime.component.ftp.FtpConfigurationMBean#getJmxSampleConfigAttr()
081: // */
082: // public String getJmxSampleConfigAttr() {
083: // return jmxSampleConfigAttr;
084: // }
085: //
086: // /* (non-Javadoc)
087: // * @see com.bostechcorp.cbesb.runtime.component.ftp.FtpConfigurationMBean#setJmxSampleConfigAttr(java.lang.String)
088: // */
089: // public void setJmxSampleConfigAttr(String jmxSampleConfigAttr) {
090: // this.jmxSampleConfigAttr = jmxSampleConfigAttr;
091: // save();
092: // }
093:
094: /**
095: * Get the rootDir.
096: *
097: * @return The rootDir.
098: */
099: public String getRootDir() {
100: return rootDir;
101: }
102:
103: /**
104: * Set the rootDir.
105: *
106: * @param rootDir The rootDir to set.
107: */
108: public void setRootDir(String rootDir) {
109: this .rootDir = rootDir;
110: }
111:
112: /**
113: * Get the inputUser.
114: *
115: * @return the inputUser
116: */
117: public String getInputUser() {
118: return inputUser;
119: }
120:
121: /**
122: * Set the inputUser.
123: *
124: * @param inputUser the inputUser to set
125: */
126: public void setInputUser(String inputUser) {
127: this .inputUser = inputUser;
128: save();
129: }
130:
131: /**
132: * Get the inputPassword.
133: *
134: * @return the inputPassword
135: */
136: public String getInputPassword() {
137: return inputPassword;
138: }
139:
140: /**
141: * Set the inputPassword.
142: *
143: * @param inputPassword the inputPassword to set
144: */
145: public void setInputPassword(String inputPassword) {
146: this .inputPassword = inputPassword;
147: save();
148: }
149:
150: /**
151: * Get the replyUser.
152: *
153: * @return the replyUser
154: */
155: public String getReplyUser() {
156: return replyUser;
157: }
158:
159: /**
160: * Set the replyUser.
161: *
162: * @param replyUser the replyUser to set
163: */
164: public void setReplyUser(String replyUser) {
165: this .replyUser = replyUser;
166: save();
167: }
168:
169: /**
170: * Get the replyPassword.
171: *
172: * @return the replyPassword
173: */
174: public String getReplyPassword() {
175: return replyPassword;
176: }
177:
178: /**
179: * Set the replyPassword.
180: *
181: * @param replyPassword the replyPassword to set
182: */
183: public void setReplyPassword(String replyPassword) {
184: this .replyPassword = replyPassword;
185: save();
186: }
187:
188: /**
189: * Get the ouputUser.
190: *
191: * @return the ouputUser
192: */
193: public String getOuputUser() {
194: return ouputUser;
195: }
196:
197: /**
198: * Set the ouputUser.
199: *
200: * @param ouputUser the ouputUser to set
201: */
202: public void setOuputUser(String ouputUser) {
203: this .ouputUser = ouputUser;
204: save();
205: }
206:
207: /**
208: * Get the outputPassword.
209: *
210: * @return the outputPassword
211: */
212: public String getOutputPassword() {
213: return outputPassword;
214: }
215:
216: /**
217: * Set the outputPassword.
218: *
219: * @param outputPassword the outputPassword to set
220: */
221: public void setOutputPassword(String outputPassword) {
222: this .outputPassword = outputPassword;
223: save();
224: }
225:
226: public void save() {
227: // properties.setProperty("jmxSampleConfigAttr", jmxSampleConfigAttr);
228: properties.setProperty("inputUser", inputUser);
229: properties.setProperty("inputPassword", inputPassword);
230: properties.setProperty("replyUser", replyUser);
231: properties.setProperty("replyPassword", replyPassword);
232: properties.setProperty("ouputUser", ouputUser);
233: properties.setProperty("outputPassword", outputPassword);
234:
235: if (rootDir != null) {
236: File f = new File(rootDir, CONFIG_FILE);
237: try {
238: this .properties.store(new FileOutputStream(f), null);
239: } catch (Exception e) {
240:
241: ErrorUtil.printError(
242: "Could not store component configuration: ", e);
243: }
244: }
245: }
246:
247: public boolean load() {
248: if (rootDir == null) {
249: return false;
250: }
251: File f = new File(rootDir, CONFIG_FILE);
252: if (!f.exists()) {
253: return false;
254: }
255: try {
256: properties.load(new FileInputStream(f));
257: } catch (IOException ioe) {
258: ErrorUtil.printError("Could not component configuration ",
259: ioe);
260: throw new RuntimeException(
261: "Could not load component configuration", ioe);
262: }
263: // if (properties.getProperty("jmxSampleConfigAttr") != null) {
264: // jmxSampleConfigAttr = properties.getProperty("jmxSampleConfigAttr");
265: // }
266: if (properties.getProperty("inputUser") != null) {
267: inputUser = properties.getProperty("inputUser");
268: }
269: if (properties.getProperty("inputPassword") != null) {
270: inputPassword = properties.getProperty("inputPassword");
271: }
272: if (properties.getProperty("replyUser") != null) {
273: replyUser = properties.getProperty("replyUser");
274: }
275: if (properties.getProperty("replyPassword") != null) {
276: replyPassword = properties.getProperty("replyPassword");
277: }
278: if (properties.getProperty("ouputUser") != null) {
279: ouputUser = properties.getProperty("ouputUser");
280: }
281: if (properties.getProperty("outputPassword") != null) {
282: outputPassword = properties.getProperty("outputPassword");
283: }
284:
285: return true;
286: }
287: }
|