public void importEntry( LDAPEntry entry, int policy )
throws LDAPException
{
LDAPEntry existing;
LDAPModificationSet modifs;
LDAPAttributeSet attrSet;
LDAPAttribute attr;
int i;
Enumeration enumeration;
if ( entry.getAttributeSet() == null ||
entry.getAttributeSet().size() == 0 ) {
if ( ( policy & ImportDescriptor.Policy.DeleteEmpty ) != 0 ) {
try {
_conn.read( entry.getDN() );
_conn.delete( entry.getDN() );
notify( entry.getDN(), ImportEventListener.Deleted );
} catch ( LDAPException except ) {
// Object does not exist, was not removed, ignore.
// Anything else, we must complain.
if ( except.getLDAPResultCode() != LDAPException.NO_SUCH_OBJECT )
throw except;
notify( entry.getDN(), ImportEventListener.Ignored );
}
} else {
notify( entry.getDN(), ImportEventListener.Ignored );
}
} else {
try {
existing = _conn.read( entry.getDN() );
modifs = new LDAPModificationSet();
attrSet = entry.getAttributeSet();
for ( i = 0 ; i < attrSet.size() ; ++i ) {
attr = attrSet.elementAt( i );
if ( existing.getAttributeSet().getAttribute( attr.getName() ) != null ) {
if ( ( policy & ImportDescriptor.Policy.NewAttrOnly ) == 0 ) {
if ( attr.size() > 0 ) {
modifs.add( LDAPModification.REPLACE, attr );
} else {
modifs.add( LDAPModification.DELETE, attr );
}
}
} else {
if ( ( policy & ImportDescriptor.Policy.UpdateOnly ) == 0 ) {
if ( attr.size() > 0 ) {
modifs.add( LDAPModification.ADD, attr );
}
}
}
}
if ( ( policy & ImportDescriptor.Policy.ReplaceAttr ) != 0 ) {
enumeration = existing.getAttributeSet().getAttributes();
while ( enumeration.hasMoreElements() ) {
attr = (LDAPAttribute) enumeration.nextElement();
if ( entry.getAttribute( attr.getName() ) == null ) {
modifs.add( LDAPModification.DELETE, attr );
}
}
}
if ( modifs.size() > 0 ) {
_conn.modify( entry.getDN(), modifs );
notify( entry.getDN(), ImportEventListener.Refreshed );
} else {
notify( entry.getDN(), ImportEventListener.Ignored );
}