2 * This file is part of the Vamsas Client version 0.2.
\r
3 * Copyright 2010 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.client.picking;
\r
25 * Abstract base class for all message types supported by the picking API.
\r
27 public abstract class Message {
\r
28 protected String message;
\r
31 * Constructs a new message.
\r
33 protected Message() {
\r
38 * Returns the raw message content as a string.
\r
40 * @return the raw message content as a string
\r
42 public String getRawMessage() {
\r
47 * compare the on-wire message content of the given message to this.
\r
50 * @return true if message content is equal
\r
52 public boolean equals(Message msg) {
\r
53 return message.equals(msg.getRawMessage());
\r
57 * Test consistence of a Message class implementation. This method throws an
\r
58 * error if the message object cannot be parsed into another instance of the
\r
59 * same object by invoking the MessageImpl(String this.getRawMessage())
\r
60 * constructor or that newinstance.getRawMessage != this.getRawMessage
\r
62 public void validate() {
\r
64 java.lang.reflect.Constructor msgcons = this.getClass().getConstructor(
\r
65 new Class[] { String.class });
\r
66 if (msgcons == null) {
\r
67 throw new Exception("No " + this.getClass().getName()
\r
68 + "(String rawmessage) constructor.");
\r
70 Message instance = (Message) msgcons.newInstance(new Object[] { this
\r
71 .getRawMessage() });
\r
72 if (!instance.getRawMessage().equals(getRawMessage())) {
\r
74 "Raw Message Content does not match :\nInitial Message:"
\r
75 + getRawMessage() + "\nParsed and regnerated as :\n"
\r
76 + instance.getRawMessage() + "\n");
\r
78 } catch (Exception e) {
\r
79 throw new Error("Message implementation broken for " + this.getClass(), e);
\r