org.opends.server.tools.makeldif
Class TemplateFile

java.lang.Object
  extended by org.opends.server.tools.makeldif.TemplateFile

public class TemplateFile
extends java.lang.Object

This class defines a template file, which is a collection of constant definitions, branches, and templates.


Field Summary
static java.lang.String FIRST_NAME_FILE
          The name of the file holding the list of first names.
static java.lang.String LAST_NAME_FILE
          The name of the file holding the list of last names.
 
Constructor Summary
TemplateFile(java.lang.String resourcePath)
          Creates a new, empty template file structure.
TemplateFile(java.lang.String resourcePath, java.util.Random random)
          Creates a new, empty template file structure.
 
Method Summary
 TagResult generateLDIF(EntryWriter entryWriter)
          Generates the LDIF content and writes it to the provided LDIF writer.
 Branch getBranch(DN branchDN)
          Retrieves the branch registered with the specified DN.
 java.util.Map<DN,Branch> getBranches()
          Retrieves the set of branches defined in this template file.
 java.lang.String getConstant(java.lang.String lowerName)
          Retrieves the value of the constant with the specified name.
 java.util.Map<java.lang.String,java.lang.String> getConstants()
          Retrieves the set of constants defined for this template file.
 java.io.File getFile(java.lang.String path)
          Retrieves a File object based on the provided path.
 java.lang.String[] getFileLines(java.io.File file)
          Retrieves the lines of the specified file as a string array.
 java.lang.String getFirstName()
          Retrieves the first name value that should be used for the current entry.
 java.lang.String getLastName()
          Retrieves the last name value that should be used for the current entry.
 java.util.Random getRandom()
          Retrieves the random number generator for this template file.
 Tag getTag(java.lang.String lowerName)
          Retrieves the tag with the specified name.
 java.util.Map<java.lang.String,Tag> getTags()
          Retrieves the set of tags that have been registered.
 Template getTemplate(java.lang.String lowerName)
          Retrieves the template with the specified name.
 java.util.Map<java.lang.String,Template> getTemplates()
          Retrieves the set of templates defined in this template file.
 void nextFirstAndLastNames()
          Updates the first and last name indexes to choose new values.
 void parse(java.io.InputStream inputStream, java.util.List<Message> warnings)
          Parses the data read from the provided input stream as a MakeLDIF template file definition.
 void parse(java.lang.String[] lines, java.util.List<Message> warnings)
          Parses the provided data as a MakeLDIF template file definition.
 void parse(java.lang.String filename, java.util.List<Message> warnings)
          Parses the contents of the specified file as a MakeLDIF template file definition.
 void registerBranch(Branch branch)
          Registers the provided branch in this template file.
 void registerConstant(java.lang.String name, java.lang.String value)
          Registers the provided constant for use in the template.
 void registerTag(java.lang.String tagClass)
          Registers the specified class as a tag that may be used in templates.
 void registerTemplate(Template template)
          Registers the provided template for use in this template file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST_NAME_FILE

public static final java.lang.String FIRST_NAME_FILE
The name of the file holding the list of first names.

See Also:
Constant Field Values

LAST_NAME_FILE

public static final java.lang.String LAST_NAME_FILE
The name of the file holding the list of last names.

See Also:
Constant Field Values
Constructor Detail

TemplateFile

public TemplateFile(java.lang.String resourcePath)
Creates a new, empty template file structure.

Parameters:
resourcePath - The path to the directory that may contain additional resource files needed during the LDIF generation process.

TemplateFile

public TemplateFile(java.lang.String resourcePath,
                    java.util.Random random)
Creates a new, empty template file structure.

Parameters:
resourcePath - The path to the directory that may contain additional resource files needed during the LDIF generation process.
random - The random number generator for this template file.
Method Detail

getTags

public java.util.Map<java.lang.String,Tag> getTags()
Retrieves the set of tags that have been registered. They will be in the form of a mapping between the name of the tag (in all lowercase characters) and the corresponding tag implementation.

Returns:
The set of tags that have been registered.

getTag

public Tag getTag(java.lang.String lowerName)
Retrieves the tag with the specified name.

Parameters:
lowerName - The name of the tag to retrieve, in all lowercase characters.
Returns:
The requested tag, or null if no such tag has been registered.

registerTag

public void registerTag(java.lang.String tagClass)
                 throws MakeLDIFException
Registers the specified class as a tag that may be used in templates.

Parameters:
tagClass - The fully-qualified name of the class to register as a tag.
Throws:
MakeLDIFException - If a problem occurs while attempting to register the specified tag.

getConstants

public java.util.Map<java.lang.String,java.lang.String> getConstants()
Retrieves the set of constants defined for this template file.

Returns:
The set of constants defined for this template file.

getConstant

public java.lang.String getConstant(java.lang.String lowerName)
Retrieves the value of the constant with the specified name.

Parameters:
lowerName - The name of the constant to retrieve, in all lowercase characters.
Returns:
The value of the constant with the specified name, or null if there is no such constant.

registerConstant

public void registerConstant(java.lang.String name,
                             java.lang.String value)
Registers the provided constant for use in the template.

Parameters:
name - The name for the constant.
value - The value for the constant.

getBranches

public java.util.Map<DN,Branch> getBranches()
Retrieves the set of branches defined in this template file.

Returns:
The set of branches defined in this template file.

getBranch

public Branch getBranch(DN branchDN)
Retrieves the branch registered with the specified DN.

Parameters:
branchDN - The DN for which to retrieve the corresponding branch.
Returns:
The requested branch, or null if no such branch has been registered.

registerBranch

public void registerBranch(Branch branch)
Registers the provided branch in this template file.

Parameters:
branch - The branch to be registered.

getTemplates

public java.util.Map<java.lang.String,Template> getTemplates()
Retrieves the set of templates defined in this template file.

Returns:
The set of templates defined in this template file.

getTemplate

public Template getTemplate(java.lang.String lowerName)
Retrieves the template with the specified name.

Parameters:
lowerName - The name of the template to retrieve, in all lowercase characters.
Returns:
The requested template, or null if there is no such template.

registerTemplate

public void registerTemplate(Template template)
Registers the provided template for use in this template file.

Parameters:
template - The template to be registered.

getRandom

public java.util.Random getRandom()
Retrieves the random number generator for this template file.

Returns:
The random number generator for this template file.

nextFirstAndLastNames

public void nextFirstAndLastNames()
Updates the first and last name indexes to choose new values. The algorithm used is designed to ensure that the combination of first and last names will never be repeated. It depends on the number of first names and the number of last names being relatively prime. This method should be called before beginning generation of each template entry.


getFirstName

public java.lang.String getFirstName()
Retrieves the first name value that should be used for the current entry.

Returns:
The first name value that should be used for the current entry.

getLastName

public java.lang.String getLastName()
Retrieves the last name value that should be used for the current entry.

Returns:
The last name value that should be used for the current entry.

parse

public void parse(java.lang.String filename,
                  java.util.List<Message> warnings)
           throws java.io.IOException,
                  InitializationException,
                  MakeLDIFException
Parses the contents of the specified file as a MakeLDIF template file definition.

Parameters:
filename - The name of the file containing the template data.
warnings - A list into which any warnings identified may be placed.
Throws:
java.io.IOException - If a problem occurs while attempting to read data from the specified file.
InitializationException - If a problem occurs while initializing any of the MakeLDIF components.
MakeLDIFException - If any other problem occurs while parsing the template file.

parse

public void parse(java.io.InputStream inputStream,
                  java.util.List<Message> warnings)
           throws java.io.IOException,
                  InitializationException,
                  MakeLDIFException
Parses the data read from the provided input stream as a MakeLDIF template file definition.

Parameters:
inputStream - The input stream from which to read the template file data.
warnings - A list into which any warnings identified may be placed.
Throws:
java.io.IOException - If a problem occurs while attempting to read data from the provided input stream.
InitializationException - If a problem occurs while initializing any of the MakeLDIF components.
MakeLDIFException - If any other problem occurs while parsing the template file.

parse

public void parse(java.lang.String[] lines,
                  java.util.List<Message> warnings)
           throws InitializationException,
                  MakeLDIFException
Parses the provided data as a MakeLDIF template file definition.

Parameters:
lines - The lines that make up the template file.
warnings - A list into which any warnings identified may be placed.
Throws:
InitializationException - If a problem occurs while initializing any of the MakeLDIF components.
MakeLDIFException - If any other problem occurs while parsing the template file.

getFile

public java.io.File getFile(java.lang.String path)
Retrieves a File object based on the provided path. If the given path is absolute, then that absolute path will be used. If it is relative, then it will first be evaluated relative to the current working directory. If that path doesn't exist, then it will be evaluated relative to the resource path. If that path doesn't exist, then it will be evaluated relative to the directory containing the template file.

Parameters:
path - The path provided for the file.
Returns:
The File object for the specified path, or null if the specified file could not be found.

getFileLines

public java.lang.String[] getFileLines(java.io.File file)
                                throws java.io.IOException
Retrieves the lines of the specified file as a string array. If the result is already cached, then it will be used. If the result is not cached, then the file data will be cached so that the contents can be re-used if there are multiple references to the same file.

Parameters:
file - The file for which to retrieve the contents.
Returns:
An array containing the lines of the specified file.
Throws:
java.io.IOException - If a problem occurs while reading the file.

generateLDIF

public TagResult generateLDIF(EntryWriter entryWriter)
                       throws java.io.IOException,
                              MakeLDIFException
Generates the LDIF content and writes it to the provided LDIF writer.

Parameters:
entryWriter - The entry writer that should be used to write the entries.
Returns:
The result that indicates whether processing should continue.
Throws:
java.io.IOException - If an error occurs while writing to the LDIF file.
MakeLDIFException - If some other problem occurs.