public class SearchResultBuffer extends java.util.Observable implements ResultHandler, java.util.Observer
This class extends class Observable, to implement the Observer pattern.
It requires the SearchResultListener from the GUI layer to implement the Observer interface, and register in this class to get notified when there are results being added into the buffer.
Constructor and Description |
---|
SearchResultBuffer() |
Modifier and Type | Method and Description |
---|---|
java.util.ArrayList<XMLDBModel> |
getResults()
Get the results stored in the buffer.
|
void |
handleIntermediateResults(java.util.List<XMLDBModel> intermediateResults,
ResultHandler resultHandler)
Handle the intermediate results found and passed by the other searchers
in the searchers chain.
|
void |
handleResults(java.util.ArrayList<XMLDBModel> modelResults)
Called by the other searcher to write the searched results
to this buffer.
|
boolean |
isSearchCancelled()
Check whether the searching process has been canceled by the user.
|
boolean |
isWholeSearchDone()
Check whether the all the searchers in the search chain have finished.
|
void |
passErrorModels(java.util.List<XMLDBModel> errorModels)
Handle the error models passed by the other searchers.
|
void |
setConnection(DBConnection connection)
Set the DB connection for this result handler.
|
void |
update(java.util.Observable observable,
java.lang.Object argument)
Implement the update method from the Observer interface.
|
void |
wholeSearchDone()
Notify the search result buffer that the searching is done.
|
public java.util.ArrayList<XMLDBModel> getResults()
public void handleIntermediateResults(java.util.List<XMLDBModel> intermediateResults, ResultHandler resultHandler)
The intermediate results are currently stored in a HashMap to distinguish the results passed by different searchers. This class can be extended later to fetch different intermediate searched results.
handleIntermediateResults
in interface ResultHandler
intermediateResults
- The intermediate results found in the other
searchers.resultHandler
- The result handler searcher that finds and passes
the intermediate results.public void handleResults(java.util.ArrayList<XMLDBModel> modelResults)
When the results are written to the buffer in this method, the buffer will notify its registered observers. The SearchResultListener, which should have registered in this buffer will be called to notify.
handleResults
in interface ResultHandler
modelResults
- The models results to be stored in this buffer.public boolean isSearchCancelled()
isSearchCancelled
in interface ResultHandler
public boolean isWholeSearchDone()
public void passErrorModels(java.util.List<XMLDBModel> errorModels)
For now, the passed error models are just stored in the buffer, but this class can be modified later to add more function for handling passed error models.
passErrorModels
in interface ResultHandler
errorModels
- The passed error models.public void setConnection(DBConnection connection)
setConnection
in interface ResultHandler
connection
- The DBConnection instance to be set in this result
handler.public void update(java.util.Observable observable, java.lang.Object argument)
update
in interface java.util.Observer
observable
- The object that this SearchResultBuffer is observing.
It is assumed that this SearchResultBuffer will only observe the
SearchResultFrame window.argument
- The argument passed to this SearcResultBuffer.public void wholeSearchDone() throws DBConnectionException
wholeSearchDone
in interface ResultHandler
DBConnectionException
- Thrown if the DB connection cannot be
obtained.