⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ainterface.java

📁 使用smslib和GSP modem 发送和接收手机短息
💻 JAVA
字号:
// SMSLib for Java v3
// A Java API library for sending and receiving SMS via a GSM modem
// or other supported gateways.
// Web Site: http://www.smslib.org
//
// Copyright (C) 2002-2008, Thanasis Delenikas, Athens/GREECE.
// SMSLib is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.smslib.smsserver;

import java.util.List;
import java.util.Properties;

/**
 * The AInterface abstract class is the base class of all implemented SMSServer
 * interfaces.
 * <p>
 * An SMSServer interface can be thought of as a message producer or a message
 * consumer.
 * <p>
 * SMSServer comes with a couple of ready-made interfaces. If you wish to extend
 * SMSServer with new interface functionality, create your own interface by
 * implementing the current abstract class.
 */
public abstract class AInterface
{
	protected String infId;

	protected Properties props;

	protected SMSServer server;

	protected InterfaceTypes type;

	protected String description;

	public AInterface(String infId, Properties props, org.smslib.smsserver.SMSServer server, InterfaceTypes type)
	{
		this.infId = infId;
		this.props = props;
		this.server = server;
		this.type = type;
	}

	/**
	 * This method is called by SMSServer every time an inbound call is
	 * received. SMSServer calls this method for all available/active
	 * interfaces.
	 * 
	 * @param gtwId
	 *            The Id of the gateway which received the call.
	 * @param callerId
	 *            The caller id.
	 */
	public abstract void CallReceived(String gtwId, String callerId) throws Exception;

	/**
	 * Returns the interface description.
	 * 
	 * @return The interface description.
	 */
	public final String getDescription()
	{
		return description;
	}

	/**
	 * SMSServer calls this method in order to query the interface for messages
	 * that need to be send out.
	 * 
	 * @return A list of Outbound messages to be sent. Return an empty list if
	 *         the interface has no messages for dispatch.
	 * @throws Exception
	 */
	public abstract List getMessagesToSend() throws Exception;

	/**
	 * Reads the property key of this interface.
	 * 
	 * @param key
	 *            The key of the property to read.
	 * @return The value of the property or null if not set
	 */
	public final String getProperty(String key)
	{
		return getProperty(key, null);
	}

	/**
	 * Reads the property key of this interface. <br />
	 * The defaultValue is returned if the key is not defined in the properties.
	 * 
	 * @param key
	 *            The key of the property to read.
	 * @param defaultValue
	 *            The defaultValue if key is not defined.
	 * @return The value of the property or defaultValue if not set.
	 */
	public final String getProperty(String key, String defaultValue)
	{
		logDebug("Search property: " + key + " (" + defaultValue + ")");
		defaultValue = props.getProperty(infId + "." + key, defaultValue);
		logDebug("Returned property: " + key + "=" + defaultValue);
		return defaultValue;
	}

	/**
	 * Returns the interface type.
	 * 
	 * @return The interface type.
	 * @see InterfaceTypes
	 */
	public final InterfaceTypes getType()
	{
		return type;
	}

	/**
	 * Returns true if the interface is for inbound messaging.
	 * 
	 * @return True if the interface is for inbound messaging.
	 */
	public final boolean isInbound()
	{
		if (InterfaceTypes.INBOUND == type || InterfaceTypes.INOUTBOUND == type)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * Returns true if the interface is for outbound messaging.
	 * 
	 * @return True if the interface is for outbound messaging.
	 */
	public final boolean isOutbound()
	{
		if (InterfaceTypes.OUTBOUND == type || InterfaceTypes.INOUTBOUND == type)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * Confinience method for server.srv.logDebug(String)
	 */
	public final void logDebug(String message)
	{
		logDebug(message, null);
	}

	/**
	 * Confinience method for server.srv.logDebug(String, Exception)
	 */
	public final void logDebug(String message, Exception e)
	{
		if (server != null)
		{
			server.srv.logDebug(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
		else
		{
			// ignore
			//System.out.println(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
	}

	/**
	 * Confinience method for server.srv.logError(String)
	 */
	public final void logError(String message)
	{
		logError(message, null);
	}

	/**
	 * Confinience method for server.srv.logError(String, Exception)
	 */
	public final void logError(String message, Exception e)
	{
		if (server != null)
		{
			server.srv.logError(message, e);
		}
		else
		{
			System.err.println(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
	}

	/**
	 * Confinience method for server.srv.logInfo(String)
	 */
	public final void logInfo(String message)
	{
		logInfo(message, null);
	}

	/**
	 * Confinience method for server.srv.logInfo(String, Exception)
	 */
	public final void logInfo(String message, Exception e)
	{
		if (server != null)
		{
			server.srv.logInfo(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
		else
		{
			System.out.println(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
	}

	/**
	 * Confinience method for server.srv.logWarn(String)
	 */
	public final void logWarn(String message)
	{
		logWarn(message, null);
	}

	/**
	 * Confinience method for server.srv.logWarn(String, Exception)
	 */
	public final void logWarn(String message, Exception e)
	{
		if (server != null)
		{
			server.srv.logWarn(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
		else
		{
			System.err.println(message + (e == null ? "" : (" (" + e.getMessage() + ")")));
		}
	}

	/**
	 * After a successful or unsuccessful attempt to send a message, SMSServer
	 * calls this method. The interface can then decide what to do with the
	 * message. Note that the message status and errors member fields are
	 * updated, so you should examine them in order to determine whether the
	 * message has been sent out, etc.
	 * 
	 * @param msg
	 *            The Outbound message.
	 * @throws Exception
	 */
	public abstract void markMessage(org.smslib.OutboundMessage msg) throws Exception;

	public void markMessages(List msgList) throws Exception
	{
		for (int i = 0; i < msgList.size(); i++)
			markMessage((org.smslib.OutboundMessage) msgList.get(i));
	}

	/**
	 * This method is called by SMSServer every time a message (or more
	 * messages) is received. SMSServer calls this method for all
	 * available/active interfaces.
	 * 
	 * @param msgList
	 *            A message list of all received messages.
	 * @throws Exception
	 */
	public abstract void MessagesReceived(List msgList) throws Exception;

	/**
	 * Called once before SMSServer starts its operation. Use this method for
	 * initialization.
	 * 
	 * @throws Exception
	 *             An exception thrown will stop SMSServer from starting its
	 *             processing.
	 */
	public abstract void start() throws Exception;

	/**
	 * Called once after SMSServer has finished. Use this method for cleaning up
	 * your interface.
	 * 
	 * @throws Exception
	 */
	public abstract void stop() throws Exception;
}

⌨️ 快捷键说明

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