Package org.astrogrid.samp
Class Response
- java.lang.Object
-
- java.util.AbstractMap
-
- org.astrogrid.samp.SampMap
-
- org.astrogrid.samp.Response
-
- All Implemented Interfaces:
java.util.Map
public class Response extends SampMap
Represents an encoded SAMP response.- Since:
- 14 Jul 2008
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringERROR_KEYKey for error map.static java.lang.StringERROR_STATUSSTATUS_KEYvalue indicating failure.static java.lang.StringOK_STATUSSTATUS_KEYvalue indicating success.static java.lang.StringRESULT_KEYKey for result map.static java.lang.StringSTATUS_KEYKey for response status.static java.lang.StringWARNING_STATUSSTATUS_KEYvalue indicating partial success.
-
Constructor Summary
Constructors Constructor Description Response()Constructs an empty response.Response(java.lang.String status, java.util.Map result, ErrInfo errinfo)Constructs a response with given status, result and error.Response(java.util.Map map)Constructs a response based on an existing map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ResponseasResponse(java.util.Map map)Returns a map as a Response object.voidcheck()Checks that this object is ready for use with the SAMP toolkit.static ResponsecreateErrorResponse(ErrInfo errinfo)Returns a new response which is an error.static ResponsecreateSuccessResponse(java.util.Map result)Returns a new response which is a success.ErrInfogetErrInfo()Returns the error object.java.util.MapgetResult()Returns the result map.java.lang.StringgetStatus()Returns the status value.booleanisOK()Indicates whether the result was an unequivocal success.voidsetErrInfo(java.util.Map errInfo)Sets the error object.voidsetResult(java.util.Map result)Sets the result map.voidsetStatus(java.lang.String status)Sets the status value.-
Methods inherited from class org.astrogrid.samp.SampMap
checkHasKeys, entrySet, getList, getMap, getString, getUrl, put
-
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
-
-
-
-
Field Detail
-
STATUS_KEY
public static final java.lang.String STATUS_KEY
- See Also:
- Constant Field Values
-
RESULT_KEY
public static final java.lang.String RESULT_KEY
Key for result map. This is a map of key-value pairs with semantics defined by the original message's MType. Only present in case of success (or warning).- See Also:
- Constant Field Values
-
ERROR_KEY
public static final java.lang.String ERROR_KEY
Key for error map. Only present in case of failure (or warning).- See Also:
- Constant Field Values
-
OK_STATUS
public static final java.lang.String OK_STATUS
STATUS_KEYvalue indicating success.- See Also:
- Constant Field Values
-
WARNING_STATUS
public static final java.lang.String WARNING_STATUS
STATUS_KEYvalue indicating partial success.- See Also:
- Constant Field Values
-
ERROR_STATUS
public static final java.lang.String ERROR_STATUS
STATUS_KEYvalue indicating failure.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Response
public Response()
Constructs an empty response.
-
Response
public Response(java.util.Map map)
Constructs a response based on an existing map.- Parameters:
map- map containing initial data for this object
-
Response
public Response(java.lang.String status, java.util.Map result, ErrInfo errinfo)Constructs a response with given status, result and error.- Parameters:
status-STATUS_KEYvalueresult-RESULT_KEYvalueerrinfo-ERROR_KEYvalue
-
-
Method Detail
-
setStatus
public void setStatus(java.lang.String status)
Sets the status value.- Parameters:
status-STATUS_KEYvalue
-
getStatus
public java.lang.String getStatus()
Returns the status value.- Returns:
STATUS_KEYvalue
-
setResult
public void setResult(java.util.Map result)
Sets the result map.- Parameters:
result-RESULT_KEYvalue
-
getResult
public java.util.Map getResult()
Returns the result map.- Returns:
RESULT_KEYvalue
-
setErrInfo
public void setErrInfo(java.util.Map errInfo)
Sets the error object.
-
getErrInfo
public ErrInfo getErrInfo()
Returns the error object.- Returns:
ERROR_KEYvalue as anErrInfo
-
isOK
public boolean isOK()
Indicates whether the result was an unequivocal success.- Returns:
- true iff
getStatus()==OK_STATUS
-
check
public void check()
Description copied from class:SampMapChecks that this object is ready for use with the SAMP toolkit. As well as callingSampUtils.checkMap(java.util.Map)(ensuring that all keys are Strings, and all values Strings, Lists or Maps), subclass-specific invariants may be checked. In the case that there's something wrong, an informativeDataExceptionwill be thrown.
-
createSuccessResponse
public static Response createSuccessResponse(java.util.Map result)
Returns a new response which is a success.- Parameters:
result- key-value map representing results of successful call- Returns:
- new success response
-
createErrorResponse
public static Response createErrorResponse(ErrInfo errinfo)
Returns a new response which is an error.- Parameters:
errinfo- error information- Returns:
- new error response
-
asResponse
public static Response asResponse(java.util.Map map)
Returns a map as a Response object.- Parameters:
map- map- Returns:
- response
-
-