/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2013 ForgeRock AS
*/
/**
* This class defines a program that can be used to generate LDIF content based
* on a template.
*/
public class MakeLDIF
implements EntryWriter
{
/**
* The fully-qualified name of this class.
*/
"org.opends.server.tools.makeldif.MakeLDIF";
// The LDIF writer that will be used to write the entries.
// The total number of entries that have been written.
private long entriesWritten;
/**
* Invokes the <CODE>makeLDIFMain</CODE> method with the provided set of
* arguments.
*
* @param args The command-line arguments provided for this program.
*/
{
if (returnCode != 0)
{
}
}
/**
* Creates a new instance of this utility. It should just be used for
* invoking the <CODE>makeLDIFMain</CODE> method.
*/
public MakeLDIF()
{
ldifWriter = null;
entriesWritten = 0L;
}
/**
* Processes the provided set of command-line arguments and begins generating
* the LDIF content.
*
* @param args The command-line arguments provided for this program.
* @param initializeServer Indicates whether to initialize the server.
* @param initializeSchema Indicates whether to initialize the schema.
* @param outStream The output stream to use for standard output, or
* {@code null} if standard output is not needed.
* @param errStream The output stream to use for standard error, or
* {@code null} if standard error is not needed.
* @return A result code of zero if all processing completed properly, or
* a nonzero result if a problem occurred.
*
*/
boolean initializeSchema,
{
{
}
else
{
}
{
}
else
{
}
// Create and initialize the argument parser for this program.
false);
try
{
false, true,
null,
configFile.setHidden(true);
OPTION_LONG_CONFIG_CLASS, false,
false, true,
null,
configClass.setHidden(true);
resourcePath.setHidden(true);
true, false, true, INFO_FILE_PLACEHOLDER.get(),
OPTION_LONG_RANDOM_SEED, false,
false, true, INFO_SEED_PLACEHOLDER.get(),
0, null,
}
catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to the program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
return 1;
}
if (initializeServer)
{
// Initialize the Directory Server configuration handler using the
// information that was provided.
try
{
}
catch (Exception e)
{
return 1;
}
try
{
configFile.getValue());
}
catch (Exception e)
{
return 1;
}
}
if (initializeSchema)
{
try
{
}
catch (Exception e)
{
return 1;
}
}
// Create the random number generator that will be used for the generation
// process.
if (randomSeed.isPresent())
{
try
{
}
catch (Exception e)
{
}
}
else
{
}
// If a resource path was provided, then make sure it's acceptable.
if (! resourceDir.exists())
{
resourcePath.getValue());
return 1;
}
// Load and parse the template file.
random);
try
{
}
catch (IOException ioe)
{
ioe.getMessage());
return 1;
}
catch (Exception e)
{
e.getMessage());
return 1;
}
// If there were any warnings, then print them.
{
{
}
}
// Create the LDIF writer that will be used to actually write the LDIF.
try
{
}
catch (IOException ioe)
{
return 1;
}
// Generate the LDIF content.
try
{
templateFile.generateLDIF(this);
}
catch (Exception e)
{
return 1;
}
finally
{
try
{
ldifWriter.close();
} catch (Exception e) {}
}
// If we've gotten here, then everything was successful.
return 0;
}
/**
* Processes the provided set of command-line arguments and begins generating
* the LDIF content.
*
* @param args The command-line arguments provided for this program.
*
* @return A result code of zero if all processing completed properly, or
* a nonzero result if a problem occurred.
*/
{
}
/**
* Writes the provided entry to the appropriate target.
*
* @param entry The entry to be written.
*
* @return <CODE>true</CODE> if the entry writer will accept more entries, or
* <CODE>false</CODE> if not.
*
* @throws IOException If a problem occurs while writing the entry to its
* intended destination.
*
* @throws MakeLDIFException If some other problem occurs.
*/
throws IOException, MakeLDIFException
{
try
{
{
{
}
}
else
{
{
{
break ;
}
}
return true;
}
return true;
}
catch (IOException ioe)
{
throw ioe;
}
catch (Exception e)
{
throw new MakeLDIFException(message, e);
}
}
/**
* Notifies the entry writer that no more entries will be provided and that
* any associated cleanup may be performed.
*/
public void closeEntryWriter()
{
}
}