directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marina <>
Subject Re: How to import LDIF file programmatically
Date Thu, 10 May 2012 17:06:28 GMT

Hi, Gokturk,
This example code does not compile - I get a few errors about missing/incorrect classes and
method signatures....
For example: 

 if ( entry.isLdifContent() ) --> The method isLdifContent() is undefined for the type
 ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();  --> ModifyDnRequest class
does not exist, and The constructor ModifyDnRequestImpl() is undefined
and others....

Which version of ApacheDS is it for? I'm using 1.5.7.
Or, maybe I'm missing some libraries? I have apacheds-all-1.5.7.jar.

Are there some published APIS/ documentation for this kind of tasks?

From: Göktürk Gezer <>
Sent: Wednesday, May 9, 2012 4:23 PM
Subject: Re: How to import LDIF file programmatically

You can use below code as your base. You might wanna slightly change it
based on which version of ApacheDS you're using.

And make sure your ldif file is constructed in correct order from the top
to the bottom. I'd preffer to use CoreSession to issue operations to make
sure they're checked, but you can issue operations on the Jdbm partition
reference you've created as well..

LdifReader ldifReader = new LdifReader(new
CoreSession conn; // Obtain it from embedded DirectoryService reference.

for ( LdifEntry entry : ldifReader )
    if ( entry.isLdifContent() )
        conn.add( entry.getEntry() );

    switch ( entry.getChangeType() )
        case ModRdn:
        case ModDn:
            ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
            modDnRequest.setName( entry.getDn() );
            modDnRequest.setDeleteOldRdn( entry.isDeleteOldRdn() );

            if ( entry.getNewSuperior() != null )
                modDnRequest.setNewSuperior( new Dn( entry.getNewSuperior()
) );

            if ( entry.getNewRdn() != null )
                modDnRequest.setNewRdn( new Rdn( entry.getNewRdn() ) );
            conn.modifyDn( modDnRequest );
        case Delete:
            conn.delete( entry.getDn() );
        case Modify:
            conn.modify( entry.getDn(), entry.getModificationArray() );
            throw new IllegalArgumentException( "Unknown change type in
LdifEntry: "
                + entry.getChangeType().toString() );

View raw message