Author: pamarcelot
Date: Thu Oct 21 14:08:00 2010
New Revision: 1026004
URL: http://svn.apache.org/viewvc?rev=1026004&view=rev
Log:
Converted more operations to the use of inner runnable to execute their task.
Modified:
directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
Modified: directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java?rev=1026004&r1=1026003&r2=1026004&view=diff
==============================================================================
--- directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
(original)
+++ directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
Thu Oct 21 14:08:00 2010
@@ -46,6 +46,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.message.AddRequest;
import org.apache.directory.shared.ldap.message.AddRequestImpl;
import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.message.BindResponse;
import org.apache.directory.shared.ldap.message.DeleteRequest;
import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
import org.apache.directory.shared.ldap.message.ModifyDnRequest;
@@ -129,8 +130,8 @@ public class DirectoryApiConnectionWrapp
LdapConnectionConfig config = new LdapConnectionConfig();
config.setLdapHost( connection.getHost() );
config.setLdapPort( connection.getPort() );
- // config.setName( connection.getBindPrincipal() );
- // config.setCredentials( connection.getBindPassword() );
+ config.setName( connection.getBindPrincipal() );
+ config.setCredentials( connection.getBindPassword() );
config.setUseSsl( connection.getEncryptionMethod() == EncryptionMethod.LDAPS );
ldapConnection = new LdapNetworkConnection( config );
@@ -172,6 +173,10 @@ public class DirectoryApiConnectionWrapp
try
{
boolean connected = getLdapConnection().connect();
+ if ( !connected )
+ {
+ throw new Exception( "Unable to connect" );
+ }
}
catch ( Exception e )
{
@@ -227,33 +232,57 @@ public class DirectoryApiConnectionWrapp
{
if ( ldapConnection != null && isConnected )
{
- // Setup credentials
- IAuthHandler authHandler = ConnectionCorePlugin.getDefault().getAuthHandler();
- if ( authHandler == null )
+ InnerRunnable runnable = new InnerRunnable()
{
- Exception exception = new Exception( Messages.model__no_auth_handler );
- monitor.setCanceled( true );
- monitor.reportError( Messages.model__no_auth_handler, exception );
- throw exception;
- }
- ICredentials credentials = authHandler.getCredentials( connection.getConnectionParameter()
);
- if ( credentials == null )
- {
- Exception exception = new Exception();
- monitor.setCanceled( true );
- monitor.reportError( Messages.model__no_credentials, exception );
- throw exception;
- }
- if ( credentials.getBindPrincipal() == null || credentials.getBindPassword()
== null )
+ public void run()
+ {
+ try
+ {
+ // Setup credentials
+ IAuthHandler authHandler = ConnectionCorePlugin.getDefault().getAuthHandler();
+ if ( authHandler == null )
+ {
+ Exception exception = new Exception( Messages.model__no_auth_handler
);
+ monitor.setCanceled( true );
+ monitor.reportError( Messages.model__no_auth_handler, exception
);
+ throw exception;
+ }
+ ICredentials credentials = authHandler.getCredentials( connection.getConnectionParameter()
);
+ if ( credentials == null )
+ {
+ Exception exception = new Exception();
+ monitor.setCanceled( true );
+ monitor.reportError( Messages.model__no_credentials, exception
);
+ throw exception;
+ }
+ if ( credentials.getBindPrincipal() == null || credentials.getBindPassword()
== null )
+ {
+ Exception exception = new Exception( Messages.model__no_credentials
);
+ monitor.reportError( Messages.model__no_credentials, exception
);
+ throw exception;
+ }
+ bindPrincipal = credentials.getBindPrincipal();
+ bindPassword = credentials.getBindPassword();
+
+ getLdapConnection().bind( bindPrincipal, bindPassword );
+ }
+ catch ( Exception e )
+ {
+ exception = e;
+ }
+ }
+ };
+
+ runAndMonitor( runnable, monitor );
+
+ if ( runnable.getException() != null )
{
- Exception exception = new Exception( Messages.model__no_credentials );
- monitor.reportError( Messages.model__no_credentials, exception );
- throw exception;
+ throw runnable.getException();
}
- bindPrincipal = credentials.getBindPrincipal();
- bindPassword = credentials.getBindPassword();
-
- getLdapConnection().bind( bindPrincipal, bindPassword );
+ }
+ else
+ {
+ throw new Exception( "No Connection" );
}
}
@@ -302,32 +331,62 @@ public class DirectoryApiConnectionWrapp
{
final long requestNum = SEARCH_RESQUEST_NUM++;
- try
+ InnerRunnable runnable = new InnerRunnable()
{
- // Preparing the search request
- SearchRequest request = new SearchRequestImpl();
- request.setBase( new DN( searchBase ) );
- request.setFilter( filter );
- request.setScope( convertSearchScope( searchControls ) );
- request.addAttributes( searchControls.getReturningAttributes() );
- request.addAllControls( convertControls( controls ) );
- request.setSizeLimit( searchControls.getCountLimit() );
- request.setTimeLimit( searchControls.getTimeLimit() );
- request.setDerefAliases( convertAliasDerefMode( aliasesDereferencingMethod )
);
-
- // Performing the search operation
- Cursor<Response> cursor = getLdapConnection().search( request );
-
- // Returning the result of the search
- return new CursorStudioNamingEnumeration( connection, cursor, searchBase, filter,
searchControls,
- aliasesDereferencingMethod, referralsHandlingMethod, controls, requestNum,
monitor, referralsInfo );
+ public void run()
+ {
+ try
+ {
+ // Preparing the search request
+ SearchRequest request = new SearchRequestImpl();
+ request.setBase( new DN( searchBase ) );
+ request.setFilter( filter );
+ request.setScope( convertSearchScope( searchControls ) );
+ request.addAttributes( searchControls.getReturningAttributes() );
+ request.addAllControls( convertControls( controls ) );
+ request.setSizeLimit( searchControls.getCountLimit() );
+ request.setTimeLimit( searchControls.getTimeLimit() );
+ request.setDerefAliases( convertAliasDerefMode( aliasesDereferencingMethod
) );
+
+ // Performing the search operation
+ Cursor<Response> cursor = getLdapConnection().search( request );
+
+ // Returning the result of the search
+ namingEnumeration = new CursorStudioNamingEnumeration( connection, cursor,
searchBase, filter,
+ searchControls,
+ aliasesDereferencingMethod, referralsHandlingMethod, controls, requestNum,
monitor,
+ referralsInfo );
+ }
+ catch ( Exception e )
+ {
+ exception = e;
+ }
+ }
+ };
+ try
+ {
+ checkConnectionAndRunAndMonitor( runnable, monitor );
}
catch ( Exception e )
{
monitor.reportError( e );
return null;
}
+
+ if ( runnable.isCanceled() )
+ {
+ monitor.setCanceled( true );
+ }
+ if ( runnable.getException() != null )
+ {
+ monitor.reportError( runnable.getException() );
+ return null;
+ }
+ else
+ {
+ return runnable.getResult();
+ }
}
@@ -433,28 +492,52 @@ public class DirectoryApiConnectionWrapp
return;
}
- try
+ InnerRunnable runnable = new InnerRunnable()
{
- // Preparing the modify request
- ModifyRequest request = new ModifyRequestImpl();
- request.setName( new DN( dn ) );
- Modification[] modifications = convertModificationItems( modificationItems );
- if ( modifications != null )
+ public void run()
{
- for ( Modification modification : modifications )
+ try
{
- request.addModification( modification );
+ // Preparing the modify request
+ ModifyRequest request = new ModifyRequestImpl();
+ request.setName( new DN( dn ) );
+ Modification[] modifications = convertModificationItems( modificationItems
);
+ if ( modifications != null )
+ {
+ for ( Modification modification : modifications )
+ {
+ request.addModification( modification );
+ }
+ }
+ request.addAllControls( convertControls( controls ) );
+
+ // Performing the modify operation
+ getLdapConnection().modify( request );
+ }
+ catch ( Exception e )
+ {
+ exception = e;
}
}
- request.addAllControls( convertControls( controls ) );
+ };
- // Performing the modify operation
- getLdapConnection().modify( request );
+ try
+ {
+ checkConnectionAndRunAndMonitor( runnable, monitor );
}
catch ( Exception e )
{
monitor.reportError( e );
}
+
+ if ( runnable.isCanceled() )
+ {
+ monitor.setCanceled( true );
+ }
+ if ( runnable.getException() != null )
+ {
+ monitor.reportError( runnable.getException() );
+ }
}
@@ -528,24 +611,48 @@ public class DirectoryApiConnectionWrapp
return;
}
- try
+ InnerRunnable runnable = new InnerRunnable()
{
- // Preparing the rename request
- ModifyDnRequest request = new ModifyDnRequestImpl();
- request.setName( new DN( oldDn ) );
- request.setDeleteOldRdn( deleteOldRdn );
- DN newName = new DN( newDn );
- request.setNewRdn( newName.getRdn() );
- request.setNewSuperior( newName.getParent() );
- request.addAllControls( convertControls( controls ) );
+ public void run()
+ {
+ try
+ {
+ // Preparing the rename request
+ ModifyDnRequest request = new ModifyDnRequestImpl();
+ request.setName( new DN( oldDn ) );
+ request.setDeleteOldRdn( deleteOldRdn );
+ DN newName = new DN( newDn );
+ request.setNewRdn( newName.getRdn() );
+ request.setNewSuperior( newName.getParent() );
+ request.addAllControls( convertControls( controls ) );
- // Performing the rename operation
- getLdapConnection().modifyDn( request );
+ // Performing the rename operation
+ getLdapConnection().modifyDn( request );
+ }
+ catch ( Exception e )
+ {
+ exception = e;
+ }
+ }
+ };
+
+ try
+ {
+ checkConnectionAndRunAndMonitor( runnable, monitor );
}
catch ( Exception e )
{
monitor.reportError( e );
}
+
+ if ( runnable.isCanceled() )
+ {
+ monitor.setCanceled( true );
+ }
+ if ( runnable.getException() != null )
+ {
+ monitor.reportError( runnable.getException() );
+ }
}
@@ -561,21 +668,45 @@ public class DirectoryApiConnectionWrapp
return;
}
- try
+ InnerRunnable runnable = new InnerRunnable()
{
- // Preparing the add request
- AddRequest request = new AddRequestImpl();
- request.setEntryDn( new DN( dn ) );
- request.setEntry( AttributeUtils.toClientEntry( attributes, new DN( dn ) ) );
- request.addAllControls( convertControls( controls ) );
+ public void run()
+ {
+ try
+ {
+ // Preparing the add request
+ AddRequest request = new AddRequestImpl();
+ request.setEntryDn( new DN( dn ) );
+ request.setEntry( AttributeUtils.toClientEntry( attributes, new DN( dn
) ) );
+ request.addAllControls( convertControls( controls ) );
- // Performing the add operation
- getLdapConnection().add( request );
+ // Performing the add operation
+ getLdapConnection().add( request );
+ }
+ catch ( Exception e )
+ {
+ exception = e;
+ }
+ }
+ };
+
+ try
+ {
+ checkConnectionAndRunAndMonitor( runnable, monitor );
}
catch ( Exception e )
{
monitor.reportError( e );
}
+
+ if ( runnable.isCanceled() )
+ {
+ monitor.setCanceled( true );
+ }
+ if ( runnable.getException() != null )
+ {
+ monitor.reportError( runnable.getException() );
+ }
}
@@ -591,20 +722,44 @@ public class DirectoryApiConnectionWrapp
return;
}
- try
+ InnerRunnable runnable = new InnerRunnable()
{
- // Preparing the delete request
- DeleteRequest request = new DeleteRequestImpl();
- request.setName( new DN( dn ) );
- request.addAllControls( convertControls( controls ) );
+ public void run()
+ {
+ try
+ {
+ // Preparing the delete request
+ DeleteRequest request = new DeleteRequestImpl();
+ request.setName( new DN( dn ) );
+ request.addAllControls( convertControls( controls ) );
+
+ // Performing the delete operation
+ getLdapConnection().delete( request );
+ }
+ catch ( Exception e )
+ {
+ exception = e;
+ }
+ }
+ };
- // Performing the delete operation
- getLdapConnection().delete( request );
+ try
+ {
+ checkConnectionAndRunAndMonitor( runnable, monitor );
}
catch ( Exception e )
{
monitor.reportError( e );
}
+
+ if ( runnable.isCanceled() )
+ {
+ monitor.setCanceled( true );
+ }
+ if ( runnable.getException() != null )
+ {
+ monitor.reportError( runnable.getException() );
+ }
}
/**
|