if ( newEntry.getRdn().size() > 0 )
{
Iterator<Ava> atavIterator = newEntry.getRdn().iterator();
while ( atavIterator.hasNext() )
{
Ava atav = atavIterator.next();
IAttribute attribute = newEntry.getAttribute( atav.getType() );
if ( attribute != null )
{
IValue[] values = attribute.getValues();
for ( int v = 0; v < values.length; v++ )
{
if ( values[v].getStringValue().equals( atav.getNormValue().getString() ) )
{
attribute.deleteValue( values[v] );
}
}
// If we have removed all the values of the attribute,
// then we also need to remove this attribute from the
// entry.
// This test has been added to fix DIRSTUDIO-222
if ( attribute.getValueSize() == 0 )
{
newEntry.deleteAttribute( attribute );
}
}
}
}
// set new Dn
Dn dn;
if ( wizard.isNewContextEntry() )
{
try
{
dn = new Dn( contextEntryDnCombo.getText() );
}
catch ( LdapInvalidDnException e )
{
dn = Dn.EMPTY_DN;
}
}
else
{
try
{
dn = dnBuilderWidget.getParentDn().add( dnBuilderWidget.getRdn() );
}
catch ( LdapInvalidDnException lide )
{
// Do nothing
dn = Dn.EMPTY_DN;
}
}
newEntry.setDn( dn );
// add new Rdn
if ( dn.getRdn().size() > 0 )
{
Iterator<Ava> atavIterator = dn.getRdn().iterator();
while ( atavIterator.hasNext() )
{
Ava atav = atavIterator.next();
IAttribute rdnAttribute = newEntry.getAttribute( atav.getType() );
if ( rdnAttribute == null )
{
rdnAttribute = new Attribute( newEntry, atav.getType() );
newEntry.addAttribute( rdnAttribute );
}
Object rdnValue = atav.getNormValue().getString();
String[] stringValues = rdnAttribute.getStringValues();
if ( !Arrays.asList( stringValues ).contains( rdnValue ) )
{
rdnAttribute.addValue( new Value( rdnAttribute, rdnValue ) );
}