try
{
// check cache
for ( String url : referralUrls )
{
String normalizedUrl = Utils.getSimpleNormalizedUrl( new LdapUrl( url ) );
if ( referralUrlToReferralConnectionCache.containsKey( normalizedUrl ) )
{
// check if referral connection exists in connection manager
Connection referralConnection = referralUrlToReferralConnectionCache.get( normalizedUrl );
Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager()
.getConnections();
for ( int i = 0; i < connections.length; i++ )
{
Connection connection = connections[i];
if ( referralConnection == connection )
{
return referralConnection;
}
}
// referral connection doesn't exist in connection manager, remove it from cache
referralUrlToReferralConnectionCache.remove( normalizedUrl );
}
}
// open dialog
PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable()
{
public void run()
{
SelectReferralConnectionDialog dialog = new SelectReferralConnectionDialog( PlatformUI
.getWorkbench()
.getDisplay().getActiveShell(), referralUrls );
if ( dialog.open() == SelectReferralConnectionDialog.OK )
{
Connection connection = dialog.getReferralConnection();
referralConnections[0] = connection;
}
}
} );
// put to cache
if ( referralConnections[0] != null )
{
for ( String url : referralUrls )
{
String normalizedUrl = Utils.getSimpleNormalizedUrl( new LdapUrl( url ) );
referralUrlToReferralConnectionCache.put( normalizedUrl, referralConnections[0] );
}
}
}
catch ( LdapURLEncodingException e )