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: * $Id: EmailConfiguration.java 7040 2007-04-24 08:28:59Z jzhang $
023: *
024: */
025: package com.bostechcorp.cbesb.runtime.component.email;
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: import com.bostechcorp.cbesb.runtime.component.email.EmailConfigurationMBean;
035:
036: /**
037: *
038: */
039: public class EmailConfiguration implements EmailConfigurationMBean {
040:
041: public final static String CONFIG_FILE = "component.properties";
042:
043: private String rootDir;
044: private Properties properties = new Properties();
045:
046: /**
047: * host name or IP address
048: */
049: private String host;
050:
051: /**
052: * remote port number
053: */
054: private String port;
055:
056: /**
057: * user name
058: */
059: private String user;
060:
061: /**
062: * password
063: */
064: private String password;
065:
066: /**
067: * @return Returns the rootDir.
068: */
069: public String getRootDir() {
070: return rootDir;
071: }
072:
073: /**
074: * @param rootDir The rootDir to set.
075: */
076: public void setRootDir(String rootDir) {
077: this .rootDir = rootDir;
078: }
079:
080: /**
081: * @return the host
082: */
083: public String getHost() {
084: return host;
085: }
086:
087: /**
088: * @param host the host to set
089: */
090: public void setHost(String host) {
091: this .host = host;
092: }
093:
094: /**
095: * @return the port
096: */
097: public String getPort() {
098: return port;
099: }
100:
101: /**
102: * @param port the port to set
103: */
104: public void setPort(String port) {
105: this .port = port;
106: }
107:
108: /**
109: * @return the user
110: */
111: public String getUser() {
112: return user;
113: }
114:
115: /**
116: * @param user the user to set
117: */
118: public void setUser(String user) {
119: this .user = user;
120: }
121:
122: /**
123: * @return the password
124: */
125: public String getPassword() {
126: return password;
127: }
128:
129: /**
130: * @param password the password to set
131: */
132: public void setPassword(String password) {
133: this .password = password;
134: }
135:
136: /**
137: * @return Returns the connectionFactory.
138: */
139:
140: public void save() {
141: properties.setProperty("host", host);
142: properties.setProperty("port", port);
143: properties.setProperty("user", user);
144: properties.setProperty("password", password);
145:
146: if (rootDir != null) {
147: File f = new File(rootDir, CONFIG_FILE);
148: try {
149: this .properties.store(new FileOutputStream(f), null);
150: } catch (Exception e) {
151: ErrorUtil.printError(
152: "Could not store component configuration", e);
153: }
154: }
155: }
156:
157: public boolean load() {
158: if (rootDir == null) {
159: return false;
160: }
161: File f = new File(rootDir, CONFIG_FILE);
162: if (!f.exists()) {
163: return false;
164: }
165: try {
166: properties.load(new FileInputStream(f));
167: } catch (IOException e) {
168: ErrorUtil.printError(
169: "Could not load component configuration", e);
170: }
171:
172: if (properties.getProperty("host") != null) {
173: host = properties.getProperty("host");
174: }
175: if (properties.getProperty("port") != null) {
176: host = properties.getProperty("port");
177: }
178: if (properties.getProperty("user") != null) {
179: host = properties.getProperty("user");
180: }
181: if (properties.getProperty("password") != null) {
182: host = properties.getProperty("password");
183: }
184: return true;
185: }
186: }
|