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.
git-svn-id: https://svn.apache.org/repos/asf/directory/shared/trunk@1333026 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java b/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
index 0ea1fcd..539489a 100644
--- a/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
+++ b/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializationTest.java
@@ -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 @@
{
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 @@
BinaryValue bvDeser = BinaryValue.deserialize( userCertificate, in );
- assertEquals( bv1n, bvDeser );
+ assertEquals( value, bvDeser );
}
@@ -240,9 +240,9 @@
{
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 @@
BinaryValue bvDeser = BinaryValue.deserialize( userCertificate, in );
- assertEquals( bv2n, bvDeser );
+ assertEquals( value, bvDeser );
}
@@ -261,9 +261,9 @@
{
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 @@
BinaryValue bvDeser = BinaryValue.deserialize( userCertificate, in );
- assertEquals( bv3n, bvDeser );
+ assertEquals( value, bvDeser );
}
@@ -282,9 +282,9 @@
{
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 @@
StringValue svDeser = StringValue.deserialize( cn, in );
- assertEquals( sv1n, svDeser );
+ assertEquals( value, svDeser );
}
@@ -303,9 +303,9 @@
{
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 @@
StringValue svDeser = StringValue.deserialize( cn, in );
- assertEquals( sv2n, svDeser );
+ assertEquals( value, svDeser );
}
@@ -324,9 +324,9 @@
{
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 @@
StringValue svDeser = StringValue.deserialize( cn, in );
- assertEquals( sv3n, svDeser );
+ assertEquals( value, svDeser );
}
}
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
index 0ca4b13..3f5608d 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
@@ -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 @@
/**
- * {@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 @@
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 )
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
index efb5405..17558f6 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
@@ -1772,8 +1772,14 @@
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 @@
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;
diff --git a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
index 09bd105..9c87f8b 100644
--- a/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
+++ b/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
@@ -41,16 +41,6 @@
/**
- * 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 @@
/**
- * 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 @@
/**
* 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 @@
/**
- * 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