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.String
ERROR_KEY
Key for error map.static java.lang.String
ERROR_STATUS
STATUS_KEY
value indicating failure.static java.lang.String
OK_STATUS
STATUS_KEY
value indicating success.static java.lang.String
RESULT_KEY
Key for result map.static java.lang.String
STATUS_KEY
Key for response status.static java.lang.String
WARNING_STATUS
STATUS_KEY
value 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 Response
asResponse(java.util.Map map)
Returns a map as a Response object.void
check()
Checks that this object is ready for use with the SAMP toolkit.static Response
createErrorResponse(ErrInfo errinfo)
Returns a new response which is an error.static Response
createSuccessResponse(java.util.Map result)
Returns a new response which is a success.ErrInfo
getErrInfo()
Returns the error object.java.util.Map
getResult()
Returns the result map.java.lang.String
getStatus()
Returns the status value.boolean
isOK()
Indicates whether the result was an unequivocal success.void
setErrInfo(java.util.Map errInfo)
Sets the error object.void
setResult(java.util.Map result)
Sets the result map.void
setStatus(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_KEY
value indicating success.- See Also:
- Constant Field Values
-
WARNING_STATUS
public static final java.lang.String WARNING_STATUS
STATUS_KEY
value indicating partial success.- See Also:
- Constant Field Values
-
ERROR_STATUS
public static final java.lang.String ERROR_STATUS
STATUS_KEY
value 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_KEY
valueresult
-RESULT_KEY
valueerrinfo
-ERROR_KEY
value
-
-
Method Detail
-
setStatus
public void setStatus(java.lang.String status)
Sets the status value.- Parameters:
status
-STATUS_KEY
value
-
getStatus
public java.lang.String getStatus()
Returns the status value.- Returns:
STATUS_KEY
value
-
setResult
public void setResult(java.util.Map result)
Sets the result map.- Parameters:
result
-RESULT_KEY
value
-
getResult
public java.util.Map getResult()
Returns the result map.- Returns:
RESULT_KEY
value
-
setErrInfo
public void setErrInfo(java.util.Map errInfo)
Sets the error object.
-
getErrInfo
public ErrInfo getErrInfo()
Returns the error object.- Returns:
ERROR_KEY
value 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:SampMap
Checks 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 informativeDataException
will 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
-
-