You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2013/08/23 05:59:46 UTC

svn commit: r1516689 - in /directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry: DefaultAttribute.java DefaultEntry.java

Author: elecharny
Date: Fri Aug 23 03:59:46 2013
New Revision: 1516689

URL: http://svn.apache.org/r1516689
Log:
Fix for DIRAPI-152

Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java?rev=1516689&r1=1516688&r2=1516689&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java Fri Aug 23 03:59:46 2013
@@ -184,6 +184,16 @@ public class DefaultAttribute implements
 
 
     /**
+     * Create a new instance of an Attribute, without value.
+     * @param upId The user provided ID
+     */
+    public DefaultAttribute( byte[] upId )
+    {
+        setUpId( upId );
+    }
+
+
+    /**
      * Create a new instance of a schema aware Attribute, without value.
      * 
      * @param upId the ID for the added attributeType
@@ -558,6 +568,15 @@ public class DefaultAttribute implements
 
 
     /**
+     * {@inheritDoc}
+     */
+    public void setUpId( byte[] upId )
+    {
+        setUpId( upId, attributeType );
+    }
+
+
+    /**
      * Check that the upId is either a name or the OID of a given AT
      */
     private boolean areCompatible( String id, AttributeType attributeType )
@@ -599,6 +618,33 @@ public class DefaultAttribute implements
 
         String newId = Strings.toLowerCase( trimmed );
 
+        setUpIdInternal( upId, newId, attributeType );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setUpId( byte[] upId, AttributeType attributeType )
+    {
+        byte[] trimmed = Strings.trim( upId );
+
+        if ( Strings.isEmpty( trimmed ) && ( attributeType == null ) )
+        {
+            throw new IllegalArgumentException( "Cannot set a null ID with a null AttributeType" );
+        }
+
+        String newId = Strings.toLowerCase( trimmed );
+
+        setUpIdInternal( Strings.utf8ToString( upId ), newId, attributeType );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    private void setUpIdInternal( String upId, String newId, AttributeType attributeType )
+    {
         if ( attributeType == null )
         {
             if ( this.attributeType == null )
@@ -2043,8 +2089,19 @@ public class DefaultAttribute implements
 
         if ( ( values != null ) && ( values.size() != 0 ) )
         {
+            boolean isFirst = true;
+
             for ( Value<?> value : values )
             {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( '\n' );
+                }
+
                 sb.append( tabs ).append( upId ).append( ": " );
 
                 if ( value.isNull() )
@@ -2055,13 +2112,11 @@ public class DefaultAttribute implements
                 {
                     sb.append( value );
                 }
-
-                sb.append( '\n' );
             }
         }
         else
         {
-            sb.append( tabs ).append( upId ).append( ": (null)\n" );
+            sb.append( tabs ).append( upId ).append( ": (null)" );
         }
 
         return sb.toString();

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java?rev=1516689&r1=1516688&r2=1516689&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java Fri Aug 23 03:59:46 2013
@@ -993,24 +993,24 @@ public final class DefaultEntry implemen
                 .clone() );
 
             // now clone all the attributes
-            clone.attributes.clear();
-
-            if ( schemaManager != null )
-            {
-                for ( Attribute attribute : attributes.values() )
-                {
-                    String oid = attribute.getAttributeType().getOid();
-                    clone.attributes.put( oid, attribute.clone() );
-                }
-            }
-            else
-            {
-                for ( Attribute attribute : attributes.values() )
-                {
-                    clone.attributes.put( attribute.getId(), attribute.clone() );
-                }
-
-            }
+            //            clone.attributes.clear();
+            //
+            //            if ( schemaManager != null )
+            //            {
+            //                for ( Attribute attribute : attributes.values() )
+            //                {
+            //                    String oid = attribute.getAttributeType().getOid();
+            //                    clone.attributes.put( oid, attribute.clone() );
+            //                }
+            //            }
+            //            else
+            //            {
+            //                for ( Attribute attribute : attributes.values() )
+            //                {
+            //                    clone.attributes.put( attribute.getId(), attribute.clone() );
+            //                }
+            //
+            //            }
 
             // We are done !
             return clone;
@@ -2580,10 +2580,23 @@ public final class DefaultEntry implemen
             }
         }
 
+        sb.append( '\n' );
+
         if ( attributes.size() != 0 )
         {
+            boolean isFirst = true;
+
             for ( Attribute attribute : attributes.values() )
             {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( '\n' );
+                }
+
                 String id = attribute.getId();
 
                 if ( schemaManager != null )