You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/26 20:44:37 UTC

svn commit: r598395 [3/7] - in /directory/sandbox/felixk: studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/ studio-aciitemedito...

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,157 @@
+package org.apache.directory.studio.connection.core;
+
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+
+
+/**
+ * Utility class for LdapDN specific stuff.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DnUtils
+{
+
+    /**
+     * Composes an DN based on the given RDN and DN.
+     * 
+     * @param rdn the RDN
+     * @param parent the parent DN
+     * 
+     * @return the composed DN
+     */
+    public static LdapDN composeDn( Rdn rdn, LdapDN parent )
+    {
+        LdapDN ldapDn = ( LdapDN ) parent.clone();
+        ldapDn.add( ( Rdn ) rdn.clone() );
+        return ldapDn;
+    }
+
+
+    /**
+     * Gets the parent DN of the given DN or null if the given 
+     * DN hasn't a parent.
+     * 
+     * @param dn the DN
+     * 
+     * @return the parent DN, null if the given DN hasn't a parent
+     */
+    public static LdapDN getParent( LdapDN dn )
+    {
+        if ( dn.size() < 1 )
+        {
+            return null;
+        }
+        else
+        {
+            LdapDN parent = ( LdapDN ) dn.getPrefix( dn.size() - 1 );
+            return parent;
+        }
+    }
+
+
+    /**
+     * Compose an DN based on the given RDN and DN.
+     * 
+     * @param rdn the RDN
+     * @param parent the parent DN
+     * 
+     * @return the composed RDN
+     * 
+     * @throws InvalidNameException the invalid name exception
+     */
+    public static LdapDN composeDn( String rdn, String parent ) throws InvalidNameException
+    {
+        return composeDn( new Rdn( rdn ), new LdapDN( parent ) );
+    }
+
+
+    /**
+     * Composes an DN based on the given prefix and suffix.
+     * 
+     * @param prefix the prefix
+     * @param suffix the suffix
+     * 
+     * @return the composed DN
+     */
+    public static LdapDN composeDn( LdapDN prefix, LdapDN suffix )
+    {
+        LdapDN ldapDn = ( LdapDN ) suffix.clone();
+
+        for ( Rdn rdn : prefix.getRdns() )
+        {
+            ldapDn.add( ( Rdn ) rdn.clone() );
+        }
+
+        return ldapDn;
+    }
+
+
+    /**
+     * Gets the prefix, cuts the suffix from the given DN.
+     * 
+     * @param dn the DN
+     * @param suffix the suffix
+     * 
+     * @return the prefix
+     */
+    public static LdapDN getPrefixName( LdapDN dn, LdapDN suffix )
+    {
+        if ( suffix.size() < 1 )
+        {
+            return null;
+        }
+        else
+        {
+            LdapDN parent = ( LdapDN ) dn.getSuffix( suffix.size() - 1 );
+            return parent;
+        }
+    }
+
+
+    /**
+     * Composes an RDN based on the given types and values.
+     * 
+     * @param rdnTypes the types
+     * @param rdnValues the values
+     * 
+     * @return the RDN
+     * 
+     * @throws InvalidNameException the invalid name exception
+     */
+    public static Rdn composeRdn( String[] rdnTypes, String[] rdnValues ) throws InvalidNameException
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( int i = 0; i < rdnTypes.length; i++ )
+        {
+            if ( i > 0 )
+            {
+                sb.append( '+' );
+            }
+
+            sb.append( rdnTypes[i] );
+            sb.append( '=' );
+            sb.append( Rdn.escapeValue( rdnValues[i] ) );
+        }
+
+        String s = sb.toString();
+        try
+        {
+            if ( LdapDN.isValid( s ) )
+            {
+                Rdn rdn = new Rdn( sb.toString() );
+                return rdn;
+            }
+        }
+        catch ( Exception e )
+        {
+        }
+
+        throw new InvalidNameException( "RDN is invalid" );
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,115 @@
+package org.apache.directory.studio.connection.core;
+
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
+
+
+/**
+ * Callback interface to log modifications
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface IJndiLogger
+{
+
+    /**
+     * Logs a changetype:add.
+     * 
+     * @param connection the connection
+     * @param dn the DN
+     * @param attributes the attributes
+     * @param controls the controls
+     * @param ex the naming exception if an error occurred, null otherwise
+     */
+    public void logChangetypeAdd( Connection connection, final String dn, final Attributes attributes, final Control[] controls, NamingException ex );
+
+
+    /**
+     * Logs a changetype:delete.
+     * 
+     * @param connection the connection
+     * @param dn the DN
+     * @param controls the controls
+     * @param ex the naming exception if an error occurred, null otherwise
+     * 
+     */
+    public void logChangetypeDelete( Connection connection, final String dn, final Control[] controls, NamingException ex );
+
+
+    /**
+     * Logs a changetype:modify.
+     * 
+     * @param connection the connection
+     * @param dn the DN
+     * @param modificationItems the modification items
+     * @param ex the naming exception if an error occurred, null otherwise
+     * @param controls the controls
+     */
+    public void logChangetypeModify( Connection connection, final String dn, final ModificationItem[] modificationItems, final Control[] controls, NamingException ex );
+
+
+    /**
+     * Logs a changetype:moddn.
+     * 
+     * @param connection the connection
+     * @param oldDn the old DN
+     * @param newDn the new DN
+     * @param deleteOldRdn the delete old RDN
+     * @param controls the controls
+     * @param ex the naming exception if an error occurred, null otherwise
+     */
+    public void logChangetypeModDn( Connection connection, final String oldDn, final String newDn, final boolean deleteOldRdn, final Control[] controls, NamingException ex );
+
+
+    /**
+     * Sets the logger ID.
+     * 
+     * @param id the new logger ID
+     */
+    public void setId( String id );
+
+
+    /**
+     * Gets the logger ID.
+     * 
+     * @return the logger ID
+     */
+    public String getId();
+    
+    
+    /**
+     * Sets the logger name.
+     * 
+     * @param name the new logger name
+     */
+    public void setName( String name );
+
+
+    /**
+     * Gets the logger name.
+     * 
+     * @return the logger name
+     */
+    public String getName();
+    
+    
+    /**
+     * Sets the logger description.
+     * 
+     * @param description the new logger description
+     */
+    public void setDescription( String description );
+    
+    
+    /**
+     * Gets the logger description.
+     * 
+     * @return the logger description
+     */
+    public String getDescription();
+
+}

Propchange: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,48 @@
+/*
+ *  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;
+
+
+import org.apache.directory.shared.ldap.codec.util.LdapURL;
+
+
+/**
+ * Callback interface to request the target connection 
+ * of a referral from a higher-level layer (from the UI plugin).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface IReferralHandler
+{
+
+    /**
+     * Gets the connection from this referral handler.
+     * The connection is used to continue a LDAP request.
+     * The referral handler may display a dialog to the user
+     * to select a proper connection.
+     * 
+     * @param referralURL the referral URL
+     * @return the target connection
+     */
+    public Connection getReferralConnection( LdapURL referralURL );
+
+}

Propchange: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IReferralHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java (original)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java Mon Nov 26 11:44:28 2007
@@ -324,12 +324,21 @@
      */
     public Throwable getException()
     {
-
         if ( errorStatusList != null )
         {
             return errorStatusList.get( 0 ).getException();
         }
         return null;
+    }
+    
+    
+    /**
+     * Resets this status.
+     */
+    public void reset()
+    {
+        this.done = false;
+        this.errorStatusList = null;
     }
 
     /**

Modified: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java (original)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java Mon Nov 26 11:44:28 2007
@@ -20,6 +20,8 @@
 
 package org.apache.directory.studio.connection.core;
 
+import org.apache.directory.shared.ldap.util.StringTools;
+
 
 /**
  * Some utils.
@@ -31,7 +33,8 @@
 {
 
     /**
-     * Shortens the given label to the given maximum length.
+     * Shortens the given label to the given maximum length
+     * and filters non-printable characters.
      * 
      * @param label the label
      * @param maxLength the max length
@@ -44,6 +47,8 @@
         {
             return null;
         }
+
+        // shorten label
         if ( maxLength < 3 )
         {
             return "...";
@@ -54,15 +59,65 @@
                 + label.substring( label.length() - maxLength / 2, label.length() );
 
         }
+
+        // filter non-printable characters
         StringBuffer sb = new StringBuffer( maxLength + 3 );
         for ( int i = 0; i < label.length(); i++ )
         {
             char c = label.charAt( i );
-            if ( c > 31 && c < 127 )
+            if ( Character.isISOControl( c ) )
+            {
+                sb.append( '.' );
+            }
+            else
+            {
                 sb.append( c );
+            }
+        }
+
+        return sb.toString();
+    }
+
+    
+
+    /**
+     * Converts a String into a String that could be used as a filename.
+     *
+     * @param s
+     *      the String to convert
+     * @return
+     *      the converted String
+     */
+    public static String getFilenameString( String s )
+    {
+        if ( s == null )
+        {
+            return null;
+        }
+
+        
+        byte[] b = StringTools.getBytesUtf8( s );
+        StringBuffer sb = new StringBuffer();
+        for ( int i = 0; i < b.length; i++ )
+        {
+
+            if ( b[i] == '-' || b[i] == '_' || ( '0' <= b[i] && b[i] <= '9' ) || ( 'A' <= b[i] && b[i] <= 'Z' )
+                || ( 'a' <= b[i] && b[i] <= 'z' ) )
+            {
+                sb.append( ( char ) b[i] );
+            }
             else
-                sb.append( '.' );
+            {
+                int x = ( int ) b[i];
+                if ( x < 0 )
+                    x = 256 + x;
+                String t = Integer.toHexString( x );
+                if ( t.length() == 1 )
+                    t = "0" + t; //$NON-NLS-1$
+                sb.append( t );
+            }
         }
+
         return sb.toString();
     }
 

Modified: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java (original)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java Mon Nov 26 11:44:28 2007
@@ -21,12 +21,15 @@
 
 
 import java.util.Hashtable;
+import java.util.List;
 
 import javax.naming.CommunicationException;
 import javax.naming.Context;
 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 +44,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.IJndiLogger;
+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;
 
 
@@ -88,9 +95,15 @@
 
     private Thread jobThread;
 
-    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 +205,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 +229,85 @@
                 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;
+                        try
+                        {
+                            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 );
+                                }
+                            }
+                        }
+                        catch ( NamingException e )
+                        {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                    }
+                    else
+                    {
+                        namingException = re;
                     }
-
                 }
                 catch ( NamingException e )
                 {
@@ -278,7 +351,7 @@
             monitor.reportError( runnable.getException().getMessage(), runnable.getException() );
             return null;
         }
-        else if ( runnable.getResult() != null && runnable.getResult() instanceof NamingEnumeration )
+        else if ( runnable.getResult() != null )
         {
             return runnable.getResult();
         }
@@ -290,6 +363,82 @@
 
 
     /**
+     * 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 ) throws NamingException
+    {
+        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;
+    }
+
+
+    /**
      * Modify attributes.
      * 
      * @param dn the DN
@@ -319,9 +468,9 @@
                     namingException = ne;
                 }
 
-                if ( modificationLogger != null )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    modificationLogger.logChangetypeModify( dn, modificationItems, controls, namingException );
+                    logger.logChangetypeModify( connection, dn, modificationItems, controls, namingException );
                 }
             }
 
@@ -400,9 +549,9 @@
                     namingException = ne;
                 }
 
-                if ( modificationLogger != null )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    modificationLogger.logChangetypeModDn( oldDn, newDn, deleteOldRdn, controls, namingException );
+                    logger.logChangetypeModDn( connection, oldDn, newDn, deleteOldRdn, controls, namingException );
                 }
             }
 
@@ -472,9 +621,9 @@
                     namingException = ne;
                 }
 
-                if ( modificationLogger != null )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    modificationLogger.logChangetypeAdd( dn, attributes, controls, namingException );
+                    logger.logChangetypeAdd( connection, dn, attributes, controls, namingException );
                 }
             }
 
@@ -541,9 +690,9 @@
                     namingException = ne;
                 }
 
-                if ( modificationLogger != null )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    modificationLogger.logChangetypeDelete( dn, controls, namingException );
+                    logger.logChangetypeDelete( connection, dn, controls, namingException );
                 }
             }
 
@@ -932,15 +1081,8 @@
         void reset();
     }
 
-
-    /**
-     * Sets the modification logger.
-     * 
-     * @param modificationLogger the new modification logger
-     */
-    public void setModificationLogger( IModificationLogger modificationLogger )
+    private List<IJndiLogger> getJndiLoggers()
     {
-        this.modificationLogger = modificationLogger;
+        return ConnectionCorePlugin.getDefault().getJndiLoggers();
     }
-
 }

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,462 @@
+/*
+ *  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.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.FileHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.naming.InvalidNameException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCoreConstants;
+import org.apache.directory.studio.connection.core.ConnectionManager;
+import org.apache.directory.studio.connection.core.DnUtils;
+import org.apache.directory.studio.connection.core.IJndiLogger;
+import org.apache.directory.studio.ldifparser.LdifFormatParameters;
+import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
+import org.apache.directory.studio.ldifparser.model.container.LdifChangeDeleteRecord;
+import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
+import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
+import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldifparser.model.lines.LdifCommentLine;
+import org.apache.directory.studio.ldifparser.model.lines.LdifDeloldrdnLine;
+import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecSepLine;
+import org.apache.directory.studio.ldifparser.model.lines.LdifNewrdnLine;
+import org.apache.directory.studio.ldifparser.model.lines.LdifNewsuperiorLine;
+import org.apache.directory.studio.ldifparser.model.lines.LdifSepLine;
+
+
+/**
+ * The ModificationLogger is used to log modifications in LDIF format into a file.
+ *
+ * TODO: log controls
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdifModificationLogger implements IJndiLogger
+{
+
+    /** The ID. */
+    private String id;
+
+    /** The name. */
+    private String name;
+
+    /** The description. */
+    private String description;
+
+    /** The file handlers. */
+    private Map<String, FileHandler> fileHandlers = new HashMap<String, FileHandler>();
+
+    /** The loggers. */
+    private Map<String, Logger> loggers = new HashMap<String, Logger>();
+
+
+    /**
+     * Creates a new instance of ModificationLogger.
+     */
+    public LdifModificationLogger()
+    {
+    }
+
+
+    /**
+     * Inits the modification logger.
+     */
+    private void initModificationLogger( Connection connection )
+    {
+        Logger logger = Logger.getAnonymousLogger();
+        loggers.put( connection.getId(), logger );
+        logger.setLevel( Level.ALL );
+
+        String logfileName = ConnectionManager.getModificationLogFileName( connection );
+        try
+        {
+            FileHandler fileHandler = new FileHandler( logfileName, 100000, 10, true );
+            fileHandlers.put( connection.getId(), fileHandler );
+            fileHandler.setFormatter( new Formatter()
+            {
+                public String format( LogRecord record )
+                {
+                    return record.getMessage();
+                }
+            } );
+            logger.addHandler( fileHandler );
+        }
+        catch ( SecurityException e )
+        {
+            e.printStackTrace();
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * Disposes the modification logger of the given connection.
+     * 
+     * @param connection the connection
+     */
+    public void dispose( Connection connection )
+    {
+        String id = connection.getId();
+        if ( loggers.containsKey( id ) )
+        {
+            Handler[] handlers = loggers.get( id ).getHandlers();
+            for ( Handler handler : handlers )
+            {
+                handler.close();
+            }
+
+            loggers.remove( id );
+        }
+    }
+
+
+    /**
+     * Logs the given text to the modification logger of the given connection.
+     * 
+     * @param text the text to log
+     * @param ex the naming exception if an error occurred, null otherwise
+     * @param connection the connection
+     */
+    private void log( String text, NamingException ex, Connection connection )
+    {
+        String id = connection.getId();
+        if ( !loggers.containsKey( id ) )
+        {
+            if ( connection.getName() != null )
+            {
+                initModificationLogger( connection );
+            }
+        }
+
+        if ( loggers.containsKey( id ) )
+        {
+            Logger logger = loggers.get( id );
+            DateFormat df = new SimpleDateFormat( ConnectionCoreConstants.DATEFORMAT );
+
+            if ( ex != null )
+            {
+                logger.log( Level.ALL, LdifCommentLine
+                    .create( "#!RESULT ERROR" ).toFormattedString( LdifFormatParameters.DEFAULT ) ); //$NON-NLS-1$
+            }
+            else
+            {
+                logger.log( Level.ALL, LdifCommentLine
+                    .create( "#!RESULT OK" ).toFormattedString( LdifFormatParameters.DEFAULT ) ); //$NON-NLS-1$
+            }
+
+            logger
+                .log(
+                    Level.ALL,
+                    LdifCommentLine
+                        .create( "#!CONNECTION ldap://" + connection.getHost() + ":" + connection.getPort() ).toFormattedString( LdifFormatParameters.DEFAULT ) ); //$NON-NLS-1$ //$NON-NLS-2$
+            logger.log( Level.ALL, LdifCommentLine
+                .create( "#!DATE " + df.format( new Date() ) ).toFormattedString( LdifFormatParameters.DEFAULT ) ); //$NON-NLS-1$
+
+            if ( ex != null )
+            {
+                String errorComment = "#!ERROR " + ex.getMessage(); //$NON-NLS-1$
+                errorComment = errorComment.replaceAll( "\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+                errorComment = errorComment.replaceAll( "\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+                LdifCommentLine errorCommentLine = LdifCommentLine.create( errorComment );
+                logger.log( Level.ALL, errorCommentLine.toFormattedString( LdifFormatParameters.DEFAULT ) );
+            }
+
+            logger.log( Level.ALL, text );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.IModificationLogger#logChangetypeAdd(java.lang.String, javax.naming.directory.Attributes, javax.naming.ldap.Control[], javax.naming.NamingException)
+     */
+    public void logChangetypeAdd( Connection connection, final String dn, final Attributes attributes,
+        final Control[] controls, NamingException ex )
+    {
+        try
+        {
+            LdifChangeAddRecord record = LdifChangeAddRecord.create( dn );
+            //record.addControl( controlLine );
+            NamingEnumeration<? extends Attribute> attributeEnumeration = attributes.getAll();
+            while ( attributeEnumeration.hasMore() )
+            {
+                Attribute attribute = attributeEnumeration.next();
+                String attributeName = attribute.getID();
+                NamingEnumeration<?> valueEnumeration = attribute.getAll();
+                while ( valueEnumeration.hasMore() )
+                {
+                    Object o = valueEnumeration.next();
+                    if ( o instanceof String )
+                    {
+                        record.addAttrVal( LdifAttrValLine.create( attributeName, ( String ) o ) );
+                    }
+                    if ( o instanceof byte[] )
+                    {
+                        record.addAttrVal( LdifAttrValLine.create( attributeName, ( byte[] ) o ) );
+                    }
+                }
+            }
+            record.finish( LdifSepLine.create() );
+
+            String formattedString = record.toFormattedString( LdifFormatParameters.DEFAULT );
+            log( formattedString, ex, connection );
+        }
+        catch ( NamingException e )
+        {
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.IModificationLogger#logChangetypeDelete(java.lang.String, javax.naming.ldap.Control[], javax.naming.NamingException)
+     */
+    public void logChangetypeDelete( Connection connection, final String dn, final Control[] controls,
+        NamingException ex )
+    {
+        LdifChangeDeleteRecord record = LdifChangeDeleteRecord.create( dn );
+        //record.addControl( controlLine );
+        record.finish( LdifSepLine.create() );
+
+        String formattedString = record.toFormattedString( LdifFormatParameters.DEFAULT );
+        log( formattedString, ex, connection );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.IModificationLogger#logChangetypeModify(java.lang.String, javax.naming.directory.ModificationItem[], javax.naming.ldap.Control[], javax.naming.NamingException)
+     */
+    public void logChangetypeModify( Connection connection, final String dn,
+        final ModificationItem[] modificationItems, final Control[] controls, NamingException ex )
+    {
+        try
+        {
+            LdifChangeModifyRecord record = LdifChangeModifyRecord.create( dn );
+            //record.addControl( controlLine );
+            for ( ModificationItem item : modificationItems )
+            {
+                Attribute attribute = item.getAttribute();
+                String attributeDescription = attribute.getID();
+                LdifModSpec modSpec;
+                switch ( item.getModificationOp() )
+                {
+                    case DirContext.ADD_ATTRIBUTE:
+                        modSpec = LdifModSpec.createAdd( attributeDescription );
+                        break;
+                    case DirContext.REMOVE_ATTRIBUTE:
+                        modSpec = LdifModSpec.createDelete( attributeDescription );
+                        break;
+                    case DirContext.REPLACE_ATTRIBUTE:
+                        modSpec = LdifModSpec.createReplace( attributeDescription );
+                        break;
+                    default:
+                        continue;
+                }
+                NamingEnumeration<?> valueEnumeration = attribute.getAll();
+                while ( valueEnumeration.hasMore() )
+                {
+                    Object o = valueEnumeration.next();
+                    if ( o instanceof String )
+                    {
+                        modSpec.addAttrVal( LdifAttrValLine.create( attributeDescription, ( String ) o ) );
+                    }
+                    if ( o instanceof byte[] )
+                    {
+                        modSpec.addAttrVal( LdifAttrValLine.create( attributeDescription, ( byte[] ) o ) );
+                    }
+                }
+                modSpec.finish( LdifModSpecSepLine.create() );
+
+                record.addModSpec( modSpec );
+            }
+            record.finish( LdifSepLine.create() );
+
+            String formattedString = record.toFormattedString( LdifFormatParameters.DEFAULT );
+            log( formattedString, ex, connection );
+        }
+        catch ( NamingException e )
+        {
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.IModificationLogger#logChangetypeModDn(java.lang.String, java.lang.String, boolean, javax.naming.ldap.Control[], javax.naming.NamingException)
+     */
+    public void logChangetypeModDn( Connection connection, final String oldDn, final String newDn,
+        final boolean deleteOldRdn, final Control[] controls, NamingException ex )
+    {
+        try
+        {
+            LdapDN dn = new LdapDN( newDn );
+            Rdn newrdn = dn.getRdn();
+            LdapDN newsuperior = DnUtils.getParent( dn );
+
+            LdifChangeModDnRecord record = LdifChangeModDnRecord.create( oldDn );
+            //record.addControl( controlLine );
+            record.setNewrdn( LdifNewrdnLine.create( newrdn.getUpName() ) );
+            record.setDeloldrdn( deleteOldRdn ? LdifDeloldrdnLine.create1() : LdifDeloldrdnLine.create0() );
+            record.setNewsuperior( LdifNewsuperiorLine.create( newsuperior.getUpName() ) );
+            record.finish( LdifSepLine.create() );
+
+            String formattedString = record.toFormattedString( LdifFormatParameters.DEFAULT );
+            log( formattedString, ex, connection );
+        }
+        catch ( InvalidNameException e )
+        {
+        }
+    }
+
+
+    /**
+     * Gets the files.
+     * 
+     * @param connection the connection
+     * 
+     * @return the files
+     */
+    public File[] getFiles( Connection connection )
+    {
+        String id = connection.getId();
+        if ( !loggers.containsKey( id ) )
+        {
+            if ( connection.getName() != null )
+            {
+                initModificationLogger( connection );
+            }
+        }
+
+        try
+        {
+            return getLogFiles( fileHandlers.get( id ) );
+        }
+        catch ( Exception e )
+        {
+            return new File[0];
+        }
+    }
+
+
+    /**
+     * Gets the log files.
+     * 
+     * @param fileHandler the file handler
+     * 
+     * @return the log files
+     * 
+     * @throws Exception the exception
+     */
+    private static File[] getLogFiles( FileHandler fileHandler ) throws Exception
+    {
+        Field field = getFieldFromClass( "java.util.logging.FileHandler", "files" ); //$NON-NLS-1$ //$NON-NLS-2$
+        field.setAccessible( true );
+        File[] files = ( File[] ) field.get( fileHandler );
+        return files;
+    }
+
+
+    /**
+     * Gets the field from class.
+     * 
+     * @param className the class name
+     * @param fieldName the field name
+     * 
+     * @return the field from class
+     * 
+     * @throws Exception the exception
+     */
+    private static Field getFieldFromClass( String className, String fieldName ) throws Exception
+    {
+        Class<?> clazz = Class.forName( className );
+        Field[] fields = clazz.getDeclaredFields();
+
+        for ( int i = 0; i < fields.length; i++ )
+        {
+            if ( fields[i].getName().equals( fieldName ) )
+                return fields[i];
+        }
+        return null;
+    }
+
+
+    public String getId()
+    {
+        return id;
+    }
+
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,99 @@
+/*
+ *  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 javax.naming.LinkLoopException;
+import javax.naming.NamingException;
+
+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 in the list or if the URL was already processed
+     * a NamingException will be thrown
+     * 
+     * @param url the URL
+     * 
+     * @throws NamingException the naming exception
+     */
+    public void addReferralUrl( LdapURL url ) throws NamingException
+    {
+        if ( !referralsToProcess.contains( url ) && !processedReferrals.contains( url ) )
+        {
+            referralsToProcess.add( url );
+        }
+        else
+        {
+            throw new LinkLoopException( "Loop detected: " + url.toString() );
+        }
+    }
+
+
+    /**
+     * 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/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ReferralsInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java Mon Nov 26 11:44:28 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/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioNamingEnumeration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java (added)
+++ directory/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java Mon Nov 26 11:44:28 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/sandbox/felixk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/StudioSearchResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java (original)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java Mon Nov 26 11:44:28 2007
@@ -78,8 +78,16 @@
      */
     public String getMessage();
 
-    
+
+    /**
+     * Gets an info message that should be displayed
+     * to the user. Null means no info message so an 
+     * existing info message should be cleared.
+     * 
+     * @return the info message
+     */
     public String getInfoMessage();
+
 
     /**
      * Creates the composite.

Modified: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPageManager.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPageManager.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPageManager.java (original)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPageManager.java Mon Nov 26 11:44:28 2007
@@ -21,9 +21,7 @@
 package org.apache.directory.studio.connection.ui;
 
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;

Modified: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java (original)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java Mon Nov 26 11:44:28 2007
@@ -20,34 +20,53 @@
 
 package org.apache.directory.studio.connection.ui;
 
+
+/**
+ * Constants used in the connection UI plugin.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public interface ConnectionUIConstants
 {
 
+    /** The dialog setting key used for the history of host names. */
     public static final String DIALOGSETTING_KEY_HOST_HISTORY = "hostHistory";
 
+    /** The dialog setting key used for the history of ports. */
     public static final String DIALOGSETTING_KEY_PORT_HISTORY = "portHistory";
-    
+
+    /** The dialog setting key used for the history of principals (bind DNs). */
     public static final String DIALOGSETTING_KEY_PRINCIPAL_HISTORY = "principalHistory";
-    
+
+    /** The dialog setting key used for the history of SASL realms. */
     public static final String DIALOGSETTING_KEY_REALM_HISTORY = "saslrealmHistory";
 
-    
+    /** The image to add a connection. */
     public static final String IMG_CONNECTION_ADD = "resources/icons/connection_add.gif";
 
+    /** The image used to display the connected state of connections. */
     public static final String IMG_CONNECTION_CONNECTED = "resources/icons/connection_connected.gif";
 
+    /** The image used to display the disconnected state of connections. */
     public static final String IMG_CONNECTION_DISCONNECTED = "resources/icons/connection_disconnected.gif";
 
+    /** The image to connect connections. */
     public static final String IMG_CONNECTION_CONNECT = "resources/icons/connection_connect.gif";
 
+    /** The image to disconnect connections. */
     public static final String IMG_CONNECTION_DISCONNECT = "resources/icons/connection_disconnect.gif";
-    
+
+    /** The new connection wizard image */
     public static final String IMG_CONNECTION_WIZARD = "resources/icons/connection_wizard.gif";
-    
+
+    /** The pull-down image */
     public static final String IMG_PULLDOWN = "resources/icons/pulldown.gif";
-    
+
+    /** The image used for connection folders. */
     public static final String IMG_CONNECTION_FOLDER = "resources/icons/connection_folder.gif";
-    
+
+    /** The image to add a connection folder. */
     public static final String IMG_CONNECTION_FOLDER_ADD = "resources/icons/connection_folder.gif";
 
 }

Modified: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java (original)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java Mon Nov 26 11:44:28 2007
@@ -79,6 +79,7 @@
         }
 
         ConnectionCorePlugin.getDefault().setAuthHandler( new UIAuthHandler() );
+        ConnectionCorePlugin.getDefault().setReferralHandler( new ConnectionUIReferralHandler() );
     }
 
 

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,93 @@
+/*
+ *  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.ui;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+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;
+
+
+/**
+ * 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
+{
+
+    /** The referral URL to referral connection cache. */
+    private Map<LdapURL, Connection> referralUrlToReferralConnectionCache = new HashMap<LdapURL, Connection>();
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Connection getReferralConnection( final LdapURL referralUrl )
+    {
+        // check cache
+        if ( referralUrlToReferralConnectionCache.containsKey( referralUrl ) )
+        {
+            Connection referralConnection = referralUrlToReferralConnectionCache.get( referralUrl );
+            if ( referralConnection != null )
+            {
+                Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
+                for ( int i = 0; i < connections.length; i++ )
+                {
+                    Connection connection = connections[i];
+                    if ( referralConnection == connection )
+                    {
+                        return referralConnection;
+                    }
+                }
+            }
+        }
+
+        referralUrlToReferralConnectionCache.remove( referralUrl );
+
+        // open dialog
+        final Connection[] referralConnection = new Connection[1];
+        PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable()
+        {
+            public void run()
+            {
+                SelectReferralConnectionDialog dialog = new SelectReferralConnectionDialog( PlatformUI.getWorkbench()
+                    .getDisplay().getActiveShell(), referralUrl );
+                if ( dialog.open() == SelectReferralConnectionDialog.OK )
+                {
+                    Connection connection = dialog.getReferralConnection();
+                    referralUrlToReferralConnectionCache.put( referralUrl, connection );
+                    referralConnection[0] = connection;
+                }
+            }
+        } );
+
+        return referralConnection[0];
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIReferralHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java (original)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/UIAuthHandler.java Mon Nov 26 11:44:28 2007
@@ -29,9 +29,19 @@
 import org.eclipse.ui.PlatformUI;
 
 
+/**
+ * Default authentication handler that ask for the password using
+ * a UI dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class UIAuthHandler implements IAuthHandler
 {
 
+    /**
+     * {@inheritDoc}
+     */
     public ICredentials getCredentials( final ConnectionParameter connectionParameter )
     {
 

Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,236 @@
+/*
+ *  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.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.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+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 LdapURL referralUrl;
+
+    private Connection selectedConnection;
+
+    private ConnectionConfiguration configuration;
+
+    private ConnectionUniversalListener universalListener;
+
+    private ConnectionActionGroup actionGroup;
+
+    private ConnectionWidget mainWidget;
+
+
+    /**
+     * 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 );
+        this.title = "Select Referral Connection";
+        this.referralUrl = referralUrl;
+        this.selectedConnection = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( title );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean close()
+    {
+        if ( mainWidget != null )
+        {
+            configuration.dispose();
+            configuration = null;
+            actionGroup.deactivateGlobalActionHandlers();
+            actionGroup.dispose();
+            actionGroup = null;
+            universalListener.dispose();
+            universalListener = null;
+            mainWidget.dispose();
+            mainWidget = null;
+        }
+        return super.close();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void cancelPressed()
+    {
+        selectedConnection = null;
+        super.cancelPressed();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridLayout gl = new GridLayout();
+        composite.setLayout( gl );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
+        composite.setLayoutData( gd );
+
+        BaseWidgetUtils.createWrappedLabeledText( composite, "Please select a connection to handle referral "
+            + referralUrl, 1 );
+
+        // create configuration
+        configuration = new ConnectionConfiguration();
+
+        // create main widget
+        mainWidget = new ConnectionWidget( configuration, null );
+        mainWidget.createWidget( composite );
+        mainWidget.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager() );
+
+        // create actions and context menu (and register global actions)
+        actionGroup = new ConnectionActionGroup( mainWidget, configuration );
+        actionGroup.fillToolBar( mainWidget.getToolBarManager() );
+        actionGroup.fillMenu( mainWidget.getMenuManager() );
+        actionGroup.fillContextMenu( mainWidget.getContextMenuManager() );
+        actionGroup.activateGlobalActionHandlers();
+
+        // create the listener
+        universalListener = new ConnectionUniversalListener( mainWidget.getViewer() );
+
+        mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof Connection )
+                    {
+                        selectedConnection = ( Connection ) o;
+                    }
+                }
+            }
+        } );
+
+        mainWidget.getViewer().addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                if ( !event.getSelection().isEmpty() )
+                {
+                    Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( o instanceof Connection )
+                    {
+                        selectedConnection = ( Connection ) o;
+                    }
+                }
+            }
+        } );
+
+        if ( referralUrl != null )
+        {
+            Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
+            for ( int i = 0; i < connections.length; i++ )
+            {
+                Connection connection = connections[i];
+                LdapURL connectionUrl = connection.getUrl();
+                if ( connectionUrl != null && referralUrl.toString().startsWith( connectionUrl.toString() ) )
+                {
+                    mainWidget.getViewer().reveal( connection );
+                    mainWidget.getViewer().setSelection( new StructuredSelection( connection ), true );
+                }
+            }
+        }
+
+        applyDialogFont( composite );
+
+        mainWidget.setFocus();
+
+        return composite;
+    }
+
+
+    /**
+     * Gets the referral connection.
+     * 
+     * @return the referral connection
+     */
+    public Connection getReferralConnection()
+    {
+        return selectedConnection;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java Mon Nov 26 11:44:28 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/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java Mon Nov 26 11:44:28 2007
@@ -32,9 +32,9 @@
 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.IValue;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldifparser.model.LdifFile;
+import org.apache.directory.studio.ldifparser.model.LdifPart;
+import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.ISelection;