
com.jelastic.api.system.persistence.Message Maven / Gradle / Ivy
/*Server class MD5: 8814a8cc2997c8659133342e17a9bb95*/
package com.jelastic.api.system.persistence;
import com.jelastic.api.development.response.interfaces.ArrayItem;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class Message extends ArrayItem {
private static final int DATA_VALUE_MAX_LENGTH = 2048;
public static final String DATA = "data";
public static final String ID = "id";
public static final String TYPE = "type";
public static final String ACTION_ID = "actionId";
public static final String ACTION = "action";
private MessageType type;
private Integer actionId;
private String action;
private String data;
public Message() {
}
public Message(MessageType type, Integer actionId) {
this.type = type;
this.actionId = actionId;
}
public Message(MessageType type, Integer actionId, String action) {
this.type = type;
this.actionId = actionId;
this.action = action;
}
public Message(MessageType type, Integer actionId, String action, String data) {
this.type = type;
this.actionId = actionId;
this.action = action;
this.data = data;
}
public MessageType getType() {
return type;
}
public void setType(MessageType type) {
this.type = type;
}
public Integer getActionId() {
return actionId;
}
public void setActionId(Integer actionId) {
this.actionId = actionId;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public JSONObject _toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put(ID, id);
json.put(TYPE, type);
json.put(ACTION_ID, actionId);
json.put(ACTION, action);
if (data != null) {
try {
json.put(DATA, new JSONObject(data));
} catch (JSONException ex) {
json.put(DATA, data);
}
}
return json;
}
@Override
public Message _fromJSON(JSONObject json) throws JSONException {
return this;
}
@Override
public String toString() {
try {
return this._toJSON().toString();
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy