public class XMLConfigurationWriter extends Object implements PlatformConfiguration
A writer to transform Spectrum configuration data into XML.
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 Spectrum configuration data
(e.g., after some XSL transforms), the XMLConfigurationHandler
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 Spectrum configuration data 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 XMLConfigurationWriter persistence = new XMLConfigurationWriter(); persistence.setContentHandler(handler); persistence.startDocument(); // ... persistence.endDocument(); writer.close();
Please note that:
startDocument()
method before elements can be added.endDocument()
method after all elements have been added.
If the endDocument()
method is not called, no valid XML is generated
by the writer. Note that this method does not implicitly call some
Closeable.close()
method of some underlying stream. Operating only on
an event interface, this class does not have access to such a method.
XMLConfigurationHandler
Constructor and Description |
---|
XMLConfigurationWriter() |
Modifier and Type | Method and Description |
---|---|
void |
addProcess(ProcessDefinition definition)
Adds a process definition.
|
void |
endDocument()
Ends the document by closing the nodes opened while starting the
document.
|
void |
setContentHandler(ContentHandler handler)
Sets the content handler to be informed about the generated SAX events.
|
void |
setRuntimeEnvironment(RuntimeEnvironmentDefinition definition)
Sets the runtime environment definition.
|
void |
startDocument()
Starts the document.
|
public void setContentHandler(ContentHandler handler)
handler
- the content handler to be informed about the generated SAX
eventspublic void startDocument()
IllegalStateException
- if the document is already startedIllegalStateException
- if the document is already endedpublic void setRuntimeEnvironment(RuntimeEnvironmentDefinition definition) throws PlatformConfigurationException
PlatformConfiguration
setRuntimeEnvironment
in interface PlatformConfiguration
definition
- the runtime environment definitionIllegalStateException
- if the document is not yet
startedIllegalStateException
- if the runtime environment definition has already been setIllegalStateException
- if the document is already endedPlatformConfigurationException
- if a configuration error occurspublic void addProcess(ProcessDefinition definition) throws PlatformConfigurationException
PlatformConfiguration
addProcess
in interface PlatformConfiguration
definition
- the process definitionIllegalStateException
- if the document is not yet
startedIllegalStateException
- if the runtime environment definition
has not been set yetIllegalStateException
- if the document is already endedPlatformConfigurationException
- if a configuration error occurspublic void endDocument()
Ends the document by closing the nodes opened while starting the document.
This method must be called after all objects have been added. If the
method is not called, no valid XML is generated by the writer. Note that
this method does not implicitly call a Closeable.close()
method
of some underlying stream. Operating only on an event interface, this
class does not have access to such a method.
IllegalStateException
- if the document is not yet
startedIllegalStateException
- if the runtime environment definition
has not been set yetIllegalStateException
- if the document is already endedCopyright © Aimpulse Intelligent Systems GmbH
All rights reserved.