/** Initialize sync scheme from json string */ public void init(String json) throws JSONException { JSONObject obj = new JSONObject(json); this.method = SyncMethod.valueOf(obj.getString("method")); this.format = SyncDataFormat.valueOf(obj.getString("dataFormat")); this.keySecret = obj.getString("kSecret"); this.keyFrom = obj.getString("kFrom"); this.keySentTimeStamp = obj.getString("kSentTimestamp"); this.keyMessage = obj.getString("kMessage"); this.keySentTo = obj.getString("kSentTo"); this.keyMessageID = obj.getString("kMessageID"); this.keyDeviceID = obj.getString("KDeviceID"); }
/** Get string JSON representation of this scheme */ public String toJSONString() { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("method", method.toString())); nameValuePairs.add(new BasicNameValuePair("dataFormat", format.toString())); nameValuePairs.add(new BasicNameValuePair("kSecret", keySecret)); nameValuePairs.add(new BasicNameValuePair("kFrom", keyFrom)); nameValuePairs.add(new BasicNameValuePair("kSentTimestamp", keySentTimeStamp)); nameValuePairs.add(new BasicNameValuePair("kMessage", keyMessage)); nameValuePairs.add(new BasicNameValuePair("kSentTo", keySentTo)); nameValuePairs.add(new BasicNameValuePair("kMessageID", keyMessageID)); nameValuePairs.add(new BasicNameValuePair("kDeviceID", keyDeviceID)); try { return DataFormatUtil.makeJSONString(nameValuePairs); } catch (JSONException ex) { return null; } }
@Override public String toString() { return "SyncScheme {" + "method:" + method.toString() + ", dataFormat:" + format.toString() + ", keys: [" + keyFrom + "," + keySecret + "," + keyMessage + "," + keySentTo + "," + keySentTimeStamp + "," + keyMessageID + "," + keyDeviceID + "] " + "}"; }