directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r584941 - in /directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core: internal/model/ jobs/ model/
Date Mon, 15 Oct 2007 22:06:26 GMT
Author: seelmann
Date: Mon Oct 15 15:06:24 2007
New Revision: 584941

URL: http://svn.apache.org/viewvc?rev=584941&view=rev
Log:
DIRSTUDIO-123: Moved delete attribute code from BrowserConnection to DeleteAttributesValueJob.

Modified:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionModifyHandler.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteAttributesValueJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameValuesJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java?rev=584941&r1=584940&r2=584941&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
Mon Oct 15 15:06:24 2007
@@ -49,7 +49,6 @@
 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.IValue;
 import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
 import org.apache.directory.studio.ldapbrowser.core.model.NameException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
@@ -850,18 +849,6 @@
     public void delete( IEntry entry, StudioProgressMonitor monitor )
     {
         modifyHandler.delete( entry, monitor );
-    }
-
-
-    public void delete( IValue[] valuesToDelete, StudioProgressMonitor monitor )
-    {
-        modifyHandler.delete( valuesToDelete, monitor );
-    }
-
-
-    public void delete( IAttribute[] attriubtesToDelete, StudioProgressMonitor monitor )
-    {
-        modifyHandler.delete( attriubtesToDelete, monitor );
     }
 
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionModifyHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionModifyHandler.java?rev=584941&r1=584940&r2=584941&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionModifyHandler.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionModifyHandler.java
Mon Oct 15 15:06:24 2007
@@ -80,68 +80,6 @@
     }
 
 
-    void delete( IValue[] valuesToDelete, StudioProgressMonitor monitor )
-    {
-        try
-        {
-            for ( int i = 0; !monitor.isCanceled() && i < valuesToDelete.length;
i++ )
-            {
-                LdifChangeModifyRecord cmr = new LdifChangeModifyRecord( LdifDnLine.create(
valuesToDelete[i]
-                    .getAttribute().getEntry().getDn().toString() ) );
-                ModelConverter.addControls( cmr, valuesToDelete[i].getAttribute().getEntry()
);
-                cmr.setChangeType( LdifChangeTypeLine.createModify() );
-
-                LdifModSpec modSpec = LdifModSpec.createDelete( valuesToDelete[i].getAttribute().getDescription()
);
-                if ( valuesToDelete[i].isString() )
-                {
-                    modSpec.addAttrVal( LdifAttrValLine.create( valuesToDelete[i].getAttribute().getDescription(),
-                        valuesToDelete[i].getStringValue() ) );
-                }
-                else
-                {
-                    modSpec.addAttrVal( LdifAttrValLine.create( valuesToDelete[i].getAttribute().getDescription(),
-                        valuesToDelete[i].getBinaryValue() ) );
-                }
-                modSpec.finish( LdifModSpecSepLine.create() );
-                cmr.addModSpec( modSpec );
-                cmr.finish( LdifSepLine.create() );
-
-                this.applyModificationAndLog( cmr, monitor );
-            }
-        }
-        catch ( ConnectionException e )
-        {
-            monitor.reportError( e );
-        }
-    }
-
-
-    void delete( IAttribute[] attriubtesToDelete, StudioProgressMonitor monitor )
-    {
-        try
-        {
-            for ( int i = 0; !monitor.isCanceled() && i < attriubtesToDelete.length;
i++ )
-            {
-                LdifChangeModifyRecord cmr = new LdifChangeModifyRecord( LdifDnLine.create(
attriubtesToDelete[i]
-                    .getEntry().getDn().toString() ) );
-                ModelConverter.addControls( cmr, attriubtesToDelete[i].getEntry() );
-                cmr.setChangeType( LdifChangeTypeLine.createModify() );
-
-                LdifModSpec modSpec = LdifModSpec.createDelete( attriubtesToDelete[i].getDescription()
);
-                modSpec.finish( LdifModSpecSepLine.create() );
-                cmr.addModSpec( modSpec );
-                cmr.finish( LdifSepLine.create() );
-
-                this.applyModificationAndLog( cmr, monitor );
-            }
-        }
-        catch ( ConnectionException e )
-        {
-            monitor.reportError( e );
-        }
-    }
-
-
     void delete( IEntry entry, StudioProgressMonitor monitor )
     {
         try

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java?rev=584941&r1=584940&r2=584941&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
Mon Oct 15 15:06:24 2007
@@ -59,18 +59,6 @@
     }
 
 
-    public void delete( IValue[] valuesToDelete, StudioProgressMonitor monitor )
-    {
-
-    }
-
-
-    public void delete( IAttribute[] attriubtesToDelete, StudioProgressMonitor monitor )
-    {
-
-    }
-
-
     public boolean existsEntry( DN dn, StudioProgressMonitor monitor )
     {
         return false;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteAttributesValueJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteAttributesValueJob.java?rev=584941&r1=584940&r2=584941&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteAttributesValueJob.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteAttributesValueJob.java
Mon Oct 15 15:06:24 2007
@@ -21,136 +21,262 @@
 package org.apache.directory.studio.ldapbrowser.core.jobs;
 
 
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
+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.AttributeDeletedEvent;
+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.ValueDeletedEvent;
 import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
 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.ModelModificationException;
 
 
+/**
+ * Job to delete attributes and values from an entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class DeleteAttributesValueJob extends AbstractAttributeModificationJob
 {
 
+    /** The entry. */
     private IEntry entry;
 
-    private IAttribute[] attributes;
-
-    private IValue[] values;
+    /** The attributes to delete. */
+    private IAttribute[] attributesToDelete;
 
-    private EntryModificationEvent event;
+    /** The values to delete. */
+    private IValue[] valuesToDelete;
 
+    /** The deleted attributes. */
+    private IAttribute[] deletedAttributes;
 
-    public DeleteAttributesValueJob( IAttribute attributes[], IValue[] values )
+    /** The deleted values. */
+    private IValue[] deletedValues;
+
+
+    /**
+     * Creates a new instance of DeleteAttributesValueJob.
+     * 
+     * @param attributesToDelete the attributes to delete
+     * @param valuesToDelete the values to delete
+     */
+    public DeleteAttributesValueJob( IAttribute attributesToDelete[], IValue[] valuesToDelete
)
     {
-        this.attributes = attributes;
-        this.values = values;
-        for ( int i = 0; attributes != null && i < attributes.length; i++ )
+        this.attributesToDelete = attributesToDelete;
+        this.valuesToDelete = valuesToDelete;
+        for ( int i = 0; attributesToDelete != null && i < attributesToDelete.length;
i++ )
         {
             if ( this.entry == null )
             {
-                this.entry = attributes[i].getEntry();
+                this.entry = attributesToDelete[i].getEntry();
             }
         }
-        for ( int i = 0; values != null && i < values.length; i++ )
+        for ( int i = 0; valuesToDelete != null && i < valuesToDelete.length;
i++ )
         {
             if ( this.entry == null )
             {
-                this.entry = values[i].getAttribute().getEntry();
+                this.entry = valuesToDelete[i].getAttribute().getEntry();
             }
         }
 
-        setName( attributes.length + values.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_name_1
+        setName( attributesToDelete.length + valuesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_name_1
             : BrowserCoreMessages.jobs__delete_attributes_name_n );
     }
 
 
-    public DeleteAttributesValueJob( AttributeHierarchy ah )
+    /**
+     * Creates a new instance of DeleteAttributesValueJob.
+     * 
+     * @param attributeHierarchyToDelete the attribute hierarchy to delete
+     */
+    public DeleteAttributesValueJob( AttributeHierarchy attributeHierarchyToDelete )
     {
-        this( ah.getAttributes(), new IValue[0] );
+        this( attributeHierarchyToDelete.getAttributes(), new IValue[0] );
     }
 
 
-    public DeleteAttributesValueJob( IValue value )
+    /**
+     * Creates a new instance of DeleteAttributesValueJob.
+     * 
+     * @param valueToDelete the value to delete
+     */
+    public DeleteAttributesValueJob( IValue valueToDelete )
     {
         this( new IAttribute[0], new IValue[]
-            { value } );
+            { valueToDelete } );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#executeAttributeModificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
     protected void executeAttributeModificationJob( StudioProgressMonitor monitor ) throws
ModelModificationException
     {
-
-        monitor.beginTask( attributes.length + values.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_task_1
-            : BrowserCoreMessages.jobs__delete_attributes_task_n, 2 );
+        monitor.beginTask(
+            attributesToDelete.length + valuesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_task_1
+                : BrowserCoreMessages.jobs__delete_attributes_task_n, 2 );
         monitor.reportProgress( " " ); //$NON-NLS-1$
         monitor.worked( 1 );
 
-        for ( int i = 0; attributes != null && i < attributes.length; i++ )
-        {
-            attributes[i].getEntry().deleteAttribute( attributes[i] );
-        }
-        for ( int i = 0; values != null && i < values.length; i++ )
-        {
-            values[i].getAttribute().deleteValue( values[i] );
-        }
-
-        entry.getBrowserConnection().delete( attributes, monitor );
-        entry.getBrowserConnection().delete( values, monitor );
+        deleteAttributesAndValues( entry.getBrowserConnection(), entry, attributesToDelete,
valuesToDelete, monitor );
 
-        if ( values.length > 0 )
-        {
-            this.event = new ValueDeletedEvent( entry.getBrowserConnection(), entry, values[0].getAttribute(),
values[0] );
-        }
-        else if ( attributes.length > 0 )
+        if ( !monitor.errorsReported() )
         {
-            this.event = new AttributeDeletedEvent( entry.getBrowserConnection(), entry,
attributes[0] );
+            deletedValues = valuesToDelete;
+            deletedAttributes = attributesToDelete;
         }
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#getModifiedEntry()
+     */
     protected IEntry getModifiedEntry()
     {
         return entry;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#getAffectedAttributeDescriptions()
+     */
     protected String[] getAffectedAttributeDescriptions()
     {
-        Set affectedAttributeNameSet = new HashSet();
-        for ( int i = 0; i < attributes.length; i++ )
+        Set<String> affectedAttributeNameSet = new HashSet<String>();
+        for ( int i = 0; i < attributesToDelete.length; i++ )
         {
-            affectedAttributeNameSet.add( attributes[i].getDescription() );
+            affectedAttributeNameSet.add( attributesToDelete[i].getDescription() );
         }
-        for ( int i = 0; i < values.length; i++ )
+        for ( int i = 0; i < valuesToDelete.length; i++ )
         {
-            affectedAttributeNameSet.add( values[i].getAttribute().getDescription() );
+            affectedAttributeNameSet.add( valuesToDelete[i].getAttribute().getDescription()
);
         }
-        return ( String[] ) affectedAttributeNameSet.toArray( new String[affectedAttributeNameSet.size()]
);
+        return affectedAttributeNameSet.toArray( new String[affectedAttributeNameSet.size()]
);
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
     protected void runNotification()
     {
-        if ( this.event != null )
+        EntryModificationEvent event;
+
+        if ( deletedValues != null && deletedValues.length > 0 )
+        {
+            event = new ValueDeletedEvent( entry.getBrowserConnection(), entry, deletedValues[0].getAttribute(),
+                deletedValues[0] );
+        }
+        if ( deletedAttributes != null && deletedAttributes.length > 0 )
+        {
+            event = new AttributeDeletedEvent( entry.getBrowserConnection(), entry, deletedAttributes[0]
);
+        }
+        else
         {
-            EventRegistry.fireEntryUpdated( this.event, this );
+            event = new AttributesInitializedEvent( entry );
         }
+
+        EventRegistry.fireEntryUpdated( event, this );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
     protected String getErrorMessage()
     {
-        return attributes.length + values.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_error_1
+        return attributesToDelete.length + valuesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_error_1
             : BrowserCoreMessages.jobs__delete_attributes_error_n;
+    }
+
+
+    /**
+     * Delete attributes and values.
+     * 
+     * @param browserConnection the browser connection
+     * @param entry the entry
+     * @param attributesToDelete the attributes to delete
+     * @param valuesToDelete the values to delete
+     * @param monitor the progress monitor
+     * 
+     * @throws ModelModificationException the model modification exception
+     */
+    static void deleteAttributesAndValues( IBrowserConnection browserConnection, IEntry entry,
+        IAttribute[] attributesToDelete, IValue[] valuesToDelete, StudioProgressMonitor monitor
)
+        throws ModelModificationException
+    {
+        if ( browserConnection.getConnection() != null )
+        {
+            // dn
+            String dn = entry.getDn().toString();
+
+            // modification items
+            List<ModificationItem> modificationItems = new ArrayList<ModificationItem>();
+            if ( attributesToDelete != null )
+            {
+                for ( IAttribute attribute : attributesToDelete )
+                {
+                    BasicAttribute ba = new BasicAttribute( attribute.getDescription() );
+                    ModificationItem modificationItem = new ModificationItem( DirContext.REMOVE_ATTRIBUTE,
ba );
+                    modificationItems.add( modificationItem );
+                }
+            }
+            if ( valuesToDelete != null )
+            {
+                for ( IValue value : valuesToDelete )
+                {
+                    BasicAttribute ba = new BasicAttribute( value.getAttribute().getDescription(),
value.getRawValue() );
+                    ModificationItem modificationItem = new ModificationItem( DirContext.REMOVE_ATTRIBUTE,
ba );
+                    modificationItems.add( modificationItem );
+                }
+            }
+
+            // controls
+            Control[] controls = null;
+            if ( entry.isReferral() )
+            {
+                controls = new Control[]
+                    { new ManageReferralControl() };
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().modifyAttributes(
dn,
+                modificationItems.toArray( new ModificationItem[modificationItems.size()]
), controls, monitor );
+        }
+        else
+        {
+            if ( attributesToDelete != null )
+            {
+                for ( IAttribute attribute : attributesToDelete )
+                {
+                    attribute.getEntry().deleteAttribute( attribute );
+                }
+            }
+            if ( valuesToDelete != null )
+            {
+                for ( IValue value : valuesToDelete )
+                {
+                    value.getAttribute().deleteValue( value );
+                }
+            }
+        }
     }
 
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameValuesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameValuesJob.java?rev=584941&r1=584940&r2=584941&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameValuesJob.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameValuesJob.java
Mon Oct 15 15:06:24 2007
@@ -111,7 +111,8 @@
         CreateValuesJob.createValues( entry.getBrowserConnection(), entry, newValues, monitor
);
         if ( !monitor.errorsReported() )
         {
-            entry.getBrowserConnection().delete( oldValues, monitor );
+            DeleteAttributesValueJob.deleteAttributesAndValues( entry.getBrowserConnection(),
entry, null, oldValues,
+                monitor );
         }
         if ( !monitor.errorsReported() )
         {

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java?rev=584941&r1=584940&r2=584941&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
Mon Oct 15 15:06:24 2007
@@ -157,12 +157,6 @@
     public abstract void delete( IEntry entryToDelete, StudioProgressMonitor monitor );
 
 
-    public abstract void delete( IValue valuesToDelete[], StudioProgressMonitor monitor );
-
-
-    public abstract void delete( IAttribute attriubtesToDelete[], StudioProgressMonitor monitor
);
-
-
     public abstract void importLdif( LdifEnumeration enumeration, Writer logWriter, boolean
continueOnError,
         StudioProgressMonitor monitor );
 



Mime
View raw message