Class Value

java.lang.Object
org.apache.directory.api.ldap.model.entry.Value
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Comparable<Value>

public class Value extends Object implements Cloneable, Externalizable, Comparable<Value>
A Class for wrapping attribute values stored into an Entry Attribute, or a AVA. We keep the value as byte[] unless we need to convert them to a String (if we have a HR Value). The serialized Value will be stored as :
 +---------+
 | boolean | isHR flag
 +---------+
 | boolean | TRUE if the value is not null, FALSE otherwise
 +---------+
[|   int   |]  If the previous flag is TRUE, the length of the value
[+---------+]
[| byte[]  |] The value itself
[+---------+]
 | boolean | TRUE if we have a prepared String
 +---------+
[| String  |] The prepared String if we have it
[+---------+]
Author:
Apache Directory Project
See Also:
  • Constructor Details

    • Value

      public Value(String upValue)
      Creates a Value with an initial user provided String value.
      Parameters:
      upValue - the value to wrap. It can be null
    • Value

      public Value(byte[] value)
      Creates a Value with an initial user provided binary value.
      Parameters:
      value - the binary value to wrap which may be null, or a zero length byte array
    • Value

      public Value(AttributeType attributeType, byte[] upValue) throws LdapInvalidAttributeValueException
      Creates a schema aware binary Value with an initial value.
      Parameters:
      attributeType - the schema type associated with this Value
      upValue - the value to wrap
      Throws:
      LdapInvalidAttributeValueException - If the added value is invalid accordingly to the schema
    • Value

      public Value(AttributeType attributeType, String upValue) throws LdapInvalidAttributeValueException
      Creates a schema aware StringValue with an initial user provided String value.
      Parameters:
      attributeType - the schema type associated with this StringValue
      upValue - the value to wrap
      Throws:
      LdapInvalidAttributeValueException - If the added value is invalid accordingly to the schema
    • Value

      public Value(AttributeType attributeType, String upValue, String normValue) throws LdapInvalidAttributeValueException
      Creates a schema aware StringValue with an initial user provided String value and its normalized Value
      Parameters:
      attributeType - the schema type associated with this StringValue
      upValue - the value to wrap
      normValue - the normalized value to wrap
      Throws:
      LdapInvalidAttributeValueException - If the added value is invalid accordingly to the schema
    • Value

      public Value(AttributeType attributeType, Value value) throws LdapInvalidAttributeValueException
      Creates a Value from an existing Value with an AttributeType
      Parameters:
      attributeType - the schema attribute type associated with this StringValue
      value - the original Value
      Throws:
      LdapInvalidAttributeValueException - If the value is invalid
  • Method Details

    • createValue

      public static Value createValue(AttributeType attributeType)
      Create a Value with an AttributeType. It will not contain anything and will only be used by the deserializer.
      Parameters:
      attributeType - The ATttributeType to use
      Returns:
      An instance of value.
    • clone

      public Value clone()
      Clone a Value
      Overrides:
      clone in class Object
      Returns:
      A cloned value
    • isNull

      public boolean isNull()
      Check if the contained value is null or not
      Returns:
      true if the inner value is null.
    • getAttributeType

      public AttributeType getAttributeType()
      Get the associated AttributeType
      Returns:
      The AttributeType
    • isInstanceOf

      public boolean isInstanceOf(AttributeType attributeType)
      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
    • getEscaped

      public String getEscaped()
      Returns:
      The value as an escaped String
    • getString

      public String getString()
      Get the User Provided value. If the value is Human Readable, it will return the stored String, otherwise it will returns a String based on the bytes - which may be invalid if the value is a pure binary -.
      Returns:
      The user provided value
    • getNormalized

      public String getNormalized()
      Returns:
      The normalized value
    • getUpValue

      public String getUpValue()
      Returns:
      The User Provided value
    • getBytes

      public byte[] getBytes()
      Get the wrapped value as a byte[], if and only if the Value is binary, otherwise returns null.
      Returns:
      the wrapped value as a byte[]
    • isSchemaAware

      public boolean isSchemaAware()
      Tells if the value is schema aware or not.
      Returns:
      true if the value is sxhema aware
    • isValid

      public final boolean isValid(SyntaxChecker syntaxChecker) throws LdapInvalidAttributeValueException
      Uses the syntaxChecker associated with the attributeType to check if the value is valid.
      Parameters:
      syntaxChecker - the SyntaxChecker to use to validate the value
      Returns:
      true if the value is valid
      Throws:
      LdapInvalidAttributeValueException - if the value cannot be validated
    • isHumanReadable

      public boolean isHumanReadable()
      Tells if the current value is Human Readable
      Returns:
      true if the value is a String, false otherwise
    • length

      public int length()
      Returns:
      The length of the interned value
    • serialize

      public int serialize(byte[] buffer, int pos)
      Serialize the Value into a buffer at the given position.
      Parameters:
      buffer - The buffer which will contain the serialized StringValue
      pos - The position in the buffer for the serialized value
      Returns:
      The new position in the buffer
    • deserialize

      public static Value deserialize(ObjectInput in) throws IOException, ClassNotFoundException
      Deserialize a Value. It will return a new Value instance.
      Parameters:
      in - The input stream
      Returns:
      A new Value instance
      Throws:
      IOException - If the stream can't be read
      ClassNotFoundException - If we can't instanciate a Value
    • deserialize

      public static Value deserialize(AttributeType attributeType, ObjectInput in) throws IOException, ClassNotFoundException
      Deserialize a Value. It will return a new Value instance.
      Parameters:
      attributeType - The AttributeType associated with the Value. Can be null
      in - The input stream
      Returns:
      A new Value instance
      Throws:
      IOException - If the stream can't be read
      ClassNotFoundException - If we can't instanciate a Value
    • deserialize

      public int deserialize(byte[] buffer, int pos) throws IOException, LdapInvalidAttributeValueException
      Deserialize a StringValue from a byte[], starting at a given position
      Parameters:
      buffer - The buffer containing the StringValue
      pos - The position in the buffer
      Returns:
      The new position
      Throws:
      IOException - If the serialized value is not a StringValue
      LdapInvalidAttributeValueException - If the value is invalid
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • compareTo

      public int compareTo(String other)
      Compare the current value with a String.
      Parameters:
      other - the String we want to compare the current value with
      Returns:
      a positive value if the current value is above the provided String, a negative value if it's below, 0 if they are equal.
      Throws:
      IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
    • compareTo

      public int compareTo(byte[] other)
      Compare two values. We compare the stored bytes
      Parameters:
      other - the byte[] we want to compare the current value with
      Returns:
      a positive value if the current value is above the provided byte[], a negative value if it's below, 0 if they are equal.
      Throws:
      IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
    • compareTo

      public int compareTo(Value other)
      Compare two values. We either compare the stored bytes, or we use the AttributeType Comparator, if we have an Ordered MatchingRule.
      Specified by:
      compareTo in interface Comparable<Value>
      Parameters:
      other - The other Value we want to compare the current value with
      Returns:
      a positive value if the current value is above the provided value, a negative value if it's below, 0 if they are equal.
      Throws:
      IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
    • equals

      public boolean equals(Object obj)
      We compare two values using their Comparator, if any.
      Overrides:
      equals in class Object
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      the instance's hashcode
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also: