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 java.lang.Object

  A fluent builder for the `StaxEventItemReader`
  Since:
    4.0
  Author:
    Michael Minella, Glenn Renfro

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StaxEventItemReaderBuilder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `StaxEventItemReaderBuilder<T>` | `addFragmentRootElements(java.util.List<java.lang.String> fragmentRootElements)` Adds the list of fragments to be used as the root of each chunk to the configuration.
    `StaxEventItemReaderBuilder<T>` | `addFragmentRootElements(java.lang.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>` | `maxItemCount(int maxItemCount)` Configure the max number of items to be read.
    `StaxEventItemReaderBuilder<T>` | `name(java.lang.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(javax.xml.stream.XMLInputFactory xmlInputFactory)` Set the `XMLInputFactory`.

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

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

- - ### Constructor Detail

    - #### StaxEventItemReaderBuilder

          public StaxEventItemReaderBuilder()

  - ### Method Detail

    - #### 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(java.lang.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(java.lang.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(java.util.List<java.lang.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(javax.xml.stream.XMLInputFactory xmlInputFactory)

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

    - #### build

          public StaxEventItemReader<T> build()

      Validates the configuration and builds a new `StaxEventItemReader`
      Returns:
        a new instance of the `StaxEventItemReader`