net.agmodel.utilBean
Class RequestBean

java.lang.Object
  |
  +--net.agmodel.utilBean.RequestBean
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ChizuRequestBean, DEMSpatialRequestBean, MetRequestBean

public abstract class RequestBean
extends Object
implements Runnable

An invisible generic bean to handle the process of getting data from a broker.
Prompts the user to log in to datasources if necessary.
As getting data may be time-consuming, the broker is called in a separate thread.
Sends out IndeterminateEvents to registered listeners at the beginning and end of the process. The results of the call are sent to registered listeners (this part handled by descendant classes).


Field Summary
protected  GenericBrokerHTTP brokerHTTP
           
protected  GenericBrokerRMI brokerRMI
           
protected  ArrayList dataListeners
           
protected  ArrayList indeterminateListeners
           
protected  LogInDialog loginDialog
           
protected  Frame parent
           
protected static ResourceBundle rb
           
protected  Thread retrieveDataThread
           
protected  String sessionID
           
protected static ResourceBundle ub
           
 
Constructor Summary
RequestBean(Frame dialogParent)
          Creates a new RequestBean.
 
Method Summary
 void addDataListener(RequestBeanListener x)
           
 void addIndeterminateListener(IndeterminateListener x)
           
protected  boolean alreadyLoggedIn(String sessionID, String candidateDBID)
           
protected  void clearListeners()
           
protected  void fireDataArrivedEvent(ServerResult result)
           
protected  void fireDataRequestedEvent()
           
protected  void fireIndeterminateEvent(IndeterminateEvent evt)
          Notifies listeners that a task of unknown duration has started and enables or disables the button as appropriate
protected abstract  void fireSpecificEvent(RequestBeanListener listener, ServerResult result)
           
protected abstract  ServerResult getData(ServerRequest request)
          Implemented by descendant requestBeans to call the broker to get the data.
protected  DataSourceDetail[] listSourceDetails(String sessionID, GeographicalArea box)
           
protected  boolean login(DataSourceDetail sourceDetail)
          Prompt the user to log in to a database if necessary.
protected  boolean login(GeographicalArea area)
          Prompt the user to log in to any or all of the databases in the region
protected  boolean loginToDataSource(String sessionID, String databaseID, String username, String password)
           
protected abstract  ServerRequest makeRequest()
          Implemented by descendant requestBeans to create an appropriate request object for this kind of broker.
protected  boolean readyToRequest()
           
 void removeDataListener(RequestBeanListener x)
           
 void removeIndeterminateListener(IndeterminateListener x)
           
 void run()
          This method is public, but should not be called directly.
protected  void runRetrieveThread()
           
protected  void setUpBean()
           
protected abstract  boolean suitableLogin(ServerRequest request)
          Implemented by descendant requestBeans to select which login mechanism to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rb

protected static ResourceBundle rb

ub

protected static ResourceBundle ub

brokerRMI

protected transient volatile GenericBrokerRMI brokerRMI

brokerHTTP

protected transient volatile GenericBrokerHTTP brokerHTTP

sessionID

protected transient volatile String sessionID

retrieveDataThread

protected transient volatile Thread retrieveDataThread

indeterminateListeners

protected transient ArrayList indeterminateListeners

dataListeners

protected transient ArrayList dataListeners

loginDialog

protected transient LogInDialog loginDialog

parent

protected Frame parent
Constructor Detail

RequestBean

public RequestBean(Frame dialogParent)
Creates a new RequestBean.

Parameters:
dialogParent - a frame to own the login dialogs (use JOptionPane.getFrameForComponent() within applets)
Method Detail

setUpBean

protected void setUpBean()

clearListeners

protected void clearListeners()

runRetrieveThread

protected void runRetrieveThread()

fireIndeterminateEvent

protected void fireIndeterminateEvent(IndeterminateEvent evt)
Notifies listeners that a task of unknown duration has started and enables or disables the button as appropriate


addIndeterminateListener

public void addIndeterminateListener(IndeterminateListener x)

removeIndeterminateListener

public void removeIndeterminateListener(IndeterminateListener x)

fireDataRequestedEvent

protected void fireDataRequestedEvent()

fireDataArrivedEvent

protected void fireDataArrivedEvent(ServerResult result)

fireSpecificEvent

protected abstract void fireSpecificEvent(RequestBeanListener listener,
                                          ServerResult result)

addDataListener

public void addDataListener(RequestBeanListener x)

removeDataListener

public void removeDataListener(RequestBeanListener x)

readyToRequest

protected boolean readyToRequest()

loginToDataSource

protected boolean loginToDataSource(String sessionID,
                                    String databaseID,
                                    String username,
                                    String password)
                             throws RemoteException,
                                    GeneralException
RemoteException
GeneralException

alreadyLoggedIn

protected boolean alreadyLoggedIn(String sessionID,
                                  String candidateDBID)
                           throws RemoteException,
                                  GeneralException
RemoteException
GeneralException

listSourceDetails

protected DataSourceDetail[] listSourceDetails(String sessionID,
                                               GeographicalArea box)
                                        throws RemoteException,
                                               GeneralException
RemoteException
GeneralException

login

protected boolean login(DataSourceDetail sourceDetail)
                 throws RemoteException,
                        GeneralException
Prompt the user to log in to a database if necessary.

Parameters:
sourceDetail -
Returns:
true if the user doesn't need to log in, or if they logged in successfully.
Throws:
RemoteException
GeneralException

login

protected boolean login(GeographicalArea area)
                 throws RemoteException,
                        GeneralException
Prompt the user to log in to any or all of the databases in the region

Parameters:
area - the area of interest
Returns:
true if there was at least one database that didn't require log in, or if the user logged in to at least one database
Throws:
RemoteException
GeneralException

makeRequest

protected abstract ServerRequest makeRequest()
Implemented by descendant requestBeans to create an appropriate request object for this kind of broker.

Returns:
a request to be sent to the broker.

getData

protected abstract ServerResult getData(ServerRequest request)
                                 throws RemoteException,
                                        GeneralException
Implemented by descendant requestBeans to call the broker to get the data.
These beans can use brokerRMI if the connection is RMI, or brokerHTTP if the connection is via HTTP.

Returns:
a request to be sent to the broker.
RemoteException
GeneralException

suitableLogin

protected abstract boolean suitableLogin(ServerRequest request)
                                  throws RemoteException,
                                         GeneralException
Implemented by descendant requestBeans to select which login mechanism to use.
Should either called login(GeographicalArea) or login(String), depending on whether spatial request bean or data source request bean

Returns:
true if at least one database is accessible after the logging in process.
RemoteException
GeneralException

run

public void run()
This method is public, but should not be called directly. Instead call runRetrieveThread();

Specified by:
run in interface Runnable