directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r593925 [1/2] - in /directory/studio/trunk: studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ studio-connection-ui/MET...
Date Sun, 11 Nov 2007 16:40:32 GMT
Author: seelmann
Date: Sun Nov 11 08:40:29 2007
New Revision: 593925

URL: http://svn.apache.org/viewvc?rev=593925&view=rev
Log:
Moved referrals handling from ldapbrowser plugins to the connection plugins.

Added:
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
      - copied, changed from r591814, directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IReferralHandler.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java   (with props)
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java   (with props)
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java   (with props)
    directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java
      - copied, changed from r591814, directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java
    directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java
      - copied, changed from r591814, directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectReferralConnectionDialog.java
Removed:
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectReferralConnectionDialog.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IReferralHandler.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/ReferralException.java
Modified:
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
    directory/studio/trunk/studio-connection-ui/META-INF/MANIFEST.MF
    directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IRootDSE.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ApacheDsSchemaConnector.java

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Connection.java Sun Nov 11 08:40:29 2007
@@ -21,6 +21,8 @@
 package org.apache.directory.studio.connection.core;
 
 
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
+import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
@@ -193,6 +195,11 @@
     }
 
     
+    /**
+     * Gets the SASL realm.
+     * 
+     * @return the SASL realm
+     */
     public String getSaslRealm ()
     {
     	return connectionParameter.getSaslRealm();
@@ -282,6 +289,11 @@
     }
     
     
+    /**
+     * Sets the SASL realm.
+     * 
+     * @param realm the new SASL realm
+     */
     public void setSaslRealm (String realm)
     {
     	connectionParameter.setSaslRealm(realm);
@@ -292,6 +304,7 @@
     /**
      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
      */
+    @SuppressWarnings("unchecked")
     public Object getAdapter( Class adapter )
     {
         //        if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) )
@@ -304,6 +317,26 @@
         }
 
         return null;
+    }
+
+
+    /**
+     * Gets the LDAP URL.
+     * 
+     * @return the LDAP URL
+     */
+    public LdapURL getUrl()
+    {
+        String s = "ldap://" + getHost() + ":" + getPort();
+        LdapURL url = null;
+        try
+        {
+            url = new LdapURL( s );
+        }
+        catch ( LdapURLEncodingException e )
+        {
+        }
+        return url;
     }
 
 }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java Sun Nov 11 08:40:29 2007
@@ -47,9 +47,11 @@
     /** The event runner. */
     private EventRunner eventRunner;
 
-    /** The credential provider */
+    /** The authentication handler */
     private IAuthHandler authHandler;
 
+    /** The referral handler */
+    private IReferralHandler referralHandler;
 
     /**
      * The constructor
@@ -160,10 +162,10 @@
 
 
     /**
-     * Gets the AuthHandler
+     * Gets the authentication handler
      *
      * @return
-     *      the AuthHandler
+     *      the authentication handler
      */
     public IAuthHandler getAuthHandler()
     {
@@ -172,14 +174,38 @@
 
 
     /**
-     * Sets the AuthHandler
+     * Sets the authentication handler
      *
      * @param authHandler
-     *      the authHandler to set
+     *      the authentication handler to set
      */
     public void setAuthHandler( IAuthHandler authHandler )
     {
         this.authHandler = authHandler;
+    }
+
+
+    /**
+     * Gets the referral handler
+     *
+     * @return
+     *      the referral handler
+     */
+    public IReferralHandler getReferralHandler()
+    {
+        return referralHandler;
+    }
+
+
+    /**
+     * Sets the referral handler
+     *
+     * @param referralHandler
+     *      the referral handler to set
+     */
+    public void setReferralHandler( IReferralHandler referralHandler )
+    {
+        this.referralHandler = referralHandler;
     }
 
 }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java Sun Nov 11 08:40:29 2007
@@ -105,7 +105,7 @@
     /** The bind password. */
     private String bindPassword;
     
-    /** The SASL realm **/
+    /** The SASL realm. */
     private String saslRealm;
 
     /** The extended properties. */
@@ -132,6 +132,7 @@
      * @param authMethod the authentication method
      * @param bindPrincipal the bind principal
      * @param bindPassword the bind password
+     * @param saslRealm the SASL realm
      * @param extendedProperties the extended properties
      */
     public ConnectionParameter( String name, String host, int port, EncryptionMethod encryptionMethod,
@@ -201,7 +202,8 @@
     
     /**
      * Gets the SASL realm
-     * @return the sasl realm
+     * 
+     * @return the SASL realm
      */
     public String getSaslRealm (){
     	return saslRealm;
@@ -210,7 +212,8 @@
     
     /**
      * Sets the SASL realm
-     * @param saslRealm the sasl realm
+     * 
+     * @param saslRealm the SASL realm
      */
     public void setSaslRealm (String saslRealm){
     	this.saslRealm = saslRealm;

Copied: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java (from r591814, directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IReferralHandler.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java?p2=directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java&p1=directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IReferralHandler.java&r1=591814&r2=593925&rev=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IReferralHandler.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java Sun Nov 11 08:40:29 2007
@@ -18,7 +18,10 @@
  *  
  */
 
-package org.apache.directory.studio.ldapbrowser.core.model;
+package org.apache.directory.studio.connection.core;
+
+
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
 
 
 /**
@@ -40,6 +43,6 @@
      * @param referralURL the referral URL
      * @return the target connection
      */
-    public IBrowserConnection getReferralConnection( URL referralURL );
+    public Connection getReferralConnection( LdapURL referralURL );
 
 }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java Sun Nov 11 08:40:29 2007
@@ -27,6 +27,8 @@
 import javax.naming.InsufficientResourcesException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.PartialResultException;
+import javax.naming.ReferralException;
 import javax.naming.ServiceUnavailableException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.ModificationItem;
@@ -41,14 +43,18 @@
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.SSLSession;
 
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
+import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.core.IAuthHandler;
 import org.apache.directory.studio.connection.core.ICredentials;
 import org.apache.directory.studio.connection.core.IModificationLogger;
+import org.apache.directory.studio.connection.core.IReferralHandler;
 import org.apache.directory.studio.connection.core.Messages;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
 
 
@@ -90,7 +96,15 @@
 
     private IModificationLogger modificationLogger;
 
-
+    /** JNDI constant for "throw" referrals handling */
+    public static final String REFERRAL_THROW = "throw";
+    
+    /** JNDI constant for "follow" referrals handling */
+    public static final String REFERRAL_FOLLOW = "follow";
+
+    /** JNDI constant for "ignore" referrals handling */
+    public static final String REFERRAL_IGNORE = "ignore";
+    
     /**
      * Creates a new instance of JNDIConnectionContext.
      * 
@@ -192,16 +206,17 @@
      * @param searchBase the search base
      * @param filter the filter
      * @param searchControls the controls
-     * @param derefAliasMethod the deref alias method
-     * @param handleReferralsMethod the handle referrals method
-     * @param controls the ldap controls
+     * @param aliasesDereferencingMethod the aliases dereferencing method
+     * @param referralsHandlingMethod the referrals handling method
+     * @param controls the LDAP controls
      * @param monitor the progress monitor
+     * @param referralsInfo the referrals info
      * 
      * @return the naming enumeration or null if an exception occurs.
      */
     public NamingEnumeration<SearchResult> search( final String searchBase, final String filter,
-        final SearchControls searchControls, final String derefAliasMethod, final String handleReferralsMethod,
-        final Control[] controls, final StudioProgressMonitor monitor )
+        final SearchControls searchControls, final String aliasesDereferencingMethod, final String referralsHandlingMethod,
+        final Control[] controls, final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
         // start
         InnerRunnable runnable = new InnerRunnable()
@@ -215,26 +230,76 @@
                 try
                 {
                     LdapContext searchCtx = context.newInstance( controls );
-                    try
+                    searchCtx.addToEnvironment( "java.naming.ldap.derefAliases", aliasesDereferencingMethod ); //$NON-NLS-1$
+                    
+                    // use "throw" if referrals handling is set to "follow" as we handle referrals manually
+                    String localReferralsHandlingMethod = REFERRAL_FOLLOW.equals( referralsHandlingMethod ) ? REFERRAL_THROW : referralsHandlingMethod;
+                    searchCtx.addToEnvironment( Context.REFERRAL, localReferralsHandlingMethod );
+
+                    namingEnumeration = searchCtx.search( new LdapName( searchBase ), filter, searchControls );
+                    namingEnumeration = new StudioNamingEnumeration( connection, namingEnumeration, searchBase, filter,
+                        searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls, monitor,
+                        referralsInfo );
+                }
+                catch ( PartialResultException pre )
+                {
+                    if ( REFERRAL_IGNORE.equals( referralsHandlingMethod ) )
                     {
-                        searchCtx.addToEnvironment( "java.naming.ldap.derefAliases", derefAliasMethod ); //$NON-NLS-1$
-                        searchCtx.addToEnvironment( Context.REFERRAL, handleReferralsMethod );
-
+                        // ignore
                     }
-                    catch ( NamingException e )
+                    else
                     {
-                        namingException = e;
+                        namingException = pre;
                     }
-
-                    try
+                }
+                catch ( ReferralException re )
+                {
+                    if ( REFERRAL_IGNORE.equals( referralsHandlingMethod ) )
                     {
-                        namingEnumeration = searchCtx.search( new LdapName( searchBase ), filter, searchControls );
+                        // ignore
                     }
-                    catch ( NamingException ne )
+                    else if ( REFERRAL_FOLLOW.equals( referralsHandlingMethod ) )
                     {
-                        namingException = ne;
+                        ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
+                        LdapURL url = newReferralsInfo.getNext();
+                        if ( url != null )
+                        {
+                            Connection referralConnection = getReferralConnection( url );
+                            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().toArray( new String[url.getAttributes().size()] ) : searchControls
+                                    .getReturningAttributes() );
+                                referralSearchControls.setCountLimit( searchControls.getCountLimit() );
+                                referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
+                                referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
+                                referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
+    
+                                if ( referralConnection.getJNDIConnectionWrapper().isConnected() )
+                                {
+                                    referralConnection.getJNDIConnectionWrapper().connect( monitor );
+                                    referralConnection.getJNDIConnectionWrapper().bind( monitor );
+                                    ConnectionEventRegistry.fireConnectionOpened( referralConnection, this );
+                                }
+                                
+                                namingEnumeration = referralConnection.getJNDIConnectionWrapper().search(
+                                    referralSearchBase, referralFilter, referralSearchControls,
+                                    aliasesDereferencingMethod, referralsHandlingMethod, controls, monitor,
+                                    newReferralsInfo );
+                            }
+                        }
+                    }
+                    else
+                    {
+                        namingException = re;
                     }
-
                 }
                 catch ( NamingException e )
                 {
@@ -286,6 +351,82 @@
         {
             return null;
         }
+    }
+
+
+    /**
+     * Gets the referral connection from the given URL.
+     * 
+     * @param url the URL
+     * 
+     * @return the referral connection
+     */
+    static Connection getReferralConnection( LdapURL url )
+    {
+        Connection referralConnection = null;
+        IReferralHandler referralHandler = ConnectionCorePlugin.getDefault().getReferralHandler();
+        if ( referralHandler != null )
+        {
+            referralConnection = referralHandler.getReferralConnection( url );
+        }
+        return referralConnection;
+    }
+
+
+    /**
+     * Retrieves all referrals from the ReferralException and 
+     * creates or updates the ReferralsInfo.
+     * 
+     * @param referralException the referral exception
+     * @param initialReferralsInfo the initial referrals info, may be null
+     * 
+     * @return the created or updated referrals info
+     */
+    static ReferralsInfo handleReferralException( ReferralException referralException,
+        ReferralsInfo initialReferralsInfo )
+    {
+        if ( initialReferralsInfo == null )
+        {
+            initialReferralsInfo = new ReferralsInfo();
+        }
+
+        try
+        {
+            initialReferralsInfo.addReferralUrl( new LdapURL( ( String ) referralException.getReferralInfo() ) );
+        }
+        catch ( LdapURLEncodingException e )
+        {
+        }
+
+        while ( referralException.skipReferral() )
+        {
+            try
+            {
+                Context ctx = referralException.getReferralContext();
+                ctx.list( "" ); //$NON-NLS-1$
+            }
+            catch ( NamingException ne )
+            {
+                if ( ne instanceof ReferralException )
+                {
+                    referralException = ( ReferralException ) ne;
+                    try
+                    {
+                        initialReferralsInfo.addReferralUrl( new LdapURL( ( String ) referralException
+                            .getReferralInfo() ) );
+                    }
+                    catch ( LdapURLEncodingException e )
+                    {
+                    }
+                }
+                else
+                {
+                    break;
+                }
+            }
+        }
+
+        return initialReferralsInfo;
     }
 
 

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java?rev=593925&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java Sun Nov 11 08:40:29 2007
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.studio.connection.core.io.jndi;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
+
+
+/**
+ * Helper class that holds info about referrals to be processed and
+ * already processed referrals. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ReferralsInfo
+{
+    private List<LdapURL> referralsToProcess;
+
+    private List<LdapURL> processedReferrals;
+
+
+    /**
+     * 
+     * Creates a new instance of ReferralsInfo.
+     */
+    public ReferralsInfo()
+    {
+        this.referralsToProcess = new ArrayList<LdapURL>();
+        this.processedReferrals = new ArrayList<LdapURL>();
+    }
+
+
+    /**
+     * Adds the referral URL to the list of referrals to be processed.
+     * If the URL is already
+     * 
+     * @param url the URL
+     */
+    public void addReferralUrl( LdapURL url )
+    {
+        if ( !referralsToProcess.contains( url ) && !processedReferrals.contains( url ) )
+        {
+            referralsToProcess.add( url );
+        }
+    }
+
+
+    /**
+     * Gets the next referral URL or null.
+     * 
+     * @return the next referral URL or null
+     */
+    public LdapURL getNext()
+    {
+        if ( !referralsToProcess.isEmpty() )
+        {
+            LdapURL url = referralsToProcess.remove( 0 );
+            processedReferrals.add( url );
+            return url;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+}

Propchange: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java?rev=593925&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java Sun Nov 11 08:40:29 2007
@@ -0,0 +1,223 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.studio.connection.core.io.jndi;
+
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.PartialResultException;
+import javax.naming.ReferralException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+
+
+/**
+ * A naming enumeration that handles referrals itself. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class StudioNamingEnumeration implements NamingEnumeration<SearchResult>
+{
+    private final Connection connection;
+    private NamingEnumeration<SearchResult> delegate;
+
+    private String searchBase;
+    private String filter;
+    private SearchControls searchControls;
+    private String aliasesDereferencingMethod;
+    private String referralsHandlingMethod;
+    private Control[] controls;
+    private StudioProgressMonitor monitor;
+    private ReferralsInfo referralsInfo;
+
+
+    /**
+     * Creates a new instance of ReferralNamingEnumeration.
+     * 
+     * @param connection the connection
+     * @param delegate the delegate
+     * @param searchBase the search base
+     * @param filter the filter
+     * @param searchControls the search controls
+     * @param aliasesDereferencingMethod the aliases dereferencing method
+     * @param referralsHandlingMethod the referrals handling method
+     * @param controls the LDAP controls
+     * @param monitor the progress monitor
+     * @param referralsInfo the referrals info
+     */
+    public StudioNamingEnumeration( Connection connection, NamingEnumeration<SearchResult> delegate, String searchBase,
+        String filter, SearchControls searchControls, String aliasesDereferencingMethod,
+        String referralsHandlingMethod, Control[] controls, StudioProgressMonitor monitor, ReferralsInfo referralsInfo )
+    {
+        this.connection = connection;
+        this.delegate = delegate;
+
+        this.searchBase = searchBase;
+        this.filter = filter;
+        this.searchControls = searchControls;
+        this.aliasesDereferencingMethod = aliasesDereferencingMethod;
+        this.referralsHandlingMethod = referralsHandlingMethod;
+        this.controls = controls;
+        this.monitor = monitor;
+        this.referralsInfo = referralsInfo;
+    }
+
+
+    /**
+     * @see javax.naming.NamingEnumeration#close()
+     */
+    public void close() throws NamingException
+    {
+        delegate.close();
+    }
+
+
+    /**
+     * @see javax.naming.NamingEnumeration#hasMore()
+     */
+    public boolean hasMore() throws NamingException
+    {
+        while ( true )
+        {
+            try
+            {
+                return delegate.hasMore();
+            }
+            catch ( PartialResultException pre )
+            {
+                if ( JNDIConnectionWrapper.REFERRAL_IGNORE.equals( referralsHandlingMethod ) )
+                {
+                    // ignore
+                    return false;
+                }
+                else
+                {
+                    throw pre;
+                }
+            }
+            catch ( ReferralException re )
+            {
+                if ( JNDIConnectionWrapper.REFERRAL_IGNORE.equals( referralsHandlingMethod ) )
+                {
+                    // ignore
+                    return false;
+                }
+                else if ( JNDIConnectionWrapper.REFERRAL_FOLLOW.equals( referralsHandlingMethod ) )
+                {
+                    referralsInfo = JNDIConnectionWrapper.handleReferralException( re, referralsInfo );
+                    LdapURL url = referralsInfo.getNext();
+                    if ( url != null )
+                    {
+                        Connection referralConnection = JNDIConnectionWrapper.getReferralConnection( url );
+                        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().toArray( new String[url.getAttributes().size()] ) : searchControls
+                                .getReturningAttributes() );
+                            referralSearchControls.setCountLimit( searchControls.getCountLimit() );
+                            referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
+                            referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
+                            referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
+
+                            if ( referralConnection.getJNDIConnectionWrapper().isConnected() )
+                            {
+                                referralConnection.getJNDIConnectionWrapper().connect( monitor );
+                                referralConnection.getJNDIConnectionWrapper().bind( monitor );
+                                ConnectionEventRegistry.fireConnectionOpened( referralConnection, this );
+                            }
+
+                            delegate = referralConnection.getJNDIConnectionWrapper().search( referralSearchBase,
+                                referralFilter, referralSearchControls, aliasesDereferencingMethod,
+                                referralsHandlingMethod, controls, monitor, referralsInfo );
+                        }
+                    }
+                }
+                else
+                {
+                    throw re;
+                }
+            }
+        }
+    }
+
+
+    /**
+     * @see java.util.Enumeration#hasMoreElements()
+     */
+    public boolean hasMoreElements()
+    {
+        return delegate.hasMoreElements();
+    }
+
+
+    /**
+     * @see javax.naming.NamingEnumeration#next()
+     */
+    public SearchResult next() throws NamingException
+    {
+        SearchResult searchResult = delegate.next();
+        StudioSearchResult studioSearchResult = new StudioSearchResult( searchResult, getConnection(),
+            referralsInfo != null );
+        return studioSearchResult;
+    }
+
+
+    /**
+     * @see java.util.Enumeration#nextElement()
+     */
+    public SearchResult nextElement()
+    {
+        SearchResult searchResult = delegate.nextElement();
+        return new StudioSearchResult( searchResult, getConnection(), referralsInfo != null );
+    }
+
+
+    /**
+     * Gets the connection.
+     * 
+     * @return the connection
+     */
+    public Connection getConnection()
+    {
+        if ( delegate instanceof StudioNamingEnumeration )
+        {
+            return ( ( StudioNamingEnumeration ) delegate ).getConnection();
+        }
+        else
+        {
+            return connection;
+        }
+    }
+
+}

Propchange: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java?rev=593925&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java Sun Nov 11 08:40:29 2007
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.studio.connection.core.io.jndi;
+
+
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.studio.connection.core.Connection;
+
+
+/**
+ * Extension of {@link SearchResult} that holds a reference to the 
+ * underlying connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class StudioSearchResult extends SearchResult
+{
+
+    private static final long serialVersionUID = 1L;
+    
+    
+    /** The connection. */
+    private Connection connection;
+    
+    
+    /** The is referral flag. */
+    private boolean isReferral;
+
+
+    /**
+     * Creates a new instance of StudioSearchResult.
+     * 
+     * @param searchResult the original search result
+     * @param connection the connection
+     * @param isReferral the is referral flag
+     */
+    public StudioSearchResult( SearchResult searchResult, Connection connection, boolean isReferral )
+    {
+        super( searchResult.getName(), searchResult.getClassName(), searchResult.getObject(), searchResult.getAttributes(), searchResult.isRelative() );
+        super.setNameInNamespace( searchResult.getNameInNamespace() );
+        this.connection = connection;
+        this.isReferral = isReferral;
+    }
+
+
+    /**
+     * Gets the connection.
+     * 
+     * @return the connection
+     */
+    public Connection getConnection()
+    {
+        return connection;
+    }
+
+
+    /**
+     * Sets the connection.
+     * 
+     * @param connection the new connection
+     */
+    public void setConnection( Connection connection )
+    {
+        this.connection = connection;
+    }
+
+
+    /**
+     * Checks if is referral.
+     * 
+     * @return true, if is referral
+     */
+    public boolean isReferral()
+    {
+        return isReferral;
+    }
+
+
+    /**
+     * Sets the referral flag.
+     * 
+     * @param isReferral the new referral flag
+     */
+    public void setReferral( boolean isReferral )
+    {
+        this.isReferral = isReferral;
+    }
+
+}

Propchange: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/studio/trunk/studio-connection-ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/META-INF/MANIFEST.MF?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/META-INF/MANIFEST.MF (original)
+++ directory/studio/trunk/studio-connection-ui/META-INF/MANIFEST.MF Sun Nov 11 08:40:29 2007
@@ -8,6 +8,7 @@
 Bundle-Localization: plugin
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
+ org.apache.directory.studio.jars,
  org.apache.directory.studio.connection.core,
  org.eclipse.ui.workbench.texteditor
 Eclipse-LazyStart: true

Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java Sun Nov 11 08:40:29 2007
@@ -79,6 +79,7 @@
         }
 
         ConnectionCorePlugin.getDefault().setAuthHandler( new UIAuthHandler() );
+        ConnectionCorePlugin.getDefault().setReferralHandler( new ConnectionUIReferralHandler() );
     }
 
 

Copied: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java (from r591814, directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java?p2=directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java&p1=directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java&r1=591814&r2=593925&rev=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java Sun Nov 11 08:40:29 2007
@@ -18,40 +18,48 @@
  *  
  */
 
-package org.apache.directory.studio.ldapbrowser.common;
+package org.apache.directory.studio.connection.ui;
 
 
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectReferralConnectionDialog;
-import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.IReferralHandler;
-import org.apache.directory.studio.ldapbrowser.core.model.URL;
-
+import org.apache.directory.shared.ldap.codec.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.ui.dialogs.SelectReferralConnectionDialog;
 import org.eclipse.ui.PlatformUI;
 
 
-public class BrowserCommonReferralHandler implements IReferralHandler
+/**
+ * Default implementation of {@link IReferralHandler}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionUIReferralHandler implements IReferralHandler
 {
 
-    private Map referralUrlToReferralConnectionCache = new HashMap();
+    /** The referral URL to referral connection cache. */
+    private Map<LdapURL, Connection> referralUrlToReferralConnectionCache = new HashMap<LdapURL, Connection>();
 
 
-    public IBrowserConnection getReferralConnection( final URL referralUrl )
+    /**
+     * {@inheritDoc}
+     */
+    public Connection getReferralConnection( final LdapURL referralUrl )
     {
-
         // check cache
         if ( referralUrlToReferralConnectionCache.containsKey( referralUrl ) )
         {
-            IBrowserConnection referralConnection = ( IBrowserConnection ) referralUrlToReferralConnectionCache.get( referralUrl );
+            Connection referralConnection = referralUrlToReferralConnectionCache.get( referralUrl );
             if ( referralConnection != null )
             {
-                IBrowserConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnections();
+                Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
                 for ( int i = 0; i < connections.length; i++ )
                 {
-                    IBrowserConnection connection = connections[i];
+                    Connection connection = connections[i];
                     if ( referralConnection == connection )
                     {
                         return referralConnection;
@@ -63,7 +71,7 @@
         referralUrlToReferralConnectionCache.remove( referralUrl );
 
         // open dialog
-        final IBrowserConnection[] referralConnection = new IBrowserConnection[1];
+        final Connection[] referralConnection = new Connection[1];
         PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable()
         {
             public void run()
@@ -72,7 +80,7 @@
                     .getDisplay().getActiveShell(), referralUrl );
                 if ( dialog.open() == SelectReferralConnectionDialog.OK )
                 {
-                    IBrowserConnection connection = dialog.getReferralConnection();
+                    Connection connection = dialog.getReferralConnection();
                     referralUrlToReferralConnectionCache.put( referralUrl, connection );
                     referralConnection[0] = connection;
                 }

Copied: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java (from r591814, directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectReferralConnectionDialog.java)
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java?p2=directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java&p1=directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectReferralConnectionDialog.java&r1=591814&r2=593925&rev=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectReferralConnectionDialog.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java Sun Nov 11 08:40:29 2007
@@ -18,19 +18,17 @@
  *  
  */
 
-package org.apache.directory.studio.ldapbrowser.common.dialogs;
+package org.apache.directory.studio.connection.ui.dialogs;
 
 
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.connection.ui.widgets.ConnectionActionGroup;
 import org.apache.directory.studio.connection.ui.widgets.ConnectionConfiguration;
 import org.apache.directory.studio.connection.ui.widgets.ConnectionUniversalListener;
 import org.apache.directory.studio.connection.ui.widgets.ConnectionWidget;
-import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
-import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.URL;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.viewers.DoubleClickEvent;
@@ -47,14 +45,20 @@
 import org.eclipse.swt.widgets.Shell;
 
 
+/**
+ * Dialog to select the connection of a referral.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SelectReferralConnectionDialog extends Dialog
 {
 
     private String title;
 
-    private URL referralUrl;
+    private LdapURL referralUrl;
 
-    private IBrowserConnection selectedConnection;
+    private Connection selectedConnection;
 
     private ConnectionConfiguration configuration;
 
@@ -65,7 +69,13 @@
     private ConnectionWidget mainWidget;
 
 
-    public SelectReferralConnectionDialog( Shell parentShell, URL referralUrl )
+    /**
+     * Creates a new instance of SelectReferralConnectionDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param referralUrl the referral URL
+     */
+    public SelectReferralConnectionDialog( Shell parentShell, LdapURL referralUrl )
     {
         super( parentShell );
         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
@@ -75,6 +85,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected void configureShell( Shell shell )
     {
         super.configureShell( shell );
@@ -82,37 +95,40 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean close()
     {
-        if ( this.mainWidget != null )
+        if ( mainWidget != null )
         {
-            this.configuration.dispose();
-            this.configuration = null;
-            this.actionGroup.deactivateGlobalActionHandlers();
-            this.actionGroup.dispose();
-            this.actionGroup = null;
-            this.universalListener.dispose();
-            this.universalListener = null;
-            this.mainWidget.dispose();
-            this.mainWidget = null;
+            configuration.dispose();
+            configuration = null;
+            actionGroup.deactivateGlobalActionHandlers();
+            actionGroup.dispose();
+            actionGroup = null;
+            universalListener.dispose();
+            universalListener = null;
+            mainWidget.dispose();
+            mainWidget = null;
         }
         return super.close();
     }
 
 
-    protected void okPressed()
-    {
-        super.okPressed();
-    }
-
-
+    /**
+     * {@inheritDoc}
+     */
     protected void cancelPressed()
     {
-        this.selectedConnection = null;
+        selectedConnection = null;
         super.cancelPressed();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected void createButtonsForButtonBar( Composite parent )
     {
         createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
@@ -120,9 +136,11 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected Control createDialogArea( Composite parent )
     {
-
         Composite composite = ( Composite ) super.createDialogArea( parent );
         GridLayout gl = new GridLayout();
         composite.setLayout( gl );
@@ -135,24 +153,24 @@
             + referralUrl, 1 );
 
         // create configuration
-        this.configuration = new ConnectionConfiguration();
+        configuration = new ConnectionConfiguration();
 
         // create main widget
-        this.mainWidget = new ConnectionWidget( this.configuration, null );
-        this.mainWidget.createWidget( composite );
-        this.mainWidget.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager() );
+        mainWidget = new ConnectionWidget( configuration, null );
+        mainWidget.createWidget( composite );
+        mainWidget.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager() );
 
         // create actions and context menu (and register global actions)
-        this.actionGroup = new ConnectionActionGroup( this.mainWidget, this.configuration );
-        this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
-        this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
-        this.actionGroup.fillContextMenu( this.mainWidget.getContextMenuManager() );
-        this.actionGroup.activateGlobalActionHandlers();
+        actionGroup = new ConnectionActionGroup( mainWidget, configuration );
+        actionGroup.fillToolBar( mainWidget.getToolBarManager() );
+        actionGroup.fillMenu( mainWidget.getMenuManager() );
+        actionGroup.fillContextMenu( mainWidget.getContextMenuManager() );
+        actionGroup.activateGlobalActionHandlers();
 
         // create the listener
-        this.universalListener = new ConnectionUniversalListener( this.mainWidget.getViewer() );
+        universalListener = new ConnectionUniversalListener( mainWidget.getViewer() );
 
-        this.mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
+        mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
         {
             public void selectionChanged( SelectionChangedEvent event )
             {
@@ -161,16 +179,13 @@
                     Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
                     if ( o instanceof Connection )
                     {
-                        Connection connection = ( Connection ) o;
-                        IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
-                            .getBrowserConnection( connection );
-                        selectedConnection = browserConnection;
+                        selectedConnection = ( Connection ) o;
                     }
                 }
             }
         } );
 
-        this.mainWidget.getViewer().addDoubleClickListener( new IDoubleClickListener()
+        mainWidget.getViewer().addDoubleClickListener( new IDoubleClickListener()
         {
             public void doubleClick( DoubleClickEvent event )
             {
@@ -179,42 +194,43 @@
                     Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
                     if ( o instanceof Connection )
                     {
-                        Connection connection = ( Connection ) o;
-                        IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
-                            .getBrowserConnection( connection );
-                        selectedConnection = browserConnection;
+                        selectedConnection = ( Connection ) o;
                     }
                 }
             }
         } );
 
-        if ( this.referralUrl != null )
+        if ( referralUrl != null )
         {
-            IBrowserConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnections();
+            Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
             for ( int i = 0; i < connections.length; i++ )
             {
-                IBrowserConnection connection = connections[i];
-                URL connectionUrl = connection.getUrl();
+                Connection connection = connections[i];
+                LdapURL connectionUrl = connection.getUrl();
                 if ( connectionUrl != null && referralUrl.toString().startsWith( connectionUrl.toString() ) )
                 {
-                    this.mainWidget.getViewer().reveal( connection );
-                    this.mainWidget.getViewer().setSelection( new StructuredSelection( connection.getConnection() ), true );
+                    mainWidget.getViewer().reveal( connection );
+                    mainWidget.getViewer().setSelection( new StructuredSelection( connection ), true );
                 }
             }
         }
 
         applyDialogFont( composite );
 
-        this.mainWidget.setFocus();
+        mainWidget.setFocus();
 
         return composite;
-
     }
 
 
-    public IBrowserConnection getReferralConnection()
+    /**
+     * Gets the referral connection.
+     * 
+     * @return the referral connection
+     */
+    public Connection getReferralConnection()
     {
-        return this.selectedConnection;
+        return selectedConnection;
     }
 
 }

Modified: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java Sun Nov 11 08:40:29 2007
@@ -23,7 +23,6 @@
 import java.io.IOException;
 import java.net.URL;
 
-import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRunner;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IConfigurationElement;
@@ -141,8 +140,6 @@
                 e.printStackTrace();
             }
         }
-
-        BrowserCorePlugin.getDefault().setReferralHandler( new BrowserCommonReferralHandler() );
     }
 
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java Sun Nov 11 08:40:29 2007
@@ -23,7 +23,6 @@
 
 import org.apache.directory.studio.ldapbrowser.core.events.CoreEventRunner;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRunner;
-import org.apache.directory.studio.ldapbrowser.core.model.IReferralHandler;
 import org.eclipse.core.runtime.Plugin;
 import org.osgi.framework.BundleContext;
 
@@ -42,9 +41,6 @@
     /** The connection manager */
     private BrowserConnectionManager connectionManager;
 
-    /** The connection provider */
-    private IReferralHandler referralHandler;
-
     /** The preferences */
     private BrowserCorePreferences preferences;
 
@@ -136,30 +132,6 @@
     public BrowserCorePreferences getCorePreferences()
     {
         return preferences;
-    }
-
-
-    /**
-     * Gets the ReferralHanlder
-     *
-     * @return
-     *      the ReferralHandler
-     */
-    public IReferralHandler getReferralHandler()
-    {
-        return referralHandler;
-    }
-
-
-    /**
-     * Sets the ReferralHandler
-     *
-     * @param referralHandler
-     *      the ReferralHandler to set
-     */
-    public void setReferralHandler( IReferralHandler referralHandler )
-    {
-        this.referralHandler = referralHandler;
     }
 
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java Sun Nov 11 08:40:29 2007
@@ -38,10 +38,7 @@
 import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ReferralException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
@@ -223,24 +220,6 @@
             if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
             {
                 // nothing
-            }
-            else if ( ce instanceof ReferralException )
-            {
-
-                if ( searchParameter.getReferralsHandlingMethod() == ReferralHandlingMethod.FOLLOW )
-                {
-                    ReferralException re = ( ReferralException ) ce;
-                    ISearch[] referralSearches = re.getReferralSearches();
-                    for ( int i = 0; i < referralSearches.length; i++ )
-                    {
-                        ISearch referralSearch = referralSearches[i];
-
-                        // export recursive
-                        exportToCsv( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(),
-                            bufferedWriter, count, monitor, attributes, attributeDelimiter, valueDelimiter,
-                            quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn );
-                    }
-                }
             }
             else
             {

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java Sun Nov 11 08:40:29 2007
@@ -40,10 +40,7 @@
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ReferralException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
@@ -189,22 +186,6 @@
                 || ce.getLdapStatusCode() == ConnectionException.STAUS_CODE_ADMINLIMIT_EXCEEDED )
             {
                 // ignore
-            }
-            else if ( ce instanceof ReferralException )
-            {
-                if ( searchParameter.getReferralsHandlingMethod() == ReferralHandlingMethod.FOLLOW )
-                {
-                    ReferralException re = ( ReferralException ) ce;
-                    ISearch[] referralSearches = re.getReferralSearches();
-                    for ( int i = 0; i < referralSearches.length; i++ )
-                    {
-                        ISearch referralSearch = referralSearches[i];
-
-                        // export recursive
-                        export( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(), bufferedWriter,
-                            count, monitor );
-                    }
-                }
             }
             else
             {

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java Sun Nov 11 08:40:29 2007
@@ -34,10 +34,7 @@
 import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
 import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ReferralException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
@@ -244,24 +241,9 @@
         }
         catch ( ConnectionException ce )
         {
-
             if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
             {
                 // nothing
-            }
-            else if ( ce instanceof ReferralException )
-            {
-                if ( searchParameter.getReferralsHandlingMethod() == ReferralHandlingMethod.FOLLOW )
-                {
-                    ReferralException re = ( ReferralException ) ce;
-                    ISearch[] referralSearches = re.getReferralSearches();
-                    for ( ISearch referralSearch : referralSearches )
-                    {
-                        // export recursive
-                        exportToXls( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(), sheet,
-                            headerRow, count, monitor, attributeNameMap, valueDelimiter, binaryEncoding, exportDn );
-                    }
-                }
             }
             else
             {

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java Sun Nov 11 08:40:29 2007
@@ -212,43 +212,11 @@
             new String[]
                 { entry.getDn().getUpName() } ) );
 
-        // entry.setAttributesInitialized(false, entry.getConnection());
-
         if ( entry instanceof IRootDSE )
         {
-//            IEntry[] oldChildren = entry.getChildren();
-//            for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
-//            {
-//                if ( oldChildren[i] != null )
-//                {
-//                    entry.deleteChild( oldChildren[i] );
-//                }
-//            }
-//            entry.setChildrenInitialized( false );
-            
             // special handling for Root DSE
             loadRootDSE( entry.getBrowserConnection(), monitor );
             
-//            if ( !monitor.errorsReported() )
-//            {
-//                try
-//                {
-//                    monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
-//                    loadRootDSE( entry.getBrowserConnection(), monitor );
-//                    monitor.worked( 1 );
-//                }
-//                catch ( Exception e )
-//                {
-//                    monitor.reportError( BrowserCoreMessages.model__error_loading_rootdse );
-//                    rootDSE = null;
-//                }
-//
-//                if ( monitor.errorsReported() )
-//                {
-//                    close();
-//                }
-//            }
-            
         	entry.setAttributesInitialized( true );
         	entry.setChildrenInitialized( true );
         }
@@ -276,12 +244,6 @@
      */
     static void loadRootDSE( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
     {
-//        if(rootDSE == null)
-//        {
-//            rootDSE = new RootDSE( this );
-//            cacheEntry( rootDSE );
-//        }
-        
         // delete old children
         IEntry[] oldChildren = browserConnection.getRootDSE().getChildren();
         for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
@@ -375,6 +337,7 @@
         }
         
         // get other metadata entries
+        // TODO: check all attributes if they are valid DNs
         String[] metadataAttributeNames = new String[]
             { IRootDSE.ROOTDSE_ATTRIBUTE_MONITORCONTEXT, IRootDSE.ROOTDSE_ATTRIBUTE_CONFIGCONTEXT,
                 IRootDSE.ROOTDSE_ATTRIBUTE_DSANAME };

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java Sun Nov 11 08:40:29 2007
@@ -33,6 +33,7 @@
 import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.model.Control;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
@@ -178,7 +179,9 @@
             AliasDereferencingMethod derefAliasMethod = parent.getBrowserConnection().getAliasesDereferencingMethod();
             ReferralHandlingMethod handleReferralsMethod = parent.getBrowserConnection().getReferralsHandlingMethod();
             if ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
-                BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) )
+                BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS )
+                && parent.getBrowserConnection().getRootDSE().isControlSupported(
+                    IBrowserConnection.CONTROL_MANAGEDSAIT ) )
             {
                 scope = ( parent.isAlias() || parent.isReferral() ) ? SearchScope.OBJECT : SearchScope.ONELEVEL;
                 derefAliasMethod = parent.isAlias() ? AliasDereferencingMethod.FINDING
@@ -205,7 +208,7 @@
             {
 
                 /*
-                 * clearing old children before filling new subenties is
+                 * clearing old children before filling new children is
                  * necessary to handle aliases and referrals.
                  */
                 IEntry[] connChildren = parent.getChildren();

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchJob.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchJob.java Sun Nov 11 08:40:29 2007
@@ -40,7 +40,10 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
+import org.apache.directory.studio.connection.core.io.jndi.StudioSearchResult;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent;
 import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
@@ -51,11 +54,10 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.ReferralException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.Entry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.ReferralBaseEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.ObjectClassDescription;
 import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
@@ -170,6 +172,15 @@
     public static void searchAndUpdateModel( IBrowserConnection browserConnection, ISearch search,
         StudioProgressMonitor monitor )
     {
+        if ( browserConnection.getConnection() == null )
+        {
+            if ( search != null )
+            {
+                search.setSearchResults( new ISearchResult[0] );
+            }
+            return;
+        }
+        
         try
         {
             if ( !monitor.isCanceled() )
@@ -186,8 +197,17 @@
                     // iterate through the search result
                     while ( !monitor.isCanceled() && enumeration.hasMore() )
                     {
-                        SearchResult sr = enumeration.nextElement(); // TODO: referrals exception
+                        SearchResult sr = enumeration.next();
                         LdapDN dn = JNDIUtils.getDn( sr );
+                        boolean isReferral = false;
+                        if ( sr instanceof StudioSearchResult )
+                        {
+                            StudioSearchResult ssr = ( StudioSearchResult ) sr;
+                            isReferral = ssr.isReferral();
+                            Connection connection = ssr.getConnection();
+                            browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
+                                .getBrowserConnection( connection );
+                        }
 
                         // get entry from cache or create it
                         IEntry entry = browserConnection.getEntryFromCache( dn );
@@ -195,16 +215,20 @@
                         {
                             entry = createAndCacheEntry( browserConnection, dn );
                         }
-
+                        
                         // initialize special flags
                         initFlags( entry, sr, searchParameter );
 
                         // fill the attributes
                         fillAttributes( entry, sr, search.getSearchParameter() );
 
-                        searchResultList
-                            .add( new org.apache.directory.studio.ldapbrowser.core.model.impl.SearchResult( entry,
-                                search ) );
+                        if(isReferral)
+                        {
+                            entry = new ReferralBaseEntry( browserConnection, dn );
+                        }
+                        
+                        searchResultList.add( new org.apache.directory.studio.ldapbrowser.core.model.impl.SearchResult(
+                            entry, search ) );
 
                         monitor
                             .reportProgress( searchResultList.size() == 1 ? BrowserCoreMessages.model__retrieved_1_entry
@@ -221,28 +245,6 @@
                     {
                         search.setCountLimitExceeded( true );
                     }
-                    else if ( ce instanceof ReferralException )
-                    {
-                        if ( search.getReferralsHandlingMethod() == ReferralHandlingMethod.FOLLOW )
-                        {
-                            ReferralException re = ( ReferralException ) ce;
-                            ISearch[] referralSearches = re.getReferralSearches();
-                            for ( int i = 0; i < referralSearches.length; i++ )
-                            {
-                                ISearch referralSearch = referralSearches[i];
-
-                                searchAndUpdateModel( referralSearch.getBrowserConnection(), referralSearch, monitor );
-
-                                ISearchResult[] referralSearchResults = referralSearch.getSearchResults();
-                                for ( int j = 0; referralSearchResults != null && j < referralSearchResults.length; j++ )
-                                {
-                                    ISearchResult referralSearchResult = referralSearchResults[j];
-                                    referralSearchResult.setSearch( search );
-                                    searchResultList.add( referralSearchResult );
-                                }
-                            }
-                        }
-                    }
                     else
                     {
                         monitor.reportError( ce );
@@ -307,7 +309,7 @@
         }
 
         NamingEnumeration<SearchResult> result = browserConnection.getConnection().getJNDIConnectionWrapper().search(
-            searchBase, filter, controls, derefAliasMethod, handleReferralsMethod, ldapControls, monitor );
+            searchBase, filter, controls, derefAliasMethod, handleReferralsMethod, ldapControls, monitor, null );
         return result;
     }
 
@@ -338,16 +340,15 @@
 
     private static String getReferralsHandlingMethod( SearchParameter parameter )
     {
-        String m = "follow"; //$NON-NLS-1$
+        String m = JNDIConnectionWrapper.REFERRAL_FOLLOW; //$NON-NLS-1$
 
         switch ( parameter.getReferralsHandlingMethod() )
         {
             case IGNORE:
-                m = "ignore"; //$NON-NLS-1$
+                m = JNDIConnectionWrapper.REFERRAL_IGNORE; //$NON-NLS-1$
                 break;
             case FOLLOW:
-                // m = "follow"; //$NON-NLS-1$
-                m = "throw"; //$NON-NLS-1$
+                m = JNDIConnectionWrapper.REFERRAL_FOLLOW; //$NON-NLS-1$
                 break;
         }
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IRootDSE.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IRootDSE.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IRootDSE.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IRootDSE.java Sun Nov 11 08:40:29 2007
@@ -87,4 +87,15 @@
      */
     public String[] getSupportedFeatures();
 
+
+    
+    /**
+     * Checks if control is supported.
+     * 
+     * @param oid the OID
+     * 
+     * @return true, if control is supported
+     */
+    public boolean isControlSupported( String oid );
+
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java Sun Nov 11 08:40:29 2007
@@ -124,5 +124,14 @@
     {
         return false;
     }
+    
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#isControlSupported(java.lang.String)
+     */
+    public boolean isControlSupported( String oid )
+    {
+        String[] supportedControls = getSupportedControls();
+        return Arrays.asList( supportedControls ).contains( oid );
+    }
 
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java?rev=593925&r1=593924&r2=593925&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java Sun Nov 11 08:40:29 2007
@@ -25,14 +25,10 @@
 import java.net.NoRouteToHostException;
 import java.net.SocketException;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
 
-import javax.naming.Context;
 import javax.naming.NamingException;
-import javax.naming.ReferralException;
 
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
@@ -104,11 +100,9 @@
         {
             String message = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
             int ldapStatusCode = -1;
-            String[] referrals = null;
 
             // get LDAP status code
-            // [LDAP: error code 21 - telephoneNumber: value #0 invalid per
-            // syntax]
+            // [LDAP: error code 21 - telephoneNumber: value #0 invalid per syntax]
             if ( message != null && message.startsWith( "[LDAP: error code " ) ) { //$NON-NLS-1$
                 int begin = "[LDAP: error code ".length(); //$NON-NLS-1$
                 int end = begin + 2;
@@ -146,51 +140,8 @@
             {
                 message = e.getMessage() + " (" + e.getMessage() + ")";; //$NON-NLS-1$ //$NON-NLS-2$
             }
-            if ( e instanceof ReferralException )
-            {
-                message = "Referrals: "; //$NON-NLS-1$
-                ReferralException re;
-                ArrayList<Object> referralsList = new ArrayList<Object>();
-
-                re = ( ReferralException ) e;
-                message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
-                referralsList.add( re.getReferralInfo() );
-
-                while ( re.skipReferral() )
-                {
-                    try
-                    {
-                        Context ctx = re.getReferralContext();
-                        ctx.list( "" ); //$NON-NLS-1$
-                    }
-                    catch ( NamingException e1 )
-                    {
-                        if ( e1 instanceof ReferralException )
-                        {
-                            re = ( ReferralException ) e1;
-                            message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
-                            referralsList.add( re.getReferralInfo() );
-                        }
-                        else
-                        {
-                            break;
-                        }
-                    }
-                }
-
-                referrals = referralsList.toArray( new String[referralsList.size()] );
-            }
 
-            ConnectionException ce;
-            if ( referrals != null )
-            {
-                ce = new org.apache.directory.studio.ldapbrowser.core.model.ReferralException( searchParameter,
-                    referrals, ldapStatusCode, message, e );
-            }
-            else
-            {
-                ce = new ConnectionException( ldapStatusCode, message, e );
-            }
+            ConnectionException ce = new ConnectionException( ldapStatusCode, message, e );
             if ( lastException != null )
             {
                 lastException.initCause( ce );



Mime
View raw message