directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r584601 - in /directory/studio/trunk: studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ studio-ldapbrowser-co...
Date Sun, 14 Oct 2007 20:58:09 GMT
Author: seelmann
Date: Sun Oct 14 13:58:09 2007
New Revision: 584601

URL: http://svn.apache.org/viewvc?rev=584601&view=rev
Log:
DIRSTUDIO-123: Moved modify value code from BrowserConnection to ModifyValueJob.

Modified:
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/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/ModifyValueJob.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-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java?rev=584601&r1=584600&r2=584601&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java
Sun Oct 14 13:58:09 2007
@@ -620,7 +620,7 @@
             }
             else
             {
-                new ModifyValueJob( attribute, oldValue, newRawValue ).execute();
+                new ModifyValueJob( oldValue, newRawValue ).execute();
             }
         }
     }

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=584601&r1=584600&r2=584601&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
Sun Oct 14 13:58:09 2007
@@ -541,12 +541,6 @@
     }
 
 
-    public void modify( IValue oldValue, IValue newValue, StudioProgressMonitor monitor )
-    {
-        modifyHandler.modify( oldValue, newValue, monitor );
-    }
-
-
     public LdifEnumeration exportLdif( SearchParameter searchParameter, StudioProgressMonitor
monitor )
         throws ConnectionException
     {

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=584601&r1=584600&r2=584601&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
Sun Oct 14 13:58:09 2007
@@ -80,74 +80,6 @@
     }
 
 
-    void modify( IValue oldValue, IValue newValue, StudioProgressMonitor monitor )
-    {
-        try
-        {
-            LdifChangeModifyRecord cmr = new LdifChangeModifyRecord( LdifDnLine.create( oldValue.getAttribute()
-                .getEntry().getDn().toString() ) );
-            ModelConverter.addControls( cmr, oldValue.getAttribute().getEntry() );
-            cmr.setChangeType( LdifChangeTypeLine.createModify() );
-
-            if ( oldValue.getAttribute().getValueSize() == 1 )
-            {
-                LdifModSpec modSpec = LdifModSpec.createReplace( oldValue.getAttribute().getDescription()
);
-                if ( newValue.isString() )
-                {
-                    modSpec.addAttrVal( LdifAttrValLine.create( oldValue.getAttribute().getDescription(),
newValue
-                        .getStringValue() ) );
-                }
-                else
-                {
-                    modSpec.addAttrVal( LdifAttrValLine.create( oldValue.getAttribute().getDescription(),
newValue
-                        .getBinaryValue() ) );
-                }
-                modSpec.finish( LdifModSpecSepLine.create() );
-                cmr.addModSpec( modSpec );
-                cmr.finish( LdifSepLine.create() );
-            }
-            else
-            {
-                LdifModSpec modSpec1 = LdifModSpec.createAdd( oldValue.getAttribute().getDescription()
);
-                if ( newValue.isString() )
-                {
-                    modSpec1.addAttrVal( LdifAttrValLine.create( oldValue.getAttribute().getDescription(),
newValue
-                        .getStringValue() ) );
-                }
-                else
-                {
-                    modSpec1.addAttrVal( LdifAttrValLine.create( oldValue.getAttribute().getDescription(),
newValue
-                        .getBinaryValue() ) );
-                }
-                modSpec1.finish( LdifModSpecSepLine.create() );
-                cmr.addModSpec( modSpec1 );
-
-                LdifModSpec modSpec2 = LdifModSpec.createDelete( oldValue.getAttribute().getDescription()
);
-                if ( oldValue.isString() )
-                {
-                    modSpec2.addAttrVal( LdifAttrValLine.create( oldValue.getAttribute().getDescription(),
oldValue
-                        .getStringValue() ) );
-                }
-                else
-                {
-                    modSpec2.addAttrVal( LdifAttrValLine.create( oldValue.getAttribute().getDescription(),
oldValue
-                        .getBinaryValue() ) );
-                }
-                modSpec2.finish( LdifModSpecSepLine.create() );
-                cmr.addModSpec( modSpec2 );
-                cmr.finish( LdifSepLine.create() );
-            }
-
-            this.applyModificationAndLog( cmr, monitor );
-
-        }
-        catch ( ConnectionException e )
-        {
-            monitor.reportError( e );
-        }
-    }
-
-
     void delete( IValue[] valuesToDelete, 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=584601&r1=584600&r2=584601&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
Sun Oct 14 13:58:09 2007
@@ -162,11 +162,6 @@
     }
 
 
-    public void modify( IValue oldValue, IValue newVaue, StudioProgressMonitor monitor )
-    {
-    }
-
-
     public void reloadSchema( StudioProgressMonitor monitor )
     {
     }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java?rev=584601&r1=584600&r2=584601&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ModifyValueJob.java
Sun Oct 14 13:58:09 2007
@@ -21,79 +21,179 @@
 package org.apache.directory.studio.ldapbrowser.core.jobs;
 
 
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ManageReferralControl;
+
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent;
 import org.apache.directory.studio.ldapbrowser.core.internal.model.Value;
 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 modify an existing value.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class ModifyValueJob extends AbstractAttributeModificationJob
 {
 
+    /** The attribute to modify. */
     private IAttribute attribute;
 
+    /** The old value. */
     private IValue oldValue;
 
+    /** The new raw value. */
     private Object newRawValue;
 
-    private ValueModifiedEvent event;
+    /** The created new value. */
+    private IValue createdNewValue;
 
 
-    public ModifyValueJob( IAttribute attribute, IValue oldValue, Object newRawValue )
+    /**
+     * Creates a new instance of ModifyValueJob.
+     * 
+     * @param oldValue the old value
+     * @param newRawValue the new raw value
+     */
+    public ModifyValueJob( IValue oldValue, Object newRawValue )
     {
-        this.attribute = attribute;
+        this.attribute = oldValue.getAttribute();
         this.oldValue = oldValue;
         this.newRawValue = newRawValue;
         setName( BrowserCoreMessages.jobs__modify_value_name );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#executeAttributeModificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
     protected void executeAttributeModificationJob( StudioProgressMonitor monitor ) throws
ModelModificationException
     {
-
         monitor.beginTask( BrowserCoreMessages.jobs__modify_value_task, 2 );
         monitor.reportProgress( " " ); //$NON-NLS-1$
         monitor.worked( 1 );
 
         IValue newValue = new Value( attribute, newRawValue );
-        attribute.modifyValue( oldValue, newValue );
-        attribute.getEntry().getBrowserConnection().modify( oldValue, newValue, monitor );
+        //attribute.modifyValue( oldValue, newValue );
 
-        this.event = new ValueModifiedEvent( attribute.getEntry().getBrowserConnection(),
attribute.getEntry(), attribute,
-            oldValue, newValue );
+        modifyValue( attribute.getEntry().getBrowserConnection(), attribute.getEntry(), oldValue,
newValue, monitor );
+        if ( !monitor.errorsReported() )
+        {
+            createdNewValue = newValue;
+        }
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#getModifiedEntry()
+     */
     protected IEntry getModifiedEntry()
     {
         return attribute.getEntry();
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractAttributeModificationJob#getAffectedAttributeDescriptions()
+     */
     protected String[] getAffectedAttributeDescriptions()
     {
         return new String[]
-            { this.attribute.getDescription() };
+            { attribute.getDescription() };
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
     protected void runNotification()
     {
-        if ( this.event != null )
+        EntryModificationEvent event;
+
+        if ( createdNewValue != null )
         {
-            EventRegistry.fireEntryUpdated( this.event, this );
+            event = new ValueModifiedEvent( attribute.getEntry().getBrowserConnection(),
attribute.getEntry(),
+                attribute, oldValue, createdNewValue );
         }
+        else
+        {
+            event = new AttributesInitializedEvent( attribute.getEntry() );
+        }
+
+        EventRegistry.fireEntryUpdated( event, this );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
     protected String getErrorMessage()
     {
         return BrowserCoreMessages.jobs__modify_value_error;
+    }
+
+
+    /**
+     * Modifies the value.
+     * 
+     * @param browserConnection the browser connection
+     * @param entry the entry
+     * @param oldValue the old value
+     * @param newValue the new value
+     * @param monitor the progress monitor
+     */
+    private void modifyValue( IBrowserConnection browserConnection, IEntry entry, IValue
oldValue, IValue newValue,
+        StudioProgressMonitor monitor )
+    {
+        // dn
+        String dn = entry.getDn().toString();
+
+        // modification items
+        // perform a replace if the current attribute is single-valued
+        // perform an add and a remove operation if the current attribute is multi-valued
+        ModificationItem[] modificationItems;
+        if ( oldValue.getAttribute().getValueSize() == 1 )
+        {
+            modificationItems = new ModificationItem[1];
+            BasicAttribute attribute = new BasicAttribute( newValue.getAttribute().getDescription(),
newValue
+                .getRawValue() );
+            modificationItems[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute
);
+        }
+        else
+        {
+            modificationItems = new ModificationItem[2];
+            BasicAttribute newAttribute = new BasicAttribute( newValue.getAttribute().getDescription(),
newValue
+                .getRawValue() );
+            modificationItems[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, newAttribute
);
+            BasicAttribute oldAttribute = new BasicAttribute( oldValue.getAttribute().getDescription(),
oldValue
+                .getRawValue() );
+            modificationItems[1] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, oldAttribute
);
+        }
+
+        // controls
+        Control[] controls = null;
+        if ( entry.isReferral() )
+        {
+            controls = new Control[]
+                { new ManageReferralControl() };
+        }
+
+        browserConnection.getConnection().getJNDIConnectionWrapper().modifyAttributes( dn,
modificationItems, controls,
+            monitor );
     }
 
 }

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=584601&r1=584600&r2=584601&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
Sun Oct 14 13:58:09 2007
@@ -163,9 +163,6 @@
     public abstract void delete( IAttribute attriubtesToDelete[], StudioProgressMonitor monitor
);
 
 
-    public abstract void modify( IValue oldValue, IValue newVaue, StudioProgressMonitor monitor
);
-
-
     public abstract void importLdif( LdifEnumeration enumeration, Writer logWriter, boolean
continueOnError,
         StudioProgressMonitor monitor );
 



Mime
View raw message