net.ex_337.xmpp.fwork
Class XMPPService

java.lang.Object
  extended bynet.ex_337.xmpp.fwork.XMPPService
All Implemented Interfaces:
org.jivesoftware.smack.PacketListener
Direct Known Subclasses:
BaseGradientService, DummyXMPPService

public abstract class XMPPService
extends Object
implements org.jivesoftware.smack.PacketListener

The based code for an XMPP service. Implementations of this class are loaded via the servlet.

Author:
Ian

Field Summary
protected  org.jivesoftware.smack.filter.PacketFilter filter
          The packet filter used to decide whether or not to call the processPacket() method on this class.
protected  ServletContext sc
          The servlet context that contains the servlet that loaded this XMPPService.
protected  org.jivesoftware.smack.XMPPConnection xmppConnection
          The XMPPConnection from which packets are received.
 
Constructor Summary
XMPPService()
          The default constructor.
 
Method Summary
 void close()
          Closes the XMPPConnection.
 void destroy()
          A method called before close().
 String getInitParameter(String name)
          Returns an initialisation parameter.
 Iterator getInitParameterNames()
           
 int getIntInitParameter(String name)
          Helper method.
 String[] getListInitParameter(String name)
          Helper method.
 void init()
          A method called before open().
 void log(String message)
          Logs the given message to the logger.
 void log(String message, Throwable throwable)
          Logs a message and the error to the logger.
 void open()
          Adds this service as a PacketListener to the given connection, using the 'filter' PacketFilter.
abstract  void processPacket(org.jivesoftware.smack.packet.Packet packet)
          The method called by the XMPPConnection when a packet is received, and passes the given PacketFilter.
 void setInitParameter(String name, String value)
          Sets an initialisation parameter.
 void setServletContext(ServletContext sc)
           
 void setXMPPConnection(org.jivesoftware.smack.XMPPConnection xmppConnection)
           
 void stop()
          Removes this service as from the XMPPConnection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

protected org.jivesoftware.smack.filter.PacketFilter filter
The packet filter used to decide whether or not to call the processPacket() method on this class. If not specified, then the filter is XMPPUtils.ALL_PACKETS.


xmppConnection

protected org.jivesoftware.smack.XMPPConnection xmppConnection
The XMPPConnection from which packets are received.


sc

protected ServletContext sc
The servlet context that contains the servlet that loaded this XMPPService.

Constructor Detail

XMPPService

public XMPPService()
The default constructor.

Method Detail

close

public void close()
Closes the XMPPConnection. If you override this, you chould call super.


open

public final void open()
Adds this service as a PacketListener to the given connection, using the 'filter' PacketFilter.


stop

public final void stop()
Removes this service as from the XMPPConnection.


log

public final void log(String message)
Logs the given message to the logger.

Parameters:
message - the message.

log

public final void log(String message,
                      Throwable throwable)
Logs a message and the error to the logger.

Parameters:
message - the message
throwable - the error

setXMPPConnection

public final void setXMPPConnection(org.jivesoftware.smack.XMPPConnection xmppConnection)
Parameters:
xmppConnection - The XMPP connection to set.

setServletContext

public final void setServletContext(ServletContext sc)
Parameters:
sc - the servlet context for this service.

setInitParameter

public final void setInitParameter(String name,
                                   String value)
Sets an initialisation parameter.

Parameters:
name - the parameter name
value - the parameter value

getInitParameter

public String getInitParameter(String name)
Returns an initialisation parameter.

Parameters:
name - the parameter name.
Returns:
the parameter, or null if it doesn't exist.

getIntInitParameter

public int getIntInitParameter(String name)
Helper method. Attempts to return Integer.parseInt of the given parameter.

Parameters:
name - the parameter name
Returns:
-1 if the parameter is null, or the int representation of the parameter otherwise
Throws:
NumberFormatException - if the parameter specified cannot be parsed into an integer.

getListInitParameter

public String[] getListInitParameter(String name)
Helper method. Assumes the named init parameter is a comma-separated list of strings. Returns an array of trimmed strings.

Parameters:
name - the parameter name.
Returns:
the list, or String[0] if the parameter does not exist.

getInitParameterNames

public Iterator getInitParameterNames()
Returns:
an unmodifiable Iterator of the init paramters

init

public void init()
A method called before open(). Override at will.


destroy

public void destroy()
A method called before close(). Override at will.


processPacket

public abstract void processPacket(org.jivesoftware.smack.packet.Packet packet)
The method called by the XMPPConnection when a packet is received, and passes the given PacketFilter.

Specified by:
processPacket in interface org.jivesoftware.smack.PacketListener
Parameters:
packet - the packet.