1 package uk.ac.vamsas.client.picking;
\r
4 * Abstract base class for all message types supported by the picking API.
\r
6 public abstract class Message
\r
8 protected String message;
\r
11 * Constructs a new message.
\r
19 * Returns the raw message content as a string.
\r
20 * @return the raw message content as a string
\r
22 public String getRawMessage()
\r
25 * compare the on-wire message content of the given message to this.
\r
27 * @return true if message content is equal
\r
29 public boolean equals(Message msg)
\r
31 return message.equals(msg.getRawMessage());
\r
34 * Test consistence of a Message class implementation. This method throws an error if
\r
35 * the message object cannot be parsed into another instance of the same object by
\r
36 * invoking the MessageImpl(String this.getRawMessage()) constructor or that
\r
37 * newinstance.getRawMessage != this.getRawMessage
\r
39 public void validate() {
\r
41 java.lang.reflect.Constructor msgcons = this.getClass().getConstructor(new Class[] { String.class });
\r
44 throw new Exception("No "+this.getClass().getName()+"(String rawmessage) constructor.");
\r
46 Message instance = (Message) msgcons.newInstance(new Object[] { this.getRawMessage() });
\r
47 if (!instance.getRawMessage().equals(getRawMessage()))
\r
49 throw new Error("Raw Message Content does not match :\nInitial Message:"+getRawMessage()+"\nParsed and regnerated as :\n"+instance.getRawMessage()+"\n");
\r
51 } catch (Exception e)
\r
53 throw new Error("Message implementation broken for "+this.getClass(),e);
\r