net.ex_337.xmpp.fwork
Class GradientSession

java.lang.Object
  extended bynet.ex_337.xmpp.fwork.GradientSession
Direct Known Subclasses:
DemoGradientSession

public class GradientSession
extends Object

Represents an XMPP session. Created on first document request, destroyed when the client goes offline.

Author:
Ian

Field Summary
protected  String remoteJID
          The remote JID of the client that owns this session.
protected  BaseGradientService service
          The service this session was created from
protected  Map threadIDs
          A map of thread IDs.
protected  org.jivesoftware.smack.XMPPConnection xmppConnection
          The XMPPConnection this session was loaded from.
 
Constructor Summary
GradientSession()
          The default constructor.
 
Method Summary
 void addThread(String threadID, String path)
          The method called by BaseGradientService when a new thread is created.
 void closeThreads()
          Closes all threads for this session.
 void destroy()
          Blank method for cleaning up code.
 String getPath(String threadID)
          Returns the path of the document with this thread ID.
 String getRemoteJID()
           
 void init()
          Blank method to override for initialisation code.
 Element processIQ(IQ.Type type, String threadID, Element element)
          Called when the client sends an IQ to the server.
 void processMessage(String threadID, List elements)
          The method called when a client document sends a message to the server.
 void removeThread(String threadID)
          The method called by BaseGradientService when a thread is removed.
 Element sendIQ(IQ.Type type, String threadID, Element element)
          Sends an IQ to the JID behind htis session
 void sendMessage(String threadID, List elements)
          Sends a message to the client.
 void setRemoteJID(String newRemoteJID)
          Sets the remote JID.
 void setService(BaseGradientService service)
          Sets the service that created this application.
 void setXMPPConnection(org.jivesoftware.smack.XMPPConnection newXMPPConnection)
          Sets the XMPP connection to use when responding to Packets passed to this session
protected  void threadAdded(String threadID, String path)
          Blank method to override if you want to know when a thread is added.
protected  void threadRemoved(String threadID, String path)
          Blank method to override if you want to know when a thread is removed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

remoteJID

protected String remoteJID
The remote JID of the client that owns this session.


threadIDs

protected Map threadIDs
A map of thread IDs. Keyed with the thread ID, value is the path.


xmppConnection

protected org.jivesoftware.smack.XMPPConnection xmppConnection
The XMPPConnection this session was loaded from.


service

protected BaseGradientService service
The service this session was created from

Constructor Detail

GradientSession

public GradientSession()
The default constructor.

Method Detail

setRemoteJID

public void setRemoteJID(String newRemoteJID)
Sets the remote JID. Can also be thought of as the "Reply-to" of a session, but I haven't tested using it like that.

Parameters:
newRemoteJID - the new JID.

setXMPPConnection

public void setXMPPConnection(org.jivesoftware.smack.XMPPConnection newXMPPConnection)
Sets the XMPP connection to use when responding to Packets passed to this session

Parameters:
newXMPPConnection - the XMPP Connection.

setService

public void setService(BaseGradientService service)
Sets the service that created this application.

Parameters:
service - the service.

getRemoteJID

public String getRemoteJID()
Returns:
the remoteJID.

sendIQ

public Element sendIQ(IQ.Type type,
                      String threadID,
                      Element element)
Sends an IQ to the JID behind htis session

Parameters:
type - the IQ type
threadID - the thread ID of the document that needs to respond to this IQ.
element - the IQ element
Returns:
the element returned by the client.

sendMessage

public void sendMessage(String threadID,
                        List elements)
Sends a message to the client.

Parameters:
threadID - The thread ID of the document that should receive this thread.
elements - the elemnts to send.

addThread

public final void addThread(String threadID,
                            String path)
The method called by BaseGradientService when a new thread is created. Calls threadAdded.

Parameters:
threadID - the new thread
path - the new path

removeThread

public final void removeThread(String threadID)
The method called by BaseGradientService when a thread is removed. calls threadRemoved

Parameters:
threadID - the thread.

getPath

public String getPath(String threadID)
Returns the path of the document with this thread ID.

Parameters:
threadID - the thread ID
Returns:
the path of this document

processIQ

public Element processIQ(IQ.Type type,
                         String threadID,
                         Element element)
Called when the client sends an IQ to the server. By default returns a 501 not implemented error.

Parameters:
type - the IQ type
threadID - the thread ID of the document that sent the IQ
element - the element recieved
Returns:
unless overridden (hint hint) returna s 501 not implemented message.

processMessage

public void processMessage(String threadID,
                           List elements)
The method called when a client document sends a message to the server.

Parameters:
threadID - the thread ID of the document that send the message
elements - the elements of the message.

threadAdded

protected void threadAdded(String threadID,
                           String path)
Blank method to override if you want to know when a thread is added.

Parameters:
threadID - the new thread
path - the new path

threadRemoved

protected void threadRemoved(String threadID,
                             String path)
Blank method to override if you want to know when a thread is removed.

Parameters:
threadID - the thread
path - the path

init

public void init()
Blank method to override for initialisation code.


destroy

public void destroy()
Blank method for cleaning up code.


closeThreads

public final void closeThreads()
Closes all threads for this session.


toString

public String toString()
Returns:
the class and remote JID for this session