READERNAME LogFormatter.java

From RifidiWiki

Revision as of 22:51, 8 February 2008 by Kyle (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This class handles how the reader should display outgoing and incoming messages in the console logger in the IDE. If the reader does not need to display this information in any special way, it does not have to implement this class and instead can use either the GenericByteLogFormatter or the GenericStringLogFormatter

formatMessage

This method needs to decode an incoming command into a command to be handled in the command formatter. It should put the command into a commandObject and put the commandObject in the first slot in an arraylist and return the arraylist.

public String formatMessage(byte[] rawMessage);

Arguments

  1. arg - The incoming or outgoing message that needs to be turned into a log message

Return Value

A string that will be printed in the console

Reference Implementation

This is the log formatter for the llrp reader. It displays both the bytes and the xml representation of the messages.

	public String formatMessage(byte[] rawMessage) {
		
		ByteArrayInputStream is = new ByteArrayInputStream(rawMessage);
		String bytes = ByteAndHexConvertingUtility.toHexString(rawMessage);
		try {
			Message m = Message.receive(is);
			return "\nBYTES: \n" + bytes + "\nXML: \n" + m.toXMLString();
		} catch (Exception e) {
			logger.error("Cannot serialize the message");
			return "\nBytes: " + bytes;
		} 
	}
Personal tools