Home | History | Annotate | Download | only in rpc
      1 package autotest.moblab.rpc;
      2 
      3 import com.google.gwt.json.client.JSONObject;
      4 import com.google.gwt.json.client.JSONValue;
      5 
      6 /**
      7  * Base class for entities passing as parameters via the JSON RPC.
      8  */
      9 public abstract class JsonRpcEntity {
     10   public abstract void fromJson(JSONObject object);
     11 
     12   public abstract JSONObject toJson();
     13 
     14   protected static String getStringFieldOrDefault(JSONObject object, String field,
     15       String defaultValue) {
     16     JSONValue value = object.get(field);
     17     if (value != null && value.isString() != null) {
     18       return value.isString().stringValue();
     19     }
     20     return defaultValue;
     21   }
     22 
     23   protected static boolean getBooleanFieldOrDefault(JSONObject object, String field,
     24       boolean defaultValue) {
     25     JSONValue value = object.get(field);
     26     if (value != null && value.isBoolean() != null) {
     27       return value.isBoolean().booleanValue();
     28     }
     29     return defaultValue;
     30   }
     31 }
     32