Inbound Marshalling Code Example
A simple inbound marshaller is shown below. The marshaller converts all events into a TextMessage with the text field set to a string containing a line for each field with the name, an equals sign, and the value.
class SimpleMarshalIn implements WmMarshalIn
{
public WmMessage mapMessageFromEvent(Object eventIn, Object userData,
WmMessageFactory msgFactory) throws Exception
{
BrokerEvent event = (BrokerEvent) eventIn;
TextMessage msg = msgFactory.createTextMessage();
String[] fieldNames = event.getFieldNames(null);
StringBuffer buf = new StringBuffer();
for (int i = 0; i < fieldNames.length; i++) {
BrokerField field = event.getField(fieldNames[i]);
buf.append(fieldNames[i]);
buf.append("=");
buf.append(field.value);
buf.append("\n");
}
msg.setText(buf.toString());
return (WmMessage) msg;
}
}