Package org.astrogrid.samp

# Class Response

java.lang.Object
java.util.AbstractMap
org.astrogrid.samp.SampMap
org.astrogrid.samp.Response

All Implemented Interfaces:
  `Map`

public class Response extends SampMap
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>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K,V>`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`ERROR_KEY`
Key for error map.
`static final String`
`ERROR_STATUS`
`STATUS_KEY` value indicating failure.
`static final String`
`OK_STATUS`
`STATUS_KEY` value indicating success.
`static final String`
`RESULT_KEY`
Key for result map.
`static final String`
`STATUS_KEY`
Key for response status.
`static final String`
`WARNING_STATUS`
`STATUS_KEY` value indicating partial success.

### Fields inherited from class org.astrogrid.samp.SampMap

`EMPTY`

## Constructor Summary

Constructors
Constructor
Description
`Response()`
Constructs an empty response.
`Response(String status, Map result, ErrInfo errinfo)`
Constructs a response with given status, result and error.
`Response(Map map)`
Constructs a response based on an existing map.

## Method Summary

Modifier and Type
Method
Description
`static 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.
`ErrInfo`
`getErrInfo()`
Returns the error object.
`Map`
`getResult()`
Returns the result map.
`String`
`getStatus()`
Returns the status value.
`boolean`
`isOK()`
Indicates whether the result was an unequivocal success.
`void`
`setErrInfo(Map errInfo)`
Sets the error object.
`void`
`setResult(Map result)`
Sets the result map.
`void`
`setStatus(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`

### 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

public static final String STATUS_KEY
Key for response status. May take one of the values `OK_STATUS`, `WARNING_STATUS` or `ERROR_STATUS`.

See Also:
  - Constant Field Values

### RESULT_KEY

public static final 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 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 String OK_STATUS
`STATUS_KEY` value indicating success.

See Also:
  - Constant Field Values

### WARNING_STATUS

public static final String WARNING_STATUS
`STATUS_KEY` value indicating partial success.

See Also:
  - Constant Field Values

### ERROR_STATUS

public static final String ERROR_STATUS
`STATUS_KEY` value indicating failure.

See Also:
  - Constant Field Values

## Constructor Details

### Response

public Response()
Constructs an empty response.

### Response

public Response(Map map)
Constructs a response based on an existing map.

Parameters:
  `map` - map containing initial data for this object

### Response

public Response(String status, Map result, ErrInfo errinfo)
Constructs a response with given status, result and error.

Parameters:
  `status` - `STATUS_KEY` value
  `result` - `RESULT_KEY` value
  `errinfo` - `ERROR_KEY` value

## Method Details

### setStatus

public void setStatus(String status)
Sets the status value.

Parameters:
  `status` - `STATUS_KEY` value

### getStatus

public String getStatus()
Returns the status value.

Returns:
  `STATUS_KEY` value

### setResult

public void setResult(Map result)
Sets the result map.

Parameters:
  `result` - `RESULT_KEY` value

### getResult

public Map getResult()
Returns the result map.

Returns:
  `RESULT_KEY` value

### setErrInfo

public void setErrInfo(Map errInfo)
Sets the error object.

Parameters:
  `errInfo` - `ERROR_KEY` value
See Also:
  - `ErrInfo`

### getErrInfo

public ErrInfo getErrInfo()
Returns the error object.

Returns:
  `ERROR_KEY` value as an `ErrInfo`

### 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 calling `SampUtils.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 informative `DataException` will be thrown.

Overrides:
  `check` in class `SampMap`

### createSuccessResponse

public static Response createSuccessResponse(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(Map map)
Returns a map as a Response object.

Parameters:
  `map` - map
Returns:
  response