directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r691910 - in /directory/studio/trunk/studio-dsml-parser/src: main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java
Date Thu, 04 Sep 2008 08:08:06 GMT
Author: pamarcelot
Date: Thu Sep  4 01:08:06 2008
New Revision: 691910

URL: http://svn.apache.org/viewvc?rev=691910&view=rev
Log:
Fixed the breakage due to Shared LDAP Modifications.

Modified:
    directory/studio/trunk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
    directory/studio/trunk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java

Modified: directory/studio/trunk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java?rev=691910&r1=691909&r2=691910&view=diff
==============================================================================
--- directory/studio/trunk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
(original)
+++ directory/studio/trunk/studio-dsml-parser/src/main/java/org/apache/directory/studio/dsmlv2/request/ModifyRequestDsml.java
Thu Sep  4 01:08:06 2008
@@ -20,14 +20,13 @@
 package org.apache.directory.studio.dsmlv2.request;
 
 
+import java.util.Iterator;
 import java.util.List;
 
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.studio.dsmlv2.ParserUtils;
 import org.dom4j.Element;
 import org.dom4j.Namespace;
@@ -88,60 +87,54 @@
         }
 
         // Modifications
-        List<ModificationItem> modifications = request.getModifications();
+        List<Modification> modifications = request.getModifications();
 
         for ( int i = 0; i < modifications.size(); i++ )
         {
-            ModificationItem modificationItem = modifications.get( i );
+            Modification modificationItem = modifications.get( i );
 
             Element modElement = element.addElement( "modification" );
             if ( modificationItem.getAttribute() != null )
             {
-                modElement.addAttribute( "name", modificationItem.getAttribute().getID()
);
+                modElement.addAttribute( "name", modificationItem.getAttribute().getId()
);
 
-                try
+                Iterator<Value<?>> iterator = modificationItem.getAttribute().getAll();
+                while ( iterator.hasNext() )
                 {
-                    NamingEnumeration ne = modificationItem.getAttribute().getAll();
-                    while ( ne.hasMoreElements() )
-                    {
-                        Object value = ( Object ) ne.nextElement();
+                    Value<?> value = iterator.next();
 
-                        if ( value != null )
+                    if ( value.get() != null )
+                    {
+                        if ( ParserUtils.needsBase64Encoding( value.get() ) )
                         {
-                            if ( ParserUtils.needsBase64Encoding( value ) )
-                            {
-                                Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
-                                Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
-                                element.getDocument().getRootElement().add( xsdNamespace
);
-                                element.getDocument().getRootElement().add( xsiNamespace
);
-
-                                Element valueElement = modElement.addElement( "value" ).addText(
-                                    ParserUtils.base64Encode( value ) );
-                                valueElement.addAttribute( new QName( "type", xsiNamespace
), "xsd:"
-                                    + ParserUtils.BASE64BINARY );
-                            }
-                            else
-                            {
-                                modElement.addElement( "value" ).setText( ( String ) value
);
-                            }
+                            Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
+                            Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
+                            element.getDocument().getRootElement().add( xsdNamespace );
+                            element.getDocument().getRootElement().add( xsiNamespace );
+
+                            Element valueElement = modElement.addElement( "value" ).addText(
+                                ParserUtils.base64Encode( value.get() ) );
+                            valueElement.addAttribute( new QName( "type", xsiNamespace ),
"xsd:"
+                                + ParserUtils.BASE64BINARY );
+                        }
+                        else
+                        {
+                            modElement.addElement( "value" ).setText( ( String ) value.get()
);
                         }
                     }
                 }
-                catch ( NamingException e )
-                {
-                }
             }
 
-            int operation = modificationItem.getModificationOp();
-            if ( operation == DirContext.ADD_ATTRIBUTE )
+            ModificationOperation operation = modificationItem.getOperation();
+            if ( operation == ModificationOperation.ADD_ATTRIBUTE )
             {
                 modElement.addAttribute( "operation", "add" );
             }
-            else if ( operation == DirContext.REPLACE_ATTRIBUTE )
+            else if ( operation == ModificationOperation.REPLACE_ATTRIBUTE )
             {
                 modElement.addAttribute( "operation", "replace" );
             }
-            else if ( operation == DirContext.REMOVE_ATTRIBUTE )
+            else if ( operation == ModificationOperation.REMOVE_ATTRIBUTE )
             {
                 modElement.addAttribute( "operation", "delete" );
             }

Modified: directory/studio/trunk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java?rev=691910&r1=691909&r2=691910&view=diff
==============================================================================
--- directory/studio/trunk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java
(original)
+++ directory/studio/trunk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/modifyRequest/ModifyRequestTest.java
Thu Sep  4 01:08:06 2008
@@ -25,12 +25,12 @@
 import java.util.List;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.ModificationItem;
 
 import org.apache.directory.shared.ldap.codec.Control;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.studio.dsmlv2.AbstractTest;
 import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
@@ -264,15 +264,15 @@
 
         assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
 
-        List<ModificationItem> modifications = modifyRequest.getModifications();
+        List<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 1, modifications.size() );
 
-        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+        Modification modification = ( Modification ) modifications.get( 0 );
 
-        Attribute attribute = modification.getAttribute();
+        EntryAttribute attribute = modification.getAttribute();
 
-        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ) );
+        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ).get() );
     }
 
 
@@ -304,20 +304,20 @@
 
         assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
 
-        List<ModificationItem> modifications = modifyRequest.getModifications();
+        List<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 1, modifications.size() );
 
-        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+        Modification modification = ( Modification ) modifications.get( 0 );
 
-        Attribute attribute = modification.getAttribute();
+        EntryAttribute attribute = modification.getAttribute();
 
         String expected = new String( new byte[]
             { 'c', 'n', '=', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', 'L', ( byte ) 0xc3,
( byte ) 0xa9, 'c', 'h',
                 'a', 'r', 'n', 'y', ',', ' ', 'o', 'u', '=', 'p', 'e', 'o', 'p', 'l', 'e',
',', ' ', 'd', 'c', '=',
                 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', ' ', 'd', 'c', '=', 'c', 'o', 'm'
}, "UTF-8" );
 
-        assertEquals( expected, new String( ( byte[] ) attribute.get( 0 ), "UTF-8" ) );
+        assertEquals( expected, new String( ( byte[] ) attribute.get( 0 ).get(), "UTF-8"
) );
     }
 
 
@@ -348,15 +348,15 @@
 
         assertEquals( "sn", modifyRequest.getCurrentAttributeType() );
 
-        List<ModificationItem> modifications = modifyRequest.getModifications();
+        List<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 2, modifications.size() );
 
-        ModificationItem modification = ( ModificationItem ) modifications.get( 1 );
+        Modification modification = ( Modification ) modifications.get( 1 );
 
-        Attribute attribute = modification.getAttribute();
+        EntryAttribute attribute = modification.getAttribute();
 
-        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 0 ) );
+        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 0 ).get() );
     }
 
 
@@ -495,11 +495,11 @@
 
         assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
 
-        List<ModificationItem> modifications = modifyRequest.getModifications();
+        List<Modification> modifications = modifyRequest.getModifications();
 
-        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+        Modification modification = ( Modification ) modifications.get( 0 );
 
-        Attribute attribute = modification.getAttribute();
+        EntryAttribute attribute = modification.getAttribute();
 
         assertEquals( 0, attribute.size() );
     }
@@ -532,17 +532,17 @@
 
         assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
 
-        List<ModificationItem> modifications = modifyRequest.getModifications();
+        List<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 1, modifications.size() );
 
-        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+        Modification modification = ( Modification ) modifications.get( 0 );
 
-        Attribute attribute = modification.getAttribute();
+        EntryAttribute attribute = modification.getAttribute();
 
         assertEquals( 2, attribute.size() );
-        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ) );
-        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 1 ) );
+        assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get( 0 ).get() );
+        assertEquals( "CN=Steve Jobs, DC=apple, DC=com", attribute.get( 1 ).get() );
     }
 
 
@@ -573,16 +573,16 @@
 
         assertEquals( "directreport", modifyRequest.getCurrentAttributeType() );
 
-        List<ModificationItem> modifications = modifyRequest.getModifications();
+        List<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 1, modifications.size() );
 
-        ModificationItem modification = ( ModificationItem ) modifications.get( 0 );
+        Modification modification = ( Modification ) modifications.get( 0 );
 
-        Attribute attribute = modification.getAttribute();
+        EntryAttribute attribute = modification.getAttribute();
 
         assertEquals( 1, attribute.size() );
-        assertEquals( "", attribute.get( 0 ) );
+        assertEquals( "", attribute.get( 0 ).get() );
     }
 
 



Mime
View raw message