Class EntryGenerator

java.lang.Object
org.forgerock.opendj.ldif.EntryGenerator
All Implemented Interfaces:
Closeable, AutoCloseable, EntryReader

public final class EntryGenerator extends Object implements EntryReader
A template driven entry generator, as used by the makeldif tool.

To build a generator with default values, including default template file, use the empty constructor:

 generator = new EntryGenerator();
 

To build a generator with some custom values, use the non-empty constructor and the set methods:

 generator = new EntryGenerator(templatePath).setResourcePath(path).setSchema(schema)
 
  • Constructor Details

    • EntryGenerator

      public EntryGenerator()
      Creates a generator using default values.

      The default template file will be used to generate entries.

    • EntryGenerator

      public EntryGenerator(String templatePath)
      Creates a generator from the provided template path.
      Parameters:
      templatePath - Path of the template file.
    • EntryGenerator

      public EntryGenerator(String... templateLines)
      Creates a generator from the provided template lines.
      Parameters:
      templateLines - Lines defining the template file.
    • EntryGenerator

      public EntryGenerator(List<String> templateLines)
      Creates a generator from the provided template lines.
      Parameters:
      templateLines - Lines defining the template file.
    • EntryGenerator

      public EntryGenerator(InputStream templateStream)
      Creates a generator from the provided input stream.
      Parameters:
      templateStream - Input stream to read the template file.
  • Method Details

    • setRandomSeed

      public EntryGenerator setRandomSeed(int seed)
      Sets the random seed to use when generating entries.
      Parameters:
      seed - The random seed to use.
      Returns:
      A reference to this EntryGenerator.
    • setResourcePath

      public EntryGenerator setResourcePath(Path path)
      Sets the resource path, used to looks for resources files like first names, last names, or other custom resources.
      Parameters:
      path - The resource path.
      Returns:
      A reference to this EntryGenerator.
    • setResourcePath

      public EntryGenerator setResourcePath(String path)
      Sets the resource path, used to looks for resources files like first names, last names, or other custom resources.
      Parameters:
      path - The resource path.
      Returns:
      A reference to this EntryGenerator.
    • setSchema

      public EntryGenerator setSchema(Schema schema)
      Sets the schema which should be when generating entries. The default schema is used if no other is specified.
      Parameters:
      schema - The schema which should be used for generating entries.
      Returns:
      A reference to this EntryGenerator.
    • setConstant

      public EntryGenerator setConstant(String name, Object value)
      Sets a constant to use in template file. It overrides the constant set in the template file.
      Parameters:
      name - The name of the constant.
      value - The value of the constant.
      Returns:
      A reference to this EntryGenerator.
    • setGenerateBranches

      public EntryGenerator setGenerateBranches(boolean generateBranches)
      Sets the flag which indicates whether branch entries should be generated. The default is true.
      Parameters:
      generateBranches - Indicates whether the branches DN entries has to be generated.
      Returns:
      A reference to this EntryGenerator.
    • hasWarnings

      public boolean hasWarnings()
      Checks if there are some warning(s) after parsing the template file.

      Warnings are available only after the first call to hasNext() or readEntry() methods.

      Returns:
      true if there is at least one warning.
    • getWarnings

      public List<LocalizableMessage> getWarnings()
      Returns the warnings generated by the parsing of template file.

      Warnings are available only after the first call to hasNext() or readEntry() methods.

      Returns:
      The list of warnings, which is empty if there are no warnings.
    • close

      public void close()
      Description copied from interface: EntryReader
      Closes this entry reader if it is not already closed. Note that this method does not need to be called if a previous call of EntryReader.readEntry() has returned null.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface EntryReader
    • hasNext

      public boolean hasNext() throws IOException
      Description copied from interface: EntryReader
      Returns true if this reader contains another entry, blocking if necessary until either the next entry is available or the end of the stream is reached.
      Specified by:
      hasNext in interface EntryReader
      Returns:
      true if this reader contains another entry.
      Throws:
      IOException - If an unexpected IO error occurred.
    • readEntry

      public Entry readEntry() throws IOException
      Description copied from interface: EntryReader
      Reads the next entry, blocking if necessary until an entry is available.
      Specified by:
      readEntry in interface EntryReader
      Returns:
      The next entry.
      Throws:
      IOException - If an unexpected IO error occurred while reading the entry.