Package org.astrogrid.samp
Class Response
java.lang.Object
java.util.AbstractMap
org.astrogrid.samp.SampMap
org.astrogrid.samp.Response
- All Implemented Interfaces:
Map
Represents an encoded SAMP response.
- Since:
- 14 Jul 2008
- Author:
- Mark Taylor
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Key for error map.static final String
STATUS_KEY
value indicating failure.static final String
STATUS_KEY
value indicating success.static final String
Key for result map.static final String
Key for response status.static final String
STATUS_KEY
value indicating partial success. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Response
asResponse
(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
(Map result) Returns a new response which is a success.Returns the error object.Returns the result map.Returns the status value.boolean
isOK()
Indicates whether the result was an unequivocal success.void
setErrInfo
(Map errInfo) Sets the error object.void
Sets the result map.void
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
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
STATUS_KEY
- See Also:
-
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:
-
ERROR_KEY
Key for error map. Only present in case of failure (or warning).- See Also:
-
OK_STATUS
STATUS_KEY
value indicating success.- See Also:
-
WARNING_STATUS
STATUS_KEY
value indicating partial success.- See Also:
-
ERROR_STATUS
STATUS_KEY
value indicating failure.- See Also:
-
-
Constructor Details
-
Response
public Response()Constructs an empty response. -
Response
Constructs a response based on an existing map.- Parameters:
map
- map containing initial data for this object
-
Response
Constructs a response with given status, result and error.- Parameters:
status
-STATUS_KEY
valueresult
-RESULT_KEY
valueerrinfo
-ERROR_KEY
value
-
-
Method Details
-
setStatus
Sets the status value.- Parameters:
status
-STATUS_KEY
value
-
getStatus
Returns the status value.- Returns:
STATUS_KEY
value
-
setResult
Sets the result map.- Parameters:
result
-RESULT_KEY
value
-
getResult
Returns the result map.- Returns:
RESULT_KEY
value
-
setErrInfo
Sets the error object.- Parameters:
errInfo
-ERROR_KEY
value- See Also:
-
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
Returns a new response which is a success.- Parameters:
result
- key-value map representing results of successful call- Returns:
- new success response
-
createErrorResponse
Returns a new response which is an error.- Parameters:
errinfo
- error information- Returns:
- new error response
-
asResponse
Returns a map as a Response object.- Parameters:
map
- map- Returns:
- response
-