com.bigllc.retsiq.simpleclient
Class AbstractSearchResponseHandler

java.lang.Object
  extended by com.bigllc.retsiq.simpleclient.AbstractSearchResponseHandler
All Implemented Interfaces:
SearchResponseHandler
Direct Known Subclasses:
DelimitedSearchResponseHandler, RawOutputResponseHandler, RecordCollectionResponseHandler

public abstract class AbstractSearchResponseHandler
extends java.lang.Object
implements SearchResponseHandler

Abstract handler for search responses. This class provides some simple processing of responses that derived handlers may find useful. Such as counting records and providing lookup of fields by field name.

Handlers derived from this can override the Child methods. So rather than trying to override data() they should override dataChild().

Author:
Marc G. Smith

Field Summary
protected  java.util.Map<java.lang.String,java.lang.Integer> columnNameIndex
           
protected  java.util.List<java.lang.String> columns
           
protected  java.util.List<java.lang.String> currentRow
           
protected  boolean hasMoreRecords
           
protected  java.lang.String path
           
protected  java.lang.String query
           
protected  int recordCount
           
protected  int recordsInResponse
           
protected  java.lang.String responseDelimiter
           
protected  java.lang.String responseDelimiterHex
           
protected  java.util.List<java.lang.String> select
           
protected  RETSUserSession session
           
 
Constructor Summary
AbstractSearchResponseHandler()
           
 
Method Summary
 void columns(java.util.List<java.lang.String> columns)
          If results are returned then this method is called with the column headers returned.
protected  void columnsChild(java.util.List<java.lang.String> columns)
          Override this method if derived handler wants to receive notification of columns().
 void count(int count)
          If a count was returned in the search response.
protected  void countChild(int count)
          Override this method if derived handler wants to receive notification of count().
 void data(java.util.List<java.lang.String> fields)
          If results are returned then the this method is called for each record returned.
protected abstract  void dataChild(SearchRecord record)
          Override this method if derived handler wants to receive notification of data().
 void delimiter(java.lang.String hex)
          If a delimiter is specified in the response then this method is called with the byte delimiter as hexidecimal string.
protected  void delimiterChild(java.lang.String hex)
          Override this method if derived handler wants to receive notification of noRecordsFound().
 void done()
          On completion of processing of the search results or if a parsing error occurs then this called.
 java.util.List<java.lang.String> getColumns()
          Get the column headers returned with the search.
 boolean getHasMoreRecords()
          Returns true if the search results were a subset of the complete record set for the query.
 java.lang.String getPath()
          Get the path requested for the search.
 java.lang.String getQuery()
          Get the query requested for the search.
 int getRecordCount()
          Return the number of records that match the query.
 int getRecordsInResponse()
          Return the number of records processed in this search response.
 java.lang.String getResponseDelimiter()
          Get the delimiter for the record.
 java.lang.String getResponseDelimiterHex()
          Get the hex representation of the delimiter for the record.
 java.util.List<java.lang.String> getSelect()
          Get the columns requested for the search.
 RETSUserSession getSession()
          Get the user session used for the search.
 void hasMoreData()
          If the results returned have been limited by either the user or the server and more results are available then this method will be called.
protected  void hasMoreDataChild()
          Override this method if derived handler wants to receive notification of hasMoreData().
 void noRecordsFound()
          Callback when search was successful but specifically no records were found.
protected  void noRecordsFoundChild()
          Override this method if derived handler wants to receive notification of noRecordsFound().
 void responseCode(int code, java.lang.String text, java.lang.String description)
          Callback for search RETS response code.
 void setContext(RETSUserSession session, java.lang.String path, java.lang.String query, java.util.List<java.lang.String> select)
          Set the search context for the results being parsed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected RETSUserSession session

path

protected java.lang.String path

query

protected java.lang.String query

select

protected java.util.List<java.lang.String> select

columnNameIndex

protected java.util.Map<java.lang.String,java.lang.Integer> columnNameIndex

columns

protected java.util.List<java.lang.String> columns

currentRow

protected java.util.List<java.lang.String> currentRow

recordCount

protected int recordCount

recordsInResponse

protected int recordsInResponse

hasMoreRecords

protected boolean hasMoreRecords

responseDelimiterHex

protected java.lang.String responseDelimiterHex

responseDelimiter

protected java.lang.String responseDelimiter
Constructor Detail

AbstractSearchResponseHandler

public AbstractSearchResponseHandler()
Method Detail

getSelect

public java.util.List<java.lang.String> getSelect()
Description copied from interface: SearchResponseHandler
Get the columns requested for the search.

Specified by:
getSelect in interface SearchResponseHandler
Returns:
A list of columns that were requested. An empty list or null may be returned if all columns were specified.
See Also:
SearchResponseHandler.getSelect()

getPath

public java.lang.String getPath()
Description copied from interface: SearchResponseHandler
Get the path requested for the search.

Specified by:
getPath in interface SearchResponseHandler
Returns:
A search path as defined in RETSUserSession.
See Also:
SearchResponseHandler.getPath()

getQuery

public java.lang.String getQuery()
Description copied from interface: SearchResponseHandler
Get the query requested for the search.

Specified by:
getQuery in interface SearchResponseHandler
Returns:
The DMQL2 query.
See Also:
SearchResponseHandler.getQuery()

getSession

public RETSUserSession getSession()
Description copied from interface: SearchResponseHandler
Get the user session used for the search.

Specified by:
getSession in interface SearchResponseHandler
Returns:
The user session.
See Also:
SearchResponseHandler.getSession()

getColumns

public java.util.List<java.lang.String> getColumns()
Get the column headers returned with the search. The order of the list is maintained as per the search results. If no results or an error occurs then null will be returned.

Returns:
A list of column names or null if no records found.

getHasMoreRecords

public boolean getHasMoreRecords()
Returns true if the search results were a subset of the complete record set for the query. This could occur either because of a server side imposed limit or a limit being specified in the search.

The result can only be determined after all the records have been returned so should only be checked after a call to done() has been made.

Returns:
True if more records are available, false if all records have been returned.

getRecordCount

public int getRecordCount()
Return the number of records that match the query. This result done() has been made.

Returns:
The number of records in the response.

getRecordsInResponse

public int getRecordsInResponse()
Return the number of records processed in this search response. Because the results are streamed the result can only be determined after all the records have been processed so should only be checked after a call to done() has been made.

Specified by:
getRecordsInResponse in interface SearchResponseHandler
Returns:
The number of records in the response.

getResponseDelimiter

public java.lang.String getResponseDelimiter()
Get the delimiter for the record. Defaults to 0x09 unless the delimiter is specified in the response.

Returns:
A single character string containing the delimiter character.

getResponseDelimiterHex

public java.lang.String getResponseDelimiterHex()
Get the hex representation of the delimiter for the record. Defaults to 09 unless the delimiter is specified in the response.

Returns:
The byte delimiter as a hexidecimal string.

noRecordsFoundChild

protected void noRecordsFoundChild()
Override this method if derived handler wants to receive notification of noRecordsFound().


delimiterChild

protected void delimiterChild(java.lang.String hex)
Override this method if derived handler wants to receive notification of noRecordsFound().


countChild

protected void countChild(int count)
Override this method if derived handler wants to receive notification of count().


columnsChild

protected void columnsChild(java.util.List<java.lang.String> columns)
                     throws RETSClientException
Override this method if derived handler wants to receive notification of columns().

Throws:
RETSClientException

dataChild

protected abstract void dataChild(SearchRecord record)
                           throws RETSClientException
Override this method if derived handler wants to receive notification of data().

Throws:
RETSClientException

hasMoreDataChild

protected void hasMoreDataChild()
Override this method if derived handler wants to receive notification of hasMoreData().


responseCode

public void responseCode(int code,
                         java.lang.String text,
                         java.lang.String description)
Description copied from interface: SearchResponseHandler
Callback for search RETS response code. A code of 0 represents search was successful, a code of 20201 means no records were found.

Specified by:
responseCode in interface SearchResponseHandler
Parameters:
code - The RETS response code.
text - The text associated with the response code.
description - An associated long description of the response code.
See Also:
SearchResponseHandler.responseCode(int, String, String)

noRecordsFound

public final void noRecordsFound()
Description copied from interface: SearchResponseHandler
Callback when search was successful but specifically no records were found.

Specified by:
noRecordsFound in interface SearchResponseHandler
See Also:
SearchResponseHandler.noRecordsFound()

count

public final void count(int count)
Description copied from interface: SearchResponseHandler
If a count was returned in the search response. This method will be called with the value. The count represents the number of records that match the query not necessarily the number of records in the response.

Specified by:
count in interface SearchResponseHandler
See Also:
SearchResponseHandler.count(int)

delimiter

public final void delimiter(java.lang.String hex)
Description copied from interface: SearchResponseHandler
If a delimiter is specified in the response then this method is called with the byte delimiter as hexidecimal string.

Specified by:
delimiter in interface SearchResponseHandler
Parameters:
hex - The byte delimiter as a hexidecimal string.
See Also:
SearchResponseHandler.delimiter(String)

columns

public final void columns(java.util.List<java.lang.String> columns)
                   throws RETSClientException
Description copied from interface: SearchResponseHandler
If results are returned then this method is called with the column headers returned. The order of the list is maintained as per the search results. If no results or an error occurs then this method will not be called.

Specified by:
columns in interface SearchResponseHandler
Parameters:
columns - A list of column names.
Throws:
RETSClientException
See Also:
SearchResponseHandler.columns(List)

data

public final void data(java.util.List<java.lang.String> fields)
                throws RETSClientException
Description copied from interface: SearchResponseHandler
If results are returned then the this method is called for each record returned. The order of the list is maintained as per the search results and will match the indexes of the list of column headers. If no results or an error occurs then this method will not be called.

Specified by:
data in interface SearchResponseHandler
Parameters:
fields - A list of the record fields.
Throws:
RETSClientException
See Also:
SearchResponseHandler.data(List)

hasMoreData

public final void hasMoreData()
Description copied from interface: SearchResponseHandler
If the results returned have been limited by either the user or the server and more results are available then this method will be called.

Specified by:
hasMoreData in interface SearchResponseHandler
See Also:
SearchResponseHandler.hasMoreData()

done

public void done()
Description copied from interface: SearchResponseHandler
On completion of processing of the search results or if a parsing error occurs then this called.

Specified by:
done in interface SearchResponseHandler
See Also:
SearchResponseHandler.done()

setContext

public void setContext(RETSUserSession session,
                       java.lang.String path,
                       java.lang.String query,
                       java.util.List<java.lang.String> select)
Description copied from interface: SearchResponseHandler
Set the search context for the results being parsed. This will be called by the parser and should not be called directly by any implementing classes.

Specified by:
setContext in interface SearchResponseHandler
Parameters:
session - The user session.
path - The search path.
query - The DMQL2 query.
select - The columns selected to be returned or null for all.
See Also:
SearchResponseHandler.setContext(RETSUserSession, String, String, List)