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 2010/04/19 16:17:50 UTC
svn commit: r935590 - in /directory:
apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/
shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/
shared/trunk/ldap/src/test/java/org/apache/directory/shared/lda...
Author: elecharny
Date: Mon Apr 19 14:17:49 2010
New Revision: 935590
URL: http://svn.apache.org/viewvc?rev=935590&view=rev
Log:
Some more simplification in the Value classes :
o Tests are now using an AT supporting null values
o Added some @SuppressWarnings
o Updated the javadoc and added some missing pieces
o Added some logs
o The syntax is checked when doing an apply(AT)
o Removed the useless getNormalizedValueCopy() method
Modified:
directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/StringValueTest.java
Modified: directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java (original)
+++ directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java Mon Apr 19 14:17:49 2010
@@ -74,6 +74,7 @@ public class DefaultServerAttributeTest
private static LdifSchemaLoader loader;
private static AttributeType atCN;
+ private static AttributeType atDC;
private static AttributeType atSN;
// A SINGLE-VALUE attribute
@@ -136,6 +137,7 @@ public class DefaultServerAttributeTest
}
atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
+ atDC = schemaManager.lookupAttributeTypeRegistry( "dc" );
atC = schemaManager.lookupAttributeTypeRegistry( "c" );
atSN = schemaManager.lookupAttributeTypeRegistry( "sn" );
atPwd = schemaManager.lookupAttributeTypeRegistry( "userpassword" );
@@ -663,16 +665,16 @@ public class DefaultServerAttributeTest
assertTrue( attr7.contains( NULL_BINARY_VALUE ) );
assertFalse( attr7.contains( BYTES3 ) );
- EntryAttribute attr8 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr8 = new DefaultServerAttribute( atDC );
- nbAdded = attr8.add( new StringValue( atCN, null ), new BinaryValue( atPwd, BYTES1 ) );
+ nbAdded = attr8.add( new StringValue( atDC, null ), new BinaryValue( atPwd, BYTES1 ) );
assertEquals( 1, nbAdded );
assertTrue( attr8.isHR() );
assertTrue( attr8.contains( NULL_STRING_VALUE ) );
assertFalse( attr8.contains( "ab" ) );
- EntryAttribute attr9 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr9 = new DefaultServerAttribute( atDC );
nbAdded = attr9.add( new StringValue( (String)null ), new StringValue( "ab" ) );
assertEquals( 2, nbAdded );
@@ -749,7 +751,7 @@ public class DefaultServerAttributeTest
assertTrue( attr4.contains( "e" ) );
assertFalse( attr4.contains( "ab" ) );
- EntryAttribute attr5 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr5 = new DefaultServerAttribute( atDC );
nbAdded = attr5.add( "a", "b", (String)null, "d" );
assertEquals( 4, nbAdded );
@@ -848,7 +850,7 @@ public class DefaultServerAttributeTest
@Test
public void testContainsValueArray()
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC );
assertEquals( 0, attr1.size() );
assertFalse( attr1.contains( STR_VALUE1 ) );
@@ -1189,28 +1191,28 @@ public class DefaultServerAttributeTest
@Test
public void testPutStringArray() throws LdapInvalidAttributeValueException
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC );
int nbAdded = attr1.put( (String)null );
assertEquals( 1, nbAdded );
assertTrue( attr1.isHR() );
assertEquals( NULL_STRING_VALUE, attr1.get() );
- EntryAttribute attr2 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr2 = new DefaultServerAttribute( atDC );
nbAdded = attr2.put( "" );
assertEquals( 1, nbAdded );
assertTrue( attr2.isHR() );
assertEquals( "", attr2.getString() );
- EntryAttribute attr3 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr3 = new DefaultServerAttribute( atDC );
nbAdded = attr3.put( "t" );
assertEquals( 1, nbAdded );
assertTrue( attr3.isHR() );
assertEquals( "t", attr3.getString() );
- EntryAttribute attr4 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr4 = new DefaultServerAttribute( atDC );
nbAdded = attr4.put( "a", "b", "c", "d" );
assertEquals( 4, nbAdded );
@@ -1235,7 +1237,7 @@ public class DefaultServerAttributeTest
assertEquals( 0, nbAdded );
assertTrue( attr4.isHR() );
- EntryAttribute attr5 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr5 = new DefaultServerAttribute( atDC );
nbAdded = attr5.put( "a", "b", (String)null, "d" );
assertEquals( 4, nbAdded );
@@ -1259,7 +1261,7 @@ public class DefaultServerAttributeTest
@Test
public void testPutValueArray() throws Exception
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC );
assertEquals( 0, attr1.size() );
@@ -1313,7 +1315,7 @@ public class DefaultServerAttributeTest
@Test
public void testPutListOfValues()
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC );
assertEquals( 0, attr1.size() );
@@ -1392,7 +1394,7 @@ public class DefaultServerAttributeTest
@Test
public void testRemoveValueArray() throws Exception
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC );
assertFalse( attr1.remove( STR_VALUE1 ) );
@@ -1788,23 +1790,23 @@ public class DefaultServerAttributeTest
@Test
public void testDefaultServerAttributeAttributeTypeValueArray() throws Exception
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
assertTrue( attr1.isHR() );
assertEquals( 3, attr1.size() );
- assertEquals( "cn", attr1.getId() );
- assertEquals( "cn", attr1.getUpId() );
- assertEquals( atCN, attr1.getAttributeType() );
+ assertEquals( "dc", attr1.getId() );
+ assertEquals( "dc", attr1.getUpId() );
+ assertEquals( atDC, attr1.getAttributeType() );
assertTrue( attr1.contains( "a", "b" ) );
assertTrue( attr1.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr2 = new DefaultServerAttribute( atCN, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr2 = new DefaultServerAttribute( atDC, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
assertTrue( attr2.isHR() );
assertEquals( 2, attr2.size() );
- assertEquals( "cn", attr2.getId() );
- assertEquals( "cn", attr2.getUpId() );
- assertEquals( atCN, attr2.getAttributeType() );
+ assertEquals( "dc", attr2.getId() );
+ assertEquals( "dc", attr2.getUpId() );
+ assertEquals( atDC, attr2.getAttributeType() );
assertTrue( attr2.contains( "a" ) );
assertTrue( attr2.contains( NULL_STRING_VALUE ) );
}
@@ -1816,43 +1818,43 @@ public class DefaultServerAttributeTest
@Test
public void testDefaultServerAttributeStringAttributeTypeValueArray()
{
- EntryAttribute attr1 = new DefaultServerAttribute( "cn", atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr1 = new DefaultServerAttribute( "dc", atDC, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
assertTrue( attr1.isHR() );
assertEquals( 3, attr1.size() );
- assertEquals( "cn", attr1.getId() );
- assertEquals( "cn", attr1.getUpId() );
- assertEquals( atCN, attr1.getAttributeType() );
+ assertEquals( "dc", attr1.getId() );
+ assertEquals( "dc", attr1.getUpId() );
+ assertEquals( atDC, attr1.getAttributeType() );
assertTrue( attr1.contains( "a", "b" ) );
assertTrue( attr1.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr2 = new DefaultServerAttribute( atCN, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr2 = new DefaultServerAttribute( atDC, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
assertTrue( attr2.isHR() );
assertEquals( 2, attr2.size() );
- assertEquals( "cn", attr2.getId() );
- assertEquals( "cn", attr2.getUpId() );
- assertEquals( atCN, attr2.getAttributeType() );
+ assertEquals( "dc", attr2.getId() );
+ assertEquals( "dc", attr2.getUpId() );
+ assertEquals( atDC, attr2.getAttributeType() );
assertTrue( attr2.contains( "a" ) );
assertTrue( attr2.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr3 = new DefaultServerAttribute( "CommonName", atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr3 = new DefaultServerAttribute( "DomainComponent", atDC, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
assertTrue( attr3.isHR() );
assertEquals( 3, attr3.size() );
- assertEquals( "commonname", attr3.getId() );
- assertEquals( "CommonName", attr3.getUpId() );
- assertEquals( atCN, attr3.getAttributeType() );
+ assertEquals( "domaincomponent", attr3.getId() );
+ assertEquals( "DomainComponent", attr3.getUpId() );
+ assertEquals( atDC, attr3.getAttributeType() );
assertTrue( attr3.contains( "a", "b" ) );
assertTrue( attr3.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr4 = new DefaultServerAttribute( " 2.5.4.3 ", atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr4 = new DefaultServerAttribute( " 0.9.2342.19200300.100.1.25 ", atDC, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
assertTrue( attr4.isHR() );
assertEquals( 3, attr4.size() );
- assertEquals( "2.5.4.3", attr4.getId() );
- assertEquals( " 2.5.4.3 ", attr4.getUpId() );
- assertEquals( atCN, attr4.getAttributeType() );
+ assertEquals( "0.9.2342.19200300.100.1.25", attr4.getId() );
+ assertEquals( " 0.9.2342.19200300.100.1.25 ", attr4.getUpId() );
+ assertEquals( atDC, attr4.getAttributeType() );
assertTrue( attr4.contains( "a", "b" ) );
assertTrue( attr4.contains( NULL_STRING_VALUE ) );
}
@@ -1864,23 +1866,23 @@ public class DefaultServerAttributeTest
@Test
public void testDefaultServerAttributeAttributeTypeStringArray()
{
- EntryAttribute attr1 = new DefaultServerAttribute( atCN, "a", "b", (String)null );
+ EntryAttribute attr1 = new DefaultServerAttribute( atDC, "a", "b", (String)null );
assertTrue( attr1.isHR() );
assertEquals( 3, attr1.size() );
- assertEquals( "cn", attr1.getId() );
- assertEquals( "cn", attr1.getUpId() );
- assertEquals( atCN, attr1.getAttributeType() );
+ assertEquals( "dc", attr1.getId() );
+ assertEquals( "dc", attr1.getUpId() );
+ assertEquals( atDC, attr1.getAttributeType() );
assertTrue( attr1.contains( "a", "b" ) );
assertTrue( attr1.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr2 = new DefaultServerAttribute( atCN, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
+ EntryAttribute attr2 = new DefaultServerAttribute( atDC, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
assertTrue( attr2.isHR() );
assertEquals( 2, attr2.size() );
- assertEquals( "cn", attr2.getId() );
- assertEquals( "cn", attr2.getUpId() );
- assertEquals( atCN, attr2.getAttributeType() );
+ assertEquals( "dc", attr2.getId() );
+ assertEquals( "dc", attr2.getUpId() );
+ assertEquals( atDC, attr2.getAttributeType() );
assertTrue( attr2.contains( "a" ) );
assertTrue( attr2.contains( NULL_STRING_VALUE ) );
}
@@ -1892,33 +1894,33 @@ public class DefaultServerAttributeTest
@Test
public void testDefaultServerAttributeStringAttributeTypeStringArray()
{
- EntryAttribute attr1 = new DefaultServerAttribute( "cn", atCN, "a", "b", (String)null );
+ EntryAttribute attr1 = new DefaultServerAttribute( "dc", atDC, "a", "b", (String)null );
assertTrue( attr1.isHR() );
assertEquals( 3, attr1.size() );
- assertEquals( "cn", attr1.getId() );
- assertEquals( "cn", attr1.getUpId() );
- assertEquals( atCN, attr1.getAttributeType() );
+ assertEquals( "dc", attr1.getId() );
+ assertEquals( "dc", attr1.getUpId() );
+ assertEquals( atDC, attr1.getAttributeType() );
assertTrue( attr1.contains( "a", "b" ) );
assertTrue( attr1.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr2 = new DefaultServerAttribute( "CommonName", atCN, "a", "b", (String)null );
+ EntryAttribute attr2 = new DefaultServerAttribute( "DomainComponent", atDC, "a", "b", (String)null );
assertTrue( attr2.isHR() );
assertEquals( 3, attr2.size() );
- assertEquals( "commonname", attr2.getId() );
- assertEquals( "CommonName", attr2.getUpId() );
- assertEquals( atCN, attr2.getAttributeType() );
+ assertEquals( "domaincomponent", attr2.getId() );
+ assertEquals( "DomainComponent", attr2.getUpId() );
+ assertEquals( atDC, attr2.getAttributeType() );
assertTrue( attr2.contains( "a", "b" ) );
assertTrue( attr2.contains( NULL_STRING_VALUE ) );
- EntryAttribute attr3 = new DefaultServerAttribute( " 2.5.4.3 ", atCN, "a", "b", (String)null );
+ EntryAttribute attr3 = new DefaultServerAttribute( " 0.9.2342.19200300.100.1.25 ", atDC, "a", "b", (String)null );
assertTrue( attr3.isHR() );
assertEquals( 3, attr3.size() );
- assertEquals( "2.5.4.3", attr3.getId() );
- assertEquals( " 2.5.4.3 ", attr3.getUpId() );
- assertEquals( atCN, attr3.getAttributeType() );
+ assertEquals( "0.9.2342.19200300.100.1.25", attr3.getId() );
+ assertEquals( " 0.9.2342.19200300.100.1.25 ", attr3.getUpId() );
+ assertEquals( atDC, attr3.getAttributeType() );
assertTrue( attr3.contains( "a", "b" ) );
assertTrue( attr3.contains( NULL_STRING_VALUE ) );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/AbstractValue.java Mon Apr 19 14:17:49 2010
@@ -63,6 +63,7 @@ public abstract class AbstractValue<T> i
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
public Value<T> clone()
{
try
@@ -78,11 +79,7 @@ public abstract class AbstractValue<T> i
/**
- * Gets a reference to the wrapped binary value.
- *
- * Warning ! The value is not copied !!!
- *
- * @return a direct handle on the binary value that is wrapped
+ * {@inheritDoc}
*/
public T getReference()
{
@@ -91,8 +88,7 @@ public abstract class AbstractValue<T> i
/**
- * Get the associated AttributeType
- * @return The AttributeType
+ * {@inheritDoc}
*/
public AttributeType getAttributeType()
{
@@ -100,13 +96,18 @@ public abstract class AbstractValue<T> i
}
+ /**
+ * {@inheritDoc}
+ */
public void apply( AttributeType attributeType )
{
if ( this.attributeType != null )
{
if ( !attributeType.equals( this.attributeType ) )
{
- throw new IllegalArgumentException( I18n.err( I18n.ERR_04476, attributeType.getName(), this.attributeType.getName() ) );
+ String message = I18n.err( I18n.ERR_04476, attributeType.getName(), this.attributeType.getName() );
+ LOG.info( message );
+ throw new IllegalArgumentException( message );
}
else
{
@@ -114,6 +115,23 @@ public abstract class AbstractValue<T> i
}
}
+ // First, check that the value is syntaxically correct
+ try
+ {
+ if ( ! isValid( attributeType.getSyntax().getSyntaxChecker() ) )
+ {
+ String message = I18n.err( I18n.ERR_04476, attributeType.getName(), this.attributeType.getName() );
+ LOG.info( message );
+ throw new IllegalArgumentException( message );
+ }
+ }
+ catch ( LdapException le )
+ {
+ String message = I18n.err( I18n.ERR_04447, le.getLocalizedMessage() );
+ LOG.info( message );
+ normalized = false;
+ }
+
this.attributeType = attributeType;
try
@@ -136,7 +154,8 @@ public abstract class AbstractValue<T> i
* @return a comparator associated with the attributeType or null if one cannot be found
* @throws LdapException if resolution of schema entities fail
*/
- protected LdapComparator<T> getLdapComparator() throws LdapException
+ @SuppressWarnings("unchecked")
+ protected final LdapComparator<T> getLdapComparator() throws LdapException
{
if ( attributeType != null )
{
@@ -165,7 +184,7 @@ public abstract class AbstractValue<T> i
* @return a matchingRule or null if one cannot be found for the attributeType
* @throws LdapException if resolution of schema entities fail
*/
- protected MatchingRule getMatchingRule() throws LdapException
+ protected final MatchingRule getMatchingRule() throws LdapException
{
if ( attributeType != null )
{
@@ -197,7 +216,7 @@ public abstract class AbstractValue<T> i
* @return a normalizer associated with the attributeType or null if one cannot be found
* @throws LdapException if resolution of schema entities fail
*/
- protected Normalizer getNormalizer() throws LdapException
+ protected final Normalizer getNormalizer() throws LdapException
{
if ( attributeType != null )
{
@@ -218,15 +237,7 @@ public abstract class AbstractValue<T> i
/**
- * 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,
- * checking for Name will match.
- *
- * @param attributeType The AttributeType we are looking at
- * @return <code>true</code> if the value is associated with the given
- * attributeType or one of its ascendant
+ * {@inheritDoc}
*/
public boolean instanceOf( AttributeType attributeType ) throws LdapException
{
@@ -245,34 +256,7 @@ public abstract class AbstractValue<T> i
/**
- * Gets the normalized (canonical) representation for the wrapped value.
- * If the wrapped value is null, null is returned, otherwise the normalized
- * form is returned. If the normalized Value is null, then the wrapped
- * value is returned
- *
- * @return gets the normalized value
- */
- public T getNormalizedValue()
- {
- if ( isNull() )
- {
- return null;
- }
-
- if ( normalizedValue == null )
- {
- return get();
- }
-
- return getNormalizedValueCopy();
- }
-
-
- /**
- * Gets a reference to the the normalized (canonical) representation
- * for the wrapped value.
- *
- * @return gets a reference to the normalized value
+ * {@inheritDoc}
*/
public T getNormalizedValueReference()
{
@@ -292,9 +276,7 @@ public abstract class AbstractValue<T> i
/**
- * Check if the contained value is null or not
- *
- * @return <code>true</code> if the inner value is null.
+ * {@inheritDoc}
*/
public final boolean isNull()
{
@@ -313,14 +295,8 @@ public abstract class AbstractValue<T> i
}
- /**
- * Uses the syntaxChecker associated with the attributeType to check if the
- * value is valid. Repeated calls to this method do not attempt to re-check
- * the syntax of the wrapped value every time if the wrapped value does not
- * change. Syntax checks only result on the first check, and when the wrapped
- * value changes.
- *
- * @see Value#isValid()
+ /**
+ * {@inheritDoc}
*/
public final boolean isValid()
{
@@ -343,13 +319,7 @@ public abstract class AbstractValue<T> i
/**
- * Uses the syntaxChecker associated with the attributeType to check if the
- * value is valid. Repeated calls to this method do not attempt to re-check
- * the syntax of the wrapped value every time if the wrapped value does not
- * change. Syntax checks only result on the first check, and when the wrapped
- * value changes.
- *
- * @see ServerValue#isValid()
+ * {@inheritDoc}
*/
public final boolean isValid( SyntaxChecker syntaxChecker ) throws LdapException
{
@@ -367,10 +337,7 @@ public abstract class AbstractValue<T> i
/**
- * Normalize the value. In order to use this method, the Value
- * must be schema aware.
- *
- * @exception LdapException If the value cannot be normalized
+ * {@inheritDoc}
*/
public void normalize() throws LdapException
{
@@ -380,9 +347,7 @@ public abstract class AbstractValue<T> i
/**
- * Tells if the value has already be normalized or not.
- *
- * @return <code>true</code> if the value has already been normalized.
+ * {@inheritDoc}
*/
public final boolean isNormalized()
{
@@ -391,9 +356,7 @@ public abstract class AbstractValue<T> i
/**
- * Set the normalized flag.
- *
- * @param the value : true or false
+ * {@inheritDoc}
*/
public final void setNormalized( boolean normalized )
{
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java Mon Apr 19 14:17:49 2010
@@ -141,7 +141,7 @@ public class BinaryValue extends Abstrac
* @return the normalized version of the wrapped value
* @throws LdapException if schema entity resolution fails or normalization fails
*/
- public byte[] getNormalizedValueCopy()
+ public byte[] getNormalizedValue()
{
if ( isNull() )
{
@@ -218,22 +218,6 @@ public class BinaryValue extends Abstrac
/**
- * Gets the normalized (canonical) representation for the wrapped byte[].
- * If the wrapped byte[] is null, null is returned, otherwise the normalized
- * form is returned. If the normalizedValue is null, then this method
- * will attempt to generate it from the wrapped value: repeated calls to
- * this method do not unnecessarily normalize the wrapped value. Only changes
- * to the wrapped value result in attempts to normalize the wrapped value.
- *
- * @return gets the normalized value
- */
- public byte[] getNormalizedValue()
- {
- return getNormalizedValueCopy();
- }
-
-
- /**
* Normalize the value. For a client String value, applies the given normalizer.
*
* It supposes that the client has access to the schema in order to select the
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java Mon Apr 19 14:17:49 2010
@@ -178,18 +178,6 @@ public class StringValue extends Abstrac
/**
- * Gets a copy of the the normalized (canonical) representation
- * for the wrapped value.
- *
- * @return gets a copy of the normalized value
- */
- public String getNormalizedValueCopy()
- {
- return getNormalizedValue();
- }
-
-
- /**
* Compute the normalized (canonical) representation for the wrapped string.
* If the wrapped String is null, the normalized form will be null too.
*
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java Mon Apr 19 14:17:49 2010
@@ -24,6 +24,7 @@ import java.io.Externalizable;
import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.schema.SyntaxChecker;
@@ -37,7 +38,17 @@ import org.apache.directory.shared.ldap.
*/
public interface Value<T> extends Cloneable, Externalizable, Comparable<Value<T>>
{
+ /**
+ * Apply an AttributeType to the current Value, normalizing it.
+ *
+ * @param attributeType The AttributeType to apply
+ */
+ void apply( AttributeType attributeType );
+
+ /**
+ * @return A cloned value
+ */
Value<T> clone();
@@ -50,6 +61,28 @@ public interface Value<T> extends Clonea
/**
+ * Get the associated AttributeType
+ *
+ * @return The AttributeType
+ */
+ AttributeType getAttributeType();
+
+
+ /**
+ * 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,
+ * checking for Name will match.
+ *
+ * @param attributeType The AttributeType we are looking at
+ * @return <code>true</code> if the value is associated with the given
+ * attributeType or one of its ascendant
+ */
+ boolean instanceOf( AttributeType attributeType ) throws LdapException;
+
+
+ /**
* Get the wrapped value. It will return a copy, not a reference.
*
* @return a copy of the wrapped value
@@ -77,9 +110,11 @@ public interface Value<T> extends Clonea
/**
- * Get a reference on the stored value.
+ * Gets a reference to the wrapped binary value.
+ *
+ * Warning ! The value is not copied !!!
*
- * @return a reference on the wrapped value.
+ * @return a direct handle on the binary value that is wrapped
*/
T getReference();
@@ -92,17 +127,24 @@ public interface Value<T> extends Clonea
boolean isNormalized();
- /**
- * Tells if the value is valid. The value must have already been
- * validated at least once through a call to isValid( SyntaxChecker ).
- *
+ /**
+ * Uses the syntaxChecker associated with the attributeType to check if the
+ * value is valid. Repeated calls to this method do not attempt to re-check
+ * the syntax of the wrapped value every time if the wrapped value does not
+ * change. Syntax checks only result on the first check, and when the wrapped
+ * value changes.
+ *
* @return <code>true</code> if the value is valid
*/
boolean isValid();
/**
- * Tells if the value is valid wrt a Syntax checker
+ * Uses the syntaxChecker associated with the attributeType to check if the
+ * value is valid. Repeated calls to this method do not attempt to re-check
+ * the syntax of the wrapped value every time if the wrapped value does not
+ * change. Syntax checks only result on the first check, and when the wrapped
+ * value changes.
*
* @param checker the SyntaxChecker to use to validate the value
* @return <code>true</code> if the value is valid
@@ -142,15 +184,6 @@ public interface Value<T> extends Clonea
/**
- * Gets a copy of the the normalized (canonical) representation
- * for the wrapped value.
- *
- * @return gets a copy of the normalized value
- */
- T getNormalizedValueCopy();
-
-
- /**
* Normalize the value. In order to use this method, the Value
* must be schema aware.
*
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java Mon Apr 19 14:17:49 2010
@@ -370,13 +370,13 @@ public class BinaryValueAttributeTypeTes
AttributeType attribute = EntryUtils.getBytesAttributeType();
BinaryValue value = new BinaryValue( attribute, null );
- assertNull( value.getNormalizedValueCopy() );
+ assertNull( value.getNormalizedValue() );
value = new BinaryValue( attribute, StringTools.EMPTY_BYTES );
- assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, value.getNormalizedValueCopy() ) );
+ assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, value.getNormalizedValue() ) );
value = new BinaryValue( attribute, BYTES2 );
- assertTrue( Arrays.equals( BYTES1, value.getNormalizedValueCopy() ) );
+ assertTrue( Arrays.equals( BYTES1, value.getNormalizedValue() ) );
}
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java Mon Apr 19 14:17:49 2010
@@ -292,7 +292,7 @@ public class BinaryValueTest
assertTrue( Arrays.equals( BYTES2, cbv.getNormalizedValue() ) );
cbv.normalize( BINARY_NORMALIZER );
- byte[] copy = cbv.getNormalizedValueCopy();
+ byte[] copy = cbv.getNormalizedValue();
assertTrue( Arrays.equals( BYTES1, copy ) );
cbv.getNormalizedValueReference()[0]=0x11;
assertTrue( Arrays.equals( BYTES1, copy ) );
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/StringValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/StringValueTest.java?rev=935590&r1=935589&r2=935590&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/StringValueTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/StringValueTest.java Mon Apr 19 14:17:49 2010
@@ -379,21 +379,21 @@ public class StringValueTest
/**
- * Test method for {@link org.apache.directory.shared.ldap.entry.StringValue#getNormalizedValueCopy()}.
+ * Test method for {@link org.apache.directory.shared.ldap.entry.StringValue#getNormalizedValue()}.
*/
@Test
public void getNormalizedValueCopy() throws LdapException
{
StringValue sv = new StringValue();
- assertEquals( null, sv.getNormalizedValueCopy() );
+ assertEquals( null, sv.getNormalizedValue() );
sv = new StringValue( " This is a TEST " );
- assertEquals( " This is a TEST ", sv.getNormalizedValueCopy() );
+ assertEquals( " This is a TEST ", sv.getNormalizedValue() );
sv.normalize( new DeepTrimToLowerNormalizer( "1.1.1" ) );
- assertEquals( "this is a test", sv.getNormalizedValueCopy() );
+ assertEquals( "this is a test", sv.getNormalizedValue() );
}