类 StaxEventItemReader<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
- org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
- org.springframework.batch.item.xml.StaxEventItemReader<T>
- 所有已实现的接口:
ResourceAwareItemReaderItemStream<T>
,ItemReader<T>
,ItemStream
,ItemStreamReader<T>
,org.springframework.beans.factory.InitializingBean
public class StaxEventItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements ResourceAwareItemReaderItemStream<T>, org.springframework.beans.factory.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.- 作者:
- Robert Kasanicky, Mahmoud Ben Hassine
构造器概要
构造器 构造器 说明 StaxEventItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 inAbstractItemCountingItemStreamItemReader.doOpen()
.protected void
doOpen()
Open resources necessary to start reading input.protected T
doRead()
Move to next fragment and map it to item.protected void
jumpToItem(int itemIndex)
Move to the given item index.protected boolean
moveCursorToNextFragment(javax.xml.stream.XMLEventReader reader)
Responsible for moving the cursor before the StartElement of the fragment root.void
setFragmentRootElementName(java.lang.String fragmentRootElementName)
void
setFragmentRootElementNames(java.lang.String[] fragmentRootElementNames)
void
setResource(org.springframework.core.io.Resource resource)
void
setStrict(boolean strict)
In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)
if the input resource does not exist.void
setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
void
setXmlInputFactory(javax.xml.stream.XMLInputFactory xmlInputFactory)
Set theXMLInputFactory
.从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.batch.item.ItemReader
read
从接口继承的方法 org.springframework.batch.item.ItemStream
close, open, update
构造器详细资料
StaxEventItemReader
public StaxEventItemReader()
方法详细资料
setStrict
public void setStrict(boolean strict)
In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)
if the input resource does not exist.- 参数:
strict
- true by default
setResource
public void setResource(org.springframework.core.io.Resource resource)
- 指定者:
setResource
在接口中ResourceAwareItemReaderItemStream<T>
setUnmarshaller
public void setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
- 参数:
unmarshaller
- maps xml fragments corresponding to records to objects
setFragmentRootElementName
public void setFragmentRootElementName(java.lang.String fragmentRootElementName)
- 参数:
fragmentRootElementName
- name of the root element of the fragment
setFragmentRootElementNames
public void setFragmentRootElementNames(java.lang.String[] fragmentRootElementNames)
- 参数:
fragmentRootElementNames
- list of the names of the root element of the fragment
setXmlInputFactory
public void setXmlInputFactory(javax.xml.stream.XMLInputFactory xmlInputFactory)
Set theXMLInputFactory
.- 参数:
xmlInputFactory
- to use
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Ensure that all required dependencies for the ItemReader to run are provided after all properties have been set.- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.IllegalArgumentException
- if the Resource, FragmentDeserializer or FragmentRootElementName is null, or if the root element is empty.java.lang.IllegalStateException
- if the Resource does not exist.java.lang.Exception
- 另请参阅:
InitializingBean.afterPropertiesSet()
moveCursorToNextFragment
protected boolean moveCursorToNextFragment(javax.xml.stream.XMLEventReader reader) throws NonTransientResourceException
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.- 参数:
reader
- theXMLEventReader
to be used to find next fragment.- 返回:
true
if next fragment was found,false
otherwise.- 抛出:
NonTransientResourceException
- if the cursor could not be moved. This will be treated as fatal and subsequent calls to read will return null.
doClose
protected void doClose() throws java.lang.Exception
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.- 指定者:
doClose
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doOpen
protected void doOpen() throws java.lang.Exception
Open resources necessary to start reading input.- 指定者:
doOpen
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doRead
protected T doRead() throws java.io.IOException, javax.xml.stream.XMLStreamException
Move to next fragment and map it to item.- 指定者:
doRead
在类中AbstractItemCountingItemStreamItemReader<T>
- 返回:
- an item or
null
if the data source is exhausted - 抛出:
java.io.IOException
javax.xml.stream.XMLStreamException
jumpToItem
protected void jumpToItem(int itemIndex) throws java.lang.Exception
Move to the given item index. Subclasses should override this method if there is a more efficient way of moving to given index than re-reading the input usingAbstractItemCountingItemStreamItemReader.doRead()
.- 覆盖:
jumpToItem
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
itemIndex
- index of item (0 based) to jump to.- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework