static void importLdifRecord( IBrowserConnection browserConnection, LdifRecord record, StudioProgressMonitor monitor )
throws ConnectionException
{
if ( !record.isValid() )
{
throw new ConnectionException( BrowserCoreMessages.model__invalid_record );
}
String dn = record.getDnLine().getValueAsString();
if ( record instanceof LdifContentRecord )
{
LdifContentRecord attrValRecord = ( LdifContentRecord ) record;
LdifAttrValLine[] attrVals = attrValRecord.getAttrVals();
Attributes jndiAttributes = new BasicAttributes();
for ( int ii = 0; ii < attrVals.length; ii++ )
{
String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
Object realValue = attrVals[ii].getValueAsObject();
if ( jndiAttributes.get( attributeName ) != null )
{
jndiAttributes.get( attributeName ).add( realValue );
}
else
{
jndiAttributes.put( attributeName, realValue );
}
}
browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
ReferralHandlingMethod.IGNORE, getControls( attrValRecord ), monitor, null );
}
else if ( record instanceof LdifChangeAddRecord )
{
LdifChangeAddRecord changeAddRecord = ( LdifChangeAddRecord ) record;
LdifAttrValLine[] attrVals = changeAddRecord.getAttrVals();
Attributes jndiAttributes = new BasicAttributes();
for ( int ii = 0; ii < attrVals.length; ii++ )
{
String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
Object realValue = attrVals[ii].getValueAsObject();
if ( jndiAttributes.get( attributeName ) != null )
{
jndiAttributes.get( attributeName ).add( realValue );
}
else
{
jndiAttributes.put( attributeName, realValue );
}
}
browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
ReferralHandlingMethod.IGNORE, getControls( changeAddRecord ), monitor, null );
}
else if ( record instanceof LdifChangeDeleteRecord )
{
LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
browserConnection.getConnection().getJNDIConnectionWrapper().deleteEntry( dn,
ReferralHandlingMethod.IGNORE, getControls( changeDeleteRecord ), monitor, null );
}
else if ( record instanceof LdifChangeModifyRecord )
{
LdifChangeModifyRecord modifyRecord = ( LdifChangeModifyRecord ) record;
LdifModSpec[] modSpecs = modifyRecord.getModSpecs();
ModificationItem[] mis = new ModificationItem[modSpecs.length];
for ( int ii = 0; ii < modSpecs.length; ii++ )
{
LdifModSpecTypeLine modSpecType = modSpecs[ii].getModSpecType();
LdifAttrValLine[] attrVals = modSpecs[ii].getAttrVals();
Attribute attribute = new BasicAttribute( modSpecType.getUnfoldedAttributeDescription() );
for ( int x = 0; x < attrVals.length; x++ )
{
attribute.add( attrVals[x].getValueAsObject() );
}
if ( modSpecType.isAdd() )
{
mis[ii] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
}
else if ( modSpecType.isDelete() )
{
mis[ii] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attribute );
}
else if ( modSpecType.isReplace() )
{
mis[ii] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute );
}
}
browserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry( dn, mis,
ReferralHandlingMethod.IGNORE, getControls( modifyRecord ), monitor, null );
}
else if ( record instanceof LdifChangeModDnRecord )
{
LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
if ( modDnRecord.getNewrdnLine() != null && modDnRecord.getDeloldrdnLine() != null )
{
String newRdn = modDnRecord.getNewrdnLine().getValueAsString();
boolean deleteOldRdn = modDnRecord.getDeloldrdnLine().isDeleteOldRdn();
try
{
LdapDN newDn;
if ( modDnRecord.getNewsuperiorLine() != null )
newDn = DnUtils.composeDn( newRdn, modDnRecord.getNewsuperiorLine().getValueAsString() );
else
{
LdapDN dnObject = new LdapDN( dn );
LdapDN parent = DnUtils.getParent( dnObject );
newDn = DnUtils.composeDn( newRdn, parent.getUpName() );
}
browserConnection.getConnection().getJNDIConnectionWrapper().renameEntry( dn, newDn.toString(),
deleteOldRdn, ReferralHandlingMethod.IGNORE, getControls( modDnRecord ), monitor, null );
}
catch ( InvalidNameException ne )
{
throw new ConnectionException( ne );
}
}
}
}