001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: SMSManagerImpl.java,v 1.1 2006-09-11 12:27:25 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.business.sms;
021:
022: import com.lutris.util.Config;
023: import com.lutris.util.KeywordValueTable;
024: import com.lutris.airsent.business.AirSentBusinessException;
025: import com.lutris.airsent.spec.sms.SMSManager;
026:
027: /**
028: * Class declaration
029: *
030: *
031: * @author
032: * @version %I%, %G%
033: */
034: public class SMSManagerImpl implements SMSManager {
035:
036: protected final static String SMS_ACTIVE = "Active";
037: protected final static String SMS_KEY = "SMS";
038: protected final static String SMS_HOSTNAME = "Hostname";
039: protected final static String SMS_PORT = "Port";
040: protected final static String SMS_SYSID = "Sysid";
041: protected final static String SMS_SYSTYPE = "Systype";
042: protected final static String SMS_SYSPASSWORD = "Password";
043:
044: protected String smsServer = null;
045: protected String smsPort = null;
046: protected String smsSysid = null;
047: protected String smsSystype = null;
048: protected String smsSyspassword = null;
049: protected boolean active = false;
050:
051: /**
052: * Plain Constructor
053: *
054: *
055: * @see
056: */
057: public SMSManagerImpl() {
058: }
059:
060: /**
061: * Constructor using the Config object to set config variables.
062: *
063: *
064: * @param config
065: *
066: * @see
067: */
068: public SMSManagerImpl(Config config)
069: throws AirSentBusinessException {
070: try {
071: // Get the email config.
072: KeywordValueTable section = config.getSection(SMS_KEY);
073: smsServer = section.getString(SMS_HOSTNAME);
074: smsPort = section.getString(SMS_PORT);
075: smsSysid = section.getString(SMS_SYSID);
076: smsSystype = section.getString(SMS_SYSTYPE);
077: smsSyspassword = section.getString(SMS_SYSPASSWORD);
078: active = Boolean.valueOf(section.getString(SMS_ACTIVE))
079: .booleanValue();
080: } catch (Exception ex) {
081: throw new AirSentBusinessException("Error sending mail:",
082: ex);
083: }
084: }
085:
086: /**
087: * Sends sms message.
088: *
089: *
090: * @param to
091: * @param toAddress
092: * @param subject
093: * @param body
094: * @param type
095: *
096: * @throws AirSentBusinessException
097: *
098: * @see
099: */
100: public void send(String id, String body)
101: throws AirSentBusinessException {
102: try {
103: if (active) {
104: SMS sms = new SMS(smsServer, smsPort, smsSysid,
105: smsSystype, smsSyspassword);
106: sms.sendMessage(id, body);
107: } else {
108: System.out
109: .println("SMS is not active. Edit airSent.conf to activate.");
110: }
111: } catch (Exception ex) {
112: throw new AirSentBusinessException("Error sending SMS:", ex);
113: }
114: }
115:
116: }
|