|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.batch.item.util.ExecutionContextUserSupport org.springframework.batch.item.xml.StaxEventItemWriter<T>
public class StaxEventItemWriter<T>
An implementation of ItemWriter
which uses StAX and
Marshaller
for serializing object to XML.
This item writer also provides restart, statistics and transaction features
by implementing corresponding interfaces.
The implementation is *not* thread-safe.
Constructor Summary | |
---|---|
StaxEventItemWriter()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
void |
close()
Flush and close the output source. |
protected Result |
createStaxResult()
Subclasses can override to customize the stax result. |
protected XMLEventFactory |
createXmlEventFactory()
Subclasses can override to customize the event factory. |
protected XMLEventWriter |
createXmlEventWriter(XMLOutputFactory outputFactory,
Writer writer)
Subclasses can override to customize the writer. |
protected XMLOutputFactory |
createXmlOutputFactory()
Subclasses can override to customize the factory. |
protected void |
endDocument(XMLEventWriter writer)
Writes the EndDocument tag manually. |
String |
getEncoding()
Get used encoding. |
Map<String,String> |
getRootElementAttributes()
Get attributes of the root element. |
String |
getRootTagName()
Get the tag name of the root element. |
String |
getRootTagNamespace()
Get the namespace of the root element. |
String |
getRootTagNamespacePrefix()
Get the namespace prefix of the root element. |
String |
getVersion()
Get XML version. |
void |
open(ExecutionContext executionContext)
Open the output source |
void |
setEncoding(String encoding)
Set encoding to be used for output file. |
void |
setFooterCallback(StaxWriterCallback footerCallback)
footerCallback is called after writing all items but before closing the file |
void |
setForceSync(boolean forceSync)
Flag to indicate that changes should be force-synced to disk on flush. |
void |
setHeaderCallback(StaxWriterCallback headerCallback)
headerCallback is called before writing any items. |
void |
setMarshaller(org.springframework.oxm.Marshaller marshaller)
Set Object to XML marshaller. |
void |
setOverwriteOutput(boolean overwriteOutput)
Set "overwrite" flag for the output file. |
void |
setResource(Resource resource)
Set output file. |
void |
setRootElementAttributes(Map<String,String> rootElementAttributes)
Set the root element attributes to be written. |
void |
setRootTagName(String rootTagName)
Set the tag name of the root element. |
void |
setSaveState(boolean saveState)
|
void |
setTransactional(boolean transactional)
Flag to indicate that writes should be deferred to the end of a transaction if present. |
void |
setVersion(String version)
Set XML version to be used for output XML. |
protected void |
startDocument(XMLEventWriter writer)
Writes simple XML header containing: xml declaration - defines encoding and XML version opening tag of the root element and its attributes If this is not sufficient for you, simply override this method. |
void |
update(ExecutionContext executionContext)
Get the restart data. |
void |
write(List<? extends T> items)
Write the value objects and flush them to the file. |
Methods inherited from class org.springframework.batch.item.util.ExecutionContextUserSupport |
---|
getKey, getName, setName |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StaxEventItemWriter()
Method Detail |
---|
public void setResource(Resource resource)
setResource
in interface ResourceAwareItemWriterItemStream<T>
resource
- the output filepublic void setMarshaller(org.springframework.oxm.Marshaller marshaller)
marshaller
- the Object to XML marshallerpublic void setHeaderCallback(StaxWriterCallback headerCallback)
public void setFooterCallback(StaxWriterCallback footerCallback)
public void setTransactional(boolean transactional)
transactional
- the flag to setpublic void setForceSync(boolean forceSync)
forceSync
- the flag value to setpublic String getEncoding()
public void setEncoding(String encoding)
encoding
- the encoding to be usedpublic String getVersion()
public void setVersion(String version)
version
- the XML version to be usedpublic String getRootTagName()
public void setRootTagName(String rootTagName)
{uri}prefix:rootThe prefix is optional (defaults to empty), but if it is specified then the uri must be provided. In addition you might want to declare other namespaces using the
root
attributes
.
rootTagName
- the tag name to be used for the root elementpublic String getRootTagNamespacePrefix()
public String getRootTagNamespace()
public Map<String,String> getRootElementAttributes()
public void setRootElementAttributes(Map<String,String> rootElementAttributes)
rootElementAttributes
- attributes of the root elementpublic void setOverwriteOutput(boolean overwriteOutput)
overwriteOutput
- public void setSaveState(boolean saveState)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
InitializingBean.afterPropertiesSet()
public void open(ExecutionContext executionContext)
open
in interface ItemStream
ItemStream.open(ExecutionContext)
protected XMLEventWriter createXmlEventWriter(XMLOutputFactory outputFactory, Writer writer) throws XMLStreamException
outputFactory
- writer
-
XMLStreamException
protected XMLOutputFactory createXmlOutputFactory() throws FactoryConfigurationError
FactoryConfigurationError
protected XMLEventFactory createXmlEventFactory() throws FactoryConfigurationError
FactoryConfigurationError
protected Result createStaxResult() throws Exception
Exception
protected void startDocument(XMLEventWriter writer) throws XMLStreamException
writer
- XML event writer
XMLStreamException
protected void endDocument(XMLEventWriter writer) throws XMLStreamException
writer
- XML event writer
XMLStreamException
public void close()
close
in interface ItemStream
ItemStream.close()
public void write(List<? extends T> items) throws org.springframework.oxm.XmlMappingException, Exception
write
in interface ItemWriter<T>
items
- the value object
IOException
org.springframework.oxm.XmlMappingException
Exception
- if there are errors. The framework will catch the
exception and convert or rethrow it as appropriate.public void update(ExecutionContext executionContext)
update
in interface ItemStream
executionContext
- to be updatedItemStream.update(ExecutionContext)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |