Package org.springframework.batch.item.xml.builder

# Class StaxEventItemReaderBuilder<T>

java.lang.Object
org.springframework.batch.item.xml.builder.StaxEventItemReaderBuilder<T>

public class StaxEventItemReaderBuilder<T> extends Object
A fluent builder for the `StaxEventItemReader`

Since:
  4.0
Author:
  Michael Minella, Glenn Renfro, Mahmoud Ben Hassine, Parikshit Dutta

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected org.apache.commons.logging.Log`
  `logger`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StaxEventItemReaderBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `StaxEventItemReaderBuilder<T>`
  `addFragmentRootElements(String... fragmentRootElements)`
  Adds the list of fragments to be used as the root of each chunk to the configuration.
  `StaxEventItemReaderBuilder<T>`
  `addFragmentRootElements(List<String> fragmentRootElements)`
  Adds the list of fragments to be used as the root of each chunk to the configuration.
  `StaxEventItemReader<T>`
  `build()`
  Validates the configuration and builds a new `StaxEventItemReader`
  `StaxEventItemReaderBuilder<T>`
  `currentItemCount(int currentItemCount)`
  Index for the current item.
  `StaxEventItemReaderBuilder<T>`
  `encoding(String encoding)`
  Encoding for the input file.
  `StaxEventItemReaderBuilder<T>`
  `maxItemCount(int maxItemCount)`
  Configure the max number of items to be read.
  `StaxEventItemReaderBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `StaxEventItemReaderBuilder<T>`
  `resource(org.springframework.core.io.Resource resource)`
  The `Resource` to be used as input.
  `StaxEventItemReaderBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
  `StaxEventItemReaderBuilder<T>`
  `strict(boolean strict)`
  Setting this value to true indicates that it is an error if the input does not exist and an exception will be thrown.
  `StaxEventItemReaderBuilder<T>`
  `unmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)`
  An implementation of the `Unmarshaller` from Spring's OXM module.
  `StaxEventItemReaderBuilder<T>`
  `xmlInputFactory(XMLInputFactory xmlInputFactory)`
  Set the `XMLInputFactory`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### logger

    protected org.apache.commons.logging.Log logger

- ## Constructor Details

  - ### StaxEventItemReaderBuilder

    public StaxEventItemReaderBuilder()

- ## Method Details

  - ### saveState

    public StaxEventItemReaderBuilder<T> saveState(boolean saveState)
    Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
    Parameters:
      `saveState` - defaults to true
    Returns:
      The current instance of the builder.

  - ### name

    public StaxEventItemReaderBuilder<T> name(String name)
    The name used to calculate the key within the `ExecutionContext`. Required if `saveState(boolean)` is set to true.
    Parameters:
      `name` - name of the reader instance
    Returns:
      The current instance of the builder.
    See Also:
      - `ItemStreamSupport.setName(String)`

  - ### maxItemCount

    public StaxEventItemReaderBuilder<T> maxItemCount(int maxItemCount)
    Configure the max number of items to be read.
    Parameters:
      `maxItemCount` - the max items to be read
    Returns:
      The current instance of the builder.
    See Also:
      - `AbstractItemCountingItemStreamItemReader.setMaxItemCount(int)`

  - ### currentItemCount

    public StaxEventItemReaderBuilder<T> currentItemCount(int currentItemCount)
    Index for the current item. Used on restarts to indicate where to start from.
    Parameters:
      `currentItemCount` - current index
    Returns:
      this instance for method chaining
    See Also:
      - `AbstractItemCountingItemStreamItemReader.setCurrentItemCount(int)`

  - ### resource

    public StaxEventItemReaderBuilder<T> resource(org.springframework.core.io.Resource resource)
    The `Resource` to be used as input.
    Parameters:
      `resource` - the input to the reader.
    Returns:
      The current instance of the builder.
    See Also:
      - `StaxEventItemReader.setResource(Resource)`

  - ### unmarshaller

    public StaxEventItemReaderBuilder<T> unmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
    An implementation of the `Unmarshaller` from Spring's OXM module.
    Parameters:
      `unmarshaller` - component responsible for unmarshalling XML chunks
    Returns:
      The current instance of the builder.
    See Also:
      - `StaxEventItemReader.setUnmarshaller(org.springframework.oxm.Unmarshaller)`

  - ### addFragmentRootElements

    public StaxEventItemReaderBuilder<T> addFragmentRootElements(String... fragmentRootElements)
    Adds the list of fragments to be used as the root of each chunk to the configuration.
    Parameters:
      `fragmentRootElements` - the XML root elements to be used to identify XML chunks.
    Returns:
      The current instance of the builder.
    See Also:
      - `StaxEventItemReader.setFragmentRootElementNames(String[])`

  - ### addFragmentRootElements

    public StaxEventItemReaderBuilder<T> addFragmentRootElements(List<String> fragmentRootElements)
    Adds the list of fragments to be used as the root of each chunk to the configuration.
    Parameters:
      `fragmentRootElements` - the XML root elements to be used to identify XML chunks.
    Returns:
      The current instance of the builder.
    See Also:
      - `StaxEventItemReader.setFragmentRootElementNames(String[])`

  - ### strict

    public StaxEventItemReaderBuilder<T> strict(boolean strict)
    Setting this value to true indicates that it is an error if the input does not exist and an exception will be thrown. Defaults to true.
    Parameters:
      `strict` - indicates the input file must exist
    Returns:
      The current instance of the builder
    See Also:
      - `StaxEventItemReader.setStrict(boolean)`

  - ### xmlInputFactory

    public StaxEventItemReaderBuilder<T> xmlInputFactory(XMLInputFactory xmlInputFactory)
    Set the `XMLInputFactory`.
    Parameters:
      `xmlInputFactory` - to use
    Returns:
      The current instance of the builder
    See Also:
      - `StaxEventItemReader.setXmlInputFactory(XMLInputFactory)`

  - ### encoding

    public StaxEventItemReaderBuilder<T> encoding(String encoding)
    Encoding for the input file. Defaults to `StaxEventItemReader.DEFAULT_ENCODING`.
    Parameters:
      `encoding` - String encoding algorithm
    Returns:
      the current instance of the builder
    See Also:
      - `StaxEventItemReader.setEncoding(String)`

  - ### build

    public StaxEventItemReader<T> build()
    Validates the configuration and builds a new `StaxEventItemReader`
    Returns:
      a new instance of the `StaxEventItemReader`