org.springframework.batch.item.ldif

## Class MappingLdifReader<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.ldif.MappingLdifReader<T>

- All Implemented Interfaces:
    ResourceAwareItemReaderItemStream<T>, ItemReader<T>, ItemStream, ItemStreamReader<T>, org.springframework.beans.factory.InitializingBean

      public class MappingLdifReader<T>
      extends AbstractItemCountingItemStreamItemReader<T>
      implements ResourceAwareItemReaderItemStream<T>, org.springframework.beans.factory.InitializingBean

  The `MappingLdifReader` is an adaptation of the `FlatFileItemReader` built around an `LdifParser`. It differs from the standard `LdifReader` in its ability to map `LdapAttributes` objects to POJOs.

  The `MappingLdifReader` requires an `RecordMapper` implementation. If mapping is not required, the `LdifReader` should be used instead. It simply returns an `LdapAttributes` object which can be consumed and manipulated as necessary by `ItemProcessor` or any output service.

  As with the `FlatFileItemReader`, the `strict` option differentiates between whether or not to require the resource to exist before processing. In the case of a value set to false, a warning is logged instead of an exception being thrown.

  Author:
    Keith Barlow

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MappingLdifReader()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()`
    `protected void` | `doClose()` Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
    `protected void` | `doOpen()` Open resources necessary to start reading input.
    `protected T` | `doRead()` Read next item from input.
    `void` | `setRecordMapper(RecordMapper<T> recordMapper)` Setter for object mapper.
    `void` | `setRecordsToSkip(int recordsToSkip)` Public setter for the number of lines to skip at the start of a file.
    `void` | `setResource(org.springframework.core.io.Resource resource)`
    `void` | `setSkippedRecordsCallback(RecordCallbackHandler skippedRecordsCallback)` `RecordCallbackHandler` implementations can be used to take action on skipped records.
    `void` | `setStrict(boolean strict)` In strict mode the reader will throw an exception on `AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)` if the input resource does not exist.

    - ### Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader

      `close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update`

    - ### Methods inherited from class org.springframework.batch.item.ItemStreamSupport

      `getExecutionContextKey, setExecutionContextName, setName`

    - ### 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.ItemStream

      `close, open, update`

    - ### Methods inherited from interface org.springframework.batch.item.ItemReader

      `read`

- - ### Constructor Detail

    - #### MappingLdifReader

          public MappingLdifReader()

  - ### Method Detail

    - #### setStrict

          public void setStrict(boolean strict)

      In strict mode the reader will throw an exception on `AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)` if the input resource does not exist.
      Parameters:
        `strict` - false by default

    - #### setSkippedRecordsCallback

          public void setSkippedRecordsCallback(RecordCallbackHandler skippedRecordsCallback)

      `RecordCallbackHandler` implementations can be used to take action on skipped records.
      Parameters:
        `skippedRecordsCallback` - will be called for each one of the initial skipped lines before any items are read.

    - #### setRecordsToSkip

          public void setRecordsToSkip(int recordsToSkip)

      Public setter for the number of lines to skip at the start of a file. Can be used if the file contains a header without useful (column name) information, and without a comment delimiter at the beginning of the lines.
      Parameters:
        `recordsToSkip` - the number of lines to skip

    - #### setRecordMapper

          public void setRecordMapper(RecordMapper<T> recordMapper)

      Setter for object mapper. This property is required to be set.
      Parameters:
        `recordMapper` - maps record to an object

    - #### doClose

          protected void doClose()
                          throws java.lang.Exception

      Description copied from class: `AbstractItemCountingItemStreamItemReader`
      Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
      Specified by:
        `doClose` in class `AbstractItemCountingItemStreamItemReader<T>`
      Throws:
        `java.lang.Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

    - #### doOpen

          protected void doOpen()
                         throws java.lang.Exception

      Description copied from class: `AbstractItemCountingItemStreamItemReader`
      Open resources necessary to start reading input.
      Specified by:
        `doOpen` in class `AbstractItemCountingItemStreamItemReader<T>`
      Throws:
        `java.lang.Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

    - #### doRead

          @Nullable
          protected T doRead()
                                throws java.lang.Exception

      Description copied from class: `AbstractItemCountingItemStreamItemReader`
      Read next item from input.
      Specified by:
        `doRead` in class `AbstractItemCountingItemStreamItemReader<T>`
      Returns:
        an item or `null` if the data source is exhausted
      Throws:
        `java.lang.Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

    - #### setResource

          public void setResource(org.springframework.core.io.Resource resource)

      Specified by:
        `setResource` in interface `ResourceAwareItemReaderItemStream<T>`

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`