* @param ldif the ldif containing entries to add to the server.
* @throws NamingException if there is a problem adding the entries from the LDIF
*/
public static void injectEntries( DirectoryService service, String ldif ) throws Exception
{
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif( ldif );
for ( LdifEntry entry : entries )
{
if ( entry.isChangeAdd() )
{
service.getAdminSession().add(
new DefaultServerEntry( service.getSchemaManager(), entry.getEntry() ) );
}
else if ( entry.isChangeModify() )
{
service.getAdminSession().modify(
entry.getDn(), entry.getModificationItems() );
}
else
{
String message = I18n.err( I18n.ERR_117, entry.getChangeType() );
LOG.error( message );
throw new NamingException( message );
}
}
// And close the reader
reader.close();
}