public class XMLMessageWriter extends Object implements MessageHandler
A writer to transform messages into XML, thereby following the FIPA ACL Message Representation in XML Specification.
This writer does not simply write an XML file. Actually, it does not write any file at all. Instead, the writer simply generates the SAX (Simple API for XML) events for the respective XML elements as if it were an XML parser. A SAX content handler can be registered in order to handle the generated events. Therewith, this class is much more versatile than a simple writer.
The registered content handler can be used in order to forward the generated SAX events directly to another XML processor. Hence, it is possible to build XML pipelines without an indirection over the file system.
In order to transform the XML events back into messages (e.g., after some XSL
transforms), the XMLMessageHandler
can be employed. Such a handler
could even be registered directly as a content handler for this writer
(although there are very rare occasions, if any, where this seems reasonable
in practice).
In order to simply persist a message in the XML format, a
TransformerHandler
can be
created with the
help of the SAXTransformerFactory
. The destination of the data
can be specified with the
Result
of the handler.
final Writer writer = new FileWriter("output.xml"); final SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory .newInstance(); final TransformerHandler handler = factory.newTransformerHandler(); handler.setResult(new StreamResult(writer)); final XMLMessageWriter persistence = new XMLMessageWriter(); persistence.setContentHandler(handler); // ... writer.close();
Note that the FIPA standard XML representation of ACL messages only covers the performatives listed in the FIPA Communicative Act Library Specification (CAL). By contrast, Aimpulse Spectrum allows defining arbitrary performatives including those not listed in the CAL. In order to safely interchange messages with external agents, you should check that only CAL performatives are used whenever this is relevant.
XMLMessageHandler
,
FIPA ACL
Message Representation in XML Specification,
FIPA
Communicative Act Library SpecificationConstructor and Description |
---|
XMLMessageWriter() |
Modifier and Type | Method and Description |
---|---|
void |
message(Message message)
Informs the handler about a message.
|
void |
setContentHandler(ContentHandler handler)
Sets the content handler to be informed about the generated SAX events.
|
public void setContentHandler(ContentHandler handler)
handler
- the content handler to be informed about the generated SAX
eventspublic void message(Message message)
MessageHandler
message
in interface MessageHandler
message
- the message to be informed aboutCopyright © Aimpulse Intelligent Systems GmbH
All rights reserved.