{
Iterator<AttributeTypeAndValue> atavIterator = newEntry.getRdn().iterator();
while ( atavIterator.hasNext() )
{
AttributeTypeAndValue atav = atavIterator.next();
IAttribute attribute = newEntry.getAttribute( atav.getUpType() );
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
LdapDN dn;
if ( wizard.isNewContextEntry() )
{
try
{
dn = new LdapDN( contextEntryDnCombo.getText() );
}
catch ( InvalidNameException e )
{
dn = LdapDN.EMPTY_LDAPDN;
}
}
else
{
dn = DnUtils.composeDn( dnBuilderWidget.getRdn(), dnBuilderWidget.getParentDn() );
}
newEntry.setDn( dn );
// add new RDN
if ( dn.getRdn().size() > 0 )
{
Iterator<AttributeTypeAndValue> atavIterator = dn.getRdn().iterator();
while ( atavIterator.hasNext() )
{
AttributeTypeAndValue atav = atavIterator.next();
IAttribute rdnAttribute = newEntry.getAttribute( atav.getUpType() );
if ( rdnAttribute == null )
{
rdnAttribute = new Attribute( newEntry, atav.getUpType() );
newEntry.addAttribute( rdnAttribute );
}
Object rdnValue = atav.getNormValue().getString();
String[] stringValues = rdnAttribute.getStringValues();
if ( !Arrays.asList( stringValues ).contains( rdnValue ) )
{
rdnAttribute.addValue( new Value( rdnAttribute, rdnValue ) );
}
}
}
}