net.anotheria.maf.json
Class JSONResponse

java.lang.Object
  extended by net.anotheria.maf.json.JSONResponse
All Implemented Interfaces:
Serializable, JSONErrorScope

public class JSONResponse
extends Object
implements JSONErrorScope

JSON error response.

Author:
Alexandr Bolbat
See Also:
Serialized Form

Field Summary
static String ERRORS_SCOPE_GLOBAL_ERRORS
          Errors scope global errors.
static String ROOT_COMMANDS_SCOPE
          Commands root scope.
static String ROOT_DATA_SCOPE
          Data root scope.
static String ROOT_ERRORS_SCOPE
          Errors root scope.
static String STATUS_JSON_FIELD
          Status json field name.
 
Constructor Summary
JSONResponse()
          Default constructor.
 
Method Summary
 void addCommand(String name, String param)
          Add command to response.
 void addError(String error)
          Add global error for this response-scope.
 void addError(String fieldName, String error)
          Add field error for this response-scope.
 void addRawData(String key, String value)
          Add some raw data to response.
 boolean equals(Object obj)
           
 JSONErrorScope getErrorObject(String objectName)
          Get error object to error scope.
 Map<String,String> getRawData()
          Get response raw data
 boolean hasErrors()
          Is response have errors.
 int hashCode()
           
 void setData(org.json.JSONObject aData)
          Set response data.
 org.json.JSONObject toJSON()
          Convert response to JSONObject.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STATUS_JSON_FIELD

public static final String STATUS_JSON_FIELD
Status json field name.

See Also:
Constant Field Values

ROOT_DATA_SCOPE

public static final String ROOT_DATA_SCOPE
Data root scope.

See Also:
Constant Field Values

ROOT_COMMANDS_SCOPE

public static final String ROOT_COMMANDS_SCOPE
Commands root scope.

See Also:
Constant Field Values

ROOT_ERRORS_SCOPE

public static final String ROOT_ERRORS_SCOPE
Errors root scope.

See Also:
Constant Field Values

ERRORS_SCOPE_GLOBAL_ERRORS

public static final String ERRORS_SCOPE_GLOBAL_ERRORS
Errors scope global errors.

See Also:
Constant Field Values
Constructor Detail

JSONResponse

public JSONResponse()
Default constructor.

Method Detail

setData

public void setData(org.json.JSONObject aData)
Set response data.

Parameters:
aData - - response data

addRawData

public void addRawData(String key,
                       String value)
Add some raw data to response.

Parameters:
key - - key
value - - value

getRawData

public Map<String,String> getRawData()
Get response raw data

Returns:
Map with raw data

addCommand

public void addCommand(String name,
                       String param)
Add command to response.

Parameters:
name - - command name
param - - command parameter

addError

public void addError(String error)
Description copied from interface: JSONErrorScope
Add global error for this response-scope.

Specified by:
addError in interface JSONErrorScope
Parameters:
error - - error text

addError

public void addError(String fieldName,
                     String error)
Description copied from interface: JSONErrorScope
Add field error for this response-scope.

Specified by:
addError in interface JSONErrorScope
Parameters:
fieldName - - field name
error - - error text

getErrorObject

public JSONErrorScope getErrorObject(String objectName)
Description copied from interface: JSONErrorScope
Get error object to error scope. New instance will be created if object not found in errors scope.

Specified by:
getErrorObject in interface JSONErrorScope
Parameters:
objectName - - inner error object name in error scope
Returns:
JSONErrorScope

hasErrors

public boolean hasErrors()
Is response have errors.

Returns:
true if have or false

toJSON

public org.json.JSONObject toJSON()
Convert response to JSONObject.

Returns:
JSONObject

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2010-2013 anotheria.net. All Rights Reserved.