annotate java/src/uk/ac/qmul/eecs/ccmi/network/Reply.java @ 1:e3935c01cde2 tip

moved license of PdPersistenceManager to the beginning of the file
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 08 Jul 2014 19:52:03 +0100
parents 78b7fc5391a2
children
rev   line source
f@0 1 /*
f@0 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0 3
f@0 4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0 5
f@0 6 This program is free software: you can redistribute it and/or modify
f@0 7 it under the terms of the GNU General Public License as published by
f@0 8 the Free Software Foundation, either version 3 of the License, or
f@0 9 (at your option) any later version.
f@0 10
f@0 11 This program is distributed in the hope that it will be useful,
f@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0 14 GNU General Public License for more details.
f@0 15
f@0 16 You should have received a copy of the GNU General Public License
f@0 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
f@0 18 */
f@0 19
f@0 20 package uk.ac.qmul.eecs.ccmi.network;
f@0 21
f@0 22 import uk.ac.qmul.eecs.ccmi.gui.DiagramEventSource;
f@0 23 import uk.ac.qmul.eecs.ccmi.utils.InteractionLog;
f@0 24
f@0 25 /**
f@0 26 * A {@code Reply} message is sent from the server to a client from which it
f@0 27 * has just received a command. The reply acknowledges the client that the command has
f@0 28 * successfully been executed on the server. By broadcasting the command to the other client and by
f@0 29 * ending the reply to the client which issued the command itself the server keeps all the clients
f@0 30 * synchronized on its diagram model.
f@0 31 *
f@0 32 */
f@0 33 public class Reply extends Message {
f@0 34
f@0 35 public Reply(Name name, String diagram, String message, long timestamp, DiagramEventSource source){
f@0 36 super(timestamp,diagram, source);
f@0 37 this.name = name;
f@0 38 this.message = message;
f@0 39 }
f@0 40
f@0 41 public Reply(Name name, String diagram, String message, DiagramEventSource source){
f@0 42 super(diagram,source);
f@0 43 this.name = name;
f@0 44 this.message = message;
f@0 45 }
f@0 46
f@0 47 public Name getName() {
f@0 48 return name;
f@0 49 }
f@0 50
f@0 51 public String getMessage() {
f@0 52 return message;
f@0 53 }
f@0 54
f@0 55 @Override
f@0 56 public DiagramEventSource getSource(){
f@0 57 return (DiagramEventSource)super.getSource();
f@0 58 }
f@0 59
f@0 60 /**
f@0 61 * @return the length of the String message conveyed by this Reply
f@0 62 */
f@0 63 public int getMessageLen(){
f@0 64 return message.length();
f@0 65 }
f@0 66
f@0 67 @Override
f@0 68 public String toString(){
f@0 69 StringBuilder builder = new StringBuilder();
f@0 70 builder.append(timestamp).append(' ').append(name).append('\n').append(message);
f@0 71 return builder.toString();
f@0 72 }
f@0 73
f@0 74 public static Name valueOf(String n){
f@0 75 Name name = Name.NONE_R;
f@0 76 try {
f@0 77 name = Name.valueOf(n);
f@0 78 }catch(IllegalArgumentException iae){
f@0 79 iae.printStackTrace();
f@0 80 }
f@0 81 return name;
f@0 82 }
f@0 83
f@0 84 public static void log(Reply reply){
f@0 85 if(reply.getName() != Reply.Name.TRANSLATE_EDGE_R && reply.getName() != Reply.Name.TRANSLATE_NODE_R && reply.getName() != Reply.Name.BEND_R){
f@0 86 StringBuilder builder = new StringBuilder(reply.getName().toString());
f@0 87 builder.append(' ').append(reply.getDiagram());
f@0 88 builder.append(' ').append(reply.getMessage());
f@0 89 InteractionLog.log("SERVER", "reply received", builder.toString());
f@0 90 }
f@0 91 }
f@0 92
f@0 93 private Name name;
f@0 94 private String message;
f@0 95 private long timestamp;
f@0 96 public static final String NAME_POSTFIX = "_R";
f@0 97 public static enum Name implements Message.MessageName {
f@0 98 NONE_R,
f@0 99 OK_R,
f@0 100 ERROR_R,
f@0 101 LIST_R,
f@0 102 GET_R,
f@0 103 INSERT_NODE_R,
f@0 104 REMOVE_NODE_R,
f@0 105 INSERT_EDGE_R,
f@0 106 REMOVE_EDGE_R,
f@0 107 SET_NODE_NAME_R,
f@0 108 SET_EDGE_NAME_R,
f@0 109 SET_PROPERTY_R,
f@0 110 SET_PROPERTIES_R,
f@0 111 CLEAR_PROPERTIES_R,
f@0 112 SET_NOTES_R,
f@0 113 ADD_PROPERTY_R,
f@0 114 REMOVE_PROPERTY_R,
f@0 115 SET_MODIFIERS_R,
f@0 116 SET_ENDDESCRIPTION_R,
f@0 117 SET_ENDLABEL_R,
f@0 118 TRANSLATE_NODE_R,
f@0 119 TRANSLATE_EDGE_R,
f@0 120 BEND_R,
f@0 121 STOP_EDGE_MOVE_R,
f@0 122 STOP_NODE_MOVE_R;
f@0 123 };
f@0 124 }