Package org.forgerock.opendj.ldif
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 Summary
Constructors Constructor Description EntryGenerator()
Creates a generator using default values.EntryGenerator(InputStream templateStream)
Creates a generator from the provided input stream.EntryGenerator(String templatePath)
Creates a generator from the provided template path.EntryGenerator(String... templateLines)
Creates a generator from the provided template lines.EntryGenerator(List<String> templateLines)
Creates a generator from the provided template lines.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this entry reader if it is not already closed.List<LocalizableMessage>
getWarnings()
Returns the warnings generated by the parsing of template file.boolean
hasNext()
Returnstrue
if this reader contains another entry, blocking if necessary until either the next entry is available or the end of the stream is reached.boolean
hasWarnings()
Checks if there are some warning(s) after parsing the template file.Entry
readEntry()
Reads the next entry, blocking if necessary until an entry is available.EntryGenerator
setConstant(String name, Object value)
Sets a constant to use in template file.EntryGenerator
setGenerateBranches(boolean generateBranches)
Sets the flag which indicates whether branch entries should be generated.EntryGenerator
setRandomSeed(int seed)
Sets the random seed to use when generating entries.EntryGenerator
setResourcePath(String path)
Sets the resource path, used to looks for resources files like first names, last names, or other custom resources.EntryGenerator
setResourcePath(Path path)
Sets the resource path, used to looks for resources files like first names, last names, or other custom resources.EntryGenerator
setSchema(Schema schema)
Sets the schema which should be when generating entries.
-
-
-
Constructor Detail
-
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 Detail
-
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 istrue
.- 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()
orreadEntry()
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()
orreadEntry()
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 ofEntryReader.readEntry()
has returnednull
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceEntryReader
-
hasNext
public boolean hasNext() throws IOException
Description copied from interface:EntryReader
Returnstrue
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 interfaceEntryReader
- 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 interfaceEntryReader
- Returns:
- The next entry.
- Throws:
IOException
- If an unexpected IO error occurred while reading the entry.
-
-