org.apache.directory.shared.ldap.entry
Class AbstractValue<T>

java.lang.Object
  extended by org.apache.directory.shared.ldap.entry.AbstractValue<T>
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Value<T>>, Value<T>
Direct Known Subclasses:
BinaryValue, StringValue

public abstract class AbstractValue<T>
extends java.lang.Object
implements Value<T>

A wrapper around byte[] values in entries.

Version:
$Rev$, $Date$
Author:
Apache Directory Project
See Also:
Serialized Form

Field Summary
protected  AttributeType attributeType
          reference to the attributeType zssociated with the value
protected  boolean normalized
          A flag set when the value has been normalized
protected  T normalizedValue
          the canonical representation of the wrapped value
protected  boolean same
          A flag set if the normalized data is different from the wrapped data
protected  java.lang.Boolean valid
          cached results of the isValid() method call
protected  T wrappedValue
          the wrapped binary value
 
Constructor Summary
AbstractValue()
           
 
Method Summary
 void apply(AttributeType attributeType)
           
 Value<T> clone()
          
 AttributeType getAttributeType()
          Get the associated AttributeType
protected  LdapComparator<T> getLdapComparator()
          Gets a comparator using getMatchingRule() to resolve the matching that the comparator is extracted from.
protected  MatchingRule getMatchingRule()
          Find a matchingRule to use for normalization and comparison.
 T getNormalizedValue()
          Gets the normalized (canonical) representation for the wrapped value.
 T getNormalizedValueReference()
          Gets a reference to the the normalized (canonical) representation for the wrapped value.
protected  Normalizer getNormalizer()
          Gets a normalizer using getMatchingRule() to resolve the matchingRule that the normalizer is extracted from.
 T getReference()
          Gets a reference to the wrapped binary value.
 boolean instanceOf(AttributeType attributeType)
          Check if the value is stored into an instance of the given AttributeType, or one of its ascendant.
 boolean isNormalized()
          Tells if the value has already be normalized or not.
 boolean isNull()
          Check if the contained value is null or not
 boolean isValid()
          Uses the syntaxChecker associated with the attributeType to check if the value is valid.
 boolean isValid(SyntaxChecker syntaxChecker)
          Uses the syntaxChecker associated with the attributeType to check if the value is valid.
 void normalize()
          Normalize the value.
 void setNormalized(boolean normalized)
          Set the normalized flag.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.directory.shared.ldap.entry.Value
get, getBytes, getNormalizedValueCopy, getString, isBinary, length, normalize
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

attributeType

protected transient AttributeType attributeType
reference to the attributeType zssociated with the value


wrappedValue

protected T wrappedValue
the wrapped binary value


normalizedValue

protected T normalizedValue
the canonical representation of the wrapped value


normalized

protected boolean normalized
A flag set when the value has been normalized


valid

protected java.lang.Boolean valid
cached results of the isValid() method call


same

protected transient boolean same
A flag set if the normalized data is different from the wrapped data

Constructor Detail

AbstractValue

public AbstractValue()
Method Detail

clone

public Value<T> clone()

Specified by:
clone in interface Value<T>
Overrides:
clone in class java.lang.Object

getReference

public T getReference()
Gets a reference to the wrapped binary value. Warning ! The value is not copied !!!

Specified by:
getReference in interface Value<T>
Returns:
a direct handle on the binary value that is wrapped

getAttributeType

public AttributeType getAttributeType()
Get the associated AttributeType

Returns:
The AttributeType

apply

public void apply(AttributeType attributeType)

getLdapComparator

protected LdapComparator<T> getLdapComparator()
                                       throws LdapException
Gets a comparator using getMatchingRule() to resolve the matching that the comparator is extracted from.

Returns:
a comparator associated with the attributeType or null if one cannot be found
Throws:
LdapException - if resolution of schema entities fail

getMatchingRule

protected MatchingRule getMatchingRule()
                                throws LdapException
Find a matchingRule to use for normalization and comparison. If an equality matchingRule cannot be found it checks to see if other matchingRules are available: SUBSTR, and ORDERING. If a matchingRule cannot be found null is returned.

Returns:
a matchingRule or null if one cannot be found for the attributeType
Throws:
LdapException - if resolution of schema entities fail

getNormalizer

protected Normalizer getNormalizer()
                            throws LdapException
Gets a normalizer using getMatchingRule() to resolve the matchingRule that the normalizer is extracted from.

Returns:
a normalizer associated with the attributeType or null if one cannot be found
Throws:
LdapException - if resolution of schema entities fail

instanceOf

public boolean instanceOf(AttributeType attributeType)
                   throws LdapException
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.

Parameters:
attributeType - The AttributeType we are looking at
Returns:
true if the value is associated with the given attributeType or one of its ascendant
Throws:
LdapException

getNormalizedValue

public T getNormalizedValue()
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

Specified by:
getNormalizedValue in interface Value<T>
Returns:
gets the normalized value

getNormalizedValueReference

public T getNormalizedValueReference()
Gets a reference to the the normalized (canonical) representation for the wrapped value.

Specified by:
getNormalizedValueReference in interface Value<T>
Returns:
gets a reference to the normalized value

isNull

public final boolean isNull()
Check if the contained value is null or not

Specified by:
isNull in interface Value<T>
Returns:
true if the inner value is null.

isValid

public final boolean isValid()
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.

Specified by:
isValid in interface Value<T>
Returns:
true if the value is valid
See Also:
Value.isValid()

isValid

public final boolean isValid(SyntaxChecker syntaxChecker)
                      throws LdapException
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.

Specified by:
isValid in interface Value<T>
Parameters:
syntaxChecker - the SyntaxChecker to use to validate the value
Returns:
true if the value is valid
Throws:
LdapException - if the value cannot be validated
See Also:
ServerValue#isValid()

normalize

public void normalize()
               throws LdapException
Normalize the value. In order to use this method, the Value must be schema aware.

Specified by:
normalize in interface Value<T>
Throws:
LdapException - If the value cannot be normalized

isNormalized

public final boolean isNormalized()
Tells if the value has already be normalized or not.

Specified by:
isNormalized in interface Value<T>
Returns:
true if the value has already been normalized.

setNormalized

public final void setNormalized(boolean normalized)
Set the normalized flag.

Specified by:
setNormalized in interface Value<T>
Parameters:
the - value : true or false


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.