com.jayway.android.robotium.remotecontrol.client.processor
Class AbstractProcessor

java.lang.Object
  extended by com.jayway.android.robotium.remotecontrol.client.processor.AbstractProcessor
All Implemented Interfaces:
ProcessorInterface
Direct Known Subclasses:
SAFSProcessor, SoloProcessor

public abstract class AbstractProcessor
extends java.lang.Object
implements ProcessorInterface


Field Summary
protected  int INITIAL_CACHE_SIZE
           
protected  java.lang.String remoteCommand
          The command from the 'reomote solo'
static java.lang.String TAG
           
protected  AbstractTestRunner testRunner
          A TestRunner by definition is already a DebugListener.
 
Constructor Summary
AbstractProcessor(AbstractTestRunner testRunner)
           
 
Method Summary
protected  java.lang.String convertToDelimitedString(java.lang.String[] items)
          Convert the array to a single string of separated values.
protected  java.lang.String convertToKey(java.util.Hashtable cache, java.lang.Object item)
          Convert a item to a unique key.
If the cache contain the item, return the cached key directly.
Else, generate a new unique key and put the item into cache with that key
then return the key.
protected  java.lang.String[] convertToKeys(java.util.Hashtable cache, java.util.List itemsList)
          Convert a list of engine-specific objects to an array of unique keys in the cache.
protected  java.lang.String[] convertToKeys(java.util.Hashtable cache, java.lang.Object[] items)
          Convert an array of engine-specific objects to an array of unique keys in the cache.
protected  void debug(java.lang.String message)
          Forward debug messages to our testRunner which may or may not have debug enabled for performance reasons.
protected  java.lang.Object getCachedItem(java.util.Hashtable cache, java.lang.Object key)
          Attempts to retrieve an item from cache using the provided key.
protected  java.lang.String getStackTrace(java.lang.Throwable x)
          Create a String from a Throwable suitable for debug output that provides comparable information to x.printStackTrace();
static java.lang.String getUniqueSeparator(java.lang.String afield)
          Return a usable single character separator string that does NOT exist in the provided field.
protected  java.lang.String makeUniqueCacheKey(java.lang.Object item)
          Routine is used to create a unique ID String key that can be used by external processes like Process Container to identify an engine-specific item in the cache.
This method is thread-safe: it guarantees that multiple threads can get unique ID.
 MessageResult processMessage(java.lang.String message)
           
 void processProperties(java.util.Properties props)
          Before calling this method, you may need to call setRemoteCommand()
protected  void putCachedItem(java.util.Hashtable cache, java.lang.Object key, java.lang.Object item)
          Attempts to put an item in cache using the provided key.
protected  java.lang.Object removeCachedItem(java.util.Hashtable cache, java.lang.Object key)
          Remove an item from cache.
 void resetExternalModeCache(java.util.Hashtable cache)
          Clear and\or reset the internal component cache used in non-typical modes of operation like MODE_EXTERNAL_PROCESSING (Process Container).
protected  void setGeneralError(java.util.Properties props, java.lang.String resultInfo)
          set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
Note: This method will concatenate remoteCommand with 'resultInfo', then with
SoloMessage.RESULT_INFO_GENERAL_FAIL
and set this string to remoteresultinfo
protected  void setGeneralError(java.util.Properties props, java.lang.String resultInfo, java.lang.String errorMessage)
          set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
set the errormsg to the string given by parameter errorMessage
Note: This method will concatenate remoteCommand with 'resultInfo', then with
SoloMessage.RESULT_INFO_GENERAL_FAIL
and set this string to remoteresultinfo
protected  void setGeneralErrorWithSpecialInfo(java.util.Properties props, java.lang.String resultInfo)
          set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
set the remoteresultinfo to the string given by parameter resultInfo
Note: If remoteresultinfo should contain result of a predefined or unmodified format you MUST call this method.
protected  void setGeneralErrorWithSpecialInfo(java.util.Properties props, java.lang.String resultInfo, java.lang.String errorMessage)
          set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
set the errormsg to the string given by parameter errorMessage
Note: If remoteresultinfo should contain result of 'predefined format', you MUST call this method.
protected  void setGeneralSuccess(java.util.Properties props)
          Call to set a "<command> : successful" result into the properties object.
protected  void setGeneralSuccess(java.util.Properties props, java.lang.String resultInfo)
          Call to set a "<command> : <resultInfo> successful." result into the properties object.
protected  void setGeneralSuccessWithSpecialInfo(java.util.Properties props, java.lang.String resultInfo)
          Call to set a "<resultInfo>" remoteresultinfo into the properties object unmodified.
protected  void setGeneralWarningWithSpecialInfo(java.util.Properties props, java.lang.String resultInfo)
          Call to set a "<resultInfo>" remoteresultinfo into the properties object unmodified.
 void setRemoteCommand(java.lang.String remoteCommand)
           
static boolean stringIsMatched(java.lang.String string1, java.lang.String string2, boolean partial, boolean caseSensitive)
          Test if the second string match with the first string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

public static java.lang.String TAG

remoteCommand

protected java.lang.String remoteCommand
The command from the 'reomote solo'


testRunner

protected AbstractTestRunner testRunner
A TestRunner by definition is already a DebugListener. This field can serve as both, if desired.


INITIAL_CACHE_SIZE

protected int INITIAL_CACHE_SIZE
Constructor Detail

AbstractProcessor

public AbstractProcessor(AbstractTestRunner testRunner)
Method Detail

debug

protected void debug(java.lang.String message)
Forward debug messages to our testRunner which may or may not have debug enabled for performance reasons.

This method will NOT add any prefix or suffix to the message. It is the responsibility of the caller to provide the complete message to be logged. This is to prevent cases where debugPrefix is NOT used or changed by the caller and incorrect debug output occurs.


getStackTrace

protected java.lang.String getStackTrace(java.lang.Throwable x)
Create a String from a Throwable suitable for debug output that provides comparable information to x.printStackTrace();

Parameters:
x -
Returns:
String ready for output to debug(String) or other sink.

processProperties

public void processProperties(java.util.Properties props)
Before calling this method, you may need to call setRemoteCommand()

Specified by:
processProperties in interface ProcessorInterface
See Also:
ProcessorInterface.processProperties(Properties)

processMessage

public MessageResult processMessage(java.lang.String message)
Specified by:
processMessage in interface ProcessorInterface
See Also:
ProcessorInterface.processMessage(String)

setRemoteCommand

public void setRemoteCommand(java.lang.String remoteCommand)
Specified by:
setRemoteCommand in interface ProcessorInterface
See Also:
ProcessorInterface.setRemoteCommand(String)

setGeneralSuccess

protected void setGeneralSuccess(java.util.Properties props)
Call to set a "<command> : successful" result into the properties object.

set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_OK_STRING
Note: This method will concatenate remoteCommand with
SoloMessage.RESULT_INFO_GENERAL_SUCCESS
and set this string to remoteresultinfo

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be modified and set to remoteresultinfo of props.

setGeneralSuccess

protected void setGeneralSuccess(java.util.Properties props,
                                 java.lang.String resultInfo)
Call to set a "<command> : <resultInfo> successful." result into the properties object.

set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_OK_STRING
Note: This method will concatenate remoteCommand with 'resultInfo', then with
SoloMessage.RESULT_INFO_GENERAL_SUCCESS
and set this string to remoteresultinfo

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be modified and set to remoteresultinfo of props.

setGeneralSuccessWithSpecialInfo

protected void setGeneralSuccessWithSpecialInfo(java.util.Properties props,
                                                java.lang.String resultInfo)
Call to set a "<resultInfo>" remoteresultinfo into the properties object unmodified. set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_OK_STRING
set the remoteresultinfo to the string given by parameter resultInfo
Note: If remoteresultinfo should contain a result of a predefined or unmodified format you MUST call this method.

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be set unmodified to remoteresultinfo of props.

setGeneralWarningWithSpecialInfo

protected void setGeneralWarningWithSpecialInfo(java.util.Properties props,
                                                java.lang.String resultInfo)
Call to set a "<resultInfo>" remoteresultinfo into the properties object unmodified. set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_WARN_STRING
set the remoteresultinfo to the string given by parameter resultInfo
Note: If remoteresultinfo should contain a result of a predefined or unmodified format you MUST call this method.

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be set unmodified to remoteresultinfo of props.

setGeneralError

protected void setGeneralError(java.util.Properties props,
                               java.lang.String resultInfo)
set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
Note: This method will concatenate remoteCommand with 'resultInfo', then with
SoloMessage.RESULT_INFO_GENERAL_FAIL
and set this string to remoteresultinfo

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be modified and set to remoteresultinfo of props.

setGeneralError

protected void setGeneralError(java.util.Properties props,
                               java.lang.String resultInfo,
                               java.lang.String errorMessage)
set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
set the errormsg to the string given by parameter errorMessage
Note: This method will concatenate remoteCommand with 'resultInfo', then with
SoloMessage.RESULT_INFO_GENERAL_FAIL
and set this string to remoteresultinfo

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be set to resultinfo of props.
errorMessage - The error message to be set to errormessage of props. Null if no error message is to be sent.

setGeneralErrorWithSpecialInfo

protected void setGeneralErrorWithSpecialInfo(java.util.Properties props,
                                              java.lang.String resultInfo)
set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
set the remoteresultinfo to the string given by parameter resultInfo
Note: If remoteresultinfo should contain result of a predefined or unmodified format you MUST call this method.

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be set unmodified to remoteresultinfo of props.

setGeneralErrorWithSpecialInfo

protected void setGeneralErrorWithSpecialInfo(java.util.Properties props,
                                              java.lang.String resultInfo,
                                              java.lang.String errorMessage)
set the isremoteresult to "true"
set the remoteresultcode to a constant code Message.STATUS_REMOTERESULT_FAIL_STRING
set the errormsg to the string given by parameter errorMessage
Note: If remoteresultinfo should contain result of 'predefined format', you MUST call this method.

Parameters:
props - The Properties object containing the in and out parameters
resultInfo - The result information to be set unmodified to resultinfo of props.
errorMessage - The error message to be set to errormessage of props. Null if no error message is to be sent.

resetExternalModeCache

public void resetExternalModeCache(java.util.Hashtable cache)
Clear and\or reset the internal component cache used in non-typical modes of operation like MODE_EXTERNAL_PROCESSING (Process Container).

Parameters:
cache - Hashtable, MUST be an initialized object
See Also:
makeUniqueCacheKey(Object), putCachedItem(Hashtable, Object, Object), getCachedItem(Hashtable, Object), removeCachedItem(Hashtable, Object)

getCachedItem

protected java.lang.Object getCachedItem(java.util.Hashtable cache,
                                         java.lang.Object key)
Attempts to retrieve an item from cache using the provided key. If not found will attempt to use key as-is. If not found will return key as-is.

Parameters:
cache - Hashtable, MUST be an initialized object
key - Object to use as lookup reference into cache
Returns:
Object stored in cache or null.
See Also:
makeUniqueCacheKey(Object), putCachedItem(Hashtable, Object, Object), removeCachedItem(Hashtable, Object)

removeCachedItem

protected java.lang.Object removeCachedItem(java.util.Hashtable cache,
                                            java.lang.Object key)
Remove an item from cache. Will attempt to use key as-is.

Parameters:
cache - Hashtable, MUST be an initialized object
key - Object to use as lookup reference into cache
Returns:
the Object removed or null if not found.
See Also:
makeUniqueCacheKey(Object), getCachedItem(Hashtable, Object), putCachedItem(Hashtable, Object, Object)

putCachedItem

protected void putCachedItem(java.util.Hashtable cache,
                             java.lang.Object key,
                             java.lang.Object item)
Attempts to put an item in cache using the provided key.

Parameters:
cache - Hashtable, MUST be an initialized object
key - Object to use as lookup reference into cache.
item - Item to store in the cache.
Throws:
java.lang.IllegalArgumentException - if either cache or key or item is null.
See Also:
makeUniqueCacheKey(Object), getCachedItem(Hashtable, Object), removeCachedItem(Hashtable, Object)

convertToKeys

protected java.lang.String[] convertToKeys(java.util.Hashtable cache,
                                           java.util.List itemsList)
Convert a list of engine-specific objects to an array of unique keys in the cache. The items will be stored in the cache using the unique keys.

Parameters:
cache - Hashtable, MUST be an initialized object
itemsList - List of objects to store in the cache.
Returns:
an array of String keys used to retrieve the items from the cache.
See Also:
convertToKeys(Hashtable, Object[])

convertToKeys

protected java.lang.String[] convertToKeys(java.util.Hashtable cache,
                                           java.lang.Object[] items)
Convert an array of engine-specific objects to an array of unique keys in the cache. The items will be stored in the cache using the unique keys.

Parameters:
cache - Hashtable, MUST be an initialized object
items - Array of objects to store in the cache.
Returns:
an array of String keys used to retrieve the items from the cache.
See Also:
convertToKey(Hashtable, Object), makeUniqueCacheKey(Object), getCachedItem(Hashtable, Object), putCachedItem(Hashtable, Object, Object)

convertToKey

protected java.lang.String convertToKey(java.util.Hashtable cache,
                                        java.lang.Object item)
Convert a item to a unique key.
If the cache contain the item, return the cached key directly.
Else, generate a new unique key and put the item into cache with that key
then return the key.

Parameters:
cache - Hashtable, MUST be an initialized object
items - Array of objects to store in the cache.
Returns:
String key used to retrieve the item from the cache.
See Also:
makeUniqueCacheKey(Object), getCachedItem(Hashtable, Object), putCachedItem(Hashtable, Object, Object)

makeUniqueCacheKey

protected java.lang.String makeUniqueCacheKey(java.lang.Object item)
Routine is used to create a unique ID String key that can be used by external processes like Process Container to identify an engine-specific item in the cache.
This method is thread-safe: it guarantees that multiple threads can get unique ID.

Parameters:
item - to be stored in cache.
Returns:
unique String suitable to be the key for the item.
See Also:
putCachedItem(Hashtable, Object, Object), getCachedItem(Hashtable, Object), removeCachedItem(Hashtable, Object)

getUniqueSeparator

public static java.lang.String getUniqueSeparator(java.lang.String afield)
Return a usable single character separator string that does NOT exist in the provided field. Tries each character in SEPS array.

Parameters:
afield - String field to keep intact.
Returns:
unique String separator that does NOT exist in afield.

convertToDelimitedString

protected java.lang.String convertToDelimitedString(java.lang.String[] items)
                                             throws ProcessorException
Convert the array to a single string of separated values. The first character in the returned string defines the delimiter used to separate the items. If there are no items in the provided array (length==0) then we return a 0-length (empty) String.

Parameters:
items -
Returns:
character delimited String of fields
Throws:
ProcessorException
See Also:
getUniqueSeparator(String)

stringIsMatched

public static boolean stringIsMatched(java.lang.String string1,
                                      java.lang.String string2,
                                      boolean partial,
                                      boolean caseSensitive)
Test if the second string match with the first string.

Parameters:
string1, - String, the first string
string2, - String, the second string
partial - boolean, if the comparison is partial match.
caseSensitive - boolean, if the comparison is case sensitive.