directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488345 [7/12] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-core/ ldapstudio-browser-core/META-INF/ ldapstudio-browser-core/about_files/ ldapstudio-browser-core/lib/ ldapstudio-browser-core/src/ ldapstudio-browser-core/...
Date Mon, 18 Dec 2006 17:15:08 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralException.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralException.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/ReferralException.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,114 @@
+/*
+ *  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.ldapstudio.browser.core.internal.model;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IReferralHandler;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.URL;
+
+
+public class ReferralException extends ConnectionException
+{
+
+    private static final long serialVersionUID = 1L;
+
+    private SearchParameter originalSearchParameter;
+
+    private String[] referrals;
+
+
+    public ReferralException( SearchParameter originalSearchParameter, String[] referrals, int ldapStatusCode,
+        String message, Throwable originalThrowable )
+    {
+        super( ldapStatusCode, message, originalThrowable );
+        this.originalSearchParameter = originalSearchParameter;
+        this.referrals = referrals;
+    }
+
+
+    public String[] getReferrals()
+    {
+        return referrals;
+    }
+
+
+    public ISearch[] getReferralSearches() throws ConnectionException
+    {
+
+        // get referral handler
+        IReferralHandler referralHandler = BrowserCorePlugin.getDefault().getReferralHandler();
+        if ( referralHandler == null )
+        {
+            throw new ConnectionException( BrowserCoreMessages.model__no_referral_handler );
+        }
+
+        List referralSearchList = new ArrayList( getReferrals().length );
+
+        for ( int i = 0; i < getReferrals().length; i++ )
+        {
+
+            // parse referral URL
+            String referral = getReferrals()[i];
+            URL referralUrl = new URL( referral );
+
+            // get referral connection
+            IConnection referralConnection = referralHandler.getReferralConnection( referralUrl );
+            if ( referralConnection == null )
+            {
+                // throw new
+                // ConnectionException(BrowserCoreMessages.model__no_referral_connection);
+                continue;
+            }
+
+            // create search
+            try
+            {
+                ISearch referralSearch = new Search(
+                    null, //
+                    referralConnection, //
+                    referralUrl.hasDn() ? referralUrl.getDn() : originalSearchParameter.getSearchBase(), referralUrl
+                        .hasFilter() ? referralUrl.getFilter() : originalSearchParameter.getFilter(),
+                    originalSearchParameter.getReturningAttributes(), referralUrl.hasScope() ? referralUrl.getScope()
+                        : originalSearchParameter.getScope(), originalSearchParameter.getCountLimit(),
+                    originalSearchParameter.getTimeLimit(), originalSearchParameter.getAliasesDereferencingMethod(),
+                    originalSearchParameter.getReferralsHandlingMethod(), originalSearchParameter.isInitChildrenFlag(),
+                    originalSearchParameter.isInitAliasAndReferralFlag(), originalSearchParameter.getControls() );
+                referralSearchList.add( referralSearch );
+            }
+            catch ( NoSuchFieldException nsfe )
+            {
+            }
+
+        }
+
+        ISearch[] referralSearches = ( ISearch[] ) referralSearchList.toArray( new ISearch[referralSearchList.size()] );
+        return referralSearches;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/RootDSE.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/RootDSE.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/RootDSE.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/RootDSE.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,140 @@
+/*
+ *  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.ldapstudio.browser.core.internal.model;
+
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IRootDSE;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+
+
+public final class RootDSE extends BaseDNEntry implements IRootDSE
+{
+
+    private static final long serialVersionUID = -8445018787232919754L;
+
+    public static Properties oidMap = new Properties();
+    static
+    {
+
+        try
+        {
+            URL url = RootDSE.class.getClassLoader().getResource(
+                "org/apache/directory/ldapstudio/browser/core/model/ldap_oids.txt" ); //$NON-NLS-1$
+            oidMap.load( url.openStream() );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    protected RootDSE()
+    {
+    }
+
+
+    public RootDSE( IConnection connection, ModelModifier source ) throws ModelModificationException
+    {
+        super();
+        this.setDirectoryEntry( true );
+        // this.connectionName = connection.getName();
+        this.connection = connection;
+        this.baseDn = new DN();
+    }
+
+
+    public boolean hasChildren()
+    {
+        return false;
+    }
+
+
+    public boolean isAttributesInitialized()
+    {
+        return true;
+    }
+
+
+    public String[] getSupportedExtensions()
+    {
+        if ( getAttribute( ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION ) != null )
+        {
+            return get( getAttribute( ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION ).getStringValues() );
+        }
+        else
+        {
+            return new String[0];
+        }
+    }
+
+
+    public String[] getSupportedControls()
+    {
+        if ( getAttribute( ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ) != null )
+        {
+            return get( getAttribute( ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ).getStringValues() );
+        }
+        else
+        {
+            return new String[0];
+        }
+    }
+
+
+    public String[] getSupportedFeatures()
+    {
+        if ( getAttribute( ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES ) != null )
+        {
+            return get( getAttribute( ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES ).getStringValues() );
+        }
+        else
+        {
+            return new String[0];
+        }
+    }
+
+
+    private String[] get( String[] a )
+    {
+        for ( int i = 0; i < a.length; i++ )
+        {
+            if ( oidMap.containsKey( a[i] ) )
+            {
+                String s = ( String ) oidMap.get( a[i] );
+                a[i] = s;
+                if ( s.matches( "^\".*\"" ) ) { //$NON-NLS-1$
+                    a[i] = s.substring( 1, s.indexOf( "\"", 1 ) ); //$NON-NLS-1$
+                }
+            }
+        }
+        Arrays.sort( a );
+        return a;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Search.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Search.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Search.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Search.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,397 @@
+/*
+ *  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.ldapstudio.browser.core.internal.model;
+
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer;
+import org.apache.directory.ldapstudio.browser.core.model.Control;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.URL;
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+
+
+public class Search implements ISearch
+{
+
+    private static final long serialVersionUID = -3482673086666351174L;
+
+    private IConnection connection;
+
+    private ISearchResult[] searchResults;
+
+    private SearchParameter searchParameter;
+
+    private boolean countLimitExceeded;
+
+
+    /**
+     * Creates a new search with the following parameters:
+     * 
+     * <li>searchName: current date
+     * <li>connection: null
+     * <li>searchBase: empty
+     * <li>filter: empty (objectClass=*)
+     * <li>returningAttributea: none
+     * <li>scope: one level
+     * <li>countLimit: preference value
+     * <li>timeLimit: preference value
+     */
+    public Search()
+    {
+        this(
+            new SimpleDateFormat( "yyyy-MM-dd HH-mm-ss" ).format( new Date() ), //$NON-NLS-1$	
+            null, new DN(), FILTER_TRUE, NO_ATTRIBUTES, ISearch.SCOPE_ONELEVEL, 0, 0,
+            IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE, false, false, null );
+    }
+
+
+    public Search( IConnection conn, SearchParameter searchParameter )
+    {
+        this.connection = conn;
+        this.searchResults = null;
+        this.searchParameter = searchParameter;
+        this.countLimitExceeded = false;
+    }
+
+
+    /**
+     * Creates a new search with the given search parameters
+     * 
+     * @param searchName
+     *                The name of the search
+     * @param conn
+     *                The connection of the search
+     * @param searchBase
+     *                The base DN of the search
+     * @param filter
+     *                The filter to use, null or empty filters will be
+     *                transformed to (objectClass=*)
+     * @param returningAttributes
+     *                The attributes to return, empty array indicates none,
+     *                null indicates all
+     * @param scope
+     *                the search scope, one of SCOPE_OBJECT, SCOPE_ONELEVEL,
+     *                SCOPE_SUBTREE
+     * @param countLimit
+     *                The count limit, 0 indicates no limit
+     * @param timeLimit
+     *                The time limit in ms, 0 indicats no limit
+     * @param aliasesDereferencingMethod
+     * @param referralsHandlingMethod
+     * @param initChildrenFlag
+     * @param initAliasFlag
+     * @param initObjectClasses
+     */
+    public Search( String searchName, IConnection conn, DN searchBase, String filter, String[] returningAttributes,
+        int scope, int countLimit, int timeLimit, int aliasesDereferencingMethod, int referralsHandlingMethod,
+        boolean initChildrenFlag, boolean initAliasAndReferralsFlag, Control[] controls )
+    {
+        this.connection = conn;
+        this.searchResults = null;
+
+        this.searchParameter = new SearchParameter();
+        this.searchParameter.setName( searchName );
+        this.searchParameter.setSearchBase( searchBase );
+        if ( filter == null || "".equals( filter ) ) { //$NON-NLS-1$
+            this.searchParameter.setFilter( FILTER_TRUE );
+        }
+        else
+        {
+            this.searchParameter.setFilter( filter );
+        }
+        if ( returningAttributes == null )
+        {
+            this.searchParameter.setReturningAttributes( new String[]
+                { ALL_USER_ATTRIBUTES } );
+        }
+        else
+        {
+            this.searchParameter.setReturningAttributes( returningAttributes );
+        }
+        this.searchParameter.setScope( scope );
+        this.searchParameter.setTimeLimit( timeLimit );
+        this.searchParameter.setCountLimit( countLimit );
+        this.searchParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod );
+        this.searchParameter.setReferralsHandlingMethod( referralsHandlingMethod );
+        this.searchParameter.setInitChildrenFlag( initChildrenFlag );
+        this.searchParameter.setInitAliasAndReferralFlag( initAliasAndReferralsFlag );
+        this.searchParameter.setControls( controls );
+        this.countLimitExceeded = false;
+    }
+
+
+    public URL getUrl()
+    {
+        return new URL( this );
+    }
+
+
+    private void fireSearchUpdated( int detail )
+    {
+        if ( this.getName() != null && !"".equals( this.getName() ) ) { //$NON-NLS-1$
+            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( this, detail ), this );
+        }
+    }
+
+
+    public boolean isInitChildrenFlag()
+    {
+        return this.searchParameter.isInitChildrenFlag();
+    }
+
+
+    public boolean isInitAliasAndReferralFlag()
+    {
+        return this.searchParameter.isInitAliasAndReferralFlag();
+    }
+
+
+    public Control[] getControls()
+    {
+        return this.searchParameter.getControls();
+    }
+
+
+    public int getCountLimit()
+    {
+        return this.searchParameter.getCountLimit();
+    }
+
+
+    public void setCountLimit( int countLimit )
+    {
+        this.searchParameter.setCountLimit( countLimit );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public String getFilter()
+    {
+        return this.searchParameter.getFilter();
+    }
+
+
+    public void setFilter( String filter )
+    {
+        if ( filter == null || "".equals( filter ) ) { //$NON-NLS-1$
+            this.searchParameter.setFilter( FILTER_TRUE );
+        }
+        else
+        {
+            this.searchParameter.setFilter( filter );
+        }
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public String[] getReturningAttributes()
+    {
+        return this.searchParameter.getReturningAttributes();
+    }
+
+
+    public void setReturningAttributes( String[] returningAttributes )
+    {
+        this.searchParameter.setReturningAttributes( returningAttributes );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public int getScope()
+    {
+        return this.searchParameter.getScope();
+    }
+
+
+    public void setScope( int scope )
+    {
+        this.searchParameter.setScope( scope );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public int getAliasesDereferencingMethod()
+    {
+        return this.searchParameter.getAliasesDereferencingMethod();
+    }
+
+
+    public void setAliasesDereferencingMethod( int aliasesDereferencingMethod )
+    {
+        this.searchParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public int getReferralsHandlingMethod()
+    {
+        return this.searchParameter.getReferralsHandlingMethod();
+    }
+
+
+    public void setReferralsHandlingMethod( int referralsHandlingMethod )
+    {
+        this.searchParameter.setReferralsHandlingMethod( referralsHandlingMethod );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public DN getSearchBase()
+    {
+        return this.searchParameter.getSearchBase();
+    }
+
+
+    public void setSearchBase( DN searchBase )
+    {
+        this.searchParameter.setSearchBase( searchBase );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public int getTimeLimit()
+    {
+        return this.searchParameter.getTimeLimit();
+    }
+
+
+    public void setTimeLimit( int timeLimit )
+    {
+        this.searchParameter.setTimeLimit( timeLimit );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public String getName()
+    {
+        return this.searchParameter.getName();
+    }
+
+
+    public void setName( String searchName )
+    {
+        this.searchParameter.setName( searchName );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_RENAMED );
+    }
+
+
+    public ISearchResult[] getSearchResults()
+    {
+        return searchResults;
+    }
+
+
+    public void setSearchResults( ISearchResult[] searchResults )
+    {
+        this.searchResults = searchResults;
+        if ( searchResults != null )
+        {
+            this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PERFORMED );
+        }
+    }
+
+
+    public boolean isCountLimitExceeded()
+    {
+        return this.countLimitExceeded;
+    }
+
+
+    public void setCountLimitExceeded( boolean countLimitExceeded )
+    {
+        this.countLimitExceeded = countLimitExceeded;
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PERFORMED );
+    }
+
+
+    public IConnection getConnection()
+    {
+        return connection;
+    }
+
+
+    public void setConnection( IConnection connection )
+    {
+        this.connection = connection;
+        this.searchParameter.setCountLimit( connection.getCountLimit() );
+        this.searchParameter.setTimeLimit( connection.getTimeLimit() );
+        this.searchParameter.setAliasesDereferencingMethod( connection.getAliasesDereferencingMethod() );
+        this.searchParameter.setReferralsHandlingMethod( connection.getReferralsHandlingMethod() );
+        this.fireSearchUpdated( SearchUpdateEvent.SEARCH_PARAMETER_UPDATED );
+    }
+
+
+    public String toString()
+    {
+        // return this.searchParameter.getFilter() +
+        // Integer.toString(this.searchResults!=null?this.searchResults.length:0);
+        return this.getName() + " (" + this.connection + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+
+    public Object clone()
+    {
+        return new Search( this.getName(), this.getConnection(), this.getSearchBase(), this.getFilter(), this
+            .getReturningAttributes(), this.getScope(), this.getCountLimit(), this.getTimeLimit(), this
+            .getAliasesDereferencingMethod(), this.getReferralsHandlingMethod(), this.isInitChildrenFlag(), this
+            .isInitAliasAndReferralFlag(), this.getControls() );
+    }
+
+
+    public SearchParameter getSearchParameter()
+    {
+        return searchParameter;
+    }
+
+
+    public void setSearchParameter( SearchParameter searchParameter )
+    {
+        this.searchParameter = searchParameter;
+    }
+
+
+    public Object getAdapter( Class adapter )
+    {
+        if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) )
+        {
+            return new LdapSearchPageScoreComputer();
+        }
+        if ( adapter == IConnection.class )
+        {
+            return this.connection;
+        }
+        if ( adapter == ISearch.class )
+        {
+            return this;
+        }
+        return null;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/SearchResult.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/SearchResult.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/SearchResult.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/SearchResult.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,132 @@
+/*
+ *  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.ldapstudio.browser.core.internal.model;
+
+
+import java.util.ArrayList;
+
+import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+
+
+public class SearchResult implements ISearchResult
+{
+
+    private static final long serialVersionUID = -5658803569872619432L;
+
+    private ISearch search;
+
+    private IEntry entry;
+
+
+    protected SearchResult()
+    {
+    }
+
+
+    public SearchResult( IEntry entry, ISearch search )
+    {
+        this.entry = entry;
+        this.search = search;
+    }
+
+
+    public DN getDn()
+    {
+        return this.entry.getDn();
+    }
+
+
+    public IAttribute[] getAttributes()
+    {
+        ArrayList attributeList = new ArrayList();
+        for ( int i = 0; i < this.search.getReturningAttributes().length; i++ )
+        {
+            if ( this.entry.getAttribute( this.search.getReturningAttributes()[i] ) != null )
+            {
+                attributeList.add( this.entry.getAttribute( this.search.getReturningAttributes()[i] ) );
+            }
+        }
+        return ( IAttribute[] ) attributeList.toArray( new IAttribute[attributeList.size()] );
+    }
+
+
+    public IAttribute getAttribute( String attributeDescription )
+    {
+        return this.entry.getAttribute( attributeDescription );
+    }
+
+
+    public AttributeHierachie getAttributeWithSubtypes( String attributeDescription )
+    {
+        return this.entry.getAttributeWithSubtypes( attributeDescription );
+    }
+
+
+    public IEntry getEntry()
+    {
+        return this.entry;
+    }
+
+
+    public Object getAdapter( Class adapter )
+    {
+        if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) )
+        {
+            return new LdapSearchPageScoreComputer();
+        }
+        if ( adapter == IConnection.class )
+        {
+            return this.getConnection();
+        }
+        if ( adapter == IEntry.class )
+        {
+            return this.getEntry();
+        }
+        return null;
+    }
+
+
+    public IConnection getConnection()
+    {
+        return this.search.getConnection();
+    }
+
+
+    public ISearch getSearch()
+    {
+        return this.search;
+    }
+
+
+    public void setSearch( ISearch search )
+    {
+        this.search = search;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Value.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Value.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Value.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/model/Value.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,285 @@
+/*
+ *  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.ldapstudio.browser.core.internal.model;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.RDNPart;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+
+
+/**
+ * Default implementation of IValue.
+ */
+public class Value implements IValue
+{
+
+    private static final long serialVersionUID = -9039209604742682740L;
+
+    private IAttribute attribute;
+
+    private Object rawValue;
+
+
+    protected Value()
+    {
+    }
+
+
+    public Value( IAttribute attribute, Object rawValue ) throws ModelModificationException
+    {
+        this.init( attribute, rawValue );
+
+        if ( rawValue == null )
+        {
+            throw new ModelModificationException( BrowserCoreMessages.model__empty_value );
+        }
+    }
+
+
+    public Value( IAttribute attribute ) throws ModelModificationException
+    {
+        this.init( attribute, null );
+    }
+
+
+    private void init( IAttribute attribute, Object rawValue ) throws ModelModificationException
+    {
+        if ( attribute == null )
+        {
+            throw new ModelModificationException( BrowserCoreMessages.model__empty_attribute );
+        }
+
+        this.attribute = attribute;
+
+        if ( rawValue == null )
+        {
+            if ( attribute.isString() )
+            {
+                this.rawValue = IValue.EMPTY_STRING_VALUE;
+            }
+            else
+            {
+                this.rawValue = IValue.EMPTY_BINARY_VALUE;
+            }
+        }
+        else
+        {
+            this.rawValue = rawValue;
+        }
+    }
+
+
+    public IAttribute getAttribute()
+    {
+        return this.attribute;
+    }
+
+
+    public Object getRawValue()
+    {
+        return this.rawValue;
+    }
+
+
+    public String getStringValue()
+    {
+
+        if ( this.rawValue == EMPTY_STRING_VALUE )
+        {
+            return EMPTY_STRING_VALUE.getStringValue();
+        }
+        else if ( this.rawValue == EMPTY_BINARY_VALUE )
+        {
+            return EMPTY_BINARY_VALUE.getStringValue();
+        }
+        else if ( this.rawValue instanceof String )
+        {
+            return ( String ) this.rawValue;
+        }
+        else if ( this.rawValue instanceof byte[] )
+        {
+            return LdifUtils.utf8decode( ( byte[] ) this.rawValue );
+        }
+        else
+        {
+            return "UNKNOWN";
+        }
+    }
+
+
+    public byte[] getBinaryValue()
+    {
+
+        if ( this.rawValue == EMPTY_STRING_VALUE )
+        {
+            return EMPTY_STRING_VALUE.getBinaryValue();
+        }
+        else if ( this.rawValue == EMPTY_BINARY_VALUE )
+        {
+            return EMPTY_BINARY_VALUE.getBinaryValue();
+        }
+        else if ( this.rawValue instanceof byte[] )
+        {
+            return ( byte[] ) this.rawValue;
+        }
+        else if ( this.rawValue instanceof String )
+        {
+            return LdifUtils.utf8encode( ( String ) this.rawValue );
+        }
+        else
+        {
+            return LdifUtils.utf8encode( "UNKNOWN" );
+        }
+    }
+
+
+    public boolean isString()
+    {
+        return this.rawValue == EMPTY_STRING_VALUE || this.attribute.isString();
+    }
+
+
+    public boolean isBinary()
+    {
+        return this.rawValue == EMPTY_BINARY_VALUE || this.attribute.isBinary();
+    }
+
+
+    public boolean isEmpty()
+    {
+        return this.rawValue == EMPTY_STRING_VALUE || this.rawValue == EMPTY_BINARY_VALUE;
+    }
+
+
+    public boolean equals( Object o )
+    {
+        // check argument
+        if ( o == null || !( o instanceof IValue ) )
+        {
+            return false;
+        }
+        IValue vc = ( IValue ) o;
+
+        // compare attributes
+        if ( !vc.getAttribute().equals( this.getAttribute() ) )
+        {
+            return false;
+        }
+
+        // compare values
+        if ( this.isEmpty() && vc.isEmpty() )
+        {
+            return true;
+        }
+        else if ( this.isBinary() && vc.isBinary() )
+        {
+            return Utils.equals( this.getBinaryValue(), vc.getBinaryValue() );
+        }
+        else if ( this.isString() && vc.isString() )
+        {
+            return ( this.getStringValue().equals( vc.getStringValue() ) );
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+
+    public int hashCode()
+    {
+        return rawValue.hashCode();
+    }
+
+
+    public String toString()
+    {
+        return attribute + ":" + ( this.isString() ? this.getStringValue() : "BINARY" ); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+
+    public Object getAdapter( Class adapter )
+    {
+        if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) )
+        {
+            return new LdapSearchPageScoreComputer();
+        }
+        if ( adapter == IConnection.class )
+        {
+            return this.getConnection();
+        }
+        if ( adapter == IEntry.class )
+        {
+            return this.getEntry();
+        }
+        if ( adapter == IAttribute.class )
+        {
+            return this.getAttribute();
+        }
+        if ( adapter == IValue.class )
+        {
+            return this;
+        }
+        return null;
+    }
+
+
+    public IConnection getConnection()
+    {
+        return this.attribute.getEntry().getConnection();
+    }
+
+
+    public IEntry getEntry()
+    {
+        return this.attribute.getEntry();
+    }
+
+
+    public IValue getValue()
+    {
+        return this;
+    }
+
+
+    public boolean isRdnPart()
+    {
+        RDNPart[] parts = getAttribute().getEntry().getRdn().getParts();
+        for ( int p = 0; p < parts.length; p++ )
+        {
+            if ( getAttribute().getDescription().equals( parts[p].getName() )
+                && getStringValue().equals( parts[p].getValue() ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/search/LdapSearchPageScoreComputer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/search/LdapSearchPageScoreComputer.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/search/LdapSearchPageScoreComputer.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/internal/search/LdapSearchPageScoreComputer.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,42 @@
+/*
+ *  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.ldapstudio.browser.core.internal.search;
+
+
+import org.eclipse.search.ui.ISearchPageScoreComputer;
+
+
+public class LdapSearchPageScoreComputer implements ISearchPageScoreComputer
+{
+
+    public static final String LDAP_SEARCH_PAGE_ID = "org.apache.directory.ldapstudio.browser.ui.search.SearchPage"; //$NON-NLS-1$
+
+
+    public int computeScore( String pageId, Object input )
+    {
+        if ( pageId.equals( LDAP_SEARCH_PAGE_ID ) )
+        {
+            return 90;
+        }
+        return 0;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractAsyncBulkJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractAsyncBulkJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractAsyncBulkJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractAsyncBulkJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,56 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+
+
+public abstract class AbstractAsyncBulkJob extends AbstractEclipseJob implements ModelModifier
+{
+
+    protected final void executeAsyncJob( ExtendedProgressMonitor pm ) throws ModelModificationException
+    {
+
+        EventRegistry.suspendEventFireingInCurrentThread();
+
+        try
+        {
+            executeBulkJob( pm );
+        }
+        finally
+        {
+            EventRegistry.resumeEventFireingInCurrentThread();
+        }
+
+        this.runNotification();
+
+    }
+
+
+    protected abstract void executeBulkJob( ExtendedProgressMonitor pm ) throws ModelModificationException;
+
+
+    protected abstract void runNotification();
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractEclipseJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractEclipseJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractEclipseJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractEclipseJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,296 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+
+public abstract class AbstractEclipseJob extends Job
+{
+
+    private IProgressMonitor externalProgressMonitor;
+
+    private IStatus externalResult;
+
+
+    protected AbstractEclipseJob()
+    {
+        super( "" ); //$NON-NLS-1$
+    }
+
+
+    protected abstract IConnection[] getConnections();
+
+
+    protected abstract void executeAsyncJob( ExtendedProgressMonitor monitor ) throws Exception;
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__error_occurred;
+    }
+
+
+    protected final IStatus run( IProgressMonitor ipm )
+    {
+
+        ExtendedProgressMonitor monitor = new ExtendedProgressMonitor( externalProgressMonitor == null ? ipm
+            : externalProgressMonitor );
+
+        // check if connection is opened
+        IConnection[] connections = getConnections();
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            IConnection connection = connections[i];
+            if ( !connection.isOpened() )
+            {
+                // monitor.reportError("Connection is closed");
+
+                EventRegistry.suspendEventFireingInCurrentThread();
+                try
+                {
+                    connection.open( monitor );
+                }
+                finally
+                {
+                    EventRegistry.resumeEventFireingInCurrentThread();
+                }
+            }
+        }
+
+        // execute job
+        if ( !monitor.errorsReported() )
+        {
+            try
+            {
+                executeAsyncJob( monitor );
+            }
+            catch ( Exception e )
+            {
+                monitor.reportError( e );
+            }
+            finally
+            {
+                monitor.done();
+                ipm.done();
+            }
+        }
+
+        // error handling
+        if ( monitor.isCanceled() )
+        {
+            // System.out.println("Job: CANCEL+CANCEL");
+            externalResult = Status.CANCEL_STATUS;
+            return Status.CANCEL_STATUS;
+        }
+        else if ( monitor.errorsReported() )
+        {
+            externalResult = monitor.getErrorStatus( getErrorMessage() );
+            if ( externalProgressMonitor == null )
+            {
+                // System.out.println("Job: ERROR+ERROR");
+                return externalResult;
+            }
+            else
+            {
+                // System.out.println("Job: ERROR+OK");
+                return Status.OK_STATUS;
+            }
+        }
+        else
+        {
+            // System.out.println("Job: OK+OK");
+            externalResult = Status.OK_STATUS;
+            return Status.OK_STATUS;
+        }
+    }
+
+
+    public void setExternalProgressMonitor( IProgressMonitor externalProgressMonitor )
+    {
+        this.externalProgressMonitor = externalProgressMonitor;
+    }
+
+
+    public IStatus getExternalResult()
+    {
+        return this.externalResult;
+    }
+
+
+    public final void execute()
+    {
+        setUser( true );
+        schedule();
+    }
+
+
+    protected abstract Object[] getLockedObjects();
+
+
+    public boolean shouldSchedule()
+    {
+
+        Object[] myLockedObjects = getLockedObjects();
+        String[] myLockedObjectsIdentifiers = getLockIdentifiers( myLockedObjects );
+
+        // TODO: read, write
+
+        Job[] jobs = Platform.getJobManager().find( null );
+        for ( int i = 0; i < jobs.length; i++ )
+        {
+            Job job = jobs[i];
+
+            // if(job instanceof AbstractEclipseJob) {
+            if ( job.getClass() == this.getClass() && job != this )
+            {
+
+                AbstractEclipseJob otherJob = ( AbstractEclipseJob ) job;
+                Object[] otherLockedObjects = otherJob.getLockedObjects();
+                String[] otherLockedObjectIdentifiers = getLockIdentifiers( otherLockedObjects );
+
+                for ( int j = 0; j < otherLockedObjectIdentifiers.length; j++ )
+                {
+                    String other = otherLockedObjectIdentifiers[j];
+                    for ( int k = 0; k < myLockedObjectsIdentifiers.length; k++ )
+                    {
+                        String my = myLockedObjectsIdentifiers[k];
+
+                        System.out.print( "other:" + other + ", my: " + my );
+
+                        if ( other.startsWith( my ) || my.startsWith( other ) )
+                        {
+                            System.out.println( ", shouldSchedule() = " + false );
+                            return false;
+                        }
+                        else
+                        {
+                            System.out.println();
+                        }
+
+                    }
+                }
+
+            }
+        }
+        return super.shouldSchedule();
+
+        // // Doesn't work
+        // Job[] jobs = getJobManager().find(null);
+        // for (int i = 0; i < jobs.length; i++) {
+        // Job job = jobs[i];
+        // if(job instanceof AbstractEclipseJob) {
+        // System.out.println("shouldSchedule() = " + false);
+        // return false;
+        // }
+        // }
+        // System.out.println("shouldSchedule() = " + true);
+        // return true;
+
+        // return super.shouldSchedule();
+    }
+
+
+    protected static String[] getLockIdentifiers( Object[] objects )
+    {
+        String[] identifiers = new String[objects.length];
+        for ( int i = 0; i < identifiers.length; i++ )
+        {
+            Object o = objects[i];
+            if ( o instanceof IConnection )
+            {
+                identifiers[i] = getLockIdentifier( ( IConnection ) o );
+            }
+            else if ( o instanceof IEntry )
+            {
+                identifiers[i] = getLockIdentifier( ( IEntry ) o );
+            }
+            else if ( o instanceof IAttribute )
+            {
+                identifiers[i] = getLockIdentifier( ( IAttribute ) o );
+            }
+            else if ( o instanceof IValue )
+            {
+                identifiers[i] = getLockIdentifier( ( IValue ) o );
+            }
+            else if ( o instanceof ISearch )
+            {
+                identifiers[i] = getLockIdentifier( ( ISearch ) o );
+            }
+            else
+            {
+                identifiers[i] = getLockIdentifier( objects[i] );
+            }
+        }
+        return identifiers;
+    }
+
+
+    protected static String getLockIdentifier( IConnection connection )
+    {
+        return connection.getHost() + ":" + connection.getPort();
+    }
+
+
+    protected static String getLockIdentifier( IEntry entry )
+    {
+        return getLockIdentifier( entry.getConnection() ) + "_"
+            + new StringBuffer( entry.getDn().toString() ).reverse().toString();
+    }
+
+
+    protected static String getLockIdentifier( IAttribute attribute )
+    {
+        return getLockIdentifier( attribute.getEntry() ) + "_" + attribute.getDescription();
+    }
+
+
+    protected static String getLockIdentifier( IValue value )
+    {
+        return getLockIdentifier( value.getAttribute() ) + "_" + value.getStringValue();
+    }
+
+
+    protected static String getLockIdentifier( ISearch search )
+    {
+        return getLockIdentifier( search.getConnection() ) + "_"
+            + new StringBuffer( search.getSearchBase().toString() ).reverse().toString();
+    }
+
+
+    protected static String getLockIdentifier( Object object )
+    {
+        return object.toString();
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractModificationJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractModificationJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractModificationJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/AbstractModificationJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,74 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+
+
+public abstract class AbstractModificationJob extends AbstractAsyncBulkJob implements ModelModifier
+{
+
+    protected void executeBulkJob( ExtendedProgressMonitor pm ) throws ModelModificationException
+    {
+
+        try
+        {
+            this.executeAsyncModificationJob( pm );
+        }
+        finally
+        {
+            // reload affected attributes
+            if ( !getModifiedEntry().getConnection().isSuspended() )
+            {
+                String[] affectedAttributeNames = getAffectedAttributeNames();
+                InitializeAttributesJob.initializeAttributes( getModifiedEntry(), affectedAttributeNames, pm );
+            }
+        }
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { getModifiedEntry().getConnection() };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        return new Object[]
+            { getModifiedEntry() };
+    }
+
+
+    protected abstract void executeAsyncModificationJob( ExtendedProgressMonitor pm ) throws ModelModificationException;
+
+
+    protected abstract IEntry getModifiedEntry();
+
+
+    protected abstract String[] getAffectedAttributeNames();
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckBindJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckBindJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckBindJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckBindJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,82 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+
+
+public class CheckBindJob extends AbstractAsyncBulkJob
+{
+
+    private IConnection connection;
+
+
+    public CheckBindJob( IConnection connection )
+    {
+        this.connection = connection;
+        setName( BrowserCoreMessages.jobs__check_bind_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[0];
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection );
+        return l.toArray();
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__check_bind_task, 4 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        connection.bind( monitor );
+
+        connection.close();
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__check_bind_error;
+    }
+
+
+    protected void runNotification()
+    {
+
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckNetworkParameterJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckNetworkParameterJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckNetworkParameterJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CheckNetworkParameterJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,76 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+
+
+public class CheckNetworkParameterJob extends AbstractEclipseJob
+{
+
+    private IConnection connection;
+
+
+    public CheckNetworkParameterJob( IConnection connection )
+    {
+        this.connection = connection;
+        setName( BrowserCoreMessages.jobs__check_network_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[0];
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection );
+        return l.toArray();
+    }
+
+
+    protected void executeAsyncJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__check_network_task, 3 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        connection.connect( monitor );
+
+        connection.close();
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__check_network_error;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CopyEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CopyEntriesJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CopyEntriesJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CopyEntriesJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,313 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.ChildrenInitializedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Entry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Search;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Value;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.NameException;
+import org.apache.directory.ldapstudio.browser.core.model.RDN;
+import org.apache.directory.ldapstudio.browser.core.model.RDNPart;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
+
+
+public class CopyEntriesJob extends AbstractAsyncBulkJob
+{
+
+    private IEntry parent;
+
+    private IEntry[] entriesToCopy;
+
+    private int scope;
+
+
+    public CopyEntriesJob( final IEntry parent, final IEntry[] entriesToCopy, int scope )
+    {
+        this.parent = parent;
+        this.entriesToCopy = entriesToCopy;
+        this.scope = scope;
+        setName( entriesToCopy.length == 1 ? BrowserCoreMessages.jobs__copy_entries_name_1
+            : BrowserCoreMessages.jobs__copy_entries_name_n );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { parent.getConnection() };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( parent );
+        l.addAll( Arrays.asList( entriesToCopy ) );
+        return l.toArray();
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( entriesToCopy.length == 1 ? BrowserCoreMessages.bind(
+            BrowserCoreMessages.jobs__copy_entries_task_1, new String[]
+                { entriesToCopy[0].getDn().toString(), parent.getDn().toString() } ) : BrowserCoreMessages.bind(
+            BrowserCoreMessages.jobs__copy_entries_task_n, new String[]
+                { Integer.toString( entriesToCopy.length ), parent.getDn().toString() } ), 2 + entriesToCopy.length );
+
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        if ( scope == ISearch.SCOPE_OBJECT || scope == ISearch.SCOPE_ONELEVEL || scope == ISearch.SCOPE_SUBTREE )
+        {
+            int num = 0;
+            for ( int i = 0; !monitor.isCanceled() && i < entriesToCopy.length; i++ )
+            {
+                IEntry entryToCopy = entriesToCopy[i];
+
+                if ( scope == ISearch.SCOPE_OBJECT
+                    || !parent.getDn().toString().endsWith( entryToCopy.getDn().toString() ) )
+                {
+                    num = this.copyEntryRecursive( entryToCopy, parent, scope, num, monitor );
+                }
+                else
+                {
+                    monitor.reportError( BrowserCoreMessages.jobs__copy_entries_source_and_target_are_equal );
+                }
+            }
+        }
+    }
+
+
+    protected void runNotification()
+    {
+        EventRegistry.fireEntryUpdated( new ChildrenInitializedEvent( parent, parent.getConnection() ), this );
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return entriesToCopy.length == 1 ? BrowserCoreMessages.jobs__copy_entries_error_1
+            : BrowserCoreMessages.jobs__copy_entries_error_n;
+    }
+
+
+    private int copyEntryRecursive( IEntry entryToCopy, IEntry parent, int scope, int num,
+        ExtendedProgressMonitor monitor )
+    {
+        try
+        {
+            SearchParameter param = new SearchParameter();
+            param.setSearchBase( entryToCopy.getDn() );
+            param.setFilter( ISearch.FILTER_TRUE );
+            param.setScope( ISearch.SCOPE_OBJECT );
+            param.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
+            param.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
+            param.setReturningAttributes( new String[]
+                { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
+            ISearch search = new Search( entryToCopy.getConnection(), param );
+            entryToCopy.getConnection().search( search, monitor );
+
+            ISearchResult[] srs = search.getSearchResults();
+            if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
+            {
+                entryToCopy = srs[0].getEntry();
+                IAttribute[] attributesToCopy = entryToCopy.getAttributes();
+
+                // create new entry
+                RDN rdn = entryToCopy.getRdn();
+                IEntry newEntry = new Entry( parent, rdn, parent.getConnection() );
+
+                // change RDN if entry already exists
+                ExtendedProgressMonitor testMonitor = new ExtendedProgressMonitor( monitor );
+                IEntry testEntry = parent.getConnection().getEntry( 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, parent.getConnection() );
+                    testEntry = parent.getConnection().getEntry( 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, parent.getConnection() );
+                        testEntry = parent.getConnection().getEntry( newEntry.getDn(), testMonitor );
+                    }
+                }
+
+                // copy attributes
+                for ( int i = 0; i < attributesToCopy.length; i++ )
+                {
+                    IAttribute attributeToCopy = attributesToCopy[i];
+
+                    if ( SchemaUtils.isModifyable( attributeToCopy.getAttributeTypeDescription() )
+                        || IAttribute.REFERRAL_ATTRIBUTE.equalsIgnoreCase( attributeToCopy.getDescription() ) )
+                    {
+                        IAttribute newAttribute = new Attribute( newEntry, attributeToCopy.getDescription() );
+                        newEntry.addAttribute( newAttribute, newEntry.getConnection() );
+                        IValue[] valuesToCopy = attributeToCopy.getValues();
+                        for ( int j = 0; j < valuesToCopy.length; j++ )
+                        {
+                            IValue valueToCopy = valuesToCopy[j];
+                            IValue newValue = new Value( newAttribute, valueToCopy.getRawValue() );
+                            newAttribute.addValue( newValue, newEntry.getConnection() );
+                        }
+                    }
+                }
+
+                // check if RDN attributes ar present
+                RDN newRdn = newEntry.getRdn();
+                RDNPart[] oldRdnParts = rdn.getParts();
+                for ( int i = 0; i < oldRdnParts.length; i++ )
+                {
+                    RDNPart part = oldRdnParts[i];
+                    IAttribute rdnAttribute = newEntry.getAttribute( part.getName() );
+                    if ( rdnAttribute != null )
+                    {
+                        IValue[] values = rdnAttribute.getValues();
+                        for ( int ii = 0; ii < values.length; ii++ )
+                        {
+                            if ( part.getUnencodedValue().equals( values[ii].getRawValue() ) )
+                            {
+                                rdnAttribute.deleteValue( values[ii], newEntry.getConnection() );
+                            }
+                            if ( rdnAttribute.getValueSize() == 0 )
+                            {
+                                newEntry.deleteAttribute( rdnAttribute, newEntry.getConnection() );
+                            }
+                        }
+                    }
+                }
+                RDNPart[] newRdnParts = newRdn.getParts();
+                for ( int i = 0; i < newRdnParts.length; i++ )
+                {
+                    RDNPart part = newRdnParts[i];
+                    IAttribute rdnAttribute = newEntry.getAttribute( part.getName() );
+                    if ( rdnAttribute == null )
+                    {
+                        rdnAttribute = new Attribute( newEntry, part.getName() );
+                        newEntry.addAttribute( rdnAttribute, newEntry.getConnection() );
+                        rdnAttribute.addValue( new Value( rdnAttribute, part.getUnencodedValue() ), newEntry
+                            .getConnection() );
+                    }
+                    else
+                    {
+                        boolean mustAdd = true;
+                        IValue[] values = rdnAttribute.getValues();
+                        for ( int ii = 0; ii < values.length; ii++ )
+                        {
+                            if ( part.getUnencodedValue().equals( values[ii].getStringValue() ) )
+                            {
+                                mustAdd = false;
+                                break;
+                            }
+                        }
+                        if ( mustAdd )
+                        {
+                            rdnAttribute.addValue( new Value( rdnAttribute, part.getUnencodedValue() ), newEntry
+                                .getConnection() );
+                        }
+                    }
+                }
+
+                newEntry.getConnection().create( newEntry, monitor );
+                newEntry.getParententry().addChild( newEntry, newEntry.getConnection() );
+                newEntry.setHasChildrenHint( false, newEntry.getConnection() );
+
+                num++;
+                monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__copied_n_entries,
+                    new String[]
+                        { Integer.toString( num ) } ) );
+
+                // check for children
+                if ( !monitor.isCanceled() && ( scope == ISearch.SCOPE_ONELEVEL || scope == ISearch.SCOPE_SUBTREE ) )
+                {
+
+                    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.getConnection(), subParam );
+                    entryToCopy.getConnection().search( 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];
+                            IEntry childEntry = subSearchResult.getEntry();
+
+                            if ( scope == ISearch.SCOPE_ONELEVEL )
+                            {
+                                num = this
+                                    .copyEntryRecursive( childEntry, newEntry, ISearch.SCOPE_OBJECT, num, monitor );
+                            }
+                            else if ( scope == ISearch.SCOPE_SUBTREE )
+                            {
+                                num = this.copyEntryRecursive( childEntry, newEntry, ISearch.SCOPE_SUBTREE, num,
+                                    monitor );
+                            }
+                        }
+
+                    }
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+        return num;
+    }
+
+
+    private RDN getNewRdn( RDN rdn, String newRdnValue ) throws NameException
+    {
+        String[] names = rdn.getNames();
+        String[] values = rdn.getValues();
+        values[0] = newRdnValue;
+        RDN newRdn = new RDN( names, values, true );
+        return newRdn;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateEntryJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateEntryJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateEntryJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateEntryJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,119 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.EntryAddedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+
+
+public class CreateEntryJob extends AbstractAsyncBulkJob
+{
+
+    private IEntry[] entriesToCreate;
+
+    private IEntry[] createdEntries;
+
+
+    public CreateEntryJob( IEntry[] entriesToCreate )
+    {
+        this.entriesToCreate = entriesToCreate;
+        createdEntries = new IEntry[entriesToCreate.length];
+        setName( entriesToCreate.length == 1 ? BrowserCoreMessages.jobs__create_entry_name_1
+            : BrowserCoreMessages.jobs__create_entry_name_n );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        IConnection[] connections = new IConnection[entriesToCreate.length];
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            connections[i] = entriesToCreate[i].getConnection();
+        }
+        return connections;
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.addAll( Arrays.asList( entriesToCreate ) );
+        return l.toArray();
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( entriesToCreate.length == 1 ? BrowserCoreMessages.bind(
+            BrowserCoreMessages.jobs__create_entry_task_1, new String[]
+                { entriesToCreate[0].getDn().toString() } ) : BrowserCoreMessages.bind(
+            BrowserCoreMessages.jobs__create_entry_task_n, new String[]
+                { Integer.toString( entriesToCreate.length ) } ), 2 + entriesToCreate.length );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        for ( int i = 0; !monitor.isCanceled() && i < entriesToCreate.length; i++ )
+        {
+            IEntry entryToCreate = entriesToCreate[i];
+
+            entryToCreate.getConnection().create( entryToCreate, monitor );
+
+            if ( !monitor.errorsReported() )
+            {
+                createdEntries[i] = entryToCreate.getConnection().getEntry( entryToCreate.getDn(), monitor );
+                // createdEntries[i].getParententry().addChild(entry, this);
+                createdEntries[i].setHasChildrenHint( false, this );
+            }
+
+            monitor.worked( 1 );
+        }
+    }
+
+
+    protected void runNotification()
+    {
+        for ( int i = 0; i < createdEntries.length; i++ )
+        {
+            if ( createdEntries[i] != null )
+            {
+                EventRegistry.fireEntryUpdated( new EntryAddedEvent( createdEntries[i].getConnection(),
+                    createdEntries[i], this ), this );
+            }
+        }
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return entriesToCreate.length == 1 ? BrowserCoreMessages.jobs__create_entry_error_1
+            : BrowserCoreMessages.jobs__create_entry_error_n;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateValuesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateValuesJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateValuesJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/CreateValuesJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,139 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.ValueAddedEvent;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Value;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+
+
+public class CreateValuesJob extends AbstractModificationJob
+{
+
+    private IEntry entry;
+
+    private String[] attributeDescriptions;
+
+    private Object[] rawValues;
+
+    private ValueAddedEvent event;
+
+
+    public CreateValuesJob( IEntry entry, String[] attributeDescriptions, Object[] rawValues )
+    {
+        this.entry = entry;
+        this.attributeDescriptions = attributeDescriptions;
+        this.rawValues = rawValues;
+
+        setName( rawValues.length == 1 ? BrowserCoreMessages.jobs__create_values_name_1
+            : BrowserCoreMessages.jobs__create_values_name_n );
+    }
+
+
+    public CreateValuesJob( IAttribute attribute, Object newValue )
+    {
+        this( attribute.getEntry(), new String[]
+            { attribute.getDescription() }, new Object[]
+            { newValue } );
+    }
+
+
+    protected void executeAsyncModificationJob( ExtendedProgressMonitor monitor ) throws ModelModificationException
+    {
+
+        monitor.beginTask( rawValues.length == 1 ? BrowserCoreMessages.jobs__create_values_task_1
+            : BrowserCoreMessages.jobs__create_values_task_n, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        IValue[] newValues = new IValue[rawValues.length];
+        for ( int i = 0; i < newValues.length; i++ )
+        {
+            IAttribute attribute = entry.getAttribute( attributeDescriptions[i] );
+            if ( attribute == null )
+            {
+                // String[] possibleAttributeNames =
+                // entry.getSubschema().getAllAttributeNames();
+                // if(!Arrays.asList(possibleAttributeNames).contains(attributeNames[i]))
+                // {
+                // throw new ModelModificationException("Attribute
+                // "+attributeNames[i]+" is not in subschema");
+                // }
+                attribute = new Attribute( entry, attributeDescriptions[i] );
+                entry.addAttribute( attribute, this );
+            }
+
+            newValues[i] = new Value( attribute, rawValues[i] );
+            attribute.addValue( newValues[i], this );
+
+            if ( this.event == null )
+            {
+                event = new ValueAddedEvent( entry.getConnection(), entry, attribute, newValues[i], this );
+            }
+        }
+
+        entry.getConnection().create( newValues, monitor );
+    }
+
+
+    protected IEntry getModifiedEntry()
+    {
+        return entry;
+    }
+
+
+    protected String[] getAffectedAttributeNames()
+    {
+        Set affectedAttributeNameSet = new HashSet();
+        for ( int i = 0; i < attributeDescriptions.length; i++ )
+        {
+            affectedAttributeNameSet.add( attributeDescriptions[i] );
+        }
+        return ( String[] ) affectedAttributeNameSet.toArray( new String[affectedAttributeNameSet.size()] );
+    }
+
+
+    protected void runNotification()
+    {
+        if ( this.event != null )
+        {
+            EventRegistry.fireEntryUpdated( this.event, this );
+        }
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return attributeDescriptions.length == 1 ? BrowserCoreMessages.jobs__create_values_error_1
+            : BrowserCoreMessages.jobs__create_values_error_n;
+    }
+
+}



Mime
View raw message