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

svn commit: r592082 [6/20] - in /directory/sandbox/felixk/studio-ldapbrowser-core: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ sr...

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,568 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.naming.InvalidNameException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.BasicControl;
+import javax.naming.ldap.Control;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.events.BulkModificationEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifCommentLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.parser.LdifParser;
+import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
+
+
+/**
+ * Job used to import an LDIF file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportLdifJob extends AbstractNotificationJob
+{
+
+    /** The browser connection. */
+    private IBrowserConnection browserConnection;
+
+    /** The LDIF file. */
+    private File ldifFile;
+
+    /** The log file. */
+    private File logFile;
+
+    /** The continue on error flag. */
+    private boolean continueOnError;
+
+
+    /**
+     * Creates a new instance of ImportLdifJob.
+     * 
+     * @param browserConnection the browser connection
+     * @param ldifFile the LDIF file
+     * @param logFile the log file
+     * @param continueOnError the continue on error flag
+     */
+    public ImportLdifJob( IBrowserConnection browserConnection, File ldifFile, File logFile, boolean continueOnError )
+    {
+        this.browserConnection = browserConnection;
+        this.ldifFile = ldifFile;
+        this.logFile = logFile;
+        this.continueOnError = continueOnError;
+
+        setName( BrowserCoreMessages.jobs__import_ldif_name );
+    }
+
+
+    /**
+     * Creates a new instance of ImportLdifJob.
+     * 
+     * @param connection the connection
+     * @param ldifFile the LDIF file
+     * @param continueOnError the continue on error
+     */
+    public ImportLdifJob( IBrowserConnection connection, File ldifFile, boolean continueOnError )
+    {
+        this( connection, ldifFile, null, continueOnError );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
+    protected Connection[] getConnections()
+    {
+        return new Connection[]
+            { browserConnection.getConnection() };
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        List<Object> l = new ArrayList<Object>();
+        l.add( browserConnection.getUrl() + "_" + DigestUtils.shaHex( ldifFile.toString() ) );
+        return l.toArray();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeNotificationJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( BrowserCoreMessages.jobs__import_ldif_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        try
+        {
+            Reader ldifReader = new BufferedReader( new FileReader( this.ldifFile ) );
+            LdifParser parser = new LdifParser();
+            LdifEnumeration enumeration = parser.parse( ldifReader );
+
+            Writer logWriter;
+            if ( this.logFile != null )
+            {
+                logWriter = new BufferedWriter( new FileWriter( this.logFile ) );
+            }
+            else
+            {
+                logWriter = new Writer()
+                {
+                    public void close() throws IOException
+                    {
+                    }
+
+
+                    public void flush() throws IOException
+                    {
+                    }
+
+
+                    public void write( char[] cbuf, int off, int len ) throws IOException
+                    {
+                    }
+                };
+            }
+
+            importLdif( browserConnection, enumeration, logWriter, continueOnError, monitor );
+
+            logWriter.close();
+            ldifReader.close();
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__import_ldif_error;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
+    protected void runNotification()
+    {
+        EventRegistry.fireEntryUpdated( new BulkModificationEvent( browserConnection ), this );
+    }
+
+
+    /**
+     * Imports the LDIF enumeration
+     * 
+     * @param browserConnection the browser connection
+     * @param enumeration the LDIF enumeration
+     * @param logWriter the log writer
+     * @param continueOnError the continue on error flag
+     * @param monitor the progress monitor
+     */
+    static void importLdif( IBrowserConnection browserConnection, LdifEnumeration enumeration, Writer logWriter,
+        boolean continueOnError, StudioProgressMonitor monitor )
+    {
+        int importedCount = 0;
+        int errorCount = 0;
+        try
+        {
+            while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
+            {
+                LdifContainer container = enumeration.next( monitor );
+
+                if ( container instanceof LdifRecord )
+                {
+                    LdifRecord record = ( LdifRecord ) container;
+                    try
+                    {
+                        importLdifRecord( browserConnection, record, monitor );
+                        logModification( browserConnection, logWriter, record, monitor );
+                        importedCount++;
+
+                        // update cache and adjust attribute/children initialization flags
+                        LdapDN dn = new LdapDN( record.getDnLine().getValueAsString() );
+                        IEntry entry = browserConnection.getEntryFromCache( dn );
+                        LdapDN parentDn = DnUtils.getParent( dn );
+                        IEntry parentEntry = parentDn != null ? browserConnection.getEntryFromCache( parentDn ) : null;
+
+                        if ( record instanceof LdifChangeDeleteRecord )
+                        {
+                            if ( entry != null )
+                            {
+                                entry.setAttributesInitialized( false );
+                                browserConnection.uncacheEntryRecursive( entry );
+                            }
+                            if ( parentEntry != null )
+                            {
+                                parentEntry.setChildrenInitialized( false );
+                            }
+                        }
+                        else if ( record instanceof LdifChangeModDnRecord )
+                        {
+                            if ( entry != null )
+                            {
+                                entry.setAttributesInitialized( false );
+                                browserConnection.uncacheEntryRecursive( entry );
+                            }
+                            if ( parentEntry != null )
+                            {
+                                parentEntry.setChildrenInitialized( false );
+                            }
+                            LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
+                            if ( modDnRecord.getNewsuperiorLine() != null )
+                            {
+                                LdapDN newSuperiorDn = new LdapDN( modDnRecord.getNewsuperiorLine().getValueAsString() );
+                                IEntry newSuperiorEntry = browserConnection.getEntryFromCache( newSuperiorDn );
+                                if ( newSuperiorEntry != null )
+                                {
+                                    newSuperiorEntry.setChildrenInitialized( false );
+                                }
+                            }
+                        }
+                        else if ( record instanceof LdifChangeAddRecord || record instanceof LdifContentRecord )
+                        {
+                            if ( parentEntry != null )
+                            {
+                                parentEntry.setChildrenInitialized( false );
+                            }
+                        }
+                        else
+                        {
+                            if ( entry != null )
+                            {
+                                entry.setAttributesInitialized( false );
+                            }
+                        }
+                    }
+                    catch ( Exception e )
+                    {
+                        logModificationError( browserConnection, logWriter, record, e, monitor );
+                        errorCount++;
+
+                        if ( !continueOnError )
+                        {
+                            monitor.reportError( e );
+                            return;
+                        }
+                    }
+
+                    monitor.reportProgress( BrowserCoreMessages.bind(
+                        BrowserCoreMessages.ldif__imported_n_entries_m_errors, new String[]
+                            { "" + importedCount, "" + errorCount } ) ); //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                else
+                {
+                    logWriter.write( container.toRawString() );
+                }
+            }
+
+            if ( errorCount > 0 )
+            {
+                monitor.reportError( BrowserCoreMessages.bind( BrowserCoreMessages.ldif__n_errors_see_logfile,
+                    new String[]
+                        { "" + errorCount } ) ); //$NON-NLS-1$
+            }
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    /**
+     * Imports the LDIF record.
+     * 
+     * @param browserConnection the browser connection
+     * @param record the LDIF record
+     * @param monitor the progress monitor
+     * 
+     * @throws ConnectionException the connection exception
+     */
+    static void importLdifRecord( IBrowserConnection browserConnection, LdifRecord record, StudioProgressMonitor monitor )
+        throws ConnectionException
+    {
+        if ( !record.isValid() )
+        {
+            throw new ConnectionException( BrowserCoreMessages.model__invalid_record );
+        }
+
+        String dn = record.getDnLine().getValueAsString();
+
+        if ( record instanceof LdifContentRecord )
+        {
+            LdifContentRecord attrValRecord = ( LdifContentRecord ) record;
+            LdifAttrValLine[] attrVals = attrValRecord.getAttrVals();
+            Attributes jndiAttributes = new BasicAttributes();
+            for ( int ii = 0; ii < attrVals.length; ii++ )
+            {
+                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
+                Object realValue = attrVals[ii].getValueAsObject();
+
+                if ( jndiAttributes.get( attributeName ) != null )
+                {
+                    jndiAttributes.get( attributeName ).add( realValue );
+                }
+                else
+                {
+                    jndiAttributes.put( attributeName, realValue );
+                }
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
+                getControls( attrValRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeAddRecord )
+        {
+            LdifChangeAddRecord changeAddRecord = ( LdifChangeAddRecord ) record;
+            LdifAttrValLine[] attrVals = changeAddRecord.getAttrVals();
+            Attributes jndiAttributes = new BasicAttributes();
+            for ( int ii = 0; ii < attrVals.length; ii++ )
+            {
+                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
+                Object realValue = attrVals[ii].getValueAsObject();
+
+                if ( jndiAttributes.get( attributeName ) != null )
+                {
+                    jndiAttributes.get( attributeName ).add( realValue );
+                }
+                else
+                {
+                    jndiAttributes.put( attributeName, realValue );
+                }
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn, jndiAttributes,
+                getControls( changeAddRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeDeleteRecord )
+        {
+            LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
+            browserConnection.getConnection().getJNDIConnectionWrapper().deleteEntry( dn,
+                getControls( changeDeleteRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeModifyRecord )
+        {
+            LdifChangeModifyRecord modifyRecord = ( LdifChangeModifyRecord ) record;
+            LdifModSpec[] modSpecs = modifyRecord.getModSpecs();
+            ModificationItem[] mis = new ModificationItem[modSpecs.length];
+            for ( int ii = 0; ii < modSpecs.length; ii++ )
+            {
+                LdifModSpecTypeLine modSpecType = modSpecs[ii].getModSpecType();
+                LdifAttrValLine[] attrVals = modSpecs[ii].getAttrVals();
+
+                Attribute attribute = new BasicAttribute( modSpecType.getUnfoldedAttributeDescription() );
+                for ( int x = 0; x < attrVals.length; x++ )
+                {
+                    attribute.add( attrVals[x].getValueAsObject() );
+                }
+
+                if ( modSpecType.isAdd() )
+                {
+                    mis[ii] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
+                }
+                else if ( modSpecType.isDelete() )
+                {
+                    mis[ii] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attribute );
+                }
+                else if ( modSpecType.isReplace() )
+                {
+                    mis[ii] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute );
+                }
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().modifyAttributes( dn, mis,
+                getControls( modifyRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeModDnRecord )
+        {
+            LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
+            if ( modDnRecord.getNewrdnLine() != null && modDnRecord.getDeloldrdnLine() != null )
+            {
+                String newRdn = modDnRecord.getNewrdnLine().getValueAsString();
+                boolean deleteOldRdn = modDnRecord.getDeloldrdnLine().isDeleteOldRdn();
+
+                try
+                {
+                    LdapDN newDn;
+                    if ( modDnRecord.getNewsuperiorLine() != null )
+                        newDn = DnUtils.composeDn( newRdn, modDnRecord.getNewsuperiorLine().getValueAsString() );
+                    else
+                    {
+                        LdapDN dnObject = new LdapDN( dn );
+                        LdapDN parent = DnUtils.getParent( dnObject );
+                        newDn = DnUtils.composeDn( newRdn, parent.getUpName() );
+                    }
+
+                    browserConnection.getConnection().getJNDIConnectionWrapper().rename( dn, newDn.toString(),
+                        deleteOldRdn, getControls( modDnRecord ), monitor );
+                }
+                catch ( InvalidNameException ne )
+                {
+                    throw new ConnectionException( ne );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Gets the controls.
+     * 
+     * @param record the LDIF record
+     * 
+     * @return the controls
+     */
+    private static Control[] getControls( LdifRecord record )
+    {
+        Control[] controls = null;
+        if ( record instanceof LdifChangeRecord )
+        {
+            LdifChangeRecord changeRecord = ( LdifChangeRecord ) record;
+            LdifControlLine[] controlLines = changeRecord.getControls();
+            controls = new Control[controlLines.length];
+            for ( int i = 0; i < controlLines.length; i++ )
+            {
+                LdifControlLine line = controlLines[i];
+                // TODO: encoded control value
+                controls[i] = new BasicControl( line.getUnfoldedOid(), line.isCritical(), null );
+            }
+        }
+        return controls;
+    }
+
+
+    /**
+     * Log a modification error to the given writer.
+     * 
+     * @param browserConnection the browser connection
+     * @param logWriter the log writer
+     * @param record the record
+     * @param exception the exception
+     * @param monitor the progress monitor
+     */
+    private static void logModificationError( IBrowserConnection browserConnection, Writer logWriter,
+        LdifRecord record, Exception exception, StudioProgressMonitor monitor )
+    {
+        try
+        {
+            DateFormat df = new SimpleDateFormat( BrowserCoreConstants.DATEFORMAT );
+
+            String errorComment = "#!ERROR " + exception.getMessage(); //$NON-NLS-1$
+            errorComment = errorComment.replaceAll( "\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+            errorComment = errorComment.replaceAll( "\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+            LdifCommentLine errorCommentLine = LdifCommentLine.create( errorComment );
+
+            logWriter.write( LdifCommentLine.create( "#!RESULT ERROR" ).toFormattedString() ); //$NON-NLS-1$
+            logWriter
+                .write( LdifCommentLine
+                    .create(
+                        "#!CONNECTION ldap://" + browserConnection.getConnection().getHost() + ":" + browserConnection.getConnection().getPort() ).toFormattedString() ); //$NON-NLS-1$ //$NON-NLS-2$
+            logWriter.write( LdifCommentLine.create( "#!DATE " + df.format( new Date() ) ).toFormattedString() ); //$NON-NLS-1$
+            logWriter.write( errorCommentLine.toFormattedString() );
+            logWriter.write( record.toFormattedString() );
+        }
+        catch ( IOException ioe )
+        {
+            monitor.reportError( BrowserCoreMessages.model__error_logging_modification, ioe );
+        }
+    }
+
+
+    /**
+     * Log a modification to the given writer.
+     * 
+     * @param browserConnection the browser connection
+     * @param logWriter the log writer
+     * @param record the record
+     * @param monitor the progress monitor
+     */
+    private static void logModification( IBrowserConnection browserConnection, Writer logWriter, LdifRecord record,
+        StudioProgressMonitor monitor )
+    {
+        try
+        {
+            DateFormat df = new SimpleDateFormat( BrowserCoreConstants.DATEFORMAT );
+            logWriter.write( LdifCommentLine.create( "#!RESULT OK" ).toFormattedString() ); //$NON-NLS-1$
+            logWriter
+                .write( LdifCommentLine
+                    .create(
+                        "#!CONNECTION ldap://" + browserConnection.getConnection().getHost() + ":" + browserConnection.getConnection().getPort() ).toFormattedString() ); //$NON-NLS-1$ //$NON-NLS-2$
+            logWriter.write( LdifCommentLine.create( "#!DATE " + df.format( new Date() ) ).toFormattedString() ); //$NON-NLS-1$
+            logWriter.write( record.toFormattedString() );
+        }
+        catch ( IOException ioe )
+        {
+            monitor.reportError( BrowserCoreMessages.model__error_logging_modification, ioe );
+        }
+    }
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,427 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+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.IBrowserConnection.AliasDereferencingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
+
+
+/**
+ * Job to initialize the attributes of an entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InitializeAttributesJob extends AbstractNotificationJob
+{
+
+    /** The entries. */
+    private IEntry[] entries;
+
+    /** The flag if operational attributes should be initialized. */
+    private boolean initOperationalAttributes;
+
+    /** The requested attributes when reading the Root DSE. */
+    public static final String[] ROOT_DSE_ATTRIBUTES =
+        { IRootDSE.ROOTDSE_ATTRIBUTE_MONITORCONTEXT, IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS,
+            IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDLDAPVERSION, IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY,
+            IRootDSE.ROOTDSE_ATTRIBUTE_ALTSERVER, IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION,
+            IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL, IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES,
+            IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDSASLMECHANISM, ISearch.ALL_OPERATIONAL_ATTRIBUTES,
+            ISearch.ALL_USER_ATTRIBUTES };
+
+
+    /**
+     * Creates a new instance of InitializeAttributesJob.
+     * 
+     * @param entries the entries
+     * @param initOperationalAttributes true if operational attributes should be initialized
+     */
+    public InitializeAttributesJob( IEntry[] entries, boolean initOperationalAttributes )
+    {
+        this.entries = entries;
+        this.initOperationalAttributes = initOperationalAttributes;
+        setName( BrowserCoreMessages.jobs__init_entries_title_attonly );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
+    protected Connection[] getConnections()
+    {
+        Connection[] connections = new Connection[entries.length];
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            connections[i] = entries[i].getBrowserConnection().getConnection();
+        }
+        return connections;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        List<Object> l = new ArrayList<Object>();
+        l.addAll( Arrays.asList( entries ) );
+        return l.toArray();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1
+            : BrowserCoreMessages.jobs__init_entries_error_n;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeNotificationJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( " ", entries.length + 2 ); //$NON-NLS-1$
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+
+        for ( int pi = 0; pi < entries.length && !monitor.isCanceled(); pi++ )
+        {
+            monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_task, new String[]
+                { this.entries[pi].getDn().getUpName() } ) );
+            monitor.worked( 1 );
+            if ( entries[pi].getBrowserConnection() != null && entries[pi].isDirectoryEntry() )
+            {
+                initializeAttributes( entries[pi], initOperationalAttributes, monitor );
+            }
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
+    protected void runNotification()
+    {
+        for ( IEntry entry : entries )
+        {
+            if ( entry.getBrowserConnection() != null && entry.isDirectoryEntry() )
+            {
+                EventRegistry.fireEntryUpdated( new AttributesInitializedEvent( entry ), this );
+            }
+        }
+    }
+
+
+    /**
+     * Initializes the attributes.
+     * 
+     * @param entry the entry
+     * @param initOperationalAttributes true if operational attributes should be initialized
+     * @param monitor the progress monitor
+     */
+    public static void initializeAttributes( IEntry entry, boolean initOperationalAttributes,
+        StudioProgressMonitor monitor )
+    {
+        // get user attributes or both user and operational attributes
+        String[] returningAttributes = null;
+        LinkedHashSet<String> raSet = new LinkedHashSet<String>();
+        raSet.add( ISearch.ALL_USER_ATTRIBUTES );
+        if ( initOperationalAttributes )
+        {
+            AttributeTypeDescription[] opAtds = SchemaUtils.getOperationalAttributeDescriptions( entry
+                .getBrowserConnection().getSchema() );
+            String[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( opAtds );
+            raSet.addAll( Arrays.asList( attributeTypeDescriptionNames ) );
+            raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
+        }
+//        if ( entry instanceof RootDSE )
+//        {
+//            raSet.add( ISearch.ALL_USER_ATTRIBUTES );
+//            raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
+//        }
+        if ( entry.isReferral() )
+        {
+            raSet.add( IAttribute.REFERRAL_ATTRIBUTE );
+        }
+        returningAttributes = ( String[] ) raSet.toArray( new String[raSet.size()] );
+
+        initializeAttributes( entry, returningAttributes, monitor );
+    }
+
+
+    /**
+     * Initializes the attributes.
+     * 
+     * @param entry the entry
+     * @param attributes the returning attributes
+     * @param monitor the progress monitor
+     */
+    public static void initializeAttributes( IEntry entry, String[] attributes, StudioProgressMonitor monitor )
+    {
+        monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_att,
+            new String[]
+                { entry.getDn().getUpName() } ) );
+
+        // entry.setAttributesInitialized(false, entry.getConnection());
+
+        if ( entry instanceof IRootDSE )
+        {
+//            IEntry[] oldChildren = entry.getChildren();
+//            for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
+//            {
+//                if ( oldChildren[i] != null )
+//                {
+//                    entry.deleteChild( oldChildren[i] );
+//                }
+//            }
+//            entry.setChildrenInitialized( false );
+            
+            // special handling for Root DSE
+            loadRootDSE( entry.getBrowserConnection(), monitor );
+            
+//            if ( !monitor.errorsReported() )
+//            {
+//                try
+//                {
+//                    monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
+//                    loadRootDSE( entry.getBrowserConnection(), monitor );
+//                    monitor.worked( 1 );
+//                }
+//                catch ( Exception e )
+//                {
+//                    monitor.reportError( BrowserCoreMessages.model__error_loading_rootdse );
+//                    rootDSE = null;
+//                }
+//
+//                if ( monitor.errorsReported() )
+//                {
+//                    close();
+//                }
+//            }
+            
+        	entry.setAttributesInitialized( true );
+        	entry.setChildrenInitialized( true );
+        }
+        else
+        {
+	        // search
+	        ISearch search = new Search( null, entry.getBrowserConnection(), entry.getDn(), entry.isSubentry()?ISearch.FILTER_SUBENTRY:ISearch.FILTER_TRUE, attributes,
+	            SearchScope.OBJECT, 0, 0, AliasDereferencingMethod.NEVER, ReferralHandlingMethod.IGNORE,
+	            false, false, null );
+	        SearchJob.searchAndUpdateModel( entry.getBrowserConnection(), search, monitor );
+	
+	        // set initialized state
+	        entry.setAttributesInitialized( true );
+        }
+    }
+
+    
+    /**
+     * Loads the Root DSE.
+     * 
+     * @param browserConnection the browser connection
+     * @param monitor the progress monitor
+     * 
+     * @throws Exception the exception
+     */
+    static void loadRootDSE( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
+    {
+//        if(rootDSE == null)
+//        {
+//            rootDSE = new RootDSE( this );
+//            cacheEntry( rootDSE );
+//        }
+        
+        // delete old children
+        IEntry[] oldChildren = browserConnection.getRootDSE().getChildren();
+        for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
+        {
+            if ( oldChildren[i] != null )
+            {
+                browserConnection.getRootDSE().deleteChild( oldChildren[i] );
+            }
+        }
+        browserConnection.getRootDSE().setChildrenInitialized( false );
+
+        // get well-known root DSE attributes, includes + and *
+        ISearch search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE,
+            InitializeAttributesJob.ROOT_DSE_ATTRIBUTES, SearchScope.OBJECT, 0, 0,
+            AliasDereferencingMethod.NEVER, ReferralHandlingMethod.IGNORE, false, false,
+            null );
+        SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+
+        // get base DNs
+        if( !browserConnection.isFetchBaseDNs() && browserConnection.getBaseDN() != null && !"".equals( browserConnection.getBaseDN().toString() ))
+        {
+            try
+            {
+                // only add the specified base DN
+                LdapDN dn = browserConnection.getBaseDN();
+                IEntry entry = new BaseDNEntry( new LdapDN( dn ), browserConnection );
+                browserConnection.cacheEntry( entry );
+                browserConnection.getRootDSE().addChild( entry );
+                
+                // check if entry exists
+                // TODO: use browserConnection.getEntry( dn, monitor ) ??
+                search = new Search( null, browserConnection, dn, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, SearchScope.OBJECT, 1, 0,
+                    AliasDereferencingMethod.NEVER, ReferralHandlingMethod.IGNORE, true, true, null );
+                SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+            }
+            catch ( InvalidNameException e )
+            {
+                monitor.reportError( BrowserCoreMessages.model__error_setting_base_dn, e );
+            }
+        }
+        else
+        {
+            // get naming contexts 
+            Set<String> namingContextSet = new HashSet<String>();
+            IAttribute attribute = browserConnection.getRootDSE().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 LdapDN( namingContext ), browserConnection );
+                        browserConnection.getRootDSE().addChild( entry );
+                        browserConnection.cacheEntry( entry );
+                    }
+                    catch ( InvalidNameException 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, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, SearchScope.ONELEVEL, 0,
+                        0, AliasDereferencingMethod.NEVER, ReferralHandlingMethod.IGNORE, false, false, null );
+                    SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+                    ISearchResult[] results = search.getSearchResults();
+                    for ( int k = 0; results != null && k < results.length; k++ )
+                    {
+                        ISearchResult result = results[k];
+                        IEntry entry = result.getEntry();
+                        browserConnection.getRootDSE().addChild( entry );
+                    }
+                }
+            }
+        }
+
+        // get schema sub-entry
+        DirectoryMetadataEntry[] schemaEntries = getDirectoryMetadataEntries( browserConnection, IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY );
+        for ( int i = 0; i < schemaEntries.length; i++ )
+        {
+            schemaEntries[i].setSchemaEntry( true );
+            browserConnection.getRootDSE().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( browserConnection, metadataAttributeNames[x] );
+            for ( int i = 0; i < metadataEntries.length; i++ )
+            {
+                browserConnection.getRootDSE().addChild( ( IEntry ) metadataEntries[i] );
+            }
+        }
+        
+        // set flags
+        browserConnection.getRootDSE().setHasMoreChildren( false );
+        browserConnection.getRootDSE().setAttributesInitialized( true );
+        browserConnection.getRootDSE().setChildrenInitialized( true );
+        browserConnection.getRootDSE().setHasChildrenHint( true );
+        browserConnection.getRootDSE().setDirectoryEntry( true );
+    }
+
+
+    private static DirectoryMetadataEntry[] getDirectoryMetadataEntries( IBrowserConnection browserConnection, String metadataAttributeName )
+    {
+        List<LdapDN> metadataEntryList = new ArrayList<LdapDN>();
+        IAttribute attribute = browserConnection.getRootDSE().getAttribute( metadataAttributeName );
+        if ( attribute != null )
+        {
+            String[] values = attribute.getStringValues();
+            for ( int i = 0; i < values.length; i++ )
+            {
+                try
+                {
+                    metadataEntryList.add( new LdapDN( values[i] ) );
+                }
+                catch ( InvalidNameException e )
+                {
+                }
+            }
+        }
+
+        DirectoryMetadataEntry[] metadataEntries = new DirectoryMetadataEntry[metadataEntryList.size()];
+        for ( int i = 0; i < metadataEntryList.size(); i++ )
+        {
+            metadataEntries[i] = new DirectoryMetadataEntry( metadataEntryList.get( i ), browserConnection );
+            metadataEntries[i].setDirectoryEntry( true );
+            browserConnection.cacheEntry( metadataEntries[i] );
+        }
+        return metadataEntries;
+    }
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,287 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.model.Control;
+import org.apache.directory.studio.ldapbrowser.core.model.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.IBrowserConnection.AliasDereferencingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.AliasBaseEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.ReferralBaseEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
+
+
+/**
+ * Job to initialize the child entries of an entry
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InitializeChildrenJob extends AbstractNotificationJob
+{
+
+    /** The entries. */
+    private IEntry[] entries;
+
+
+    /**
+     * Creates a new instance of InitializeChildrenJob.
+     * 
+     * @param entries the entries
+     */
+    public InitializeChildrenJob( IEntry[] entries )
+    {
+        this.entries = entries;
+        setName( BrowserCoreMessages.jobs__init_entries_title_subonly );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
+    protected Connection[] getConnections()
+    {
+        Connection[] connections = new Connection[entries.length];
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            connections[i] = entries[i].getBrowserConnection().getConnection();
+        }
+        return connections;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        List<Object> l = new ArrayList<Object>();
+        l.addAll( Arrays.asList( entries ) );
+        return l.toArray();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1
+            : BrowserCoreMessages.jobs__init_entries_error_n;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeNotificationJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( " ", entries.length + 2 ); //$NON-NLS-1$
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+
+        for ( int pi = 0; pi < entries.length && !monitor.isCanceled(); pi++ )
+        {
+            monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_task, new String[]
+                { this.entries[pi].getDn().getUpName() } ) );
+            monitor.worked( 1 );
+
+            if ( entries[pi].getBrowserConnection() != null && entries[pi].isDirectoryEntry() )
+            {
+                initializeChildren( entries[pi], monitor );
+            }
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
+    protected void runNotification()
+    {
+        for ( int pi = 0; pi < entries.length; pi++ )
+        {
+            IEntry parent = entries[pi];
+            if ( parent.getBrowserConnection() != null && parent.isDirectoryEntry() )
+            {
+                EventRegistry.fireEntryUpdated( new ChildrenInitializedEvent( parent ), this );
+            }
+        }
+    }
+
+
+    /**
+     * Initializes the child entries.
+     * 
+     * @param parent the parent
+     * @param monitor the progress monitor
+     */
+    public static void initializeChildren( IEntry parent, StudioProgressMonitor monitor )
+    {
+        if ( parent instanceof IRootDSE )
+        {
+            // special handling for Root DSE
+            return;
+        }
+        else
+        {
+            monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_sub,
+                new String[]
+                    { parent.getDn().getUpName() } ) );
+
+            // clear old children
+            IEntry[] oldChildren = parent.getChildren();
+            for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
+            {
+                if ( oldChildren[i] != null )
+                {
+                    parent.deleteChild( oldChildren[i] );
+                }
+            }
+            parent.setChildrenInitialized( false );
+            
+            // determine alias and referral handling
+            SearchScope scope = SearchScope.ONELEVEL;
+            AliasDereferencingMethod derefAliasMethod = parent.getBrowserConnection().getAliasesDereferencingMethod();
+            ReferralHandlingMethod handleReferralsMethod = parent.getBrowserConnection().getReferralsHandlingMethod();
+            if ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) )
+            {
+                scope = ( parent.isAlias() || parent.isReferral() ) ? SearchScope.OBJECT : SearchScope.ONELEVEL;
+                derefAliasMethod = parent.isAlias() ? AliasDereferencingMethod.FINDING
+                    : AliasDereferencingMethod.NEVER;
+                handleReferralsMethod = parent.isReferral() ? ReferralHandlingMethod.FOLLOW
+                    : ReferralHandlingMethod.IGNORE;
+            }
+
+            // get children,
+            ISearch search = new Search( null, parent.getBrowserConnection(), parent.getDn(), parent.getChildrenFilter(),
+                ISearch.NO_ATTRIBUTES, scope, parent.getBrowserConnection().getCountLimit(),
+                parent.getBrowserConnection().getTimeLimit(), derefAliasMethod, handleReferralsMethod, BrowserCorePlugin
+                    .getDefault().getPluginPreferences().getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ),
+                BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                    BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ), null );
+            SearchJob.searchAndUpdateModel( parent.getBrowserConnection(), search, monitor );
+            ISearchResult[] srs = search.getSearchResults();
+            monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_subcount,
+                new String[]
+                    { srs == null ? Integer.toString( 0 ) : Integer.toString( srs.length ), parent.getDn().getUpName() } ) );
+
+            // fill children in search result
+            if ( srs != null && srs.length > 0 )
+            {
+
+                /*
+                 * clearing old children before filling new subenties is
+                 * necessary to handle aliases and referrals.
+                 */
+                IEntry[] connChildren = parent.getChildren();
+                for ( int i = 0; connChildren != null && i < connChildren.length; i++ )
+                {
+                    if ( connChildren[i] != null )
+                    {
+                        parent.deleteChild( connChildren[i] );
+                    }
+                }
+                parent.setChildrenInitialized( false );
+
+                for ( int i = 0; srs != null && i < srs.length; i++ )
+                {
+                    if ( parent.isReferral() )
+                    {
+                        ReferralBaseEntry referralBaseEntry = new ReferralBaseEntry( srs[i].getEntry().getBrowserConnection(),
+                            srs[i].getEntry().getDn() );
+                        parent.addChild( referralBaseEntry );
+                        // System.out.println("Ref: " +
+                        // referralBaseEntry.getUrl());
+                    }
+                    else if ( parent.isAlias() )
+                    {
+                        AliasBaseEntry aliasBaseEntry = new AliasBaseEntry( srs[i].getEntry().getBrowserConnection(), srs[i]
+                            .getEntry().getDn() );
+                        parent.addChild( aliasBaseEntry );
+                        // System.out.println("Ali: " +
+                        // aliasBaseEntry.getUrl());
+                    }
+                    else
+                    {
+                        parent.addChild( srs[i].getEntry() );
+                    }
+                }
+            }
+            else
+            {
+                parent.setHasChildrenHint( false );
+            }
+
+            // get subentries
+            ISearch subSearch = new Search( null, parent.getBrowserConnection(), parent.getDn(), parent.getChildrenFilter()!=null?parent.getChildrenFilter():ISearch.FILTER_SUBENTRY,
+                ISearch.NO_ATTRIBUTES, scope, parent.getBrowserConnection().getCountLimit(),
+                parent.getBrowserConnection().getTimeLimit(), derefAliasMethod, handleReferralsMethod, BrowserCorePlugin
+                    .getDefault().getPluginPreferences().getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ),
+                BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                    BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ), new Control[]
+                    { Control.SUBENTRIES_CONTROL } );
+            if ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) )
+            {
+                SearchJob.searchAndUpdateModel( parent.getBrowserConnection(), subSearch, monitor );
+                ISearchResult[] subSrs = subSearch.getSearchResults();
+                monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_subcount,
+                    new String[]
+                        { subSrs == null ? Integer.toString( 0 ) : Integer.toString( subSrs.length ),
+                            parent.getDn().getUpName() } ) );
+                // fill children in search result
+                if ( subSrs != null && subSrs.length > 0 )
+                {
+
+                    for ( int i = 0; subSrs != null && i < subSrs.length; i++ )
+                    {
+                        parent.addChild( subSrs[i].getEntry() );
+                    }
+                }
+            }
+
+            // check exceeded limits / canceled
+            parent.setHasMoreChildren( search.isCountLimitExceeded() || subSearch.isCountLimitExceeded()
+                || monitor.isCanceled() );
+            
+            // set initialized state
+            parent.setChildrenInitialized( true );
+        }
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,204 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ManageReferralControl;
+
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent;
+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.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
+
+
+/**
+ * Job to modify an existing value.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModifyValueJob extends AbstractAttributeModificationJob
+{
+
+    /** The attribute to modify. */
+    private IAttribute attribute;
+
+    /** The old value. */
+    private IValue oldValue;
+
+    /** The new raw value. */
+    private Object newRawValue;
+
+    /** The created new value. */
+    private IValue createdNewValue;
+
+
+    /**
+     * Creates a new instance of ModifyValueJob.
+     * 
+     * @param oldValue the old value
+     * @param newRawValue the new raw value
+     */
+    public ModifyValueJob( IValue oldValue, Object newRawValue )
+    {
+        this.attribute = oldValue.getAttribute();
+        this.oldValue = oldValue;
+        this.newRawValue = newRawValue;
+        setName( BrowserCoreMessages.jobs__modify_value_name );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#executeAttributeModificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeAttributeModificationJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( BrowserCoreMessages.jobs__modify_value_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        IValue newValue = new Value( attribute, newRawValue );
+
+        modifyValue( attribute.getEntry().getBrowserConnection(), attribute.getEntry(), oldValue, newValue, monitor );
+        if ( !monitor.errorsReported() )
+        {
+            createdNewValue = newValue;
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#getModifiedEntry()
+     */
+    protected IEntry getModifiedEntry()
+    {
+        return attribute.getEntry();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#getAffectedAttributeDescriptions()
+     */
+    protected String[] getAffectedAttributeDescriptions()
+    {
+        return new String[]
+            { attribute.getDescription() };
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
+    protected void runNotification()
+    {
+        EntryModificationEvent event;
+
+        if ( createdNewValue != null )
+        {
+            event = new ValueModifiedEvent( attribute.getEntry().getBrowserConnection(), attribute.getEntry(),
+                attribute, oldValue, createdNewValue );
+        }
+        else
+        {
+            event = new AttributesInitializedEvent( attribute.getEntry() );
+        }
+
+        EventRegistry.fireEntryUpdated( event, this );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__modify_value_error;
+    }
+
+
+    /**
+     * Modifies the value.
+     * 
+     * @param browserConnection the browser connection
+     * @param entry the entry
+     * @param oldValue the old value
+     * @param newValue the new value
+     * @param monitor the progress monitor
+     */
+    private void modifyValue( IBrowserConnection browserConnection, IEntry entry, IValue oldValue, IValue newValue,
+        StudioProgressMonitor monitor )
+    {
+        if ( browserConnection.getConnection() != null )
+        {
+            // dn
+            String dn = entry.getDn().getUpName();
+
+            // modification items
+            // perform a replace if the current attribute is single-valued
+            // perform an add and a remove operation if the current attribute is multi-valued
+            ModificationItem[] modificationItems;
+            if ( oldValue.getAttribute().getValueSize() == 1 )
+            {
+                modificationItems = new ModificationItem[1];
+                BasicAttribute attribute = new BasicAttribute( newValue.getAttribute().getDescription(), newValue
+                    .getRawValue() );
+                modificationItems[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute );
+            }
+            else
+            {
+                modificationItems = new ModificationItem[2];
+                BasicAttribute newAttribute = new BasicAttribute( newValue.getAttribute().getDescription(), newValue
+                    .getRawValue() );
+                modificationItems[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, newAttribute );
+                BasicAttribute oldAttribute = new BasicAttribute( oldValue.getAttribute().getDescription(), oldValue
+                    .getRawValue() );
+                modificationItems[1] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, oldAttribute );
+            }
+
+            // controls
+            Control[] controls = null;
+            if ( entry.isReferral() )
+            {
+                controls = new Control[]
+                    { new ManageReferralControl() };
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().modifyAttributes( dn, modificationItems,
+                controls, monitor );
+        }
+        else
+        {
+            oldValue.getAttribute().modifyValue( oldValue, newValue );
+        }
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,242 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ManageReferralControl;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryMovedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+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.utils.DnUtils;
+
+
+/**
+ * Job to move entries.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MoveEntriesJob extends AbstractNotificationJob
+{
+
+    /** The browser connection. */
+    private IBrowserConnection browserConnection;
+
+    /** The entries to move. */
+    private IEntry[] oldEntries;
+
+    /** The new parent. */
+    private IEntry newParent;
+
+    /** The moved entries. */
+    private IEntry[] newEntries;
+
+    private Set<ISearch> updatedSearches = new HashSet<ISearch>();
+
+
+    /**
+     * Creates a new instance of MoveEntriesJob.
+     * 
+     * @param entries the entries to move
+     * @param newParent the new parent
+     */
+    public MoveEntriesJob( IEntry[] entries, IEntry newParent )
+    {
+        this.browserConnection = newParent.getBrowserConnection();
+        this.oldEntries = entries;
+        this.newParent = newParent;
+
+        setName( entries.length == 1 ? BrowserCoreMessages.jobs__move_entry_name_1
+            : BrowserCoreMessages.jobs__move_entry_name_n );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
+    protected Connection[] getConnections()
+    {
+        return new Connection[]
+            { browserConnection.getConnection() };
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        List<IEntry> l = new ArrayList<IEntry>();
+        l.add( newParent );
+        l.addAll( Arrays.asList( oldEntries ) );
+        return l.toArray();
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeNotificationJob( StudioProgressMonitor monitor )
+    {
+        monitor.beginTask( BrowserCoreMessages.bind(
+            oldEntries.length == 1 ? BrowserCoreMessages.jobs__move_entry_task_1
+                : BrowserCoreMessages.jobs__move_entry_task_n, new String[]
+                {} ), 3 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        newEntries = new IEntry[oldEntries.length];
+        for ( int i = 0; i < oldEntries.length; i++ )
+        {
+            newEntries[i] = oldEntries[i];
+        }
+
+        for ( int i = 0; i < oldEntries.length; i++ )
+        {
+            IEntry oldEntry = oldEntries[i];
+            IEntry oldParent = oldEntry.getParententry();
+            LdapDN newDn = DnUtils.composeDn( oldEntry.getRdn(), newParent.getDn() );
+
+            // move in directory
+            // TODO: use manual/simulated move, if move of subtree is not supported (JNDI)
+            int errorStatusSize1 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
+            moveEntry( browserConnection, oldEntry, newDn, monitor );
+            //connection.move( oldEntry, newParent.getDn(), monitor );
+            int errorStatusSize2 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
+
+            if ( errorStatusSize1 == errorStatusSize2 )
+            {
+                // move in parent
+                oldParent.deleteChild( oldEntry );
+                IEntry newEntry = ReadEntryJob.getEntry( browserConnection, newDn, monitor );
+                newEntries[i] = newEntry;
+                newParent.addChild( newEntry );
+                newParent.setHasMoreChildren( false );
+
+                newEntry.setHasChildrenHint( oldEntry.hasChildren() );
+                if ( oldEntry.isChildrenInitialized() )
+                {
+                    InitializeChildrenJob.initializeChildren( newEntry, monitor );
+                }
+
+                // move in searches
+                ISearch[] searches = browserConnection.getSearchManager().getSearches();
+                for ( int j = 0; j < searches.length; j++ )
+                {
+                    ISearch search = searches[j];
+                    if ( search.getSearchResults() != null )
+                    {
+                        ISearchResult[] searchResults = search.getSearchResults();
+                        for ( int k = 0; k < searchResults.length; k++ )
+                        {
+                            ISearchResult result = searchResults[k];
+                            if ( oldEntry.equals( result.getEntry() ) )
+                            {
+                                ISearchResult[] newsrs = new ISearchResult[searchResults.length - 1];
+                                System.arraycopy( searchResults, 0, newsrs, 0, k );
+                                System.arraycopy( searchResults, k + 1, newsrs, k, searchResults.length - k - 1 );
+                                search.setSearchResults( newsrs );
+                                searchResults = newsrs;
+                                k--;
+                                updatedSearches.add( search );
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
+    protected void runNotification()
+    {
+        for ( int i = 0; i < newEntries.length; i++ )
+        {
+            if ( oldEntries[i] != null && newEntries[i] != null )
+            {
+                EventRegistry.fireEntryUpdated( new EntryMovedEvent( oldEntries[i], newEntries[i] ), this );
+            }
+        }
+        for ( ISearch search : updatedSearches )
+        {
+            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( search,
+                SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ), this );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return oldEntries.length == 1 ? BrowserCoreMessages.jobs__move_entry_error_1
+            : BrowserCoreMessages.jobs__move_entry_error_n;
+    }
+
+
+    /**
+     * Moves an entry.
+     * 
+     * @param browserConnection the browser connection
+     * @param oldEntry the old entry
+     * @param newDn the new DN
+     * @param monitor the progress monitor
+     */
+    private void moveEntry( IBrowserConnection browserConnection, IEntry oldEntry, LdapDN newDn,
+        StudioProgressMonitor monitor )
+    {
+        // dn
+        String oldDnString = oldEntry.getDn().getUpName();
+        String newDnString = newDn.getUpName();
+
+        // controls
+        Control[] controls = null;
+        if ( oldEntry.isReferral() )
+        {
+            controls = new Control[]
+                { new ManageReferralControl() };
+        }
+
+        browserConnection.getConnection().getJNDIConnectionWrapper().rename( oldDnString, newDnString, false, controls,
+            monitor );
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,182 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+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.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.AliasDereferencingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
+
+
+/**
+ * Job to read a single entry from directory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ReadEntryJob extends AbstractNotificationJob
+{
+
+    /** The browser connection. */
+    private IBrowserConnection browserConnection;
+
+    /** The DN of the entry. */
+    private LdapDN dn;
+
+    /** The entry read from directory. */
+    private IEntry readEntry;
+
+
+    /**
+     * Creates a new instance of ReadEntryJob.
+     * 
+     * @param browserConnection the browser connection
+     * @param dn the DN of the entry
+     */
+    public ReadEntryJob( IBrowserConnection browserConnection, LdapDN dn )
+    {
+        this.browserConnection = browserConnection;
+        this.dn = dn;
+        this.readEntry = null;
+
+        setName( BrowserCoreMessages.jobs__read_entry_name );
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
+    protected Connection[] getConnections()
+    {
+        return new Connection[]
+            { browserConnection.getConnection() };
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
+    protected Object[] getLockedObjects()
+    {
+        return new Object[]
+            { browserConnection };
+    }
+
+
+    /**
+     * Gets the read entry.
+     * 
+     * @return the read entry
+     */
+    public IEntry getReadEntry()
+    {
+        return readEntry;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__read_entry_error;
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
+    protected void executeNotificationJob( StudioProgressMonitor pm )
+    {
+        readEntry = browserConnection.getEntryFromCache( dn );
+        if ( readEntry == null )
+        {
+            pm.beginTask( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__read_entry_task, new String[]
+                { dn.toString() } ), 2 );
+            pm.reportProgress( " " ); //$NON-NLS-1$
+            pm.worked( 1 );
+
+            readEntry = getEntry( browserConnection, dn, pm );
+        }
+    }
+
+
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
+    protected void runNotification()
+    {
+    }
+
+
+    /**
+     * Gets the entry, either from the BrowserConnection's cache or from the directory.
+     * 
+     * @param browserConnection the browser connection
+     * @param dn the DN of the entry
+     * @param monitor the progress monitor
+     * 
+     * @return the read entry
+     */
+    static IEntry getEntry( IBrowserConnection browserConnection, LdapDN dn, StudioProgressMonitor monitor )
+    {
+        try
+        {
+            // first check cache
+            IEntry entry = browserConnection.getEntryFromCache( dn );
+            if ( entry != null )
+            {
+                return entry;
+            }
+
+            // search in directory
+            ISearch search = new Search( null, browserConnection, dn, null, ISearch.NO_ATTRIBUTES,
+                SearchScope.OBJECT, 1, 0, AliasDereferencingMethod.NEVER,
+                ReferralHandlingMethod.IGNORE, true, true, null );
+            SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+            ISearchResult[] srs = search.getSearchResults();
+            if ( srs.length > 0 )
+            {
+                return srs[0].getEntry();
+            }
+            else
+            {
+                monitor.reportError( BrowserCoreMessages.bind( BrowserCoreMessages.model__no_such_entry, dn ) );
+                return null;
+            }
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e.getMessage(), e );
+            return null;
+        }
+    }
+
+}

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