001/*
002 * Copyright (c) 2013 - 2016 TDP Ltd All Rights Reserved.
003 * TDP Ltd grants permission, free of charge, to any person obtaining copies
004 * of this software and its associated documentation files (the "Software"),
005 * to deal in the Software without restriction, including to use, copy, adapt,
006 * publish, distribute, display, perform, sublicense, and sell copies of the
007 * Software, subject to the following condition: You must include the above
008 * copyright notice and this permission notice in all full or partial copies
009 * of the Software.
010 * TDP LTD PROVIDES THE SOFTWARE "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY,
011 * INCLUDING WITHOUT THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
012 * PARTICULAR PURPOSE, AND NON-INFRINGMENT. TDP LTD, THE AUTHORS OF THE SOFTWARE,
013 * AND THE OWNERS OF COPYRIGHT IN THE SOFTWARE ARE NOT LIABLE FOR ANY CLAIM, DAMAGES,
014 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING
015 * FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
016 * THE SOFTWARE.
017 */
018package cz.tdp.kshield.client;
019
020import java.io.Serializable;
021
022
023/**
024 * This class represents KShield client message data
025 */
026public class ClientMessage implements Serializable
027{
028  private static final long serialVersionUID = 1558718065109210827L;
029
030  private final String id;
031  private final String from;
032  private final String to;
033  private final String message;
034  
035  
036  /**
037   * @param from
038   * @param to
039   * @param message
040   */
041  public ClientMessage(String from, String to, String message) {
042    this(null, from, to, message);
043  }
044  
045  public ClientMessage(String id, String from, String to, String message) {
046    this.id = id;
047    this.from = from;
048    this.to = to;
049    this.message = message;
050  }
051
052
053  public String toJSON() {
054    final StringBuilder json = new StringBuilder(200);
055    
056    JSONUtil.startObject(json);
057    if (id != null && !id.isEmpty()) {
058      JSONUtil.appendProperty(json, "id", id);
059    }
060    JSONUtil.appendProperty(json, "from", from);
061    JSONUtil.appendProperty(json, "to", to);
062    JSONUtil.appendProperty(json, "message", message);
063    JSONUtil.endObject(json);
064    
065    return json.toString();
066  }
067}