directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r586929 [1/3] - in /directory/studio/trunk: studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ studio-l...
Date Sun, 21 Oct 2007 18:41:08 GMT
Author: seelmann
Date: Sun Oct 21 11:41:06 2007
New Revision: 586929

URL: http://svn.apache.org/viewvc?rev=586929&view=rev
Log:
DIRSTUDIO-123: Moved search code from BrowserConnection to Job classes.

Removed:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionSearchHandler.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIConnectionProvider.java
Modified:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/AttributeComparator.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BaseDNEntry.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionException.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DirectoryMetadataEntry.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/Entry.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIUtils.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/OpenBrowserConnectionsJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/RootDSE.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CreateEntryJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameEntryJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/SearchJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java
    directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/schemabrowser/ReloadSchemaAction.java

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/AttributeComparator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/AttributeComparator.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/AttributeComparator.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/AttributeComparator.java Sun Oct 21 11:41:06 2007
@@ -214,4 +214,5 @@
             : s2.compareToIgnoreCase( s1 );
     }
 
+
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BaseDNEntry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BaseDNEntry.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BaseDNEntry.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BaseDNEntry.java Sun Oct 21 11:41:06 2007
@@ -21,23 +21,28 @@
 package org.apache.directory.studio.ldapbrowser.core.internal.model;
 
 
-import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
-import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
 import org.apache.directory.studio.ldapbrowser.core.model.RDN;
 
 
+/**
+ * The BaseDNEntry class represents an entry without a logical parent entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class BaseDNEntry extends AbstractEntry
 {
 
     private static final long serialVersionUID = -5444229580355372176L;
 
+    /** The base DN. */
     protected DN baseDn;
 
-    // protected String connectionName;
-    protected IBrowserConnection connection;
+    /** The browser connection. */
+    protected IBrowserConnection browserConnection;
 
 
     protected BaseDNEntry()
@@ -45,51 +50,61 @@
     }
 
 
-    public BaseDNEntry( DN baseDn, IBrowserConnection connection ) throws ModelModificationException
+    /**
+     * Creates a new instance of BaseDNEntry.
+     * 
+     * @param baseDn the base DN
+     * @param browserConnection the browser connection
+     */
+    public BaseDNEntry( DN baseDn, IBrowserConnection browserConnection )
     {
-        super();
-
-        if ( baseDn == null )
-        {
-            throw new ModelModificationException( BrowserCoreMessages.model__empty_dn );
-        }
-        if ( connection == null )
-        {
-            throw new ModelModificationException( BrowserCoreMessages.model__empty_connection );
-        }
+        assert baseDn != null;
+        assert browserConnection != null;
 
         this.setDirectoryEntry( true );
         this.baseDn = baseDn;
-        // this.connectionName = connection.getName();
-        this.connection = connection;
+        this.browserConnection = browserConnection;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getDn()
+     */
     public DN getDn()
     {
-        return this.baseDn;
+        return baseDn;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getParententry()
+     */
     public IEntry getParententry()
     {
         return getBrowserConnection().getRootDSE();
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getBrowserConnection()
+     */
     public IBrowserConnection getBrowserConnection()
     {
-        // return
-        // BrowserCorePlugin.getDefault().getConnectionManager().getConnection(this.connectionName);
-        return this.connection;
+        return browserConnection;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#setRdn(org.apache.directory.studio.ldapbrowser.core.model.RDN)
+     */
     protected void setRdn( RDN newRdn )
     {
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#setParent(org.apache.directory.studio.ldapbrowser.core.model.IEntry)
+     */
     protected void setParent( IEntry newParent )
     {
     }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java Sun Oct 21 11:41:06 2007
@@ -22,38 +22,24 @@
 
 
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionFolder;
-import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
 import org.apache.directory.studio.ldapbrowser.core.BookmarkManager;
-import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.SearchManager;
 import org.apache.directory.studio.ldapbrowser.core.events.BrowserConnectionUpdateEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer;
-import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesJob;
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
-import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
 import org.apache.directory.studio.ldapbrowser.core.model.NameException;
-import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
 import org.apache.directory.studio.ldapbrowser.core.model.URL;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
 import org.eclipse.search.ui.ISearchPageScoreComputer;
 
@@ -83,12 +69,8 @@
 
     private volatile Map<IEntry, ChildrenInfo> entryToChildrenInfoMap;
 
-    transient JNDIConnectionProvider connectionProvider;
-    
     transient ModificationLogger modificationLogger;
 
-    transient ConnectionSearchHandler searchHandler;
-
 
     /**
      * Creates a new instance of BrowserConnection.
@@ -117,20 +99,20 @@
 //        this.browserConnectionParameter.setFetchBaseDNs( true );
 //        this.browserConnectionParameter.setBaseDN( new DN() );
         
-        this.rootDSE = null;
 
-        this.schema = Schema.DEFAULT_SCHEMA;
+
         this.searchManager = new SearchManager( this );
         this.bookmarkManager = new BookmarkManager( this );
+        this.modificationLogger = new ModificationLogger( this );
 
         this.entryToChildrenFilterMap = new HashMap<IEntry, String>();
         this.dnToEntryCache = new HashMap<String, IEntry>();
         this.entryToAttributeInfoMap = new HashMap<IEntry, AttributeInfo>();
         this.entryToChildrenInfoMap = new HashMap<IEntry, ChildrenInfo>();
-
-        this.connectionProvider = new JNDIConnectionProvider( connection );
-        this.modificationLogger = new ModificationLogger( this );
-        this.searchHandler = new ConnectionSearchHandler( this );
+        
+        this.schema = Schema.DEFAULT_SCHEMA;
+        this.rootDSE = new RootDSE( this );
+        cacheEntry( this.rootDSE );
         
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
     }
@@ -146,141 +128,9 @@
 
 
     /**
-     * @see org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection#reloadSchema(org.apache.directory.studio.connection.core.StudioProgressMonitor)
-     */
-    public void reloadSchema( StudioProgressMonitor monitor )
-    {
-        InitializeAttributesJob.initializeAttributes( getRootDSE(), true, monitor );
-        
-        monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
-        loadSchema( monitor );
-    }
-
-
-    /**
-     * @see org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection#fetchRootDSE(org.apache.directory.studio.connection.core.StudioProgressMonitor)
-     */
-    public void fetchRootDSE( StudioProgressMonitor monitor )
-    {
-        if ( !monitor.errorsReported() )
-        {
-            try
-            {
-                monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
-                loadRootDSE( monitor );
-                monitor.worked( 1 );
-            }
-            catch ( Exception e )
-            {
-                monitor.reportError( BrowserCoreMessages.model__error_loading_rootdse );
-                rootDSE = null;
-            }
-
-            if ( monitor.errorsReported() )
-            {
-                close();
-            }
-        }
-    }
-
-
-    /**
-     * Open.
-     * 
-     * @param monitor the monitor
-     */
-    public void open( StudioProgressMonitor monitor )
-    {
-        this.fetchRootDSE( monitor );
-
-        if ( this.connectionProvider != null && this.rootDSE != null )
-        {
-            try
-            {
-                monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
-
-                // check if schema is cached
-                if ( this.schema == Schema.DEFAULT_SCHEMA )
-                {
-                    this.loadSchema( monitor );
-                }
-                else
-                {
-                    if ( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
-                    {
-                        // check if schema is up-to-date
-                        SearchParameter sp = new SearchParameter();
-                        sp.setSearchBase( new DN( this.rootDSE.getAttribute(
-                            IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ).getStringValue() ) );
-                        sp.setFilter( Schema.SCHEMA_FILTER );
-                        sp.setScope( ISearch.SCOPE_OBJECT );
-                        sp.setReturningAttributes( new String[]
-                            { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
-                                IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
-                        ISearch search = new Search( this, sp );
-                        // ISearch search = new Search(null, this, new
-                        // DN(this.rootDSE.getAttribute("subschemaSubentry").getStringValue()),
-                        // ISearch.FILTER_TRUE,
-                        // new String[] {
-                        // IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
-                        // IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP },
-                        // ISearch.SCOPE_OBJECT, 0, 0);
-                        this.search( search, monitor );
-                        ISearchResult[] results = search.getSearchResults();
-
-                        if ( results != null && results.length == 1 )
-                        {
-                            String schemaTimestamp = results[0]
-                                .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) != null ? results[0]
-                                .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ).getStringValue()
-                                : null;
-                            if ( schemaTimestamp == null )
-                            {
-                                schemaTimestamp = results[0]
-                                    .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) != null ? results[0]
-                                    .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ).getStringValue()
-                                    : null;
-                            }
-                            String cacheTimestamp = this.schema.getModifyTimestamp() != null ? this.schema
-                                .getModifyTimestamp() : this.schema.getCreateTimestamp();
-                            if ( cacheTimestamp == null
-                                || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp
-                                    .compareTo( cacheTimestamp ) > 0 ) )
-                            {
-                                this.loadSchema( monitor );
-                            }
-                        }
-                        else
-                        {
-                            this.schema = Schema.DEFAULT_SCHEMA;
-                            monitor.reportError( BrowserCoreMessages.model__no_schema_information );
-                        }
-                    }
-                    else
-                    {
-                        this.schema = Schema.DEFAULT_SCHEMA;
-                        monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
-                    }
-                }
-
-            }
-            catch ( Exception e )
-            {
-                this.schema = Schema.DEFAULT_SCHEMA;
-                monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
-                e.printStackTrace();
-                return;
-            }
-        }
-    }
-
-
-    /**
      * Closes the connections, clears all caches
-     * 
-     * TODO: call when connection is closed
      */
-    private void close()
+    private void clearCaches()
     {
         for ( int i = 0; i < getSearchManager().getSearchCount(); i++ )
         {
@@ -292,229 +142,15 @@
         entryToChildrenInfoMap.clear();
         entryToChildrenFilterMap.clear();
 
-        searchHandler.connectionClosed();
-
-        rootDSE = null;
         schema = Schema.DEFAULT_SCHEMA;
+        rootDSE = new RootDSE( this );
+        cacheEntry( rootDSE );
 
         System.gc();
     }
 
 
-    /**
-     * Loads the Root DSE.
-     * 
-     * @param monitor the progress monitor
-     * 
-     * @throws Exception the exception
-     */
-    private void loadRootDSE( StudioProgressMonitor monitor ) throws Exception
-    {
-        if(rootDSE == null)
-        {
-            rootDSE = new RootDSE( this );
-            cacheEntry( rootDSE );
-        }
-
-        // get well-known root DSE attributes, includes + and *
-        ISearch search = new Search( null, this, new DN(), ISearch.FILTER_TRUE, ROOT_DSE_ATTRIBUTES, ISearch.SCOPE_OBJECT, 0,
-            0, IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE, false, false, null );
-        search( search, monitor );
-
-        // get base DNs
-        if( !isFetchBaseDNs() && getBaseDN() != null && !"".equals( getBaseDN().toString() ))
-        {
-            // only add the specified base DN
-            DN dn = getBaseDN();
-            IEntry entry = new BaseDNEntry( new DN( dn ), this );
-            cacheEntry( entry );
-            rootDSE.addChild( entry );
-            
-            // check if entry exists
-            search = new Search( null, this, dn, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, ISearch.SCOPE_OBJECT, 1, 0,
-                IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE, true, true, null );
-            search( search, monitor );
-        }
-        else
-        {
-            // get naming contexts 
-            Set<String> namingContextSet = new HashSet<String>();
-            IAttribute attribute = rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS );
-            if ( attribute != null )
-            {
-                String[] values = attribute.getStringValues();
-                for ( int i = 0; i < values.length; i++ )
-                {
-                    namingContextSet.add( values[i] );
-                }
-            }
-            for ( String namingContext : namingContextSet )
-            {
-                if ( !"".equals( namingContext ) ) { //$NON-NLS-1$
-                    try
-                    {
-                        IEntry entry = new BaseDNEntry( new DN( namingContext ), this );
-                        rootDSE.addChild( entry );
-                        cacheEntry( entry );
-                    }
-                    catch ( Exception e )
-                    {
-                        monitor.reportError( BrowserCoreMessages.model__error_setting_base_dn, e );
-                    }
-                }
-                else
-                {
-                    // special handling of empty namingContext: perform a one-level search and add all result DNs to the set
-                    search = new Search( null, this, new DN(), ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, ISearch.SCOPE_ONELEVEL, 0,
-                        0, IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE, false, false, null );
-                    search( search, monitor );
-                    ISearchResult[] results = search.getSearchResults();
-                    for ( int k = 0; results != null && k < results.length; k++ )
-                    {
-                        ISearchResult result = results[k];
-                        IEntry entry = result.getEntry();
-                        rootDSE.addChild( entry );
-                    }
-                }
-            }
-        }
 
-        // get schema entry
-        DirectoryMetadataEntry[] schemaEntries = getDirectoryMetadataEntries( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY );
-        for ( int i = 0; i < schemaEntries.length; i++ )
-        {
-            schemaEntries[i].setSchemaEntry( true );
-            rootDSE.addChild( ( IEntry ) schemaEntries[i] );
-        }
-        
-        // get other metadata entries
-        String[] metadataAttributeNames = new String[]
-            { IRootDSE.ROOTDSE_ATTRIBUTE_MONITORCONTEXT, IRootDSE.ROOTDSE_ATTRIBUTE_CONFIGCONTEXT,
-                IRootDSE.ROOTDSE_ATTRIBUTE_DSANAME };
-        for ( int x = 0; x < metadataAttributeNames.length; x++ )
-        {
-            DirectoryMetadataEntry[] metadataEntries = getDirectoryMetadataEntries( metadataAttributeNames[x] );
-            for ( int i = 0; i < metadataEntries.length; i++ )
-            {
-                rootDSE.addChild( ( IEntry ) metadataEntries[i] );
-            }
-        }
-        
-        // set flags
-        rootDSE.setHasMoreChildren( false );
-        rootDSE.setAttributesInitialized( true );
-        rootDSE.setChildrenInitialized( true );
-        rootDSE.setHasChildrenHint( true );
-        rootDSE.setDirectoryEntry( true );
-    }
-
-
-    /**
-     * Gets the directory metadata entries.
-     * 
-     * @param metadataAttributeName the metadata attribute name
-     * 
-     * @return the directory metadata entries
-     * 
-     * @throws ModelModificationException the model modification exception
-     */
-    private DirectoryMetadataEntry[] getDirectoryMetadataEntries( String metadataAttributeName )
-        throws ModelModificationException
-    {
-        List<DN> metadataEntryList = new ArrayList<DN>();
-        IAttribute attribute = getRootDSE().getAttribute( metadataAttributeName );
-        if ( attribute != null )
-        {
-            String[] values = attribute.getStringValues();
-            for ( int i = 0; i < values.length; i++ )
-            {
-                try
-                {
-                    metadataEntryList.add( new DN( values[i] ) );
-                }
-                catch ( NameException e )
-                {
-                }
-            }
-        }
-
-        DirectoryMetadataEntry[] metadataEntries = new DirectoryMetadataEntry[metadataEntryList.size()];
-        for ( int i = 0; i < metadataEntryList.size(); i++ )
-        {
-            metadataEntries[i] = new DirectoryMetadataEntry( metadataEntryList.get( i ), this );
-            metadataEntries[i].setDirectoryEntry( true );
-            cacheEntry( metadataEntries[i] );
-        }
-        return metadataEntries;
-    }
-
-
-    /**
-     * Loads the schema.
-     * 
-     * @param monitor the progress monitor
-     */
-    private void loadSchema( StudioProgressMonitor monitor )
-    {
-        schema = Schema.DEFAULT_SCHEMA;
-
-        try
-        {
-            if ( getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
-            {
-                SearchParameter sp = new SearchParameter();
-                sp.setSearchBase( new DN( getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
-                    .getStringValue() ) );
-                sp.setFilter( Schema.SCHEMA_FILTER );
-                sp.setScope( ISearch.SCOPE_OBJECT );
-                sp.setReturningAttributes( new String[]
-                    { Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES, Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES,
-                        Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES,
-                        Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE, IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
-                        IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
-                LdifEnumeration le = connectionProvider.search( sp, monitor );
-                if ( le.hasNext( monitor ) )
-                {
-                    LdifContentRecord schemaRecord = ( LdifContentRecord ) le.next( monitor );
-                    schema = new Schema();
-                    schema.loadFromRecord( schemaRecord );
-                    // TODO: Schema update event
-//                    EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
-//                        ConnectionUpdateEvent.EventDetail.SCHEMA_LOADED ), this );
-                }
-                else
-                {
-                    monitor.reportError( BrowserCoreMessages.model__no_schema_information );
-                }
-            }
-            else
-            {
-                monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
-            }
-        }
-        catch ( Exception e )
-        {
-            monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
-            e.printStackTrace();
-        }
-
-        if ( schema == null )
-        {
-            schema = Schema.DEFAULT_SCHEMA;
-        }
-    }
-
-
-    public void search( ISearch searchRequest, StudioProgressMonitor monitor )
-    {
-        searchHandler.search( searchRequest, monitor );
-    }
-
-
-    public boolean existsEntry( DN dn, StudioProgressMonitor monitor )
-    {
-        return searchHandler.existsEntry( dn, monitor );
-    }
 
 
     public IEntry getEntryFromCache( DN dn )
@@ -531,21 +167,6 @@
         return null;
     }
 
-
-    public IEntry getEntry( DN dn, StudioProgressMonitor monitor )
-    {
-        return searchHandler.getEntry( dn, monitor );
-    }
-
-
-    public LdifEnumeration exportLdif( SearchParameter searchParameter, StudioProgressMonitor monitor )
-        throws ConnectionException
-    {
-        LdifEnumeration subEnumeration = this.connectionProvider.search( searchParameter, monitor );
-        return subEnumeration;
-    }
-
-
     
     
     /**
@@ -674,18 +295,7 @@
      */
     public final IRootDSE getRootDSE()
     {
-        if( rootDSE == null )
-        {
-            try
-            {
-                rootDSE = new RootDSE( this );
-                cacheEntry( rootDSE );
-            }
-            catch ( ModelModificationException e )
-            {
-            }
-        }
-        return this.rootDSE;
+        return rootDSE;
     }
 
 
@@ -756,7 +366,7 @@
     }
 
 
-    protected void cacheEntry( IEntry entry )
+    public void cacheEntry( IEntry entry )
     {
         this.dnToEntryCache.put( entry.getDn().toOidString( this.schema ), entry );
     }
@@ -872,7 +482,7 @@
     {
         if(this.connection == connection)
         {
-            close();
+            clearCaches();
             BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent( this,
                 BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_CLOSED );
             EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent , this );

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionException.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionException.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionException.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionException.java Sun Oct 21 11:41:06 2007
@@ -24,6 +24,10 @@
 public class ConnectionException extends Exception
 {
 
+    public static final int STAUS_CODE_TIMELIMIT_EXCEEDED = 3;
+    public static final int STAUS_CODE_SIZELIMIT_EXCEEDED = 4;
+    public static final int STAUS_CODE_ADMINLIMIT_EXCEEDED = 11;
+    
     private static final long serialVersionUID = 1L;
 
     private int ldapStatusCode;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DirectoryMetadataEntry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DirectoryMetadataEntry.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DirectoryMetadataEntry.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DirectoryMetadataEntry.java Sun Oct 21 11:41:06 2007
@@ -23,14 +23,21 @@
 
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
 
 
+/**
+ * The DirectoryMetadataEntry class represents entries that are listed in the root DSE.
+ * Examples are the schema sub-entry, the monitorContext or the configContext entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class DirectoryMetadataEntry extends BaseDNEntry
 {
 
     private static final long serialVersionUID = 1340597532850853276L;
 
+    /** The schema entry flag. */
     private boolean schemaEntry;
 
 
@@ -39,17 +46,24 @@
     }
 
 
-    public DirectoryMetadataEntry( DN dn, IBrowserConnection connection )
-        throws ModelModificationException
+    /**
+     * Creates a new instance of DirectoryMetadataEntry.
+     * 
+     * @param dn the DN
+     * @param browserConnection the browser connection
+     */
+    public DirectoryMetadataEntry( DN dn, IBrowserConnection browserConnection )
     {
         super();
         this.baseDn = dn;
-        // this.connectionName = connection.getName();
-        this.connection = connection;
+        this.browserConnection = browserConnection;
         this.schemaEntry = false;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#hasChildren()
+     */
     public boolean hasChildren()
     {
         if ( getDn().equals( getBrowserConnection().getSchema().getDn() ) )
@@ -63,12 +77,22 @@
     }
 
 
+    /**
+     * Checks if is schema entry.
+     * 
+     * @return true, if is schema entry
+     */
     public boolean isSchemaEntry()
     {
         return schemaEntry;
     }
 
 
+    /**
+     * Sets the schema entry flag.
+     * 
+     * @param schemaEntry the schema entry flag
+     */
     public void setSchemaEntry( boolean schemaEntry )
     {
         this.schemaEntry = schemaEntry;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java Sun Oct 21 11:41:06 2007
@@ -22,17 +22,13 @@
 
 
 import org.apache.directory.studio.connection.core.Connection;
-import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.ldapbrowser.core.BookmarkManager;
 import org.apache.directory.studio.ldapbrowser.core.SearchManager;
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
 import org.apache.directory.studio.ldapbrowser.core.model.URL;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
 
 
@@ -50,24 +46,6 @@
     }
 
 
-    public boolean existsEntry( DN dn, StudioProgressMonitor monitor )
-    {
-        return false;
-    }
-
-
-    public LdifEnumeration exportLdif( SearchParameter searchParameter, StudioProgressMonitor pm )
-        throws ConnectionException
-    {
-        throw new UnsupportedOperationException();
-    }
-
-
-    public void fetchRootDSE( StudioProgressMonitor monitor )
-    {
-    }
-
-
     public DN getBaseDN()
     {
         return new DN();
@@ -92,12 +70,6 @@
     }
 
 
-    public IEntry getEntry( DN dn, StudioProgressMonitor monitor )
-    {
-        return null;
-    }
-
-
     public IEntry getEntryFromCache( DN dn )
     {
         return null;
@@ -134,16 +106,6 @@
     }
 
 
-    public void reloadSchema( StudioProgressMonitor monitor )
-    {
-    }
-
-
-    public void search( ISearch searchRequest, StudioProgressMonitor monitor )
-    {
-    }
-
-
     public void setBaseDN( DN baseDN )
     {
     }
@@ -216,6 +178,10 @@
         return null;
     }
 
+    public void cacheEntry( IEntry entry )
+    {
+    }
+    
     public void uncacheEntryRecursive( IEntry entry )
     {
     }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/Entry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/Entry.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/Entry.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/Entry.java Sun Oct 21 11:41:06 2007
@@ -21,21 +21,27 @@
 package org.apache.directory.studio.ldapbrowser.core.internal.model;
 
 
-import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
-import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
 import org.apache.directory.studio.ldapbrowser.core.model.RDN;
 
 
+/**
+ * The Entry class represents an entry with a logical parent entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class Entry extends AbstractEntry
 {
 
     private static final long serialVersionUID = -4718107307581983276L;
 
+    /** The RDN. */
     protected RDN rdn;
 
+    /** The parent entry. */
     protected IEntry parent;
 
 
@@ -44,59 +50,73 @@
     }
 
 
-    public Entry( IEntry parent, RDN rdn ) throws ModelModificationException
-    {
-        super();
-
-        if ( parent == null )
-        {
-            throw new ModelModificationException( BrowserCoreMessages.model__empty_entry );
-        }
-        if ( rdn == null )
-        {
-            throw new ModelModificationException( BrowserCoreMessages.model__empty_rdn );
-        }
-        if ( "".equals( rdn.toString() ) ) { //$NON-NLS-1$
-            throw new ModelModificationException( BrowserCoreMessages.model__empty_rdn );
-        }
+    /**
+     * Creates a new instance of Entry.
+     * 
+     * @param parent the parent entry
+     * @param rdn the RDN
+     */
+    public Entry( IEntry parent, RDN rdn )
+    {
+        assert parent != null;
+        assert rdn != null;
+        assert !"".equals( rdn.toString() );
 
         this.parent = parent;
         this.rdn = rdn;
     }
 
 
-    // performance opt.
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#getRdn()
+     */
     public RDN getRdn()
     {
-        return this.rdn;
+        // performance opt.
+        return rdn;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getDn()
+     */
     public DN getDn()
     {
-        DN dn = new DN( new RDN( this.rdn ), this.parent.getDn() );
+        DN dn = new DN( new RDN( rdn ), parent.getDn() );
         return dn;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getParententry()
+     */
     public IEntry getParententry()
     {
-        return this.parent;
+        return parent;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getBrowserConnection()
+     */
     public IBrowserConnection getBrowserConnection()
     {
-        return this.getParententry().getBrowserConnection();
+        return getParententry().getBrowserConnection();
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#setRdn(org.apache.directory.studio.ldapbrowser.core.model.RDN)
+     */
     protected void setRdn( RDN newRdn )
     {
         this.rdn = newRdn;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#setParent(org.apache.directory.studio.ldapbrowser.core.model.IEntry)
+     */
     protected void setParent( IEntry newParent )
     {
         this.parent = newParent;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIUtils.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIUtils.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIUtils.java Sun Oct 21 11:41:06 2007
@@ -20,10 +20,21 @@
 
 package org.apache.directory.studio.ldapbrowser.core.internal.model;
 
+import java.net.ConnectException;
+import java.net.NoRouteToHostException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+
+import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.ReferralException;
 
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
 import org.apache.directory.studio.ldapbrowser.core.model.NameException;
+import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
 
 
 
@@ -31,7 +42,7 @@
 public class JNDIUtils
 {
 
-    public static DN getDn( javax.naming.directory.SearchResult sr, String base ) throws NamingException,
+    public static DN getDn( javax.naming.directory.SearchResult sr ) throws NamingException,
         NameException, NoSuchFieldException
     {
         String dn = sr.getNameInNamespace();
@@ -63,6 +74,123 @@
         name = name.replaceAll( "\\\\5C", "\\\\\\\\" ); //$NON-NLS-1$ //$NON-NLS-2$
 
         return name;
+    }
+
+
+    public static ConnectionException createConnectionException( SearchParameter searchParameter, Throwable e )
+    {
+        ConnectionException connectionException = null;
+        ConnectionException lastException = null;
+    
+        do
+        {
+            String message = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
+            int ldapStatusCode = -1;
+            String[] referrals = null;
+    
+            // get LDAP status code
+            // [LDAP: error code 21 - telephoneNumber: value #0 invalid per
+            // syntax]
+            if ( message != null && message.startsWith( "[LDAP: error code " ) ) { //$NON-NLS-1$
+                int begin = "[LDAP: error code ".length(); //$NON-NLS-1$
+                int end = begin + 2;
+                try
+                {
+                    ldapStatusCode = Integer.parseInt( message.substring( begin, end ).trim() );
+                }
+                catch ( NumberFormatException nfe )
+                {
+                }
+            }
+    
+            // special causes
+            // java_io_IOException=I/O exception occurred: {0}
+            // java_io_EOFException=End of file encountered: {0}
+            // java_io_FileNotFoundException=File not found: {0}
+            // java_io_InterruptedIOException=I/O has been interrupted.
+            // java_net_UnknownHostException=Cannot locate host: {0}
+            // java_net_ConnectException=Cannot connect to host: {0}
+            // java_net_SocketException=Socket Exception: {0}
+            // java_net_NoRouteToHostException={0}
+            if ( e instanceof ConnectException )
+            {
+                message = e.getMessage() + " (" + e.getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            if ( e instanceof NoRouteToHostException )
+            {
+                message += e.getMessage() + " (" + e.getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            if ( e instanceof UnknownHostException )
+            {
+                message = BrowserCoreMessages.model__unknown_host + e.getMessage();
+            }
+            if ( e instanceof SocketException )
+            {
+                message = e.getMessage() + " (" + e.getMessage() + ")";; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            if ( e instanceof ReferralException )
+            {
+    
+                message = "Referrals: "; //$NON-NLS-1$
+                ReferralException re;
+                ArrayList referralsList = new ArrayList();
+    
+                re = ( ReferralException ) e;
+                message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
+                referralsList.add( re.getReferralInfo() );
+    
+                while ( re.skipReferral() )
+                {
+                    try
+                    {
+                        Context ctx = re.getReferralContext();
+                        ctx.list( "" ); //$NON-NLS-1$
+                    }
+                    catch ( NamingException e1 )
+                    {
+                        if ( e1 instanceof ReferralException )
+                        {
+                            re = ( ReferralException ) e1;
+                            message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
+                            referralsList.add( re.getReferralInfo() );
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                }
+    
+                referrals = ( String[] ) referralsList.toArray( new String[referralsList.size()] );
+            }
+    
+            ConnectionException ce;
+            if ( referrals != null )
+            {
+                ce = new org.apache.directory.studio.ldapbrowser.core.internal.model.ReferralException(
+                    searchParameter, referrals, ldapStatusCode, message, e );
+            }
+            else
+            {
+                ce = new ConnectionException( ldapStatusCode, message, e );
+            }
+            if ( lastException != null )
+            {
+                lastException.initCause( ce );
+            }
+            lastException = ce;
+            if ( connectionException == null )
+            {
+                connectionException = lastException;
+            }
+    
+            // next cause
+            e = e.getCause();
+        }
+        while ( e != null );
+    
+        return connectionException;
+    
     }
 
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/OpenBrowserConnectionsJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/OpenBrowserConnectionsJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/OpenBrowserConnectionsJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/OpenBrowserConnectionsJob.java Sun Oct 21 11:41:06 2007
@@ -25,56 +25,176 @@
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob;
-
-
+import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesJob;
+import org.apache.directory.studio.ldapbrowser.core.jobs.ReloadSchemasJob;
+import org.apache.directory.studio.ldapbrowser.core.jobs.SearchJob;
+import org.apache.directory.studio.ldapbrowser.core.model.DN;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+
+
+/**
+ * Job to open the browser connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class OpenBrowserConnectionsJob extends AbstractNotificationJob
 {
 
-    private BrowserConnection connection;
+    /** The browser connection. */
+    private BrowserConnection browserConnection;
 
 
-    public OpenBrowserConnectionsJob( BrowserConnection connection )
+    /**
+     * Creates a new instance of OpenBrowserConnectionsJob.
+     * 
+     * @param browserConnection the browser connection
+     */
+    public OpenBrowserConnectionsJob( BrowserConnection browserConnection )
     {
-        this.connection = connection;
+        this.browserConnection = browserConnection;
         setName( BrowserCoreMessages.jobs__open_connections_name_1 );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
     protected Connection[] getConnections()
     {
         return new Connection[0];
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
     protected Object[] getLockedObjects()
     {
         return new Object[]
-            { connection };
+            { browserConnection };
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
     protected String getErrorMessage()
     {
         return BrowserCoreMessages.jobs__open_connections_error_1;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
     protected void executeNotificationJob( StudioProgressMonitor monitor )
     {
-
         monitor.beginTask( " ", 1 * 6 + 1 ); //$NON-NLS-1$
         monitor.reportProgress( " " ); //$NON-NLS-1$
 
         monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__open_connections_task, new String[]
-            { this.connection.getConnection().getName() } ) );
+            { this.browserConnection.getConnection().getName() } ) );
         monitor.worked( 1 );
 
-        connection.open( monitor );
+        openBrowserConnection( browserConnection, monitor );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
     protected void runNotification()
     {
     }
 
+
+    /**
+     * Opens the browser connection.
+     * 
+     * @param browserConnection the browser connection
+     * @param monitor the progress monitor
+     */
+    static void openBrowserConnection( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
+    {
+        IRootDSE rootDSE = browserConnection.getRootDSE();
+        InitializeAttributesJob.initializeAttributes( rootDSE, true, monitor );
+
+        // check schema reload
+        if ( rootDSE != null )
+        {
+            try
+            {
+                monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
+
+                // check if schema is cached
+                Schema schema = browserConnection.getSchema();
+                if ( schema == Schema.DEFAULT_SCHEMA )
+                {
+                    ReloadSchemasJob.reloadSchema( browserConnection, monitor );
+                }
+                else if ( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
+                {
+                    // check if schema is up-to-date
+                    SearchParameter sp = new SearchParameter();
+                    sp.setSearchBase( new DN( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
+                        .getStringValue() ) );
+                    sp.setFilter( Schema.SCHEMA_FILTER );
+                    sp.setScope( ISearch.SCOPE_OBJECT );
+                    sp.setReturningAttributes( new String[]
+                        { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
+                            IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
+                    ISearch search = new Search( browserConnection, sp );
+
+                    SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+                    ISearchResult[] results = search.getSearchResults();
+
+                    if ( results != null && results.length == 1 )
+                    {
+                        String schemaTimestamp = results[0]
+                            .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) != null ? results[0]
+                            .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ).getStringValue() : null;
+                        if ( schemaTimestamp == null )
+                        {
+                            schemaTimestamp = results[0]
+                                .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) != null ? results[0]
+                                .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ).getStringValue()
+                                : null;
+                        }
+                        String cacheTimestamp = schema.getModifyTimestamp() != null ? schema.getModifyTimestamp()
+                            : schema.getCreateTimestamp();
+                        if ( cacheTimestamp == null
+                            || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp
+                                .compareTo( cacheTimestamp ) > 0 ) )
+                        {
+                            ReloadSchemasJob.reloadSchema( browserConnection, monitor );
+                        }
+                    }
+                    else
+                    {
+                        browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+                        monitor.reportError( BrowserCoreMessages.model__no_schema_information );
+                    }
+                }
+                else
+                {
+                    browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+                    monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
+                }
+            }
+            catch ( Exception e )
+            {
+                browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+                monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
+                e.printStackTrace();
+                return;
+            }
+        }
+    }
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/RootDSE.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/RootDSE.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/RootDSE.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/RootDSE.java Sun Oct 21 11:41:06 2007
@@ -28,9 +28,14 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
-import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
 
 
+/**
+ * The RootDSE class represents a root DSE entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public final class RootDSE extends BaseDNEntry implements IRootDSE
 {
 
@@ -42,53 +47,63 @@
     }
 
 
-    public RootDSE( IBrowserConnection connection ) throws ModelModificationException
+    /**
+     * Creates a new instance of RootDSE.
+     * 
+     * @param browserConnection the browser connection
+     */
+    public RootDSE( IBrowserConnection browserConnection )
     {
-        super( new DN(), connection );
+        super( new DN(), browserConnection );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.BaseDNEntry#getParententry()
+     */
     public IEntry getParententry()
     {
         return null;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#getSupportedExtensions()
+     */
     public String[] getSupportedExtensions()
     {
-        IAttribute supportedExtensionsAttr = getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION );
-        if ( supportedExtensionsAttr != null )
-        {
-            String[] stringValues = supportedExtensionsAttr.getStringValues();
-            Arrays.sort( stringValues );
-            return stringValues;
-        }
-        else
-        {
-            return new String[0];
-        }
+        return getAttributeValues( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#getSupportedControls()
+     */
     public String[] getSupportedControls()
     {
-        IAttribute supportedControlsAttr = getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL );
-        if ( supportedControlsAttr != null )
-        {
-            String[] stringValues = supportedControlsAttr.getStringValues();
-            Arrays.sort( stringValues );
-            return stringValues;
-        }
-        else
-        {
-            return new String[0];
-        }
+        return getAttributeValues( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#getSupportedFeatures()
+     */
     public String[] getSupportedFeatures()
     {
-        IAttribute supportedFeaturesAttr = getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES );
+        return getAttributeValues( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES );
+    }
+
+
+    /**
+     * Gets the attribute values.
+     * 
+     * @param attributeDescription the attribute description
+     * 
+     * @return the attribute values
+     */
+    private String[] getAttributeValues( String attributeDescription )
+    {
+        IAttribute supportedFeaturesAttr = getAttribute( attributeDescription );
         if ( supportedFeaturesAttr != null )
         {
             String[] stringValues = supportedFeaturesAttr.getStringValues();
@@ -100,8 +115,11 @@
             return new String[0];
         }
     }
-    
-    
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.internal.model.AbstractEntry#isSubentry()
+     */
     public boolean isSubentry()
     {
         return false;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java Sun Oct 21 11:41:06 2007
@@ -176,6 +176,7 @@
     {
         try
         {
+            // TODO: use JNDI here!!!
             SearchParameter param = new SearchParameter();
             param.setSearchBase( entryToCopy.getDn() );
             param.setFilter( ISearch.FILTER_TRUE );
@@ -185,7 +186,8 @@
             param.setReturningAttributes( new String[]
                 { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
             ISearch search = new Search( entryToCopy.getBrowserConnection(), param );
-            entryToCopy.getBrowserConnection().search( search, monitor );
+            
+            SearchJob.searchAndUpdateModel( entryToCopy.getBrowserConnection(), search, monitor );
 
             ISearchResult[] srs = search.getSearchResults();
             if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
@@ -199,20 +201,20 @@
 
                 // change RDN if entry already exists
                 StudioProgressMonitor testMonitor = new StudioProgressMonitor( monitor );
-                IEntry testEntry = parent.getBrowserConnection().getEntry( newEntry.getDn(), testMonitor );
+                IEntry testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
                 if ( testEntry != null )
                 {
                     String rdnValue = rdn.getValue();
                     String newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, "", rdnValue ); //$NON-NLS-1$
                     RDN newRdn = getNewRdn( rdn, newRdnValue );
                     newEntry = new Entry( parent, newRdn );
-                    testEntry = parent.getBrowserConnection().getEntry( newEntry.getDn(), testMonitor );
+                    testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
                     for ( int i = 2; testEntry != null; i++ )
                     {
                         newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, i + " ", rdnValue ); //$NON-NLS-1$
                         newRdn = getNewRdn( rdn, newRdnValue );
                         newEntry = new Entry( parent, newRdn );
-                        testEntry = parent.getBrowserConnection().getEntry( newEntry.getDn(), testMonitor );
+                        testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
                     }
                 }
 
@@ -300,19 +302,18 @@
                 // check for children
                 if ( !monitor.isCanceled() && ( scope == ISearch.SCOPE_ONELEVEL || scope == ISearch.SCOPE_SUBTREE ) )
                 {
-
+                    // TODO: use JNDI here!!!
                     SearchParameter subParam = new SearchParameter();
                     subParam.setSearchBase( entryToCopy.getDn() );
                     subParam.setFilter( ISearch.FILTER_TRUE );
                     subParam.setScope( ISearch.SCOPE_ONELEVEL );
                     subParam.setReturningAttributes( ISearch.NO_ATTRIBUTES );
                     ISearch subSearch = new Search( entryToCopy.getBrowserConnection(), subParam );
-                    entryToCopy.getBrowserConnection().search( subSearch, monitor );
+                    SearchJob.searchAndUpdateModel( entryToCopy.getBrowserConnection(), subSearch, monitor );
 
                     ISearchResult[] subSrs = subSearch.getSearchResults();
                     if ( !monitor.isCanceled() && subSrs != null && subSrs.length > 0 )
                     {
-
                         for ( int i = 0; i < subSrs.length; i++ )
                         {
                             ISearchResult subSearchResult = subSrs[i];

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CreateEntryJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CreateEntryJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CreateEntryJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CreateEntryJob.java Sun Oct 21 11:41:06 2007
@@ -106,7 +106,7 @@
 
         if ( !monitor.errorsReported() )
         {
-            createdEntry = browserConnection.getEntry( entryToCreate.getDn(), monitor );
+            createdEntry = ReadEntryJob.getEntry( browserConnection, entryToCreate.getDn(), monitor );
             // createdEntries[i].getParententry().addChild(entry, this);
             createdEntry.setHasChildrenHint( false );
         }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java Sun Oct 21 11:41:06 2007
@@ -28,8 +28,6 @@
 import java.util.List;
 import java.util.Set;
 
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
 import javax.naming.ldap.Control;
 import javax.naming.ldap.ManageReferralControl;
 
@@ -46,10 +44,19 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.IValue;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
 
 
+/*
+ * Search+Delete vs. Delete+SearchOnError
+ * 
+ * Test for:
+ * - delete leaf entry 100.000 times
+ * - tree with 100.000 childs
+ * - tree with 1000 childs each with 1000 childs 
+ * 
+ */
+
 public class DeleteEntriesJob extends AbstractNotificationJob
 {
 
@@ -151,17 +158,37 @@
     }
 
 
+    
+    private int deleteEntryRecursive( IBrowserConnection browserConnection, String dn, int numberOfDeletedEntries, StudioProgressMonitor monitor )
+    {
+//        int numberInBatch;
+//        
+//        JNDIConnectionWrapper connectionWrapper = browserConnection.getConnection().getJNDIConnectionWrapper();
+//        
+//        SearchControls searchControls = new SearchControls();
+//        searchControls.setCountLimit( 1000 );
+//        searchControls.setReturningAttributes( new String[]
+//                                                          { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
+//        searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+//        
+//        connectionWrapper.search( dn, ISearch.FILTER_TRUE, searchControls, derefAliasMethod, handleReferralsMethod, controls, monitor )
+        
+        return 0;
+    }
+    
+    
     private int deleteEntryRecursive( IEntry entry, boolean refInitialized, int numberOfDeletedEntries,
         StudioProgressMonitor monitor )
     {
         try
         {
-
             int numberInBatch;
             do
             {
                 numberInBatch = 0;
-
+                
+                // TODO: use JNDI here!!!
+                
                 SearchParameter subParam = new SearchParameter();
                 subParam.setSearchBase( entry.getDn() );
                 subParam.setFilter( ISearch.FILTER_TRUE );
@@ -170,9 +197,9 @@
                 subParam.setReferralsHandlingMethod( IBrowserConnection.HANDLE_REFERRALS_IGNORE );
                 subParam.setReturningAttributes( new String[]
                     { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
-                subParam.setCountLimit( 100 );
+                subParam.setCountLimit( 1000 );
                 ISearch search = new Search( entry.getBrowserConnection(), subParam );
-                entry.getBrowserConnection().search( search, monitor );
+                SearchJob.searchAndUpdateModel( entry.getBrowserConnection(), search, monitor );
 
                 ISearchResult[] srs = search.getSearchResults();
                 for ( int i = 0; !monitor.isCanceled() && srs != null && i < srs.length; i++ )
@@ -187,10 +214,10 @@
 
             if ( !monitor.isCanceled() && !monitor.errorsReported() )
             {
-
                 // check for referrals
                 if ( !refInitialized )
                 {
+                    // TODO: use JNDI here!!!
                     SearchParameter param = new SearchParameter();
                     param.setSearchBase( entry.getDn() );
                     param.setFilter( ISearch.FILTER_TRUE );
@@ -200,7 +227,7 @@
                     param.setReturningAttributes( new String[]
                         { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
                     ISearch search = new Search( entry.getBrowserConnection(), param );
-                    entry.getBrowserConnection().search( search, monitor );
+                    SearchJob.searchAndUpdateModel( entry.getBrowserConnection(), search, monitor );
 
                     ISearchResult[] srs = search.getSearchResults();
                     if ( !monitor.isCanceled() && srs != null && srs.length == 1 )

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java Sun Oct 21 11:41:06 2007
@@ -26,9 +26,7 @@
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.nio.charset.Charset;
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.codec.digest.DigestUtils;
@@ -51,23 +49,41 @@
 import org.eclipse.core.runtime.Preferences;
 
 
+/**
+ * Job to export directory content to an CSV file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class ExportCsvJob extends AbstractEclipseJob
 {
 
-    private String exportLdifFilename;
+    /** The filename of the CSV file. */
+    private String exportCsvFilename;
 
-    private IBrowserConnection connection;
+    /** The browser connection. */
+    private IBrowserConnection browserConnection;
 
+    /** The search parameter. */
     private SearchParameter searchParameter;
 
+    /** The export dn flag. */
     private boolean exportDn;
 
 
-    public ExportCsvJob( String exportLdifFilename, IBrowserConnection connection, SearchParameter searchParameter,
-        boolean exportDn )
+    /**
+     * Creates a new instance of ExportCsvJob.
+     * 
+     * @param exportCsvFilename the filename of the csv file
+     * @param browserConnection the browser connection
+     * @param searchParameter the search parameter
+     * @param exportDn true to export the DN
+     */
+    public ExportCsvJob( String exportCsvFilename, IBrowserConnection browserConnection,
+        SearchParameter searchParameter, boolean exportDn )
     {
-        this.exportLdifFilename = exportLdifFilename;
-        this.connection = connection;
+        this.exportCsvFilename = exportCsvFilename;
+        this.browserConnection = browserConnection;
         this.searchParameter = searchParameter;
         this.exportDn = exportDn;
 
@@ -75,24 +91,31 @@
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
     protected Connection[] getConnections()
     {
         return new Connection[]
-            { connection.getConnection() };
+            { browserConnection.getConnection() };
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
     protected Object[] getLockedObjects()
     {
-        List l = new ArrayList();
-        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
-        return l.toArray();
+        return new Object[]
+            { browserConnection.getUrl() + "_" + DigestUtils.shaHex( exportCsvFilename ) };
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
     protected void executeAsyncJob( StudioProgressMonitor monitor )
     {
-
         monitor.beginTask( BrowserCoreMessages.jobs__export_csv_task, 2 );
         monitor.reportProgress( " " ); //$NON-NLS-1$
         monitor.worked( 1 );
@@ -110,7 +133,7 @@
         try
         {
             // open file
-            FileOutputStream fos = new FileOutputStream( exportLdifFilename );
+            FileOutputStream fos = new FileOutputStream( exportCsvFilename );
             OutputStreamWriter osw = new OutputStreamWriter( fos, encoding );
             BufferedWriter bufferedWriter = new BufferedWriter( osw );
 
@@ -128,11 +151,11 @@
                     bufferedWriter.write( attributeDelimiter );
             }
             bufferedWriter.write( BrowserCoreConstants.LINE_SEPARATOR );
-            
+
             // export
             int count = 0;
-            export( connection, searchParameter, bufferedWriter, count, monitor, exportAttributes, attributeDelimiter,
-                valueDelimiter, quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn );
+            exportToCsv( browserConnection, searchParameter, bufferedWriter, count, monitor, exportAttributes,
+                attributeDelimiter, valueDelimiter, quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn );
 
             // close file
             bufferedWriter.close();
@@ -147,15 +170,34 @@
     }
 
 
-    private static void export( IBrowserConnection connection, SearchParameter searchParameter, BufferedWriter bufferedWriter,
-        int count, StudioProgressMonitor monitor, String[] attributes, String attributeDelimiter,
-        String valueDelimiter, String quoteCharacter, String lineSeparator, String encoding, int binaryEncoding, boolean exportDn )
-        throws IOException, ConnectionException
+    /**
+     * Exports to CSV.
+     * 
+     * @param browserConnection the browser connection
+     * @param searchParameter the search parameter
+     * @param bufferedWriter the buffered writer
+     * @param count the count
+     * @param monitor the monitor
+     * @param attributes the attributes
+     * @param attributeDelimiter the attribute delimiter
+     * @param valueDelimiter the value delimiter
+     * @param quoteCharacter the quote character
+     * @param lineSeparator the line separator
+     * @param encoding the encoding
+     * @param binaryEncoding the binary encoding
+     * @param exportDn the export dn
+     * 
+     * @throws IOException Signals that an I/O exception has occurred.
+     * @throws ConnectionException the connection exception
+     */
+    private static void exportToCsv( IBrowserConnection browserConnection, SearchParameter searchParameter,
+        BufferedWriter bufferedWriter, int count, StudioProgressMonitor monitor, String[] attributes,
+        String attributeDelimiter, String valueDelimiter, String quoteCharacter, String lineSeparator, String encoding,
+        int binaryEncoding, boolean exportDn ) throws IOException, ConnectionException
     {
         try
         {
-
-            LdifEnumeration enumeration = connection.exportLdif( searchParameter, monitor );
+            LdifEnumeration enumeration = ExportLdifJob.search( browserConnection, searchParameter, monitor );
             while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
             {
                 LdifContainer container = enumeration.next( monitor );
@@ -164,8 +206,8 @@
                 {
 
                     LdifContentRecord record = ( LdifContentRecord ) container;
-                    bufferedWriter.write( recordToCsv( connection, record, attributes, attributeDelimiter, valueDelimiter,
-                        quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn ) );
+                    bufferedWriter.write( recordToCsv( browserConnection, record, attributes, attributeDelimiter,
+                        valueDelimiter, quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn ) );
 
                     count++;
                     monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
@@ -194,9 +236,9 @@
                         ISearch referralSearch = referralSearches[i];
 
                         // export recursive
-                        export( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(), bufferedWriter,
-                            count, monitor, attributes, attributeDelimiter, valueDelimiter, quoteCharacter,
-                            lineSeparator, encoding, binaryEncoding, exportDn );
+                        exportToCsv( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(),
+                            bufferedWriter, count, monitor, attributes, attributeDelimiter, valueDelimiter,
+                            quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn );
                     }
                 }
             }
@@ -209,12 +251,30 @@
     }
 
 
-    private static String recordToCsv( IBrowserConnection connection, LdifContentRecord record, String[] attributes, String attributeDelimiter,
-        String valueDelimiter, String quoteCharacter, String lineSeparator, String encoding, int binaryEncoding, boolean exportDn )
+    /**
+     * Transforms an LDIF rRecord to CSV.
+     * 
+     * @param browserConnection the browser connection
+     * @param record the record
+     * @param attributes the attributes
+     * @param attributeDelimiter the attribute delimiter
+     * @param valueDelimiter the value delimiter
+     * @param quoteCharacter the quote character
+     * @param lineSeparator the line separator
+     * @param encoding the encoding
+     * @param binaryEncoding the binary encoding
+     * @param exportDn the export dn
+     * 
+     * @return the string
+     */
+    private static String recordToCsv( IBrowserConnection browserConnection, LdifContentRecord record,
+        String[] attributes, String attributeDelimiter, String valueDelimiter, String quoteCharacter,
+        String lineSeparator, String encoding, int binaryEncoding, boolean exportDn )
     {
 
         // group multi-valued attributes
-        Map attributeMap = getAttributeMap( connection, record, valueDelimiter, encoding, binaryEncoding );
+        Map<String, String> attributeMap = getAttributeMap( browserConnection, record, valueDelimiter, encoding,
+            binaryEncoding );
 
         // print attributes
         StringBuffer sb = new StringBuffer();
@@ -232,10 +292,10 @@
 
             String attributeName = attributes[i];
             AttributeDescription ad = new AttributeDescription( attributeName );
-            String oidString = ad.toOidString( connection.getSchema() );
+            String oidString = ad.toOidString( browserConnection.getSchema() );
             if ( attributeMap.containsKey( oidString ) )
             {
-                String value = ( String ) attributeMap.get( oidString );
+                String value = attributeMap.get( oidString );
 
                 // escape
                 value = value.replaceAll( quoteCharacter, quoteCharacter + quoteCharacter );
@@ -259,21 +319,33 @@
     }
 
 
-    static Map getAttributeMap( IBrowserConnection connection, LdifContentRecord record, String valueDelimiter, String encoding, int binaryEncoding )
+    /**
+     * Gets the attribute map.
+     * 
+     * @param browserConnection the browser connection
+     * @param record the record
+     * @param valueDelimiter the value delimiter
+     * @param encoding the encoding
+     * @param binaryEncoding the binary encoding
+     * 
+     * @return the attribute map
+     */
+    static Map<String, String> getAttributeMap( IBrowserConnection browserConnection, LdifContentRecord record,
+        String valueDelimiter, String encoding, int binaryEncoding )
     {
-        Map attributeMap = new HashMap();
+        Map<String, String> attributeMap = new HashMap<String, String>();
         LdifAttrValLine[] lines = record.getAttrVals();
         for ( int i = 0; i < lines.length; i++ )
         {
             String attributeName = lines[i].getUnfoldedAttributeDescription();
-            if ( connection != null )
+            if ( browserConnection != null )
             {
                 // convert attributeName to oid
                 AttributeDescription ad = new AttributeDescription( attributeName );
-                attributeName = ad.toOidString( connection.getSchema() );
+                attributeName = ad.toOidString( browserConnection.getSchema() );
             }
             String value = lines[i].getValueAsString();
-            if ( ! Charset.forName( encoding ).newEncoder().canEncode( value ) )
+            if ( !Charset.forName( encoding ).newEncoder().canEncode( value ) )
             {
                 if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_BASE64 )
                 {
@@ -315,6 +387,9 @@
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
     protected String getErrorMessage()
     {
         return BrowserCoreMessages.jobs__export_cvs_error;



Mime
View raw message