f@0: /* f@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool f@0: f@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: f@0: package uk.ac.qmul.eecs.ccmi.network; f@0: f@0: /** f@0: * This class represents a lock message,through which the clients get exclusivity on f@0: * editing the elements of the diagram. The class is used by both the client, f@0: * to request a lock, and the server, to acknowledge the success/failure of the request. f@0: * f@0: * The argument of the message can be either the path to a three node or the id of a diagram element. f@0: * The former is used for lock for notes editing which can concern every tree node in the tree, f@0: * the latter for all the other types of lock as they only concern diagram elements. f@0: * The path to a tree node is a sequence of integers representing the index of the children f@0: * from the root to the affected node. So for instance 4,2,3 would be the third son of the f@0: * second son of the fourth son of the root node. f@0: */ f@0: public class LockMessage extends Message { f@0: f@0: /** f@0: * Creates a lock message for the given diagram and with the given timestamp. f@0: * f@0: * @param name the message name f@0: * @param timestamp the time when the message was issued f@0: * @param diagram the name of the diagram this message refers to f@0: * @param args arguments of the message f@0: * @param source the source that generated this message see {@link DiagramEventActionSource} f@0: */ f@0: public LockMessage(Name name, long timestamp, String diagram, Object[] args, Object source) { f@0: super(timestamp, diagram,source); f@0: this.args = args; f@0: this.name = name; f@0: } f@0: f@0: /** f@0: * Creates a lock message for the given diagram and timestamp of the moment f@0: * the message is created. f@0: * f@0: * @param name the message name f@0: * @param diagram the name of the diagram this message refers to f@0: * @param args arguments of the message f@0: * @param source the source that generated this message see {@link DiagramEventActionSource} f@0: */ f@0: public LockMessage(Name name, String diagram, Object[] args, DiagramEventActionSource source) { f@0: super(diagram,source); f@0: this.args = args; f@0: this.name = name; f@0: } f@0: f@0: public LockMessage(Name name, long timestamp, String diagram, long id, DiagramEventActionSource source) { f@0: this(name,timestamp,diagram,new Object[]{id},source); f@0: } f@0: f@0: public LockMessage(Name name, String diagram, long id, DiagramEventActionSource source){ f@0: this(name,diagram,new Object[]{id},source); f@0: } f@0: f@0: @Override f@0: public Name getName() { f@0: return name; f@0: } f@0: f@0: public Object getArgAt(int index) { f@0: return args[index]; f@0: } f@0: f@0: public Object[] getArgs(){ f@0: return args; f@0: } f@0: f@0: public int getArgNum(){ f@0: return args.length; f@0: } f@0: f@0: @Override f@0: public DiagramEventActionSource getSource(){ f@0: return (DiagramEventActionSource)super.getSource(); f@0: } f@0: f@0: public static LockMessage.Name valueOf(String n){ f@0: Name name = Name.NONE_L; f@0: try { f@0: name = Name.valueOf(n); f@0: }catch(IllegalArgumentException iae){ f@0: iae.printStackTrace(); f@0: return Name.NONE_L; f@0: } f@0: return name; f@0: } f@0: f@0: /** used to distinguish between different kinds of messages. */ f@0: public static final String NAME_POSTFIX = "_L"; f@0: public static final String GET_LOCK_PREFIX = "GET_"; f@0: public static final String YIELD_LOCK_PREFIX = "YIELD_"; f@0: private Name name; f@0: private Object[] args; f@0: f@0: /** f@0: * enum containing all the possible lock messages that can be exchanged f@0: * between server and client in either direction. f@0: */ f@0: public static enum Name implements Message.MessageName { f@0: GET_DELETE_L, f@0: GET_NAME_L, f@0: GET_PROPERTIES_L, f@0: GET_EDGE_END_L, f@0: GET_MOVE_L, f@0: GET_NOTES_L, f@0: GET_BOOKMARK_L, f@0: GET_MUST_EXIST_L, f@0: f@0: YIELD_DELETE_L, f@0: YIELD_NAME_L, f@0: YIELD_PROPERTIES_L, f@0: YIELD_EDGE_END_L, f@0: YIELD_MOVE_L, f@0: YIELD_NOTES_L, f@0: YIELD_BOOKMARK_L, f@0: YIELD_MUST_EXISTS_L, f@0: f@0: YES_L, f@0: NO_L, f@0: NONE_L; f@0: } f@0: }