directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1333026 - in /directory/shared/trunk: integ/src/test/java/org/apache/directory/shared/ldap/entry/ ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/
Date Wed, 02 May 2012 13:07:35 GMT
Author: elecharny
Date: Wed May  2 13:07:34 2012
New Revision: 1333026

URL: http://svn.apache.org/viewvc?rev=1333026&view=rev
Log:
o Removed the apply( AttributeType ) from the Value interface
o Instead of applying an AttributeType to an existing Value, it's now required to use the
constructor, as Value is immutabl.

Modified:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java?rev=1333026&r1=1333025&r2=1333026&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
Wed May  2 13:07:34 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.entry;
 
@@ -219,9 +219,9 @@ public class SchemaAwareValueSerializati
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
-        bv1n.apply( userCertificate );
+        BinaryValue value = new BinaryValue( userCertificate, bv1n.getBytes() );
 
-        bv1n.writeExternal( out );
+        value.writeExternal( out );
 
         ObjectInputStream in = null;
 
@@ -230,7 +230,7 @@ public class SchemaAwareValueSerializati
 
         BinaryValue bvDeser = BinaryValue.deserialize( userCertificate, in );
 
-        assertEquals( bv1n, bvDeser );
+        assertEquals( value, bvDeser );
     }
 
 
@@ -240,9 +240,9 @@ public class SchemaAwareValueSerializati
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
-        bv2n.apply( userCertificate );
+        BinaryValue value = new BinaryValue( userCertificate, bv2n.getBytes() );
 
-        bv2n.writeExternal( out );
+        value.writeExternal( out );
 
         ObjectInputStream in = null;
 
@@ -251,7 +251,7 @@ public class SchemaAwareValueSerializati
 
         BinaryValue bvDeser = BinaryValue.deserialize( userCertificate, in );
 
-        assertEquals( bv2n, bvDeser );
+        assertEquals( value, bvDeser );
     }
 
 
@@ -261,9 +261,9 @@ public class SchemaAwareValueSerializati
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
-        bv3n.apply( userCertificate );
+        BinaryValue value = new BinaryValue( userCertificate, bv3n.getBytes() );
 
-        bv3n.writeExternal( out );
+        value.writeExternal( out );
 
         ObjectInputStream in = null;
 
@@ -272,7 +272,7 @@ public class SchemaAwareValueSerializati
 
         BinaryValue bvDeser = BinaryValue.deserialize( userCertificate, in );
 
-        assertEquals( bv3n, bvDeser );
+        assertEquals( value, bvDeser );
     }
 
 
@@ -282,9 +282,9 @@ public class SchemaAwareValueSerializati
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
-        sv1n.apply( cn );
+        StringValue value = new StringValue( cn, sv1n.getString() );
 
-        sv1n.writeExternal( out );
+        value.writeExternal( out );
 
         ObjectInputStream in = null;
 
@@ -293,7 +293,7 @@ public class SchemaAwareValueSerializati
 
         StringValue svDeser = StringValue.deserialize( cn, in );
 
-        assertEquals( sv1n, svDeser );
+        assertEquals( value, svDeser );
     }
 
 
@@ -303,9 +303,9 @@ public class SchemaAwareValueSerializati
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
-        sv2n.apply( dc );
+        StringValue value = new StringValue( dc, sv2n.getString() );
 
-        sv2n.writeExternal( out );
+        value.writeExternal( out );
 
         ObjectInputStream in = null;
 
@@ -314,7 +314,7 @@ public class SchemaAwareValueSerializati
 
         StringValue svDeser = StringValue.deserialize( cn, in );
 
-        assertEquals( sv2n, svDeser );
+        assertEquals( value, svDeser );
     }
 
 
@@ -324,9 +324,9 @@ public class SchemaAwareValueSerializati
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
-        sv3n.apply( dc );
+        StringValue value = new StringValue( dc, sv3n.getString() );
 
-        sv3n.writeExternal( out );
+        value.writeExternal( out );
 
         ObjectInputStream in = null;
 
@@ -335,6 +335,6 @@ public class SchemaAwareValueSerializati
 
         StringValue svDeser = StringValue.deserialize( cn, in );
 
-        assertEquals( sv3n, svDeser );
+        assertEquals( value, svDeser );
     }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java?rev=1333026&r1=1333025&r2=1333026&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
Wed May  2 13:07:34 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.entry;
 
@@ -116,9 +116,13 @@ public abstract class AbstractValue<T> i
 
 
     /**
-     * {@inheritDoc}
+     * Apply an AttributeType to the current Value, normalizing it.
+     *
+     * @param attributeType The AttributeType to apply
+     * @throws LdapInvalidAttributeValueException If the value is not valid accordingly
+     * to the schema
      */
-    public void apply( AttributeType attributeType ) throws LdapInvalidAttributeValueException
+    protected void apply( AttributeType attributeType ) throws LdapInvalidAttributeValueException
     {
         if ( attributeType == null )
         {
@@ -130,7 +134,7 @@ public abstract class AbstractValue<T> i
         this.attributeType = attributeType;
 
         // We first have to normalize the value before we can check its syntax
-        // Get the Aequality matchingRule, if we have one
+        // Get the equality matchingRule, if we have one
         MatchingRule equality = attributeType.getEquality();
 
         if ( equality != null )

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java?rev=1333026&r1=1333025&r2=1333026&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
Wed May  2 13:07:34 2012
@@ -1772,8 +1772,14 @@ public class DefaultAttribute implements
 
             for ( Value<?> value : values )
             {
-                value.apply( attributeType );
-                newValues.add( value );
+                if ( value instanceof StringValue )
+                {
+                    newValues.add( new StringValue( attributeType, value.getString() ) );
+                }
+                else
+                {
+                    newValues.add( new BinaryValue( attributeType, value.getBytes() ) );
+                }
             }
 
             values = newValues;
@@ -1934,7 +1940,8 @@ public class DefaultAttribute implements
 
             for ( Value<?> value : values )
             {
-                attribute.values.add( value.clone() );
+                // No need to clone the value, it will never be changed
+                attribute.values.add( value );
             }
 
             return attribute;

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java?rev=1333026&r1=1333025&r2=1333026&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
Wed May  2 13:07:34 2012
@@ -41,16 +41,6 @@ public interface Value<T> extends Clonea
 
 
     /**
-     * Apply an AttributeType to the current Value, normalizing it.
-     *
-     * @param attributeType The AttributeType to apply
-     * @throws LdapInvalidAttributeValueException If the value is not valid accordingly
-     * to the schema
-     */
-    void apply( AttributeType attributeType ) throws LdapInvalidAttributeValueException;
-
-
-    /**
      * Clone a Value
      * 
      * @return A cloned value
@@ -75,7 +65,7 @@ public interface Value<T> extends Clonea
 
 
     /**
-     * Check if the value is stored into an instance of the given 
+     * Check if the value is stored into an instance of the given
      * AttributeType, or one of its ascendant.
      * 
      * For instance, if the Value is associated with a CommonName,
@@ -107,7 +97,7 @@ public interface Value<T> extends Clonea
 
     /**
      * Get the wrapped value as a String. If the original value
-     * is binary, this method will return the value as if it was 
+     * is binary, this method will return the value as if it was
      * an UTF-8 encoded String.
      *
      * @return the wrapped value as a String
@@ -156,7 +146,7 @@ public interface Value<T> extends Clonea
 
 
     /**
-     * Gets a reference to the the normalized (canonical) representation 
+     * Gets a reference to the the normalized (canonical) representation
      * for the wrapped value.
      *
      * @return gets a reference to the normalized value



Mime
View raw message