net.ex_337.xmpp.fwork
Class BaseGradientService

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

public abstract class BaseGradientService
extends XMPPService

This class extends XMPPService to add some of the functionality expected to be required when creating Gradient services. Specifically, sessions are supported, and document request processing is included.

Author:
Ian

Field Summary
protected  Map sessions
          The map of all sessions, keyed by remote JID.
 
Fields inherited from class net.ex_337.xmpp.fwork.XMPPService
filter, sc, xmppConnection
 
Constructor Summary
BaseGradientService()
          The default constuctor.
 
Method Summary
 GradientSession getSession(String remoteJID)
           
 Map getSessions()
           
protected  GradientSession newSession()
          Creates a new session.
protected  void processDocRequestIQ(DocRequestIQ docRequest, String remoteJID)
          Process a document request IQ.
abstract  Element processDocumentRequest(String remoteJID, String path, Map parameters)
          Should be overridden.
protected  void processIncomingMessage(Message message, String remoteJID)
          Processes an incoming message.
 void processPacket(org.jivesoftware.smack.packet.Packet packet)
          The implementation of XMPPService.processPacket that routes the packets to their correct sessions.
protected  void processPresence(Presence presence, String remoteJID)
          Processes a presence packet.
protected  void processRPCStyleIQ(IQ iq, String remoteJID)
          Processes a normal, i.e.
 void sendStanza(String path, GradientSession session, String threadID, Element element)
           
 void sendStanza(String path, GradientSession session, String threadID, List elements)
           
 
Methods inherited from class net.ex_337.xmpp.fwork.XMPPService
close, destroy, getInitParameter, getInitParameterNames, getIntInitParameter, getListInitParameter, init, log, log, open, setInitParameter, setServletContext, setXMPPConnection, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sessions

protected Map sessions
The map of all sessions, keyed by remote JID. Values are GradientSessions.

Constructor Detail

BaseGradientService

public BaseGradientService()
The default constuctor. Feel free to override.

Method Detail

sendStanza

public void sendStanza(String path,
                       GradientSession session,
                       String threadID,
                       Element element)
Parameters:
path - the path, if any, to target with this event.
session - the session, if any, to target with this event.
threadID - the user vieport ID, if any, to target with this event.
element - the element to send.

sendStanza

public void sendStanza(String path,
                       GradientSession session,
                       String threadID,
                       List elements)
Parameters:
path - the path, if any, to target with this event.
session - the session, if any, to target with this event.
threadID - the user viewport ID, if any, to target with this event.
elements - the elements to send.

getSession

public GradientSession getSession(String remoteJID)
Parameters:
remoteJID - the JID of the session to get.
Returns:
the session object, or null.

getSessions

public Map getSessions()
Returns:
an unmodifiable map of all sessions.

processPacket

public void processPacket(org.jivesoftware.smack.packet.Packet packet)
The implementation of XMPPService.processPacket that routes the packets to their correct sessions.

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

processPresence

protected void processPresence(Presence presence,
                               String remoteJID)
Processes a presence packet. UNAVAILABLE and ERROR packets remove the sending sesssion.

Parameters:
presence - the presence packet.
remoteJID - the sender.

processRPCStyleIQ

protected void processRPCStyleIQ(IQ iq,
                                 String remoteJID)
Processes a normal, i.e. non-document-request IQ.

Parameters:
iq - the IQ packet
remoteJID - the sender

processIncomingMessage

protected void processIncomingMessage(Message message,
                                      String remoteJID)
Processes an incoming message.

Parameters:
message - the message
remoteJID - the remote JID

processDocRequestIQ

protected void processDocRequestIQ(DocRequestIQ docRequest,
                                   String remoteJID)
Process a document request IQ.

Parameters:
docRequest - the document request.
remoteJID - the sender.

processDocumentRequest

public abstract Element processDocumentRequest(String remoteJID,
                                               String path,
                                               Map parameters)
Should be overridden. Should return something based on XMPPUtils.newDocResponseElement().

Parameters:
remoteJID - the document requester
path - the path of the request
parameters - the paramters. Keyed with strings, Values are strings or elements.
Returns:
the document response element.

newSession

protected GradientSession newSession()
Creates a new session. Should be overridden to return an extension of GradientSession if you want to do anything useful at the session level.

Returns:
a new session.