directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r827920 [1/4] - in /directory/studio/trunk: connection-core/src/main/java/org/apache/directory/studio/connection/core/ connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ connection-ui/src/main/java/org/apache...
Date Wed, 21 Oct 2009 08:35:58 GMT
Author: seelmann
Date: Wed Oct 21 08:35:55 2009
New Revision: 827920

URL: http://svn.apache.org/viewvc?rev=827920&view=rev
Log:
Fixed referrals handling:
o DIRSTUDIO-371 (Entries with a ref attribute should be shown N times in the browser (N = number of ref values))
o DIRSTUDIO-409 (No error message in some special case)
o DIRSTUDIO-410 (Referral handling is problematic)
o DIRSTUDIO-533 (Only show referral handling dialog when opening or expanding referral entry)
o DIRSTUDIO-571 (Modification is logged even if referred to another directory server)
o Removed 'manage' referral handling, use explicit 'ManageDsaIT control' instead
o Added 'follow manually' referral handling for use in the browser
o Added IContinuation interface, added SearchContinuation and ContinuedSearchResultEntry classes
o Removed ReferralBaseEntry and AliasBaseEntry
o Moved StudioControl class to connection.core plugin
o Introduced IComparableEntry interface for comparable entry classes

Added:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioControl.java
      - copied, changed from r824908, directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioControl.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.java
      - copied, changed from r824908, directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioPagedResultsControl.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/ICompareableEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IContinuation.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BookmarkEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ContinuedSearchResultEntry.java
      - copied, changed from r824908, directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ReferralBaseEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/SearchContinuation.java
Removed:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioControl.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioPagedResultsControl.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/AliasBaseEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ReferralBaseEntry.java
Modified:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/DeleteAction.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchReferralsAction.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserContentProvider.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/messages.properties
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/messages_de.properties
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/messages_fr.properties
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReferralsHandlingWidget.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/SearchPageWrapper.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/messages.properties
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/messages_de.properties
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/messages_fr.properties
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CreateEntryRunnable.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesRunnable.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenRunnable.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryRunnable.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameEntryJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchRunnable.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/ISearch.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/SearchParameter.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/AbstractEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Bookmark.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Search.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/SearchResult.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorInput.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorUtils.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditor.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorNavigationLocation.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewLabelDecorator.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/BatchOperationApplyOnWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportCsvFromWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlFromWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportExcelFromWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportLdifFromWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportOdfFromWizardPage.java
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ApacheDsSchemaConnector.java
    directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java Wed Oct 21 08:35:55 2009
@@ -46,28 +46,28 @@
      */
     public static enum AliasDereferencingMethod
     {
-    
+
         /** Never. */
         NEVER(0),
-    
+
         /** Always. */
         ALWAYS(1),
-    
+
         /** Finding. */
         FINDING(2),
-    
+
         /** Search. */
         SEARCH(3);
-    
+
         private final int ordinal;
-    
-    
+
+
         private AliasDereferencingMethod( int ordinal )
         {
             this.ordinal = ordinal;
         }
-    
-    
+
+
         /**
          * Gets the ordinal.
          * 
@@ -77,8 +77,8 @@
         {
             return ordinal;
         }
-    
-    
+
+
         /**
          * Gets the AliasDereferencingMethod by ordinal.
          * 
@@ -104,7 +104,6 @@
         }
     }
 
-
     /**
      * Enum for referral handling method.
      * 
@@ -113,25 +112,28 @@
      */
     public static enum ReferralHandlingMethod
     {
-    
+
         /** Ignore. */
         IGNORE(0),
-    
-        /** Follow. */
+
+        /** Follow automatically. */
         FOLLOW(1),
-    
+
         /** Manage. */
-        MANAGE(2);
-    
+        //MANAGE(2),
+
+        /** Follow manually. */
+        FOLLOW_MANUALLY(3);
+
         private final int ordinal;
-    
-    
+
+
         private ReferralHandlingMethod( int ordinal )
         {
             this.ordinal = ordinal;
         }
-    
-    
+
+
         /**
          * Gets the ordinal.
          * 
@@ -141,8 +143,8 @@
         {
             return ordinal;
         }
-    
-    
+
+
         /**
          * Gets the ReferralHandlingMethod by ordinal.
          * 
@@ -159,18 +161,21 @@
                 case 1:
                     return FOLLOW;
                 case 2:
-                    return MANAGE;
+                    //return MANAGE;
+                    return FOLLOW_MANUALLY;
+                case 3:
+                    return FOLLOW_MANUALLY;
                 default:
                     return null;
             }
         }
     }
 
-
     private ConnectionParameter connectionParameter;
 
     private JNDIConnectionWrapper jndiConnectionWrapper;
 
+
     /**
      * Creates a new instance of Connection.
      *
@@ -288,8 +293,8 @@
     {
         return connectionParameter.getId();
     }
-    
-    
+
+
     /**
      * Gets the host.
      * 
@@ -322,15 +327,15 @@
         return connectionParameter.getPort();
     }
 
-    
+
     /**
      * Gets the SASL realm.
      * 
      * @return the SASL realm
      */
-    public String getSaslRealm ()
+    public String getSaslRealm()
     {
-    	return connectionParameter.getSaslRealm();
+        return connectionParameter.getSaslRealm();
     }
 
 
@@ -343,8 +348,8 @@
     {
         return connectionParameter.isReadOnly();
     }
-    
-    
+
+
     /**
      * Sets the auth method.
      * 

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java Wed Oct 21 08:35:55 2009
@@ -309,7 +309,7 @@
             // that just cancels referral chasing
             referralHandler = new IReferralHandler()
             {
-                public Connection getReferralConnection( LdapURL referralURL )
+                public Connection getReferralConnection( List<LdapURL> referralUrls )
                 {
                     // null cancels referral chasing
                     return null;

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java Wed Oct 21 08:35:55 2009
@@ -174,12 +174,12 @@
      * Logs a search result reference.
      *
      * @param connection the connection
-     * @param urlAndDn the first URL and DN
+     * @param referral the referral
      * @param referralsInfo the referrals info containing further URLs and DNs
      * @param requestNum the request number
      * @param the naming exception if an error occurred, null otherwise
      */
-    public void logSearchResultReference( Connection connection, ReferralsInfo.UrlAndDn urlAndDn,
+    public void logSearchResultReference( Connection connection, ReferralsInfo.Referral referral,
         ReferralsInfo referralsInfo, long requestNum, NamingException namingException );
 
 

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java Wed Oct 21 08:35:55 2009
@@ -21,6 +21,8 @@
 package org.apache.directory.studio.connection.core;
 
 
+import java.util.List;
+
 import org.apache.directory.shared.ldap.util.LdapURL;
 
 
@@ -40,9 +42,9 @@
      * The referral handler may display a dialog to the user
      * to select a proper connection.
      * 
-     * @param referralURL the referral URL
+     * @param referralURLs the referral URLs
      * @return the target connection, null to cancel referral chasing
      */
-    public Connection getReferralConnection( LdapURL referralURL );
+    public Connection getReferralConnection( List<LdapURL> referralUrls );
 
 }

Copied: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioControl.java (from r824908, directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioControl.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioControl.java?p2=directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioControl.java&p1=directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioControl.java&r1=824908&r2=827920&rev=827920&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioControl.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioControl.java Wed Oct 21 08:35:55 2009
@@ -18,7 +18,7 @@
  *  
  */
 
-package org.apache.directory.studio.ldapbrowser.core.model;
+package org.apache.directory.studio.connection.core;
 
 
 import java.io.Serializable;

Copied: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.java (from r824908, directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioPagedResultsControl.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.java?p2=directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.java&p1=directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioPagedResultsControl.java&r1=824908&r2=827920&rev=827920&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/StudioPagedResultsControl.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.java Wed Oct 21 08:35:55 2009
@@ -18,7 +18,7 @@
  *  
  */
 
-package org.apache.directory.studio.ldapbrowser.core.model;
+package org.apache.directory.studio.connection.core;
 
 
 import java.io.IOException;

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java Wed Oct 21 08:35:55 2009
@@ -84,6 +84,7 @@
         return null;
     }
 
+
     /**
      * Shortens the given label to the given maximum length
      * and filters non-printable characters.
@@ -209,6 +210,19 @@
 
 
     /**
+     * Gets the simple normalized form of the LDAP URL: schema, host and port.
+     * 
+     * @param url the LDAP URL
+     * 
+     * @return the simple normalized form of the LDAP URL
+     */
+    public static String getSimpleNormalizedUrl( LdapURL url )
+    {
+        return url.getScheme() + ( url.getHost() != null ? url.getHost().toLowerCase() : "" ) + ":" + url.getPort();
+    }
+
+
+    /**
      * Transforms the given search parameters into an ldapsearch command line.
      *
      * @param connection the connection

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java Wed Oct 21 08:35:55 2009
@@ -47,7 +47,6 @@
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 import javax.naming.ldap.LdapName;
-import javax.naming.ldap.ManageReferralControl;
 import javax.naming.ldap.StartTlsRequest;
 import javax.naming.ldap.StartTlsResponse;
 import javax.net.ssl.HostnameVerifier;
@@ -85,7 +84,7 @@
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
-import org.apache.directory.studio.connection.core.io.jndi.ReferralsInfo.UrlAndDn;
+import org.apache.directory.studio.connection.core.io.jndi.ReferralsInfo.Referral;
 import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 import org.eclipse.core.runtime.Preferences;
 import org.eclipse.osgi.util.NLS;
@@ -340,13 +339,11 @@
         {
             public void run()
             {
-                // add ManageDsaIT control
-                Control[] localControls = addManageDsaItControls( controls, referralsHandlingMethod );
-
+                LdapContext searchCtx = context;
                 try
                 {
                     // create the search context
-                    LdapContext searchCtx = context.newInstance( localControls );
+                    searchCtx = context.newInstance( controls );
 
                     // translate alias dereferencing method
                     searchCtx.addToEnvironment( JAVA_NAMING_LDAP_DEREF_ALIASES,
@@ -356,76 +353,26 @@
                     searchCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // perform the search
-                    NamingEnumeration<SearchResult> ne = searchCtx.search( getSaveJndiName( searchBase ), filter,
-                        searchControls );
-                    namingEnumeration = new StudioNamingEnumeration( connection, searchCtx, ne, searchBase, filter,
-                        searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls, requestNum,
-                        monitor, referralsInfo );
-                }
-                catch ( PartialResultException pre )
-                {
-                    // ignore exception if referrals handling method is IGNORE
-                    // report exception if referrals handling method is FOLLOW or MANGAGE
-                    if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW
-                        || referralsHandlingMethod == ReferralHandlingMethod.MANAGE )
-                    {
-                        namingException = pre;
-                    }
-                }
-                catch ( ReferralException re )
-                {
-                    // ignore exception if referrals handling method is IGNORE
-                    // report exception if referrals handling method is MANGAGE
-                    // follow referral if referrals handling method is FOLLOW
-                    if ( referralsHandlingMethod == ReferralHandlingMethod.MANAGE )
-                    {
-                        namingException = re;
-                    }
-                    else if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW )
-                    {
-                        try
-                        {
-                            ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
-                            UrlAndDn urlAndDn = newReferralsInfo.getNext();
-                            if ( urlAndDn != null )
-                            {
-                                LdapURL url = urlAndDn.getUrl();
-                                Connection referralConnection = getReferralConnection( url, monitor, this );
-                                if ( referralConnection != null )
-                                {
-                                    String referralSearchBase = url.getDn() != null && !url.getDn().isEmpty() ? url
-                                        .getDn().getUpName() : searchBase;
-                                    String referralFilter = url.getFilter() != null && url.getFilter().length() == 0 ? url
-                                        .getFilter()
-                                        : filter;
-                                    SearchControls referralSearchControls = new SearchControls();
-                                    referralSearchControls.setSearchScope( url.getScope() > -1 ? url.getScope()
-                                        : searchControls.getSearchScope() );
-                                    referralSearchControls.setReturningAttributes( url.getAttributes() != null
-                                        && url.getAttributes().size() > 0 ? url.getAttributes().toArray(
-                                        new String[url.getAttributes().size()] ) : searchControls
-                                        .getReturningAttributes() );
-                                    referralSearchControls.setCountLimit( searchControls.getCountLimit() );
-                                    referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
-                                    referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
-                                    referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
-
-                                    namingEnumeration = ( StudioNamingEnumeration ) referralConnection
-                                        .getJNDIConnectionWrapper().search( referralSearchBase, referralFilter,
-                                            referralSearchControls, aliasesDereferencingMethod,
-                                            referralsHandlingMethod, controls, monitor, newReferralsInfo );
-                                }
-                            }
-                        }
-                        catch ( NamingException ne )
-                        {
-                            namingException = ne;
-                        }
-                    }
+                    NamingEnumeration<SearchResult> result = searchCtx.search( JNDIConnectionWrapper
+                        .getSaveJndiName( searchBase ), filter, searchControls );
+                    namingEnumeration = new StudioNamingEnumeration( connection, searchCtx, result, null, searchBase,
+                        filter, searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls,
+                        requestNum, monitor, referralsInfo );
+                }
+                catch ( PartialResultException e )
+                {
+                    namingEnumeration = new StudioNamingEnumeration( connection, searchCtx, null, e, searchBase,
+                        filter, searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls,
+                        requestNum, monitor, referralsInfo );
+                }
+                catch ( ReferralException e )
+                {
+                    namingEnumeration = new StudioNamingEnumeration( connection, searchCtx, null, e, searchBase,
+                        filter, searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls,
+                        requestNum, monitor, referralsInfo );
                 }
                 catch ( NamingException e )
                 {
-                    // report each other naming exception
                     namingException = e;
                 }
 
@@ -434,12 +381,12 @@
                     if ( namingEnumeration != null )
                     {
                         logger.logSearchRequest( connection, searchBase, filter, searchControls,
-                            aliasesDereferencingMethod, localControls, requestNum, namingException );
+                            aliasesDereferencingMethod, controls, requestNum, namingException );
                     }
                     else
                     {
                         logger.logSearchRequest( connection, searchBase, filter, searchControls,
-                            aliasesDereferencingMethod, localControls, requestNum, namingException );
+                            aliasesDereferencingMethod, controls, requestNum, namingException );
                         logger.logSearchResultDone( connection, 0, requestNum, namingException );
                     }
                 }
@@ -461,14 +408,9 @@
             monitor.reportError( runnable.getException() );
             return null;
         }
-        else if ( runnable.getResult() != null )
-        {
-            return runnable.getResult();
-        }
         else
         {
-            return new StudioNamingEnumeration( connection, null, null, searchBase, filter, searchControls,
-                aliasesDereferencingMethod, referralsHandlingMethod, controls, requestNum, monitor, referralsInfo );
+            return runnable.getResult();
         }
     }
 
@@ -478,13 +420,11 @@
      * 
      * @param dn the DN
      * @param modificationItems the modification items
-     * @param referralsHandlingMethod the referrals handling method
      * @param controls the controls
      * @param monitor the progress monitor
      * @param referralsInfo the referrals info
      */
-    public void modifyEntry( final String dn, final ModificationItem[] modificationItems,
-        final ReferralHandlingMethod referralsHandlingMethod, final Control[] controls,
+    public void modifyEntry( final String dn, final ModificationItem[] modificationItems, final Control[] controls,
         final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
         if ( connection.isReadOnly() )
@@ -497,13 +437,11 @@
         {
             public void run()
             {
-                // add ManageDsaIT control
-                Control[] localControls = addManageDsaItControls( controls, referralsHandlingMethod );
-
+                boolean logModifycation = true;
                 try
                 {
                     // create modify context
-                    LdapContext modCtx = context.newInstance( localControls );
+                    LdapContext modCtx = context.newInstance( controls );
 
                     // use "throw" as we handle referrals manually
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
@@ -513,22 +451,25 @@
                 }
                 catch ( ReferralException re )
                 {
+                    logModifycation = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
-                        UrlAndDn urlAndDn = newReferralsInfo.getNext();
-                        if ( urlAndDn != null )
+                        Referral referral = newReferralsInfo.getNextReferral();
+                        if ( referral != null )
                         {
-                            Connection referralConnection = getReferralConnection( urlAndDn.getUrl(), monitor, this );
+                            Connection referralConnection = getReferralConnection( referral, monitor, this );
                             if ( referralConnection != null )
                             {
-                                String referralDn = urlAndDn.getDn() != null && !urlAndDn.getDn().isEmpty() ? urlAndDn
+                                String referralDn = referral.getDn() != null && !referral.getDn().isEmpty() ? referral
                                     .getDn().getUpName() : dn;
 
                                 referralConnection.getJNDIConnectionWrapper().modifyEntry( referralDn,
-                                    modificationItems, referralsHandlingMethod, controls, monitor, newReferralsInfo );
+                                    modificationItems, controls, monitor, newReferralsInfo );
                             }
                         }
+
+                        return;
                     }
                     catch ( NamingException ne )
                     {
@@ -540,9 +481,12 @@
                     namingException = ne;
                 }
 
-                for ( IJndiLogger logger : getJndiLoggers() )
+                if ( logModifycation )
                 {
-                    logger.logChangetypeModify( connection, dn, modificationItems, localControls, namingException );
+                    for ( IJndiLogger logger : getJndiLoggers() )
+                    {
+                        logger.logChangetypeModify( connection, dn, modificationItems, controls, namingException );
+                    }
                 }
             }
         };
@@ -569,14 +513,12 @@
      * @param oldDn the old DN
      * @param newDn the new DN
      * @param deleteOldRdn true to delete the old RDN
-     * @param referralsHandlingMethod the referrals handling method
      * @param controls the controls
      * @param monitor the progress monitor
      * @param referralsInfo the referrals info
      */
     public void renameEntry( final String oldDn, final String newDn, final boolean deleteOldRdn,
-        final ReferralHandlingMethod referralsHandlingMethod, final Control[] controls,
-        final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
+        final Control[] controls, final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
         if ( connection.isReadOnly() )
         {
@@ -588,13 +530,11 @@
         {
             public void run()
             {
-                // add ManageDsaIT control
-                Control[] localControls = addManageDsaItControls( controls, referralsHandlingMethod );
-
+                boolean logModifycation = true;
                 try
                 {
                     // create modify context
-                    LdapContext modCtx = context.newInstance( localControls );
+                    LdapContext modCtx = context.newInstance( controls );
 
                     // use "throw" as we handle referrals manually
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
@@ -614,20 +554,18 @@
                 }
                 catch ( ReferralException re )
                 {
+                    logModifycation = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
-                        UrlAndDn urlAndDn = newReferralsInfo.getNext();
-                        if ( urlAndDn != null )
+                        Referral referral = newReferralsInfo.getNextReferral();
+                        if ( referral != null )
                         {
-                            Connection referralConnection = getReferralConnection( urlAndDn.getUrl(), monitor, this );
+                            Connection referralConnection = getReferralConnection( referral, monitor, this );
                             if ( referralConnection != null )
                             {
-                                //                                String referralDn = url.getDn() != null && !url.getDn().isEmpty() ? url.getDn()
-                                //                                    .getUpName() : dn;
-                                // TODO: referral DN???
                                 referralConnection.getJNDIConnectionWrapper().renameEntry( oldDn, newDn, deleteOldRdn,
-                                    referralsHandlingMethod, controls, monitor, newReferralsInfo );
+                                    controls, monitor, newReferralsInfo );
                             }
                         }
                     }
@@ -641,9 +579,12 @@
                     namingException = ne;
                 }
 
-                for ( IJndiLogger logger : getJndiLoggers() )
+                if ( logModifycation )
                 {
-                    logger.logChangetypeModDn( connection, oldDn, newDn, deleteOldRdn, localControls, namingException );
+                    for ( IJndiLogger logger : getJndiLoggers() )
+                    {
+                        logger.logChangetypeModDn( connection, oldDn, newDn, deleteOldRdn, controls, namingException );
+                    }
                 }
             }
         };
@@ -669,13 +610,11 @@
      * 
      * @param dn the entry's DN
      * @param attributes the entry's attributes
-     * @param referralsHandlingMethod the referrals handling method
      * @param controls the controls
      * @param monitor the progress monitor
      * @param referralsInfo the referrals info
      */
-    public void createEntry( final String dn, final Attributes attributes,
-        final ReferralHandlingMethod referralsHandlingMethod, final Control[] controls,
+    public void createEntry( final String dn, final Attributes attributes, final Control[] controls,
         final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
         if ( connection.isReadOnly() )
@@ -688,13 +627,11 @@
         {
             public void run()
             {
-                // add ManageDsaIT control
-                Control[] localControls = addManageDsaItControls( controls, referralsHandlingMethod );
-
+                boolean logModifycation = true;
                 try
                 {
                     // create modify context
-                    LdapContext modCtx = context.newInstance( localControls );
+                    LdapContext modCtx = context.newInstance( controls );
 
                     // use "throw" as we handle referrals manually
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
@@ -704,20 +641,21 @@
                 }
                 catch ( ReferralException re )
                 {
+                    logModifycation = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
-                        UrlAndDn urlAndDn = newReferralsInfo.getNext();
-                        if ( urlAndDn != null )
+                        Referral referral = newReferralsInfo.getNextReferral();
+                        if ( referral != null )
                         {
-                            Connection referralConnection = getReferralConnection( urlAndDn.getUrl(), monitor, this );
+                            Connection referralConnection = getReferralConnection( referral, monitor, this );
                             if ( referralConnection != null )
                             {
-                                String referralDn = urlAndDn.getDn() != null && !urlAndDn.getDn().isEmpty() ? urlAndDn
+                                String referralDn = referral.getDn() != null && !referral.getDn().isEmpty() ? referral
                                     .getDn().getUpName() : dn;
 
                                 referralConnection.getJNDIConnectionWrapper().createEntry( referralDn, attributes,
-                                    referralsHandlingMethod, controls, monitor, newReferralsInfo );
+                                    controls, monitor, newReferralsInfo );
                             }
                         }
                     }
@@ -731,9 +669,12 @@
                     namingException = ne;
                 }
 
-                for ( IJndiLogger logger : getJndiLoggers() )
+                if ( logModifycation )
                 {
-                    logger.logChangetypeAdd( connection, dn, attributes, localControls, namingException );
+                    for ( IJndiLogger logger : getJndiLoggers() )
+                    {
+                        logger.logChangetypeAdd( connection, dn, attributes, controls, namingException );
+                    }
                 }
             }
         };
@@ -758,13 +699,12 @@
      * Deletes an entry.
      * 
      * @param dn the DN of the entry to delete
-     * @param referralsHandlingMethod the referrals handling method
      * @param controls the controls
      * @param monitor the progress monitor
      * @param referralsInfo the referrals info
      */
-    public void deleteEntry( final String dn, final ReferralHandlingMethod referralsHandlingMethod,
-        final Control[] controls, final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
+    public void deleteEntry( final String dn, final Control[] controls, final StudioProgressMonitor monitor,
+        final ReferralsInfo referralsInfo )
     {
         if ( connection.isReadOnly() )
         {
@@ -776,13 +716,11 @@
         {
             public void run()
             {
-                // add ManageDsaIT control
-                Control[] localControls = addManageDsaItControls( controls, referralsHandlingMethod );
-
+                boolean logModifycation = true;
                 try
                 {
                     // create modify context
-                    LdapContext modCtx = context.newInstance( localControls );
+                    LdapContext modCtx = context.newInstance( controls );
 
                     // use "throw" as we handle referrals manually
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
@@ -792,20 +730,21 @@
                 }
                 catch ( ReferralException re )
                 {
+                    logModifycation = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
-                        UrlAndDn urlAndDn = newReferralsInfo.getNext();
-                        if ( urlAndDn != null )
+                        Referral referral = newReferralsInfo.getNextReferral();
+                        if ( referral != null )
                         {
-                            Connection referralConnection = getReferralConnection( urlAndDn.getUrl(), monitor, this );
+                            Connection referralConnection = getReferralConnection( referral, monitor, this );
                             if ( referralConnection != null )
                             {
-                                String referralDn = urlAndDn.getDn() != null && !urlAndDn.getDn().isEmpty() ? urlAndDn
+                                String referralDn = referral.getDn() != null && !referral.getDn().isEmpty() ? referral
                                     .getDn().getUpName() : dn;
 
-                                referralConnection.getJNDIConnectionWrapper().deleteEntry( referralDn,
-                                    referralsHandlingMethod, controls, monitor, newReferralsInfo );
+                                referralConnection.getJNDIConnectionWrapper().deleteEntry( referralDn, controls,
+                                    monitor, newReferralsInfo );
                             }
                         }
                     }
@@ -819,9 +758,12 @@
                     namingException = ne;
                 }
 
-                for ( IJndiLogger logger : getJndiLoggers() )
+                if ( logModifycation )
                 {
-                    logger.logChangetypeDelete( connection, dn, localControls, namingException );
+                    for ( IJndiLogger logger : getJndiLoggers() )
+                    {
+                        logger.logChangetypeDelete( connection, dn, controls, namingException );
+                    }
                 }
             }
         };
@@ -1460,49 +1402,6 @@
 
 
     /**
-     * Adds the ManageDsaIT controls if the referrals handling method is MANAGE and 
-     * if the current controls don't contain the ManageDsaIT control.
-     * 
-     * @param currentControls the current controls
-     * @param referralsHandlingMethod the referrals handling method
-     * 
-     * @return the new controls
-     */
-    private Control[] addManageDsaItControls( final Control[] currentControls,
-        final ReferralHandlingMethod referralsHandlingMethod )
-    {
-        Control[] localControls = currentControls;
-        if ( referralsHandlingMethod == ReferralHandlingMethod.MANAGE )
-        {
-            if ( currentControls == null )
-            {
-                localControls = new Control[]
-                    { new ManageReferralControl( false ) };
-            }
-            else
-            {
-                boolean manageDsaItControlAlreadyContained = false;
-                for ( Control control : currentControls )
-                {
-                    if ( ManageReferralControl.OID.equals( control.getID() ) )
-                    {
-                        manageDsaItControlAlreadyContained = true;
-                        break;
-                    }
-                }
-                if ( !manageDsaItControlAlreadyContained )
-                {
-                    localControls = new Control[currentControls.length + 1];
-                    System.arraycopy( currentControls, 0, localControls, 0, currentControls.length );
-                    localControls[localControls.length - 1] = new ManageReferralControl( false );
-                }
-            }
-        }
-        return localControls;
-    }
-
-
-    /**
      * Gets a Name object that is save for JNDI operations.
      * <p>
      * In JNDI we have could use the following classes for names:
@@ -1536,7 +1435,7 @@
      * 
      * @throws InvalidNameException the invalid name exception
      */
-    private Name getSaveJndiName( String name ) throws InvalidNameException
+    static Name getSaveJndiName( String name ) throws InvalidNameException
     {
         if ( name == null || StringUtils.isEmpty( name ) ) //$NON-NLS-1$
         {
@@ -1558,14 +1457,15 @@
      * 
      * @return the referral connection
      */
-    static Connection getReferralConnection( LdapURL url, StudioProgressMonitor monitor, Object source )
+    static Connection getReferralConnection( Referral referral, StudioProgressMonitor monitor, Object source )
     {
         Connection referralConnection = null;
         IReferralHandler referralHandler = ConnectionCorePlugin.getDefault().getReferralHandler();
         if ( referralHandler != null )
         {
-            referralConnection = referralHandler.getReferralConnection( url );
+            referralConnection = referralHandler.getReferralConnection( referral.getLdapURLs() );
 
+            // open connection if not yet open
             if ( referralConnection != null && !referralConnection.getJNDIConnectionWrapper().isConnected() )
             {
                 referralConnection.getJNDIConnectionWrapper().connect( monitor );
@@ -1600,17 +1500,7 @@
             initialReferralsInfo = new ReferralsInfo();
         }
 
-        try
-        {
-            String info = ( String ) referralException.getReferralInfo();
-            String name = referralException.getRemainingName().toString();
-            LdapURL url = new LdapURL( info );
-            LdapDN dn = new LdapDN( name );
-            initialReferralsInfo.addReferralUrl( url, dn );
-        }
-        catch ( LdapURLEncodingException e )
-        {
-        }
+        Referral referral = handleReferralException( referralException, initialReferralsInfo, null );
 
         while ( referralException.skipReferral() )
         {
@@ -1623,18 +1513,17 @@
             {
                 if ( ne instanceof ReferralException )
                 {
-                    referralException = ( ReferralException ) ne;
-                    try
-                    {
-                        String info = ( String ) referralException.getReferralInfo();
-                        String name = referralException.getRemainingName().toString();
-                        LdapURL url = new LdapURL( info );
-                        LdapDN dn = new LdapDN( name );
-                        initialReferralsInfo.addReferralUrl( url, dn );
-                    }
-                    catch ( LdapURLEncodingException e )
+                    if ( ne != referralException )
                     {
+                        // what a hack: 
+                        // if the same exception is throw, we have another URL for the same Referral/SearchResultReference
+                        // if another exception is throws, we have a new Referral/SearchResultReference
+                        // in the latter case we null out the reference, a new one will be created by handleReferral()
+                        referral = null;
                     }
+                    referralException = ( ReferralException ) ne;
+
+                    referral = handleReferralException( referralException, initialReferralsInfo, referral );
                 }
                 else
                 {
@@ -1646,4 +1535,29 @@
         return initialReferralsInfo;
     }
 
+
+    private static Referral handleReferralException( ReferralException referralException,
+        ReferralsInfo initialReferralsInfo, Referral referral ) throws NamingException
+    {
+        try
+        {
+            String info = ( String ) referralException.getReferralInfo();
+            String name = referralException.getRemainingName().toString();
+            LdapURL url = new LdapURL( info );
+            LdapDN dn = new LdapDN( name );
+
+            if ( referral == null )
+            {
+                referral = initialReferralsInfo.new Referral( dn );
+                initialReferralsInfo.addReferral( referral );
+            }
+            referral.addUrl( url );
+        }
+        catch ( LdapURLEncodingException e )
+        {
+        }
+
+        return referral;
+    }
+
 }

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java Wed Oct 21 08:35:55 2009
@@ -466,7 +466,7 @@
     /**
      * {@inheritDoc}
      */
-    public void logSearchResultReference( Connection connection, ReferralsInfo.UrlAndDn urlAndDn,
+    public void logSearchResultReference( Connection connection, ReferralsInfo.Referral referral,
         ReferralsInfo referralsInfo, long requestNum, NamingException ex )
     {
         // don't log searches 

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java Wed Oct 21 08:35:55 2009
@@ -411,7 +411,7 @@
     /**
      * {@inheritDoc}
      */
-    public void logSearchResultReference( Connection connection, ReferralsInfo.UrlAndDn urlAndDn,
+    public void logSearchResultReference( Connection connection, ReferralsInfo.Referral referral,
         ReferralsInfo referralsInfo, long requestNum, NamingException ex )
     {
         if ( !isSearchResultEntryLogEnabled() )
@@ -420,7 +420,7 @@
         }
 
         Collection<LdifLineBase> lines = new ArrayList<LdifLineBase>();
-        lines.add( LdifCommentLine.create( "# reference : " + ( urlAndDn != null ? urlAndDn.getUrl() : "null" ) ) ); //$NON-NLS-1$ //$NON-NLS-2$
+        lines.add( LdifCommentLine.create( "# reference : " + ( referral != null ? referral.getLdapURLs() : "null" ) ) ); //$NON-NLS-1$ //$NON-NLS-2$
         lines.add( LdifSepLine.create() );
 
         String formattedString = ""; //$NON-NLS-1$

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java Wed Oct 21 08:35:55 2009
@@ -21,12 +21,15 @@
 
 
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 
 import javax.naming.LinkLoopException;
 
-import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Messages;
 import org.eclipse.osgi.util.NLS;
 
@@ -40,44 +43,24 @@
  */
 public class ReferralsInfo
 {
-    private List<UrlAndDn> referralsToProcess;
-
-    private List<UrlAndDn> processedReferrals;
+    private LinkedList<Referral> referralsToProcess = new LinkedList<Referral>();
 
-
-    /**
-     * 
-     * Creates a new instance of ReferralsInfo.
-     */
-    public ReferralsInfo()
-    {
-        this.referralsToProcess = new ArrayList<UrlAndDn>();
-        this.processedReferrals = new ArrayList<UrlAndDn>();
-    }
+    private Set<LdapURL> processedUrls = new HashSet<LdapURL>();
 
 
     /**
-     * Adds the referral URL and DN to the list of referrals to be processed.
+     * Adds the referral entry to the list of referrals to be processed.
      * 
-     * If the URL is already in the list or if the URL was already processed
+     * If the URLs are already in the list or if the URL was already processed
      * a NamingException will be thrown
      * 
-     * @param url the URL
-     * @param dn the DN
+     * @param referral the referral
      * 
      * @throws LinkLoopException if a loop was encountered.
      */
-    public void addReferralUrl( LdapURL url, LdapDN dn ) throws LinkLoopException
+    public void addReferral( Referral referral )
     {
-        UrlAndDn urlAndDn = new UrlAndDn( url, dn );
-        if ( !referralsToProcess.contains( urlAndDn ) && !processedReferrals.contains( urlAndDn ) )
-        {
-            referralsToProcess.add( urlAndDn );
-        }
-        else
-        {
-            throw new LinkLoopException( NLS.bind( Messages.error__loop_detected, url ) );
-        }
+        referralsToProcess.addLast( referral );
     }
 
 
@@ -86,13 +69,16 @@
      * 
      * @return the next referral URL or null
      */
-    public UrlAndDn getNext()
+    public Referral getNextReferral()
     {
         if ( !referralsToProcess.isEmpty() )
         {
-            UrlAndDn urlAndDn = referralsToProcess.remove( 0 );
-            processedReferrals.add( urlAndDn );
-            return urlAndDn;
+            Referral referral = referralsToProcess.removeFirst();
+            for ( LdapURL url : referral.urls )
+            {
+                processedUrls.add( url );
+            }
+            return referral;
         }
         else
         {
@@ -100,47 +86,37 @@
         }
     }
 
+
     /**
-     * Container for an LDAP URL and an LDAP DN.
-     *
-     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
-     * @version $Rev$, $Date$
+     * Checks for more referrals.
+     * 
+     * @return true, if there are more referrals
      */
-    public static class UrlAndDn
+    public boolean hasMoreReferrals()
     {
-        private LdapURL url;
+        return !referralsToProcess.isEmpty();
+    }
+
+    public class Referral
+    {
+        private List<LdapURL> urls = new ArrayList<LdapURL>();
         private LdapDN dn;
 
 
-        /**
-         * Creates a new instance of UrlAndDn.
-         *
-         * @param url the URL, never null
-         * @param dn the DN, never null
-         */
-        private UrlAndDn( LdapURL url, LdapDN dn )
+        public Referral( LdapDN dn )
         {
-            if ( url == null )
-            {
-                throw new IllegalArgumentException( "URL may not be null" ); //$NON-NLS-1$
-            }
-            if ( dn == null )
-            {
-                throw new IllegalArgumentException( "DN may not be null" ); //$NON-NLS-1$
-            }
-            this.url = url;
             this.dn = dn;
         }
 
 
         /**
-         * Gets the URL.
+         * Gets the list of {@link LdapURL}.
          * 
-         * @return the URL
+         * @return the list of {@link LdapURL}
          */
-        public LdapURL getUrl()
+        public List<LdapURL> getLdapURLs()
         {
-            return url;
+            return urls;
         }
 
 
@@ -156,35 +132,20 @@
 
 
         /**
-         * {@inheritDoc}
-         */
-        public int hashCode()
-        {
-            // dn and url are never null
-            int h = 37;
-            h = h * 17 + url.hashCode();
-            h = h * 17 + dn.hashCode();
-            return h;
-        }
-
-
-        /**
-         * {@inheritDoc}
+         * Adds the URL.
+         * 
+         * @param url the URL
+         * 
+         * @throws LinkLoopException if a loop was encountered.
          */
-        public boolean equals( Object obj )
+        public void addUrl( LdapURL url ) throws LinkLoopException
         {
-            // dn and url are never null
-            if ( this == obj )
-            {
-                return true;
-            }
-            if ( !( obj instanceof UrlAndDn ) )
+            if ( processedUrls.contains( url ) )
             {
-                return false;
+                throw new LinkLoopException( NLS.bind( Messages.error__loop_detected, url ) );
             }
 
-            UrlAndDn other = ( UrlAndDn ) obj;
-            return dn.equals( other.dn ) && url.equals( other.url );
+            urls.add( url );
         }
 
     }

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java Wed Oct 21 08:35:55 2009
@@ -20,10 +20,14 @@
 package org.apache.directory.studio.connection.core.io.jndi;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.PartialResultException;
 import javax.naming.ReferralException;
+import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.Control;
@@ -35,7 +39,7 @@
 import org.apache.directory.studio.connection.core.IJndiLogger;
 import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
 import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
-import org.apache.directory.studio.connection.core.io.jndi.ReferralsInfo.UrlAndDn;
+import org.apache.directory.studio.connection.core.io.jndi.ReferralsInfo.Referral;
 import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 
 
@@ -49,7 +53,9 @@
 {
     private final Connection connection;
     private final LdapContext ctx;
+    private NamingEnumeration<SearchResult> initialNamingEnumeration;
     private NamingEnumeration<SearchResult> delegate;
+    private NamingException initialReferralException;
 
     private long requestNum;
     private long resultEntryCounter;
@@ -68,8 +74,7 @@
      * Creates a new instance of ReferralNamingEnumeration.
      * 
      * @param connection the connection
-     * @param LdapContext ctx the JNDI context
-     * @param delegate the delegate
+     * @param ctx the JNDI context
      * @param searchBase the search base
      * @param filter the filter
      * @param searchControls the search controls
@@ -79,14 +84,16 @@
      * @param monitor the progress monitor
      * @param referralsInfo the referrals info
      */
-    public StudioNamingEnumeration( Connection connection, LdapContext ctx, NamingEnumeration<SearchResult> delegate, String searchBase,
-        String filter, SearchControls searchControls, AliasDereferencingMethod aliasesDereferencingMethod,
-        ReferralHandlingMethod referralsHandlingMethod, Control[] controls, long requestNum,
-        StudioProgressMonitor monitor, ReferralsInfo referralsInfo )
+    StudioNamingEnumeration( Connection connection, LdapContext ctx, NamingEnumeration<SearchResult> delegate,
+        NamingException initialReferralException, String searchBase, String filter, SearchControls searchControls,
+        AliasDereferencingMethod aliasesDereferencingMethod, ReferralHandlingMethod referralsHandlingMethod,
+        Control[] controls, long requestNum, StudioProgressMonitor monitor, ReferralsInfo referralsInfo )
     {
         this.connection = connection;
         this.ctx = ctx;
+        this.initialNamingEnumeration = delegate;
         this.delegate = delegate;
+        this.initialReferralException = initialReferralException;
         this.requestNum = requestNum;
         this.resultEntryCounter = 0;
 
@@ -116,19 +123,33 @@
     public boolean hasMore() throws NamingException
     {
         NamingException logResultDoneException = null;
-        boolean logResultDone = false;
+        boolean done = false;
 
         while ( true )
         {
             try
             {
+                if ( initialReferralException != null )
+                {
+                    NamingException referralException = initialReferralException;
+                    initialReferralException = null;
+                    throw referralException;
+                }
+
                 boolean hasMore = delegate != null && delegate.hasMore();
-                logResultDone = !hasMore;
-                return hasMore;
+                if ( !hasMore && !done && referralsInfo != null && referralsInfo.hasMoreReferrals() )
+                {
+                    done = checkReferral();
+                }
+                else
+                {
+                    done = !hasMore;
+                    return hasMore;
+                }
             }
             catch ( PartialResultException pre )
             {
-                logResultDone = true;
+                done = true;
                 logResultDoneException = pre;
 
                 // ignore exception if referrals handling method is IGNORE
@@ -144,73 +165,24 @@
             }
             catch ( ReferralException re )
             {
-                logResultDone = true;
+                done = true;
                 logResultDoneException = re;
                 referralsInfo = JNDIConnectionWrapper.handleReferralException( re, referralsInfo );
-                UrlAndDn urlAndDn = referralsInfo.getNext();
-                for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
-                {
-                    logger.logSearchResultReference( connection, urlAndDn, referralsInfo, requestNum, null );
-                }
-
-                // ignore exception if referrals handling method is IGNORE OR MANAGE
-                // follow referral if referrals handling method is FOLLOW
-                if ( referralsHandlingMethod == ReferralHandlingMethod.IGNORE
-                    || referralsHandlingMethod == ReferralHandlingMethod.MANAGE )
+                if ( referralsInfo.hasMoreReferrals() )
                 {
-                    logResultDone = true;
                     logResultDoneException = null;
-                    return false;
-                }
-                else if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW )
-                {
-                    if ( urlAndDn != null )
-                    {
-                        LdapURL url = urlAndDn.getUrl();
-                        Connection referralConnection = JNDIConnectionWrapper
-                            .getReferralConnection( url, monitor, this );
-                        if ( referralConnection != null )
-                        {
-                            logResultDone = false;
-                            logResultDoneException = null;
-                            
-                            String referralSearchBase = url.getDn() != null && !url.getDn().isEmpty() ? url.getDn()
-                                .getUpName() : searchBase;
-                            String referralFilter = url.getFilter() != null && url.getFilter().length() == 0 ? url
-                                .getFilter() : filter;
-                            SearchControls referralSearchControls = new SearchControls();
-                            referralSearchControls.setSearchScope( url.getScope() > -1 ? url.getScope()
-                                : searchControls.getSearchScope() );
-                            referralSearchControls.setReturningAttributes( url.getAttributes() != null
-                                && url.getAttributes().size() > 0 ? url.getAttributes().toArray(
-                                new String[url.getAttributes().size()] ) : searchControls.getReturningAttributes() );
-                            referralSearchControls.setCountLimit( searchControls.getCountLimit() );
-                            referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
-                            referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
-                            referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
-
-                            delegate = referralConnection.getJNDIConnectionWrapper().search( referralSearchBase,
-                                referralFilter, referralSearchControls, aliasesDereferencingMethod,
-                                referralsHandlingMethod, controls, monitor, referralsInfo );
-                        }
-                        else
-                        {
-                            logResultDone = true;
-                            logResultDoneException = null;
-                            return false;
-                        }
-                    }
+                    done = checkReferral();
                 }
             }
             catch ( NamingException ne )
             {
-                logResultDone = true;
+                done = true;
                 logResultDoneException = ne;
                 throw ne;
             }
             finally
             {
-                if ( logResultDone )
+                if ( done )
                 {
                     for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
                     {
@@ -227,15 +199,7 @@
      */
     public boolean hasMoreElements()
     {
-        boolean hasMore = delegate.hasMoreElements();
-        if ( !hasMore )
-        {
-            for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
-            {
-                logger.logSearchResultDone( connection, resultEntryCounter, requestNum, null );
-            }
-        }
-        return hasMore;
+        throw new UnsupportedOperationException( "Call hasMore() instead of hasMoreElements() !" );
     }
 
 
@@ -250,7 +214,14 @@
         {
             SearchResult searchResult = delegate.next();
             resultEntryCounter++;
-            studioSearchResult = new StudioSearchResult( searchResult, getConnection(), referralsInfo != null );
+            if ( searchResult instanceof StudioSearchResult )
+            {
+                studioSearchResult = ( StudioSearchResult ) searchResult;
+            }
+            else
+            {
+                studioSearchResult = new StudioSearchResult( searchResult, getConnection(), referralsInfo != null, null );
+            }
             return studioSearchResult;
         }
         catch ( NamingException ne )
@@ -260,9 +231,12 @@
         }
         finally
         {
-            for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
+            if ( delegate == initialNamingEnumeration )
             {
-                logger.logSearchResultEntry( connection, studioSearchResult, requestNum, namingException );
+                for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
+                {
+                    logger.logSearchResultEntry( connection, studioSearchResult, requestNum, namingException );
+                }
             }
         }
     }
@@ -273,15 +247,7 @@
      */
     public StudioSearchResult nextElement()
     {
-        SearchResult searchResult = delegate.nextElement();
-        resultEntryCounter++;
-        StudioSearchResult studioSearchResult = new StudioSearchResult( searchResult, getConnection(),
-            referralsInfo != null );
-        for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
-        {
-            logger.logSearchResultEntry( connection, studioSearchResult, requestNum, null );
-        }
-        return studioSearchResult;
+        throw new UnsupportedOperationException( "Call next() instead of nextElement() !" );
     }
 
 
@@ -302,8 +268,7 @@
         }
     }
 
-    
-    
+
     /**
      * Gets the response controls.
      * 
@@ -316,4 +281,113 @@
         return ctx != null ? ctx.getResponseControls() : null;
     }
 
+
+    private boolean checkReferral()
+    {
+        boolean done = false;
+
+        // ignore exception if referrals handling method is IGNORE
+        // follow referral if referrals handling method is FOLLOW
+        // follow manually if referrals handling method is FOLLOW_MANUALLY
+        if ( referralsHandlingMethod == ReferralHandlingMethod.IGNORE )
+        {
+            done = true;
+            delegate = null;
+        }
+        else if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW_MANUALLY )
+        {
+            delegate = new NamingEnumeration<SearchResult>()
+            {
+
+                List<LdapURL> urls = new ArrayList<LdapURL>();
+                {
+                    while ( referralsInfo.hasMoreReferrals() )
+                    {
+                        Referral referral = referralsInfo.getNextReferral();
+                        for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
+                        {
+                            logger.logSearchResultReference( connection, referral, referralsInfo, requestNum, null );
+                        }
+                        urls.addAll( referral.getLdapURLs() );
+                    }
+                }
+
+
+                public SearchResult nextElement()
+                {
+                    throw new UnsupportedOperationException( "Call next() instead of nextElement() !" );
+                }
+
+
+                public boolean hasMoreElements()
+                {
+                    throw new UnsupportedOperationException( "Call hasMore() instead of hasMoreElements() !" );
+                }
+
+
+                public SearchResult next() throws NamingException
+                {
+                    LdapURL url = urls.remove( 0 );
+                    SearchResult searchResult = new SearchResult( url.getDn().getUpName(), null, new BasicAttributes(),
+                        false );
+                    searchResult.setNameInNamespace( url.getDn().getUpName() );
+                    StudioSearchResult ssr = new StudioSearchResult( searchResult, null, false, url );
+                    return ssr;
+                }
+
+
+                public boolean hasMore() throws NamingException
+                {
+                    return !urls.isEmpty();
+                }
+
+
+                public void close() throws NamingException
+                {
+                    urls.clear();
+                    referralsInfo = null;
+                }
+            };
+        }
+        else if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW )
+        {
+            Referral referral = referralsInfo.getNextReferral();
+            for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
+            {
+                logger.logSearchResultReference( connection, referral, referralsInfo, requestNum, null );
+            }
+
+            LdapURL url = referral.getLdapURLs().get( 0 );
+            Connection referralConnection = JNDIConnectionWrapper.getReferralConnection( referral, monitor, this );
+            if ( referralConnection != null )
+            {
+                done = false;
+                String referralSearchBase = url.getDn() != null && !url.getDn().isEmpty() ? url.getDn().getUpName()
+                    : searchBase;
+                String referralFilter = url.getFilter() != null && url.getFilter().length() == 0 ? url.getFilter()
+                    : filter;
+                SearchControls referralSearchControls = new SearchControls();
+                referralSearchControls.setSearchScope( url.getScope() > -1 ? url.getScope() : searchControls
+                    .getSearchScope() );
+                referralSearchControls.setReturningAttributes( url.getAttributes() != null
+                    && url.getAttributes().size() > 0 ? url.getAttributes().toArray(
+                    new String[url.getAttributes().size()] ) : searchControls.getReturningAttributes() );
+                referralSearchControls.setCountLimit( searchControls.getCountLimit() );
+                referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
+                referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
+                referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
+
+                delegate = referralConnection.getJNDIConnectionWrapper().search( referralSearchBase, referralFilter,
+                    referralSearchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls, monitor,
+                    referralsInfo );
+            }
+            else
+            {
+                done = true;
+                delegate = null;
+            }
+        }
+        return done;
+    }
+
 }

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java Wed Oct 21 08:35:55 2009
@@ -22,6 +22,7 @@
 
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
 
 
@@ -36,14 +37,15 @@
 {
 
     private static final long serialVersionUID = 1L;
-    
-    
+
     /** The connection. */
     private Connection connection;
-    
-    
-    /** The is referral flag. */
-    private boolean isReferral;
+
+    /** The is continued search result flag */
+    private boolean isContinuedSearchResult;
+
+    /** The URL with information on how to continue the search. */
+    private LdapURL searchContinuationUrl;
 
 
     /**
@@ -51,14 +53,18 @@
      * 
      * @param searchResult the original search result
      * @param connection the connection
-     * @param isReferral the is referral flag
+     * @param isContinuedSearchResult if the search result is a result from a continued search
+     * @param searchContinuationUrl the URL with information on how to continue the search
      */
-    public StudioSearchResult( SearchResult searchResult, Connection connection, boolean isReferral )
+    public StudioSearchResult( SearchResult searchResult, Connection connection, boolean isContinuedSearchResult,
+        LdapURL searchContinuationUrl )
     {
-        super( searchResult.getName(), searchResult.getClassName(), searchResult.getObject(), searchResult.getAttributes(), searchResult.isRelative() );
+        super( searchResult.getName(), searchResult.getClassName(), searchResult.getObject(), searchResult
+            .getAttributes(), searchResult.isRelative() );
         super.setNameInNamespace( searchResult.getNameInNamespace() );
         this.connection = connection;
-        this.isReferral = isReferral;
+        this.isContinuedSearchResult = isContinuedSearchResult;
+        this.searchContinuationUrl = searchContinuationUrl;
     }
 
 
@@ -85,24 +91,24 @@
 
 
     /**
-     * Checks if is referral.
+     * Checks if this search result is a result from a continued search.
      * 
-     * @return true, if is referral
+     * @return true, if this search result is a result from a continued search
      */
-    public boolean isReferral()
+    public boolean isContinuedSearchResult()
     {
-        return isReferral;
+        return isContinuedSearchResult;
     }
 
 
     /**
-     * Sets the referral flag.
+     * The URL with information on how to continue the search.
      * 
-     * @param isReferral the new referral flag
+     * @return the URL with information on how to continue the search
      */
-    public void setReferral( boolean isReferral )
+    public LdapURL getSearchContinuationUrl()
     {
-        this.isReferral = isReferral;
+        return searchContinuationUrl;
     }
 
 }

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java?rev=827920&r1=827919&r2=827920&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java (original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java Wed Oct 21 08:35:55 2009
@@ -22,12 +22,16 @@
 
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.IReferralHandler;
+import org.apache.directory.studio.connection.core.Utils;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+import org.apache.directory.studio.connection.core.event.ConnectionUpdateAdapter;
 import org.apache.directory.studio.connection.ui.dialogs.SelectReferralConnectionDialog;
 import org.eclipse.ui.PlatformUI;
 
@@ -38,24 +42,40 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ConnectionUIReferralHandler implements IReferralHandler
+public class ConnectionUIReferralHandler extends ConnectionUpdateAdapter implements IReferralHandler
 {
 
     /** The referral URL to referral connection cache. */
-    private Map<LdapURL, Connection> referralUrlToReferralConnectionCache = new HashMap<LdapURL, Connection>();
+    private Map<String, Connection> referralUrlToReferralConnectionCache = new HashMap<String, Connection>();
+
+
+    public ConnectionUIReferralHandler()
+    {
+        ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
+    }
+
+
+    @Override
+    public void connectionClosed( Connection connection )
+    {
+        referralUrlToReferralConnectionCache.clear();
+    }
 
 
     /**
      * {@inheritDoc}
      */
-    public Connection getReferralConnection( final LdapURL referralUrl )
+    public Connection getReferralConnection( final List<LdapURL> referralUrls )
     {
         // check cache
-        if ( referralUrlToReferralConnectionCache.containsKey( referralUrl ) )
+        for ( LdapURL url : referralUrls )
         {
-            Connection referralConnection = referralUrlToReferralConnectionCache.get( referralUrl );
-            if ( referralConnection != null )
+            String normalizedUrl = Utils.getSimpleNormalizedUrl( 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++ )
                 {
@@ -65,29 +85,39 @@
                         return referralConnection;
                     }
                 }
+
+                // referral connection doesn't exist in connection manager, remove it from cache
+                referralUrlToReferralConnectionCache.remove( normalizedUrl );
             }
         }
 
-        referralUrlToReferralConnectionCache.remove( referralUrl );
-
         // open dialog
-        final Connection[] referralConnection = new Connection[1];
+        final Connection[] referralConnections = new Connection[1];
         PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable()
         {
             public void run()
             {
                 SelectReferralConnectionDialog dialog = new SelectReferralConnectionDialog( PlatformUI.getWorkbench()
-                    .getDisplay().getActiveShell(), referralUrl );
+                    .getDisplay().getActiveShell(), referralUrls );
                 if ( dialog.open() == SelectReferralConnectionDialog.OK )
                 {
                     Connection connection = dialog.getReferralConnection();
-                    referralUrlToReferralConnectionCache.put( referralUrl, connection );
-                    referralConnection[0] = connection;
+                    referralConnections[0] = connection;
                 }
             }
         } );
 
-        return referralConnection[0];
+        // put to cache
+        if ( referralConnections[0] != null )
+        {
+            for ( LdapURL url : referralUrls )
+            {
+                String normalizedUrl = Utils.getSimpleNormalizedUrl( url );
+                referralUrlToReferralConnectionCache.put( normalizedUrl, referralConnections[0] );
+            }
+        }
+
+        return referralConnections[0];
     }
 
 }



Mime
View raw message