org.springframework.batch.item.xml
Class StaxEventItemReader

java.lang.Object
  extended by org.springframework.batch.item.support.AbstractBufferedItemReaderItemStream
      extended by org.springframework.batch.item.xml.StaxEventItemReader
All Implemented Interfaces:
ResourceAwareItemReaderItemStream, ItemReader, ItemStream, InitializingBean

public class StaxEventItemReader
extends AbstractBufferedItemReaderItemStream
implements ResourceAwareItemReaderItemStream, InitializingBean

Item reader for reading XML input based on StAX. It extracts fragments from the input XML document which correspond to records for processing. The fragments are wrapped with StartDocument and EndDocument events so that the fragments can be further processed like standalone XML documents. The implementation is *not* thread-safe.

Author:
Robert Kasanicky

Constructor Summary
StaxEventItemReader()
           
 
Method Summary
 void afterPropertiesSet()
          Ensure that all required dependencies for the ItemReader to run are provided after all properties have been set.
protected  void doClose()
          Close the resources opened in AbstractBufferedItemReaderItemStream.doOpen().
protected  void doOpen()
          Open resources necessary to start reading input.
protected  Object doRead()
          Move to next fragment and map it to item.
protected  boolean moveCursorToNextFragment(javax.xml.stream.XMLEventReader reader)
          Responsible for moving the cursor before the StartElement of the fragment root.
 void setFragmentDeserializer(EventReaderDeserializer eventReaderDeserializer)
           
 void setFragmentRootElementName(String fragmentRootElementName)
           
 void setResource(Resource resource)
           
 
Methods inherited from class org.springframework.batch.item.support.AbstractBufferedItemReaderItemStream
close, getCurrentItemCount, jumpToItem, mark, open, read, reset, setCurrentItemCount, setName, setSaveState, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.batch.item.ItemReader
mark, read, reset
 
Methods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
 

Constructor Detail

StaxEventItemReader

public StaxEventItemReader()
Method Detail

setResource

public void setResource(Resource resource)
Specified by:
setResource in interface ResourceAwareItemReaderItemStream

setFragmentDeserializer

public void setFragmentDeserializer(EventReaderDeserializer eventReaderDeserializer)
Parameters:
eventReaderDeserializer - maps xml fragments corresponding to records to objects

setFragmentRootElementName

public void setFragmentRootElementName(String fragmentRootElementName)
Parameters:
fragmentRootElementName - name of the root element of the fragment TODO String can be ambiguous due to namespaces, use QName?

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Ensure that all required dependencies for the ItemReader to run are provided after all properties have been set.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
IllegalArgumentException - if the Resource, FragmentDeserializer or FragmentRootElementName is null, or if the root element is empty.
IllegalStateException - if the Resource does not exist.
Exception
See Also:
InitializingBean.afterPropertiesSet()

moveCursorToNextFragment

protected boolean moveCursorToNextFragment(javax.xml.stream.XMLEventReader reader)
Responsible for moving the cursor before the StartElement of the fragment root. This implementation simply looks for the next corresponding element, it does not care about element nesting. You will need to override this method to correctly handle composite fragments.

Returns:
true if next fragment was found, false otherwise.

doClose

protected void doClose()
                throws Exception
Description copied from class: AbstractBufferedItemReaderItemStream
Close the resources opened in AbstractBufferedItemReaderItemStream.doOpen().

Specified by:
doClose in class AbstractBufferedItemReaderItemStream
Throws:
Exception

doOpen

protected void doOpen()
               throws Exception
Description copied from class: AbstractBufferedItemReaderItemStream
Open resources necessary to start reading input.

Specified by:
doOpen in class AbstractBufferedItemReaderItemStream
Throws:
Exception

doRead

protected Object doRead()
                 throws Exception
Move to next fragment and map it to item.

Specified by:
doRead in class AbstractBufferedItemReaderItemStream
Returns:
item
Throws:
Exception


Copyright © 2009 SpringSource. All Rights Reserved.