You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/08/23 15:15:45 UTC

svn commit: r568964 [2/3] - in /directory/studio/trunk/studio-connection-core: ./ META-INF/ lib/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ s...

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,385 @@
+/*
+ *  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 java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.ProgressMonitorWrapper;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+
+/**
+ * The StudioProgressMonitor extends the the Eclipse
+ * Progress Monitor with active cancellation capabilities.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class StudioProgressMonitor extends ProgressMonitorWrapper
+{
+
+    private boolean done;
+
+    private List<Status> errorStatusList;
+
+    private List<CancelListener> cancelListenerList;
+
+    private Job checkCanceledJob;
+
+    private Job reportProgressJob = null;
+
+    private String reportProgressMessage = null;
+
+
+    /**
+     * Creates a new instance of ExtendedProgressMonitor.
+     * 
+     * @param monitor the progress monitor to forward to
+     */
+    public StudioProgressMonitor( IProgressMonitor monitor )
+    {
+        super( monitor );
+        this.done = false;
+
+        this.checkCanceledJob = new Job( Messages.jobs__progressmonitor_check_cancellation )
+        {
+            protected IStatus run( IProgressMonitor monitor )
+            {
+                while ( !done )
+                {
+                    if ( isCanceled() )
+                    {
+                        fireCancelRequested();
+                        break;
+                    }
+                    else
+                    {
+                        try
+                        {
+                            Thread.sleep( 1000 );
+                        }
+                        catch ( InterruptedException e )
+                        {
+                        }
+                    }
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        this.checkCanceledJob.setSystem( true );
+        this.checkCanceledJob.schedule();
+    }
+
+
+    /**
+     * @see org.eclipse.core.runtime.ProgressMonitorWrapper#setCanceled(boolean)
+     */
+    public void setCanceled( boolean b )
+    {
+        super.setCanceled( b );
+        if ( b )
+        {
+            fireCancelRequested();
+        }
+    }
+
+
+    /**
+     * @see org.eclipse.core.runtime.ProgressMonitorWrapper#done()
+     */
+    public void done()
+    {
+        synchronized ( this )
+        {
+            done = true;
+            super.done();
+        }
+    }
+
+
+    /**
+     * Adds the cancel listener.
+     * 
+     * @param listener the listener
+     */
+    public void addCancelListener( CancelListener listener )
+    {
+        if ( cancelListenerList == null )
+        {
+            cancelListenerList = new ArrayList<CancelListener>();
+        }
+        if ( !cancelListenerList.contains( listener ) )
+        {
+            cancelListenerList.add( listener );
+        }
+    }
+
+
+    /**
+     * Removes the cancel listener.
+     * 
+     * @param listener the listener
+     */
+    public void removeCancelListener( CancelListener listener )
+    {
+        if ( cancelListenerList != null && cancelListenerList.contains( listener ) )
+        {
+            cancelListenerList.remove( listener );
+        }
+    }
+
+
+    private void fireCancelRequested()
+    {
+        CancelEvent event = new CancelEvent( this );
+        if ( cancelListenerList != null )
+        {
+            for ( int i = 0; i < cancelListenerList.size(); i++ )
+            {
+                CancelListener listener = cancelListenerList.get( i );
+                listener.cancelRequested( event );
+            }
+        }
+    }
+
+
+    /**
+     * Report progress.
+     * 
+     * @param message the message
+     */
+    public void reportProgress( String message )
+    {
+        synchronized ( this )
+        {
+            if ( !done )
+            {
+                if ( reportProgressJob == null )
+                {
+                    reportProgressJob = new Job( Messages.jobs__progressmonitor_report_progress )
+                    {
+                        protected IStatus run( IProgressMonitor monitor )
+                        {
+                            synchronized ( StudioProgressMonitor.this )
+                            {
+                                if ( !done )
+                                {
+                                    subTask( reportProgressMessage );
+                                }
+                                return Status.OK_STATUS;
+                            }
+                        }
+                    };
+                    reportProgressJob.setSystem( true );
+                }
+
+                reportProgressMessage = message;
+                reportProgressJob.schedule( 1000 );
+            }
+        }
+    }
+
+
+    /**
+     * Report error.
+     * 
+     * @param message the message
+     */
+    public void reportError( String message )
+    {
+        this.reportError( message, null );
+    }
+
+
+    /**
+     * Report error.
+     * 
+     * @param throwable the throwable
+     */
+    public void reportError( Throwable throwable )
+    {
+        reportError( throwable.getMessage() != null ? throwable.getMessage() : throwable.toString(), throwable );
+    }
+
+
+    /**
+     * Report error.
+     * 
+     * @param exception the exception
+     * @param message the message
+     */
+    public void reportError( String message, Throwable exception )
+    {
+        if ( errorStatusList == null )
+        {
+            errorStatusList = new ArrayList<Status>( 3 );
+        }
+
+        do
+        {
+            if ( message == null )
+            {
+                message = ""; //$NON-NLS-1$
+            }
+
+            Status errorStatus = new Status( IStatus.ERROR, ConnectionCorePlugin.PLUGIN_ID, IStatus.ERROR, message,
+                exception );
+            errorStatusList.add( errorStatus );
+
+            if ( exception != null )
+            {
+                exception = exception.getCause();
+            }
+            if ( exception != null )
+            {
+                message = exception.getMessage();
+            }
+        }
+        while ( exception != null );
+    }
+
+
+    /**
+     * Errors reported.
+     * 
+     * @return true, if errors reported
+     */
+    public boolean errorsReported()
+    {
+        return errorStatusList != null;
+    }
+
+
+    /**
+     * Gets the error status.
+     * 
+     * @param message the message
+     * 
+     * @return the error status
+     */
+    public IStatus getErrorStatus( String message )
+    {
+        if ( errorStatusList != null && !errorStatusList.isEmpty() )
+        {
+            Throwable exception = null;
+            for ( Iterator<Status> it = errorStatusList.iterator(); it.hasNext(); )
+            {
+                Status status = it.next();
+                if ( status.getException() != null )
+                {
+                    exception = status.getException();
+                    break;
+                }
+            }
+
+            MultiStatus multiStatus = new MultiStatus( ConnectionCorePlugin.PLUGIN_ID, IStatus.ERROR, message,
+                exception );
+
+            for ( Iterator<Status> it = errorStatusList.iterator(); it.hasNext(); )
+            {
+                Status status = it.next();
+                multiStatus.add( new Status( status.getSeverity(), status.getPlugin(), status.getCode(), status
+                    .getMessage(), null ) );
+            }
+
+            return multiStatus;
+
+        }
+        else
+        {
+            return Status.OK_STATUS;
+        }
+    }
+
+
+    /**
+     * Gets the exception.
+     * 
+     * @return the exception
+     */
+    public Throwable getException()
+    {
+
+        if ( errorStatusList != null )
+        {
+            return errorStatusList.get( 0 ).getException();
+        }
+        return null;
+    }
+
+    /**
+     * CancelEvent.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public static class CancelEvent
+    {
+        private IProgressMonitor monitor;
+
+
+        /**
+         * Creates a new instance of CancelEvent.
+         * 
+         * @param monitor the progress monitor
+         */
+        public CancelEvent( IProgressMonitor monitor )
+        {
+            this.monitor = monitor;
+        }
+
+
+        /**
+         * Gets the monitor.
+         * 
+         * @return the progress monitor
+         */
+        public IProgressMonitor getMonitor()
+        {
+            return monitor;
+        }
+    }
+
+    /**
+     * CancelListener.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public interface CancelListener
+    {
+
+        /**
+         * Cancel requested.
+         * 
+         * @param event the event
+         */
+        public void cancelRequested( CancelEvent event );
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/Utils.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,69 @@
+/*
+ *  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;
+
+
+/**
+ * Some utils.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class Utils
+{
+
+    /**
+     * Shortens the given label to the given maximum length.
+     * 
+     * @param label the label
+     * @param maxLength the max length
+     * 
+     * @return the shortened label
+     */
+    public static String shorten( String label, int maxLength )
+    {
+        if ( label == null )
+        {
+            return null;
+        }
+        if ( maxLength < 3 )
+        {
+            return "...";
+        }
+        if ( label.length() > maxLength )
+        {
+            label = label.substring( 0, maxLength / 2 ) + "..."
+                + label.substring( label.length() - maxLength / 2, label.length() );
+
+        }
+        StringBuffer sb = new StringBuffer( maxLength + 3 );
+        for ( int i = 0; i < label.length(); i++ )
+        {
+            char c = label.charAt( i );
+            if ( c > 31 && c < 127 )
+                sb.append( c );
+            else
+                sb.append( '.' );
+        }
+        return sb.toString();
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,336 @@
+/*
+ *  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.event;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.directory.studio.connection.core.Connection;
+
+
+/**
+ * The ConnectionEventRegistry is a central point to register for connection specific
+ * events and to fire events to registered listeners.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionEventRegistry
+{
+
+    /** The list of threads with suspended event fireing. */
+    private static Set<Thread> suspendedEventFireringThreads = new HashSet<Thread>();;
+
+    /** The lock used to synchronize event fireings */
+    private static Object lock = new Object();
+
+
+    /**
+     * Checks if event fireing is suspended in the current thread.
+     *
+     * @return true, if event fireing is suspended in the current thread
+     */
+    public static boolean isEventFireingSuspendedInCurrentThread()
+    {
+        return suspendedEventFireringThreads.contains( Thread.currentThread() );
+    }
+
+
+    /**
+     * Resumes event fireing in the current thread.
+     */
+    public static void resumeEventFireingInCurrentThread()
+    {
+        suspendedEventFireringThreads.remove( Thread.currentThread() );
+    }
+
+
+    /**
+     * Suspends event fireing in the current thread.
+     */
+    public static void suspendEventFireingInCurrentThread()
+    {
+        suspendedEventFireringThreads.add( Thread.currentThread() );
+    }
+
+    /** The map with connection update listeners and their runners */
+    private static Map<ConnectionUpdateListener, EventRunner> connectionUpdateListeners = new HashMap<ConnectionUpdateListener, EventRunner>();
+
+
+    /**
+     * Adds the connection update listener.
+     *
+     * @param listener the listener
+     * @param runner the runner
+     */
+    public static void addConnectionUpdateListener( ConnectionUpdateListener listener, EventRunner runner )
+    {
+        assert listener != null;
+        assert runner != null;
+
+        if ( !connectionUpdateListeners.containsKey( listener ) )
+        {
+            connectionUpdateListeners.put( listener, runner );
+        }
+    }
+
+
+    /**
+     * Removes the connection update listener.
+     *
+     * @param listener the listener
+     */
+    public static void removeConnectionUpdateListener( ConnectionUpdateListener listener )
+    {
+        if ( connectionUpdateListeners.containsKey( listener ) )
+        {
+            connectionUpdateListeners.remove( listener );
+        }
+    }
+
+
+    /**
+     * Notifies each {@link ConnectionUpdateListener} about the opened connection.
+     * Uses the {@link EventRunner}s.
+     *
+     * @param connection the opened connection
+     * @param source the source
+     */
+    public static void fireConnectionOpened( final Connection connection, final Object source )
+    {
+        if ( isEventFireingSuspendedInCurrentThread() )
+        {
+            return;
+        }
+
+        Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+            connectionUpdateListeners );
+        Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+        while ( it.hasNext() )
+        {
+            final ConnectionUpdateListener listener = it.next();
+            EventRunnable runnable = new EventRunnable()
+            {
+                public void run()
+                {
+                    listener.connectionOpened( connection );
+                }
+            };
+
+            EventRunner runner = listeners.get( listener );
+            synchronized ( lock )
+            {
+                runner.execute( runnable );
+            }
+        }
+    }
+
+
+    /**
+     * Notifies each {@link ConnectionUpdateListener} about the closed connection.
+     * Uses the {@link EventRunner}s.
+     *
+     * @param connection the closed connection
+     * @param source the source
+     */
+    public static void fireConnectionClosed( final Connection connection, final Object source )
+    {
+        if ( isEventFireingSuspendedInCurrentThread() )
+        {
+            return;
+        }
+
+        Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+            connectionUpdateListeners );
+        Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+        while ( it.hasNext() )
+        {
+            final ConnectionUpdateListener listener = it.next();
+            EventRunnable runnable = new EventRunnable()
+            {
+                public void run()
+                {
+                    listener.connectionClosed( connection );
+                }
+            };
+
+            EventRunner runner = listeners.get( listener );
+            synchronized ( lock )
+            {
+                runner.execute( runnable );
+            }
+        }
+    }
+
+
+    /**
+     * Notifies each {@link ConnectionUpdateListener} about the updated connection.
+     * Uses the {@link EventRunner}s.
+     *
+     * @param connection the updated connection
+     * @param source the source
+     */
+    public static void fireConnectionUpdated( final Connection connection, final Object source )
+    {
+        if ( isEventFireingSuspendedInCurrentThread() )
+        {
+            return;
+        }
+
+        Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+            connectionUpdateListeners );
+        Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+        while ( it.hasNext() )
+        {
+            final ConnectionUpdateListener listener = it.next();
+            EventRunnable runnable = new EventRunnable()
+            {
+                public void run()
+                {
+                    listener.connectionUpdated( connection );
+                }
+            };
+
+            EventRunner runner = listeners.get( listener );
+            synchronized ( lock )
+            {
+                runner.execute( runnable );
+            }
+        }
+    }
+
+
+    /**
+     * Notifies each {@link ConnectionUpdateListener} about the renamed connection.
+     * Uses the {@link EventRunner}s.
+     *
+     * @param connection the renamed connection
+     * @param oldName the old name
+     * @param source the source
+     */
+    public static void fireConnectionRenamed( final Connection connection, final String oldName, final Object source )
+    {
+        if ( isEventFireingSuspendedInCurrentThread() )
+        {
+            return;
+        }
+
+        Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+            connectionUpdateListeners );
+        Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+        while ( it.hasNext() )
+        {
+            final ConnectionUpdateListener listener = it.next();
+            EventRunnable runnable = new EventRunnable()
+            {
+                public void run()
+                {
+                    listener.connectionRenamed( connection, oldName );
+                }
+            };
+
+            EventRunner runner = listeners.get( listener );
+            synchronized ( lock )
+            {
+                runner.execute( runnable );
+            }
+        }
+    }
+
+
+    /**
+     * Notifies each {@link ConnectionUpdateListener} about the added connection.
+     * Uses the {@link EventRunner}s.
+     *
+     * @param connection the added connection
+     * @param source the source
+     */
+    public static void fireConnectionAdded( final Connection connection, final Object source )
+    {
+        if ( isEventFireingSuspendedInCurrentThread() )
+        {
+            return;
+        }
+
+        Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+            connectionUpdateListeners );
+        Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+        while ( it.hasNext() )
+        {
+            final ConnectionUpdateListener listener = it.next();
+            EventRunnable runnable = new EventRunnable()
+            {
+                public void run()
+                {
+                    listener.connectionAdded( connection );
+                }
+            };
+
+            EventRunner runner = listeners.get( listener );
+            synchronized ( lock )
+            {
+                runner.execute( runnable );
+            }
+        }
+    }
+
+
+    /**
+     * Notifies each {@link ConnectionUpdateListener} about the removed connection.
+     * Uses the {@link EventRunner}s.
+     *
+     * @param connection the removed connection
+     * @param source the source
+     */
+    public static void fireConnectionRemoved( final Connection connection, final Object source )
+    {
+        if ( isEventFireingSuspendedInCurrentThread() )
+        {
+            return;
+        }
+
+        Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+            connectionUpdateListeners );
+        Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+        while ( it.hasNext() )
+        {
+            final ConnectionUpdateListener listener = it.next();
+            EventRunnable runnable = new EventRunnable()
+            {
+                public void run()
+                {
+                    listener.connectionRemoved( connection );
+                }
+            };
+
+            EventRunner runner = listeners.get( listener );
+            synchronized ( lock )
+            {
+                runner.execute( runnable );
+            }
+        }
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,86 @@
+/*
+ *  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.event;
+
+
+import java.util.EventListener;
+
+import org.apache.directory.studio.connection.core.Connection;
+
+
+/**
+ * A listener for connection updates
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface ConnectionUpdateListener extends EventListener
+{
+
+    /**
+     * Called when an {@link Connection} was opened.
+     *
+     * @param connection the opened connection 
+     */
+    public void connectionOpened( Connection connection );
+
+
+    /**
+     * Called when an {@link Connection} was closed.
+     *
+     * @param connection the closed connection 
+     */
+    public void connectionClosed( Connection connection );
+
+
+    /**
+     * Called when an {@link Connection} was added.
+     *
+     * @param connection the added connection 
+     */
+    public void connectionAdded( Connection connection );
+
+
+    /**
+     * Called when an {@link Connection} was removed.
+     *
+     * @param connection the removed connection 
+     */
+    public void connectionRemoved( Connection connection );
+
+
+    /**
+     * Called when an {@link Connection} was renamed.
+     *
+     * @param connection the renamed connection 
+     * @param oldName the old connection name
+     */
+    public void connectionRenamed( Connection connection, String oldName );
+
+
+    /**
+     * Called when {@link Connection} parameters were updated.
+     *
+     * @param connection the updated connection 
+     */
+    public void connectionUpdated( Connection connection );
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/CoreEventRunner.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/CoreEventRunner.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/CoreEventRunner.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/CoreEventRunner.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,25 @@
+package org.apache.directory.studio.connection.core.event;
+
+
+/**
+ * Default implementation of {@link EventRunner} that executes an {@link EventRunnable}
+ * withing the current thread.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CoreEventRunner implements EventRunner
+{
+
+    /**
+     * {@inheritDoc}
+     *
+     * This implementation executes the given {@link EventRunnable} within
+     * the current thread.
+     */
+    public void execute( EventRunnable runnable )
+    {
+        runnable.run();
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunnable.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunnable.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunnable.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,35 @@
+/*
+ *  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.event;
+
+
+/**
+ * The <code>EventRunnable</code> interface should be implemented by any
+ * class whose instances are intended to be executed by an {@link EventRunner}.
+ * The class must define a method of no arguments called <code>run</code>.
+ * <p>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface EventRunnable extends Runnable
+{
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunner.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunner.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunner.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/EventRunner.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,20 @@
+package org.apache.directory.studio.connection.core.event;
+
+
+/**
+ * An EventRunner is used to execute an {@link EventRunnable}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface EventRunner
+{
+
+    /**
+     * Executes the given {@link EventRunnable}.
+     *
+     * @param runnable the event runnable to run
+     */
+    public void execute( EventRunnable runnable );
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,51 @@
+package org.apache.directory.studio.connection.core.io;
+
+
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+
+
+/**
+ * A ConnectionWrapper is a wrapper for a real directory connection implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface ConnectionWrapper
+{
+
+    /**
+     * Connects to the directory server.
+     * 
+     * @param monitor the progres monitor
+     */
+    public void connect( StudioProgressMonitor monitor );
+
+
+    /**
+     * Disconnects from the directory server.
+     */
+    public void disconnect();
+
+
+    /**
+     * Binds to the directory server.
+     * 
+     * @param monitor the progress monitor
+     */
+    public void bind( StudioProgressMonitor monitor );
+
+
+    /**
+     * Unbinds from the directory server.
+     */
+    public void unbind();
+
+
+    /**
+     * Checks if is connected.
+     * 
+     * @return true, if is connected
+     */
+    public boolean isConnected();
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/CancelException.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/CancelException.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/CancelException.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/CancelException.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,58 @@
+/*
+ *  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.NamingException;
+
+
+/**
+ * A specific {@link NamingException} that represents the cancellation of an request.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CancelException extends NamingException
+{
+
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     * Creates a new instance of CancelException.
+     */
+    public CancelException()
+    {
+        super();
+    }
+
+
+    /**
+     * Creates a new instance of CancelException.
+     *
+     * @param message the message
+     */
+    public CancelException( String message )
+    {
+        super( message );
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/DummySSLSocketFactory.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/DummySSLSocketFactory.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/DummySSLSocketFactory.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/DummySSLSocketFactory.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,192 @@
+/*
+ *  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.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+
+/**
+ * A SSLSocketFactory that accepts every certificat without validation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DummySSLSocketFactory extends SSLSocketFactory
+{
+
+    /** The delegate. */
+    private SSLSocketFactory delegate;
+
+
+    /**
+     * Creates a new instance of DummySSLSocketFactory.
+     */
+    public DummySSLSocketFactory()
+    {
+        try
+        {
+            TrustManager tm = new X509TrustManager()
+            {
+                public X509Certificate[] getAcceptedIssuers()
+                {
+                    return new X509Certificate[0];
+                }
+
+
+                public void checkClientTrusted( X509Certificate[] arg0, String arg1 ) throws CertificateException
+                {
+                }
+
+
+                public void checkServerTrusted( X509Certificate[] arg0, String arg1 ) throws CertificateException
+                {
+                }
+            };
+            TrustManager[] tma =
+                { tm };
+            SSLContext sc = SSLContext.getInstance( "TLS" ); //$NON-NLS-1$
+            sc.init( null, tma, new SecureRandom() );
+            delegate = sc.getSocketFactory();
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
+     */
+    public String[] getDefaultCipherSuites()
+    {
+        return delegate.getDefaultCipherSuites();
+    }
+
+
+    /**
+     * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
+     */
+    public String[] getSupportedCipherSuites()
+    {
+        return delegate.getSupportedCipherSuites();
+    }
+
+
+    /**
+     * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean)
+     */
+    public Socket createSocket( Socket arg0, String arg1, int arg2, boolean arg3 ) throws IOException
+    {
+        try
+        {
+            return delegate.createSocket( arg0, arg1, arg2, arg3 );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
+     */
+    public Socket createSocket( String arg0, int arg1 ) throws IOException, UnknownHostException
+    {
+        try
+        {
+            return delegate.createSocket( arg0, arg1 );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
+     */
+    public Socket createSocket( InetAddress arg0, int arg1 ) throws IOException
+    {
+        try
+        {
+            return delegate.createSocket( arg0, arg1 );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * @see javax.net.SocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int)
+     */
+    public Socket createSocket( String arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException,
+        UnknownHostException
+    {
+        try
+        {
+            return delegate.createSocket( arg0, arg1, arg2, arg3 );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int, java.net.InetAddress, int)
+     */
+    public Socket createSocket( InetAddress arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException
+    {
+        try
+        {
+            return delegate.createSocket( arg0, arg1, arg2, arg3 );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+}

Added: 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=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,869 @@
+package org.apache.directory.studio.connection.core.io.jndi;
+
+
+import java.util.Hashtable;
+
+import javax.naming.CommunicationException;
+import javax.naming.Context;
+import javax.naming.InsufficientResourcesException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.ServiceUnavailableException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.StartTlsRequest;
+import javax.naming.ldap.StartTlsResponse;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSession;
+
+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.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.IAuthHandler;
+import org.apache.directory.studio.connection.core.ICredentials;
+import org.apache.directory.studio.connection.core.Messages;
+import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
+
+
+/**
+ * A connection wrapper that uses JNDI.
+ * 
+ * - asychron + cancelable
+ * - SSL certificate
+ * - manages broken/closed connections
+ * - delete old RDN
+ * - exception handling 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JNDIConnectionWrapper implements ConnectionWrapper
+{
+    private Connection connection;
+
+    private boolean useLdaps;
+
+    private boolean useStartTLS;
+
+    private String authMethod;
+
+    private String bindPrincipal;
+
+    private String bindCredentials;
+
+    private Hashtable<String, String> environment;
+
+    private InitialLdapContext context;
+
+    private boolean isConnected;
+
+    private Thread jobThread;
+
+
+    /**
+     * Creates a new instance of JNDIConnectionContext.
+     * 
+     * @param connection the connection
+     */
+    public JNDIConnectionWrapper( Connection connection )
+    {
+        this.connection = connection;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.io.ConnectionWrapper#connect(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    public void connect( StudioProgressMonitor monitor )
+    {
+        String host = connection.getConnectionParameter().getHost();
+        int port = connection.getConnectionParameter().getPort();
+
+        useLdaps = connection.getConnectionParameter().getEncryptionMethod() == ConnectionParameter.EncryptionMethod.LDAPS;
+        useStartTLS = connection.getConnectionParameter().getEncryptionMethod() == ConnectionParameter.EncryptionMethod.START_TLS;
+
+        environment = new Hashtable<String, String>();
+        environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); //$NON-NLS-1$
+        environment.put( "java.naming.ldap.version", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        // timeouts
+        if ( !useLdaps )
+        {
+            environment.put( "com.sun.jndi.ldap.connect.timeout", "10000" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        environment.put( "com.sun.jndi.dns.timeout.initial", "2000" ); //$NON-NLS-1$ //$NON-NLS-2$
+        environment.put( "com.sun.jndi.dns.timeout.retries", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        // ldaps://
+        if ( useLdaps )
+        {
+            environment.put( Context.PROVIDER_URL, "ldaps://" + host + ":" + port ); //$NON-NLS-1$ //$NON-NLS-2$
+            environment.put( Context.SECURITY_PROTOCOL, "ssl" ); //$NON-NLS-1$
+            environment.put( "java.naming.ldap.factory.socket", DummySSLSocketFactory.class.getName() ); //$NON-NLS-1$
+        }
+        else
+        {
+            environment.put( Context.PROVIDER_URL, "ldap://" + host + ":" + port ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        context = null;
+        isConnected = false;
+        jobThread = null;
+
+        try
+        {
+            doConnect( monitor );
+        }
+        catch ( NamingException ne )
+        {
+            disconnect();
+            monitor.reportError( ne.getMessage(), ne );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.io.ConnectionWrapper#disconnect()
+     */
+    public void disconnect()
+    {
+        if ( jobThread != null )
+        {
+            Thread t = jobThread;
+            jobThread = null;
+            t.interrupt();
+        }
+        if ( context != null )
+        {
+            try
+            {
+                context.close();
+            }
+            catch ( NamingException e )
+            {
+                // ignore
+            }
+            context = null;
+        }
+        isConnected = false;
+        System.gc();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.io.ConnectionWrapper#bind(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    public void bind( StudioProgressMonitor monitor )
+    {
+        authMethod = "none";
+        if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SIMPLE )
+        {
+            authMethod = "simple";
+        }
+        else if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SASL_DIGEST_MD5 )
+        {
+            authMethod = "DIGEST-MD5";
+        }
+        else if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SASL_CRAM_MD5 )
+        {
+            authMethod = "CRAM-MD5";
+        }
+
+        IAuthHandler authHandler = ConnectionCorePlugin.getDefault().getAuthHandler();
+        if ( authHandler == null )
+        {
+            monitor.reportError( Messages.model__no_auth_handler, new Exception() );
+        }
+
+        ICredentials credentials = authHandler.getCredentials( connection.getConnectionParameter() );
+        if ( credentials == null )
+        {
+            monitor.reportError( Messages.model__no_credentials, new Exception() );
+        }
+
+        bindPrincipal = credentials.getBindPrincipal();
+        bindCredentials = credentials.getBindPassword();
+
+        try
+        {
+            doBind( monitor );
+        }
+        catch ( NamingException ne )
+        {
+            disconnect();
+            monitor.reportError( ne.getMessage(), ne );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.io.ConnectionWrapper#unbind()
+     */
+    public void unbind()
+    {
+        disconnect();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.io.ConnectionWrapper#isConnected()
+     */
+    public boolean isConnected()
+    {
+        return context != null;
+    }
+
+
+    /**
+     * Search.
+     * 
+     * @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 monitor the progress monitor
+     * 
+     * @return the naming enumeration or null if an exception occurs.
+     */
+    public NamingEnumeration search( final String searchBase, final String filter, final SearchControls searchControls,
+        final String derefAliasMethod, final String handleReferralsMethod, final Control[] controls,
+        final StudioProgressMonitor monitor )
+    {
+        // start
+        InnerRunnable runnable = new InnerRunnable()
+        {
+            private NamingEnumeration namingEnumeration = null;
+            private NamingException namingException = null;
+
+
+            public void run()
+            {
+                try
+                {
+                    LdapContext searchCtx = context.newInstance( controls );
+                    try
+                    {
+                        searchCtx.addToEnvironment( "java.naming.ldap.derefAliases", derefAliasMethod ); //$NON-NLS-1$
+                        searchCtx.addToEnvironment( Context.REFERRAL, handleReferralsMethod );
+
+                    }
+                    catch ( NamingException e )
+                    {
+                        namingException = e;
+                    }
+
+                    try
+                    {
+                        namingEnumeration = searchCtx.search( new LdapName( searchBase ), filter, searchControls );
+                    }
+                    catch ( NamingException ne )
+                    {
+                        namingException = ne;
+                    }
+
+                }
+                catch ( NamingException e )
+                {
+                    namingException = e;
+                }
+            }
+
+
+            public NamingException getException()
+            {
+                return namingException;
+            }
+
+
+            public Object getResult()
+            {
+                return namingEnumeration;
+            }
+
+
+            public void reset()
+            {
+                namingEnumeration = null;
+                namingException = null;
+            }
+
+        };
+
+        try
+        {
+            checkConnectionAndRunAndMonitor( runnable, monitor );
+        }
+        catch ( NamingException ne )
+        {
+            monitor.reportError( ne.getMessage(), ne );
+            return null;
+        }
+
+        if ( runnable.getException() != null )
+        {
+            monitor.reportError( runnable.getException().getMessage(), runnable.getException() );
+            return null;
+        }
+        else if ( runnable.getResult() != null && runnable.getResult() instanceof NamingEnumeration )
+        {
+            return ( NamingEnumeration ) runnable.getResult();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Modify attributes.
+     * 
+     * @param dn the dn
+     * @param modificationItems the modification items
+     * @param controls the controls
+     * @param monitor the progress monitor
+     */
+    public void modifyAttributes( final String dn, final ModificationItem[] modificationItems,
+        final Control[] controls, final StudioProgressMonitor monitor )
+    {
+        InnerRunnable runnable = new InnerRunnable()
+        {
+            private NamingException namingException = null;
+
+
+            public void run()
+            {
+                try
+                {
+                    LdapContext modCtx = context.newInstance( controls );
+                    modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+
+                    modCtx.modifyAttributes( new LdapName( dn ), modificationItems );
+                }
+                catch ( NamingException ne )
+                {
+                    namingException = ne;
+                }
+            }
+
+
+            public NamingException getException()
+            {
+                return namingException;
+            }
+
+
+            public Object getResult()
+            {
+                return null;
+            }
+
+
+            public void reset()
+            {
+                namingException = null;
+            }
+        };
+
+        try
+        {
+            checkConnectionAndRunAndMonitor( runnable, monitor );
+        }
+        catch ( NamingException ne )
+        {
+            monitor.reportError( ne.getMessage(), ne );
+        }
+
+        if ( runnable.getException() != null )
+        {
+            monitor.reportError( runnable.getException().getMessage(), runnable.getException() );
+        }
+    }
+
+
+    /**
+     * Renames an entry.
+     * 
+     * @param oldDn the old dn
+     * @param newDn the new dn
+     * @param deleteOldRdn the delete old rdn flag
+     * @param controls the controls
+     * @param monitor the monitor
+     */
+    public void rename( final String oldDn, final String newDn, final boolean deleteOldRdn, final Control[] controls,
+        final StudioProgressMonitor monitor )
+    {
+        InnerRunnable runnable = new InnerRunnable()
+        {
+            private NamingException namingException = null;
+
+
+            // TODO: delteOldRdn
+
+            public void run()
+            {
+                try
+                {
+                    LdapContext modCtx = context.newInstance( controls );
+                    modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+                    modCtx.rename( new LdapName( oldDn ), new LdapName( newDn ) );
+                }
+                catch ( NamingException ne )
+                {
+                    namingException = ne;
+                }
+            }
+
+
+            public NamingException getException()
+            {
+                return namingException;
+            }
+
+
+            public Object getResult()
+            {
+                return null;
+            }
+
+
+            public void reset()
+            {
+                namingException = null;
+            }
+        };
+
+        try
+        {
+            checkConnectionAndRunAndMonitor( runnable, monitor );
+        }
+        catch ( NamingException ne )
+        {
+            monitor.reportError( ne.getMessage(), ne );
+        }
+
+        if ( runnable.getException() != null )
+        {
+            monitor.reportError( runnable.getException().getMessage(), runnable.getException() );
+        }
+    }
+
+
+    /**
+     * Creates an entry.
+     * 
+     * @param dn the dn
+     * @param attributes the attributes
+     * @param controls the controls
+     * @param monitor the monitor
+     */
+    public void createEntry( final String dn, final Attributes attributes, final Control[] controls,
+        final StudioProgressMonitor monitor )
+    {
+        InnerRunnable runnable = new InnerRunnable()
+        {
+            private NamingException namingException = null;
+
+
+            public void run()
+            {
+                try
+                {
+                    LdapContext modCtx = context.newInstance( controls );
+                    modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+                    modCtx.createSubcontext( new LdapName( dn ), attributes );
+                }
+                catch ( NamingException ne )
+                {
+                    namingException = ne;
+                }
+            }
+
+
+            public NamingException getException()
+            {
+                return namingException;
+            }
+
+
+            public Object getResult()
+            {
+                return null;
+            }
+
+
+            public void reset()
+            {
+                namingException = null;
+            }
+        };
+
+        try
+        {
+            checkConnectionAndRunAndMonitor( runnable, monitor );
+        }
+        catch ( NamingException ne )
+        {
+            monitor.reportError( ne.getMessage(), ne );
+        }
+
+        if ( runnable.getException() != null )
+        {
+            monitor.reportError( runnable.getException().getMessage(), runnable.getException() );
+        }
+    }
+
+
+    /**
+     * Deletes an entry.
+     * 
+     * @param dn the dn
+     * @param controls the controls
+     * @param monitor the monitor
+     */
+    public void deleteEntry( final String dn, final Control[] controls, final StudioProgressMonitor monitor )
+    {
+        InnerRunnable runnable = new InnerRunnable()
+        {
+            private NamingException namingException = null;
+
+
+            public void run()
+            {
+                try
+                {
+                    LdapContext modCtx = context.newInstance( controls );
+                    modCtx.addToEnvironment( Context.REFERRAL, "throw" ); //$NON-NLS-1$
+
+                    modCtx.destroySubcontext( new LdapName( dn ) );
+                }
+                catch ( NamingException ne )
+                {
+                    namingException = ne;
+                }
+            }
+
+
+            public NamingException getException()
+            {
+                return namingException;
+            }
+
+
+            public Object getResult()
+            {
+                return null;
+            }
+
+
+            public void reset()
+            {
+                namingException = null;
+            }
+        };
+
+        try
+        {
+            checkConnectionAndRunAndMonitor( runnable, monitor );
+        }
+        catch ( NamingException ne )
+        {
+            monitor.reportError( ne.getMessage(), ne );
+        }
+
+        if ( runnable.getException() != null )
+        {
+            monitor.reportError( runnable.getException().getMessage(), runnable.getException() );
+        }
+    }
+
+
+    private void doConnect( final StudioProgressMonitor monitor ) throws NamingException
+    {
+        context = null;
+        isConnected = true;
+
+        InnerRunnable runnable = new InnerRunnable()
+        {
+            private NamingException namingException = null;
+
+
+            public void run()
+            {
+                try
+                {
+                    context = new InitialLdapContext( environment, null );
+
+                    if ( useStartTLS )
+                    {
+                        try
+                        {
+                            StartTlsResponse tls = ( StartTlsResponse ) context
+                                .extendedOperation( new StartTlsRequest() );
+                            tls.setHostnameVerifier( new HostnameVerifier()
+                            {
+                                public boolean verify( String arg0, SSLSession arg1 )
+                                {
+                                    return true;
+                                }
+                            } );
+                            tls.negotiate( new DummySSLSocketFactory() );
+
+                        }
+                        catch ( Exception e )
+                        {
+                            namingException = new NamingException( e.getMessage() != null ? e.getMessage()
+                                : "Error while establishing TLS session" ); //$NON-NLS-1$
+                            namingException.setRootCause( e );
+                            context.close();
+                        }
+                    }
+                }
+                catch ( NamingException ne )
+                {
+                    namingException = ne;
+                }
+            }
+
+
+            public NamingException getException()
+            {
+                return namingException;
+            }
+
+
+            public Object getResult()
+            {
+                return null;
+            }
+
+
+            public void reset()
+            {
+                namingException = null;
+            }
+        };
+
+        runAndMonitor( runnable, monitor );
+
+        if ( runnable.getException() != null )
+        {
+            throw runnable.getException();
+        }
+        else if ( context != null )
+        {
+            // all OK
+        }
+        else
+        {
+            throw new NamingException( "???" ); //$NON-NLS-1$
+        }
+    }
+
+
+    private void doBind( final StudioProgressMonitor monitor ) throws NamingException
+    {
+        if ( context != null && isConnected )
+        {
+            InnerRunnable runnable = new InnerRunnable()
+            {
+                private NamingException namingException = null;
+
+
+                public void run()
+                {
+                    try
+                    {
+                        context.removeFromEnvironment( Context.SECURITY_AUTHENTICATION );
+                        context.removeFromEnvironment( Context.SECURITY_PRINCIPAL );
+                        context.removeFromEnvironment( Context.SECURITY_CREDENTIALS );
+
+                        context.addToEnvironment( Context.SECURITY_PRINCIPAL, bindPrincipal );
+                        context.addToEnvironment( Context.SECURITY_CREDENTIALS, bindCredentials );
+                        context.addToEnvironment( Context.SECURITY_AUTHENTICATION, authMethod );
+
+                        context.reconnect( context.getConnectControls() );
+                    }
+                    catch ( NamingException ne )
+                    {
+                        namingException = ne;
+                    }
+                }
+
+
+                public NamingException getException()
+                {
+                    return namingException;
+                }
+
+
+                public Object getResult()
+                {
+                    return null;
+                }
+
+
+                public void reset()
+                {
+                    namingException = null;
+                }
+            };
+
+            runAndMonitor( runnable, monitor );
+
+            if ( runnable.getException() != null )
+            {
+                throw runnable.getException();
+            }
+            else if ( context != null )
+            {
+                // all OK
+            }
+            else
+            {
+                throw new NamingException( "???" ); //$NON-NLS-1$
+            }
+
+        }
+        else
+        {
+            throw new NamingException( "No connection" );
+        }
+    }
+
+
+    private void checkConnectionAndRunAndMonitor( final InnerRunnable runnable, final StudioProgressMonitor monitor )
+        throws NamingException
+    {
+        // check connection
+        if ( !isConnected || context == null )
+        {
+            doConnect( monitor );
+            doBind( monitor );
+        }
+        if ( context == null )
+        {
+            throw new NamingException( "No connection" );
+        }
+
+        // loop for reconnection
+        for ( int i = 0; i <= 1; i++ )
+        {
+            runAndMonitor( runnable, monitor );
+
+            // check reconnection
+            if ( i == 0
+                && runnable.getException() != null
+                && ( ( runnable.getException() instanceof CommunicationException )
+                    || ( runnable.getException() instanceof ServiceUnavailableException ) || ( runnable.getException() instanceof InsufficientResourcesException ) ) )
+            {
+
+                doConnect( monitor );
+                doBind( monitor );
+                runnable.reset();
+            }
+            else
+            {
+                break;
+            }
+        }
+    }
+
+
+    private void runAndMonitor( final InnerRunnable runnable, final StudioProgressMonitor monitor )
+        throws CancelException
+    {
+        if ( !monitor.isCanceled() )
+        {
+            // monitor
+            StudioProgressMonitor.CancelListener listener = new StudioProgressMonitor.CancelListener()
+            {
+                public void cancelRequested( StudioProgressMonitor.CancelEvent event )
+                {
+                    if ( monitor.isCanceled() )
+                    {
+                        if ( jobThread.isAlive() )
+                        {
+                            jobThread.interrupt();
+                        }
+                        if ( context != null )
+                        {
+                            try
+                            {
+                                context.close();
+                            }
+                            catch ( NamingException ne )
+                            {
+                            }
+                            isConnected = false;
+                            context = null;
+                            System.gc();
+                        }
+                        isConnected = false;
+                    }
+                }
+            };
+            monitor.addCancelListener( listener );
+            jobThread = Thread.currentThread();
+
+            // run
+            try
+            {
+                // try {
+                // Thread.sleep(5000);
+                // } catch (InterruptedException e) {
+                // System.out.println(System.currentTimeMillis() + ": sleep
+                // interrupted!");
+                // }
+                // System.out.println(System.currentTimeMillis() + ": " +
+                // runnable);
+
+                runnable.run();
+            }
+            finally
+            {
+                monitor.removeCancelListener( listener );
+                jobThread = null;
+            }
+
+            if ( monitor.isCanceled() )
+            {
+                throw new CancelException();
+            }
+        }
+    }
+
+    interface InnerRunnable extends Runnable
+    {
+
+        /**
+         * Gets the exception.
+         * 
+         * @return the exception
+         */
+        NamingException getException();
+
+
+        /**
+         * Gets the result.
+         * 
+         * @return the result
+         */
+        Object getResult();
+
+
+        /**
+         * Reset.
+         */
+        void reset();
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractAsyncBulkJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractAsyncBulkJob.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractAsyncBulkJob.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractAsyncBulkJob.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,72 @@
+/*
+ *  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.jobs;
+
+
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+
+
+/**
+ * Base class for bulk jobs. It is used to execute large modifications without
+ * firering modification events. The notification of the listeners is done after 
+ * the job is executed.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractAsyncBulkJob extends AbstractConnectionJob
+{
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected final void executeAsyncJob( StudioProgressMonitor pm )
+    {
+        ConnectionEventRegistry.suspendEventFireingInCurrentThread();
+
+        try
+        {
+            executeBulkJob( pm );
+        }
+        finally
+        {
+            ConnectionEventRegistry.resumeEventFireingInCurrentThread();
+        }
+
+        this.runNotification();
+    }
+
+
+    /**
+     * Executes the bulk job.
+     * 
+     * @param pm the pm
+     */
+    protected abstract void executeBulkJob( StudioProgressMonitor pm );
+
+
+    /**
+     * Notifies about changed objects.
+     */
+    protected abstract void runNotification();
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractConnectionJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractConnectionJob.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractConnectionJob.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/AbstractConnectionJob.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,256 @@
+/*
+ *  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.jobs;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.Messages;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+
+/**
+ * Base class for all connections related jobs.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractConnectionJob extends Job
+{
+
+    /** The external progress monitor. */
+    private IProgressMonitor externalProgressMonitor;
+
+    /** The external result. */
+    private IStatus externalResult;
+
+
+    /**
+     * Creates a new instance of AbstractConnectionJob.
+     */
+    protected AbstractConnectionJob()
+    {
+        super( "" ); //$NON-NLS-1$
+    }
+
+
+    /**
+     * Executes the job asynchronously.
+     * 
+     * @param monitor the progress monitor
+     * 
+     * @throws Exception the exception
+     */
+    protected abstract void executeAsyncJob( StudioProgressMonitor monitor ) throws Exception;
+
+
+    /**
+     * Gets the error message.
+     * 
+     * @return the error message.
+     */
+    protected String getErrorMessage()
+    {
+        return Messages.jobs__error_occurred;
+    }
+
+
+    /**
+     * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+     */
+    protected final IStatus run( IProgressMonitor ipm )
+    {
+        StudioProgressMonitor monitor = new StudioProgressMonitor( externalProgressMonitor == null ? ipm
+            : externalProgressMonitor );
+
+        // execute job
+        if ( !monitor.errorsReported() )
+        {
+            try
+            {
+                executeAsyncJob( monitor );
+            }
+            catch ( Exception e )
+            {
+                monitor.reportError( e );
+            }
+            finally
+            {
+                monitor.done();
+                ipm.done();
+            }
+        }
+
+        // error handling
+        if ( monitor.isCanceled() )
+        {
+            // System.out.println("Job: CANCEL+CANCEL");
+            externalResult = Status.CANCEL_STATUS;
+            return Status.CANCEL_STATUS;
+        }
+        else if ( monitor.errorsReported() )
+        {
+            externalResult = monitor.getErrorStatus( getErrorMessage() );
+            if ( externalProgressMonitor == null )
+            {
+                // System.out.println("Job: ERROR+ERROR");
+                return externalResult;
+            }
+            else
+            {
+                // System.out.println("Job: ERROR+OK");
+                return Status.OK_STATUS;
+            }
+        }
+        else
+        {
+            // System.out.println("Job: OK+OK");
+            externalResult = Status.OK_STATUS;
+            return Status.OK_STATUS;
+        }
+    }
+
+
+    /**
+     * Sets the external progress monitor.
+     * 
+     * @param externalProgressMonitor the external progress monitor
+     */
+    public void setExternalProgressMonitor( IProgressMonitor externalProgressMonitor )
+    {
+        this.externalProgressMonitor = externalProgressMonitor;
+    }
+
+
+    /**
+     * Gets the result of the executed job. Either Status.OK_STATUS, 
+     * Status.CANCEL_STATUS or an error status.
+     * 
+     * @return the result of the executed job
+     */
+    public IStatus getExternalResult()
+    {
+        return this.externalResult;
+    }
+
+
+    /**
+     * Executes the job.
+     */
+    public final void execute()
+    {
+        setUser( true );
+        schedule();
+    }
+
+
+    /**
+     * Gets the locked objects.
+     * 
+     * @return the locked objects
+     */
+    protected abstract Object[] getLockedObjects();
+
+
+    /**
+     * @see org.eclipse.core.runtime.jobs.Job#shouldSchedule()
+     */
+    public boolean shouldSchedule()
+    {
+        Object[] myLockedObjects = getLockedObjects();
+        String[] myLockedObjectsIdentifiers = getLockIdentifiers( myLockedObjects );
+
+        // TODO: read, write
+
+        Job[] jobs = Platform.getJobManager().find( null );
+        for ( int i = 0; i < jobs.length; i++ )
+        {
+            Job job = jobs[i];
+
+            // if(job instanceof AbstractEclipseJob) {
+            if ( job.getClass() == this.getClass() && job != this )
+            {
+                AbstractConnectionJob otherJob = ( AbstractConnectionJob ) job;
+                Object[] otherLockedObjects = otherJob.getLockedObjects();
+                String[] otherLockedObjectIdentifiers = getLockIdentifiers( otherLockedObjects );
+
+                for ( int j = 0; j < otherLockedObjectIdentifiers.length; j++ )
+                {
+                    String other = otherLockedObjectIdentifiers[j];
+                    for ( int k = 0; k < myLockedObjectsIdentifiers.length; k++ )
+                    {
+                        String my = myLockedObjectsIdentifiers[k];
+
+                        //System.out.print( "other:" + other + ", my: " + my );
+                        if ( other.startsWith( my ) || my.startsWith( other ) )
+                        {
+                            //System.out.println( ", shouldSchedule() = " + false );
+                            return false;
+                        }
+                        else
+                        {
+                            //System.out.println();
+                        }
+
+                    }
+                }
+
+            }
+        }
+        return super.shouldSchedule();
+    }
+
+
+    private static String[] getLockIdentifiers( Object[] objects )
+    {
+        String[] identifiers = new String[objects.length];
+        for ( int i = 0; i < identifiers.length; i++ )
+        {
+            Object o = objects[i];
+            if ( o instanceof Connection )
+            {
+                identifiers[i] = getLockIdentifier( ( Connection ) o );
+            }
+            else
+            {
+                identifiers[i] = getLockIdentifier( objects[i] );
+            }
+        }
+        return identifiers;
+    }
+
+
+    private static String getLockIdentifier( Connection connection )
+    {
+        return connection.getHost() + ":" + connection.getPort();
+    }
+
+
+    private static String getLockIdentifier( Object object )
+    {
+        return object.toString();
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckBindJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckBindJob.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckBindJob.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckBindJob.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,86 @@
+/*
+ *  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.jobs;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.Messages;
+
+
+/**
+ * Job to check binding (authentication) to a directory server
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CheckBindJob extends AbstractConnectionJob
+{
+
+    private Connection connection;
+
+
+    /**
+     * Creates a new instance of CheckBindJob.
+     * 
+     * @param connection the connection
+     */
+    public CheckBindJob( Connection connection )
+    {
+        this.connection = connection;
+        setName( Messages.jobs__check_bind_name );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        return new Object[]
+            { connection };
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeAsyncJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( Messages.jobs__check_bind_task, 4 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        connection.getJNDIConnectionWrapper().connect( monitor );
+        connection.getJNDIConnectionWrapper().bind( monitor );
+        connection.getJNDIConnectionWrapper().disconnect();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return Messages.jobs__check_bind_error;
+    }
+
+}

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckNetworkParameterJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckNetworkParameterJob.java?rev=568964&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckNetworkParameterJob.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CheckNetworkParameterJob.java Thu Aug 23 06:15:22 2007
@@ -0,0 +1,86 @@
+/*
+ *  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.jobs;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.Messages;
+
+
+/**
+ * Job to check if a connection to a directory server could be established
+ * using the given connection parmeter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CheckNetworkParameterJob extends AbstractConnectionJob
+{
+
+    private Connection connection;
+
+
+    /**
+     * Creates a new instance of CheckNetworkParameterJob.
+     * 
+     * @param connection the connection
+     */
+    public CheckNetworkParameterJob( Connection connection )
+    {
+        this.connection = connection;
+        setName( Messages.jobs__check_network_name );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        return new Object[]
+            { connection };
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeAsyncJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( Messages.jobs__check_network_task, 3 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        connection.getJNDIConnectionWrapper().connect( monitor );
+        connection.getJNDIConnectionWrapper().disconnect();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return Messages.jobs__check_network_error;
+    }
+
+}