if (!(m.getMessageData() instanceof LogEntry)) {
Logger.getLogger(XmlPacker.class.getName()).log(Level.SEVERE,
"packLogEntryMessage() - Expected data class LogEntry, got {0}",
m.getMessageData().getClass().getName());
}
LogEntry logEntry = (LogEntry) m.getMessageData();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Create instance of DocumentBuilderFactory
DocumentBuilder db = null; // Get the DocumentBuilder
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException ex) {
Logger.getLogger(XmlPacker.class.getName()).log(Level.SEVERE, null, ex);
}
Document doc = db.newDocument(); // Create a blank Document
Element root = doc.createElement("LogEntry"); // Create the root element
doc.appendChild(root); // Root element is child of the Document
packNewElement(doc, root, "sourceAddress", Mediator.getProperty("Instance.Address"));
packNewElement(doc, root, "sourceName", Mediator.getProperty("Instance.Name"));
packNewElement(doc, root, "messageId", m.getMessageId());
packNewElement(doc, root, "severity", logEntry.getSeverity());
packNewElement(doc, root, "class", logEntry.getClassName());
packNewElement(doc, root, "dateTime", packDateTime(logEntry.getDateTime()));
packNewElement(doc, root, "message", logEntry.getMessage());
return doc;
}