xmppgroupnotificationstrategy.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 135 行

JAVA
135
字号
/* * Created on Mar 7, 2005 * Copyright (C) 2005, The OpenNMS Group, Inc.. *  */package org.opennms.netmgt.notifd;import java.util.List;import java.util.Properties;import org.apache.log4j.Category;import org.opennms.core.utils.Argument;import org.opennms.core.utils.ThreadCategory;import org.opennms.netmgt.config.NotificationManager;/** * Implements NotificationStragey pattern used to send notifications using the * XMPP message protocol *  * @author <A HREF="mailto:jonathan@opennms.org">Jonathan Sartin </A> */public class XMPPGroupNotificationStrategy implements NotificationStrategy {	/**	 * String used to identify the user to whom the XMPP message will be sent.	 */	private static final int XMPP_TO;	/**	 * Text of XMPP Message to be sent.	 */	private static final int XMPP_MESSAGE;	/**	 * The value of this constant indicates the number of XMPP constants	 * defined.	 */	private static final int XMPP_MAX;	/**	 * Mapping of index values to meaningful strings.	 */	private static final String[] INDEX_TO_NAME;	private Properties props = new Properties();	private Category log = null;	// Initialize constant class data	static {		XMPP_TO = 0;		XMPP_MESSAGE = 1;		XMPP_MAX = 2;		INDEX_TO_NAME = new String[XMPP_MAX];		INDEX_TO_NAME[XMPP_TO] = "To";		INDEX_TO_NAME[XMPP_MESSAGE] = "Message";	}	/**	 * 	 */	public XMPPGroupNotificationStrategy() {	}	/*	 * (non-Javadoc)	 * 	 * @see org.opennms.netmgt.notifd.NotificationStrategy#send(java.util.List)	 */	public int send(List arguments) {		try {			String[] parsedArgs = this.parseArguments(arguments);			XMPPNotificationManager xmppManager = XMPPNotificationManager.getInstance();			xmppManager.sendGroupChat(parsedArgs[XMPP_TO],parsedArgs[XMPP_MESSAGE]);		} catch (Exception e) {			ThreadCategory.getInstance(getClass()).error(e.getMessage());			return 1;		}		return 0;	}	/**	 * This method extracts the xmpp address and message text from the	 * parameters passed in the notification.	 * 	 * @param arguments	 * @return String[]	 * @throws Exception	 */	private String[] parseArguments(List arguments) throws Exception {		String[] parsedArgs = new String[XMPP_MAX];		for (int i = 0; i < arguments.size(); i++) {			Argument arg = (Argument) arguments.get(i);			if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch())) {				parsedArgs[XMPP_TO] = arg.getValue();			} else if (NotificationManager.PARAM_TEXT_MSG.equals(arg					.getSwitch())) {				parsedArgs[XMPP_MESSAGE] = arg.getValue();			}		}		for (int i = 0; i < XMPP_MAX; ++i) {			if (parsedArgs[i] == null) {				throw (new Exception(						"Incomplete argument set, missing argument: "								+ INDEX_TO_NAME[i]));			}		}		return parsedArgs;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?