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
setmethods: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 voidclose()Closes this entry reader if it is not already closed.List<LocalizableMessage>getWarnings()Returns the warnings generated by the parsing of template file.booleanhasNext()Returnstrueif this reader contains another entry, blocking if necessary until either the next entry is available or the end of the stream is reached.booleanhasWarnings()Checks if there are some warning(s) after parsing the template file.EntryreadEntry()Reads the next entry, blocking if necessary until an entry is available.EntryGeneratorsetConstant(String name, Object value)Sets a constant to use in template file.EntryGeneratorsetGenerateBranches(boolean generateBranches)Sets the flag which indicates whether branch entries should be generated.EntryGeneratorsetRandomSeed(int seed)Sets the random seed to use when generating entries.EntryGeneratorsetResourcePath(String path)Sets the resource path, used to looks for resources files like first names, last names, or other custom resources.EntryGeneratorsetResourcePath(Path path)Sets the resource path, used to looks for resources files like first names, last names, or other custom resources.EntryGeneratorsetSchema(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:
trueif 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:EntryReaderCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceEntryReader
-
hasNext
public boolean hasNext() throws IOExceptionDescription copied from interface:EntryReaderReturnstrueif 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:
hasNextin interfaceEntryReader- Returns:
trueif this reader contains another entry.- Throws:
IOException- If an unexpected IO error occurred.
-
readEntry
public Entry readEntry() throws IOException
Description copied from interface:EntryReaderReads the next entry, blocking if necessary until an entry is available.- Specified by:
readEntryin interfaceEntryReader- Returns:
- The next entry.
- Throws:
IOException- If an unexpected IO error occurred while reading the entry.
-
-