78 lines
2.2 KiB
Java
78 lines
2.2 KiB
Java
package netpaint.messaging;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
/**
|
|
* Class AdministrativeMessage: This class extends Client Message and
|
|
* is the base for all administrative network messages that will be
|
|
* sent by the client. All of the more specific client message classes
|
|
* will be derived from it and will add more and more spcific
|
|
* functionality onto the basics provided in this class.
|
|
*
|
|
* <PRE>
|
|
* Revision History:
|
|
* v1.0 (Jan. 29, 2004) - Created the AdministrativeMessage class
|
|
* </PRE>
|
|
*
|
|
* @author <A HREF="mailto:gtg563g@mail.gatech.edu">Daniyar Zhanbekov</A>
|
|
* @version Version 1.0, Jan. 29, 2004
|
|
*/
|
|
|
|
public abstract class AdministrativeMessage extends ClientMessage {
|
|
/**
|
|
* Creates a new <code>AdministrativeMessage</code> instance.
|
|
*
|
|
* @param type a <code>String</code> value
|
|
* @param author a <code>String</code> value
|
|
*/
|
|
public AdministrativeMessage(final String type, final String author) {
|
|
super(type, author);
|
|
}
|
|
|
|
/**
|
|
* Returns a string representation of the message fit for plain-text
|
|
* transmission over the network.
|
|
*
|
|
* @return a <code>String</code> value
|
|
*/
|
|
public final String tokenize() {
|
|
return getMessageType() + ":" + getAuthor();
|
|
}
|
|
|
|
/**
|
|
* Parses the string into the specific message.
|
|
*
|
|
* @param message a <code>String</code> value
|
|
* @return an <code>AbstractMessage</code> value
|
|
*/
|
|
protected static AbstractMessage parse(final String message) {
|
|
String type = getMessageType(message);
|
|
StringTokenizer st = null;
|
|
|
|
if (type == null) {
|
|
return null;
|
|
}
|
|
|
|
if (!(type.equals(MessageSettings.JOIN_TYPE)
|
|
|| type.equals(MessageSettings.QUIT_TYPE))) {
|
|
return null;
|
|
}
|
|
|
|
st = new StringTokenizer(message, ":");
|
|
|
|
//Message type:
|
|
if (!st.hasMoreTokens()) { return null; }
|
|
type = st.nextToken();
|
|
|
|
//Username:
|
|
if (!st.hasMoreTokens()) { return null; }
|
|
if (type.equals(MessageSettings.JOIN_TYPE)) {
|
|
return new JoinMessage(st.nextToken());
|
|
} else if (type.equals(MessageSettings.QUIT_TYPE)) {
|
|
return new QuitMessage(st.nextToken());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|