View Javadoc
1 /* 2 * $Id: MSNMessageBean.java,v 1.3 2003/10/02 01:25:53 smulube Exp $ 3 * 4 * ***** BEGIN LICENSE BLOCK ***** 5 * =========================================================================== 6 * Copyright (c) 2003 Sam Mulube 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 * SOFTWARE.COPYRIGHT AND PERMISSION NOTICE 25 * =========================================================================== 26 * ***** END LICENSE BLOCK ***** 27 */ 28 package org.zerofun.maven.im.beans; 29 30 import org.apache.commons.lang.StringUtils; 31 import org.hn.sleek.jmml.MessengerServerManager; 32 import org.zerofun.maven.im.MavenIMException; 33 34 /*** 35 * This bean provides the actual functionality for sending a message to MSN 36 * clients. It's functionality is invoked by the corresponding 37 * MSNMessageTag class. 38 * 39 * @author <a href="mailto:sam@mulube.com">Sam Mulube</a> 40 * @version $Revision: 1.3 $ 41 * 42 */ 43 public class MSNMessageBean { 44 45 private int counter = 0; 46 private String from = null; 47 private String message = null; 48 private String password = null; 49 private String to = null; 50 51 /*** 52 * The main method of the bean. This performs the function of creating and 53 * sending the message to all MSN recipients. 54 * @throws Exception 55 */ 56 public void execute() throws Exception { 57 if (getTo()== null) { 58 throw new MavenIMException("No MSN recipients specified."); 59 } 60 System.out.println("Connecting to MSN server..."); 61 System.out.println("Logging in user: " + getFrom()); 62 63 MessengerServerManager msn = MessengerServerManager.getInstance(); 64 65 msn.signIn(getFrom(), getPassword()); 66 Thread.sleep(1000); // we need to wait here for msn to sign us in. 67 68 String[] recipients = UtilityBean.getRecipients(getTo()); 69 70 for (int i = 0; i < recipients.length; i++) { 71 String recipient = recipients[i]; 72 System.out.println("Sending message to: " + recipient); 73 msn.sendMessage(recipient, getMessage()); 74 Thread.sleep(1500); // we need to manually wait here. 75 } 76 System.out.println("Disconnecting from MSN server..."); 77 msn.signOut(); 78 } 79 80 /*** 81 * Gets the MSN username from which messages should be sent. 82 * @return the from String 83 */ 84 public String getFrom() { 85 return from; 86 } 87 88 /*** 89 * Gets the message which will be sent to all recipients. 90 * @return the message String 91 */ 92 public String getMessage() { 93 return message; 94 } 95 96 /*** 97 * Gets the password which will be used to authenticate the specified user 98 * to the MSN server. 99 * @return the password String 100 */ 101 public String getPassword() { 102 return password; 103 } 104 105 /*** 106 * Gets the complete list of recipients, which could be a single name, or a 107 * comma separated list of recipients. 108 * @return the to String 109 */ 110 public String getTo() { 111 return to; 112 } 113 114 /*** 115 * Sets the username from which messages will be sent. 116 * @param from the from String to set 117 */ 118 public void setFrom(String from) { 119 this.from = from; 120 } 121 122 /*** 123 * Sets the message which will be sent to all users. 124 * @param message the message String to set 125 */ 126 public void setMessage(String message) { 127 this.message = message; 128 } 129 130 /*** 131 * Sets the password which will be used to authenticate the specified 132 * user with the MSN server. 133 * @param password the password String to set 134 */ 135 public void setPassword(String password) { 136 this.password = password; 137 } 138 139 /*** 140 * Sets the list of recipients to which messages should be sent. 141 * @param to the to String to set 142 */ 143 public void setTo(String to) { 144 this.to = to; 145 } 146 147 } 148 149 /* 150 * $Log: MSNMessageBean.java,v $ 151 * Revision 1.3 2003/10/02 01:25:53 smulube 152 * added better comments. 153 * 154 * Revision 1.2 2003/10/01 17:16:24 smulube 155 * beans now throw exception if no recipients specified. 156 * 157 * Revision 1.1 2003/09/26 01:19:35 smulube 158 * Sends messages, but thread has to sleep or else message sending fails. 159 * 160 */

This page was automatically generated by Maven