mymobilesite.communication
Class LibertyProtocol

java.lang.Object
  extended by mymobilesite.communication.LibertyProtocol
All Implemented Interfaces:
java.lang.Runnable

public class LibertyProtocol
extends java.lang.Object
implements java.lang.Runnable

The LibertyProtocol class is responsible for coordinating the messages that are sent between the mobile phone and the Identity Provdier, Discovery Service and Web Service Provider.

Author:
Gunn Olaussen & Kirsti N. Torgersen

Field Summary
private  boolean abort
           
static int AUTHENTICATING_USER
          State constant indicating that the class is in the process of authenticating the user.
static int CONTACTING_IDP
          State constant indicating that the class is establishing the session with the Identity Provider.
private  int currentState
           
private  ResourceOffering discoResource
           
private  HttpTransport discoSession
           
static int DONE
          State constant indicating that the class has completed its tasks successfully.
private  java.lang.Thread executingThread
           
private  AuthTransport idpSession
           
private  LibertyProtocolListener listener
           
static int NOT_STARTED
          State constant indicating that the class has not yet started its work.
private  HttpTransport providerSession
           
private  java.lang.String pwd
           
static int REQUESTING_SERVICE
          State constant indicating that the class is requesting the service chosen by the user from the Web Service Provider.
private  ResourceOffering[] resourceOfferings
           
static int RETRIEVING_PROVIDER_LIST
          State constant indicating that the class is retrieving the list of resource offerings from the Discovery Service.
private  boolean running
           
private  java.lang.String un
           
private  int userchoice
           
 
Constructor Summary
LibertyProtocol(LibertyProtocolListener listener)
          The contstructor registers the listener and initialises the executing thread.
 
Method Summary
 void abort()
          This method can be called if the current operation of the LibertyProtocol class needs to be aborted for some reason.
 void establishIdpSession()
          This method causes the class to enter the CONTACTING_IDP state and starts the executing thread.
 void getProviders(java.lang.String un, java.lang.String pwd)
          This method causes the class to enter the AUTHENTICATING_USER state and starts the executing thread.
 void requestService(int userchoice)
          This method causes the class to enter the REQUESTING_SERVICE state and starts the executing thread.
 void retryDiscoQuery()
          In some cases the Controller will have to retry to retrieve the list of providers.
 void retryGetProviders()
          In some cases the Controller will have to retry the authentication.
 void run()
          This method takes care of the actual execution and performs tasks appropriate to the current state of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idpSession

private AuthTransport idpSession

discoSession

private HttpTransport discoSession

providerSession

private HttpTransport providerSession

discoResource

private ResourceOffering discoResource

resourceOfferings

private ResourceOffering[] resourceOfferings

listener

private LibertyProtocolListener listener

executingThread

private java.lang.Thread executingThread

NOT_STARTED

public static final int NOT_STARTED
State constant indicating that the class has not yet started its work.

See Also:
Constant Field Values

CONTACTING_IDP

public static final int CONTACTING_IDP
State constant indicating that the class is establishing the session with the Identity Provider.

See Also:
Constant Field Values

AUTHENTICATING_USER

public static final int AUTHENTICATING_USER
State constant indicating that the class is in the process of authenticating the user.

See Also:
Constant Field Values

RETRIEVING_PROVIDER_LIST

public static final int RETRIEVING_PROVIDER_LIST
State constant indicating that the class is retrieving the list of resource offerings from the Discovery Service.

See Also:
Constant Field Values

REQUESTING_SERVICE

public static final int REQUESTING_SERVICE
State constant indicating that the class is requesting the service chosen by the user from the Web Service Provider.

See Also:
Constant Field Values

DONE

public static final int DONE
State constant indicating that the class has completed its tasks successfully.

See Also:
Constant Field Values

currentState

private int currentState

abort

private boolean abort

running

private boolean running

un

private java.lang.String un

pwd

private java.lang.String pwd

userchoice

private int userchoice
Constructor Detail

LibertyProtocol

public LibertyProtocol(LibertyProtocolListener listener)
The contstructor registers the listener and initialises the executing thread.

Parameters:
listener - LibertyProtocolListener The listener that should be notified of events in this class.
Method Detail

abort

public void abort()
This method can be called if the current operation of the LibertyProtocol class needs to be aborted for some reason. It attempts to halt the execution by closing the input and output streams, which will cause the communication to fail and throw an exception.


establishIdpSession

public void establishIdpSession()
This method causes the class to enter the CONTACTING_IDP state and starts the executing thread.


getProviders

public void getProviders(java.lang.String un,
                         java.lang.String pwd)
This method causes the class to enter the AUTHENTICATING_USER state and starts the executing thread. If the authentication is succsessful the state will change to RETRIEVING_PROVIDER_LIST automatically.

Parameters:
un - String The username to be authenticated.
pwd - String The password provided by the user.

retryGetProviders

public void retryGetProviders()
In some cases the Controller will have to retry the authentication. If the credentials are the same as last time, it can call this method instead of the getProviders(un, pwd) method.


retryDiscoQuery

public void retryDiscoQuery()
In some cases the Controller will have to retry to retrieve the list of providers. If the authentication is valid, it can use this method to contact the Discovery Service once more. The class will then enter the RETRIEVING_PROVIDER_LIST directly.


requestService

public void requestService(int userchoice)
This method causes the class to enter the REQUESTING_SERVICE state and starts the executing thread. It will then try to contact the Web Service Provider chosen by the user.

Parameters:
userchoice - int The index of the WSP chosen by the user.

run

public void run()
This method takes care of the actual execution and performs tasks appropriate to the current state of the class. When the results are ready it notifies the listener by calling the resultsReady method. If it encounters an exception that was not caused by an abort, it notifies the listener with the encounteredException method.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()