1 package autotest.moblab.rpc; 2 3 import com.google.gwt.json.client.JSONBoolean; 4 import com.google.gwt.json.client.JSONObject; 5 import com.google.gwt.json.client.JSONString; 6 import com.google.gwt.json.client.JSONValue; 7 8 /** 9 * Moblab RPC operation status. 10 */ 11 public class OperationStatus extends JsonRpcEntity { 12 public static final String JSON_FIELD_STATUS_OK = "status_ok"; 13 public static final String JSON_FIELD_STATUS_DETAILS = "status_details"; 14 15 private boolean ok; 16 private String details; 17 OperationStatus()18 public OperationStatus() { 19 this(true); 20 } 21 OperationStatus(boolean valid)22 public OperationStatus(boolean valid) { 23 this(valid, null); 24 } 25 OperationStatus(boolean valid, String details)26 public OperationStatus(boolean valid, String details) { 27 this.ok = valid; 28 this.details = details; 29 } 30 isOk()31 public boolean isOk() { 32 return ok; 33 } 34 getDetails()35 public String getDetails() { 36 return details; 37 } 38 39 @Override fromJson(JSONObject object)40 public void fromJson(JSONObject object) { 41 JSONValue value = object.get(OperationStatus.JSON_FIELD_STATUS_OK); 42 ok = value != null && value.isBoolean() != null && value.isBoolean().booleanValue(); 43 details = null; 44 value = object.get(OperationStatus.JSON_FIELD_STATUS_DETAILS); 45 if (value != null && value.isString() != null) { 46 details = value.isString().stringValue(); 47 } 48 } 49 50 @Override toJson()51 public JSONObject toJson() { 52 JSONObject object = new JSONObject(); 53 object.put(JSON_FIELD_STATUS_OK, JSONBoolean.getInstance(ok)); 54 if (details != null) { 55 object.put(JSON_FIELD_STATUS_DETAILS, new JSONString(details)); 56 } 57 return object; 58 } 59 } 60