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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Value(byte[] value)
Creates a Value with an initial user provided binary value.Value(String upValue)
Creates a Value with an initial user provided String value.Value(AttributeType attributeType, byte[] upValue)
Creates a schema aware binary Value with an initial value.Value(AttributeType attributeType, String upValue)
Creates a schema aware StringValue with an initial user provided String value.Value(AttributeType attributeType, String upValue, String normValue)
Creates a schema aware StringValue with an initial user provided String value and its normalized ValueValue(AttributeType attributeType, Value value)
Creates a Value from an existing Value with an AttributeType
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Value
clone()
Clone a Valueint
compareTo(byte[] other)
Compare two values.int
compareTo(String other)
Compare the current value with a String.int
compareTo(Value other)
Compare two values.static Value
createValue(AttributeType attributeType)
Create a Value with an AttributeType.int
deserialize(byte[] buffer, int pos)
Deserialize a StringValue from a byte[], starting at a given positionstatic Value
deserialize(ObjectInput in)
Deserialize a Value.static Value
deserialize(AttributeType attributeType, ObjectInput in)
Deserialize a Value.boolean
equals(Object obj)
We compare two values using their Comparator, if any.AttributeType
getAttributeType()
Get the associated AttributeTypebyte[]
getBytes()
Get the wrapped value as a byte[], if and only if the Value is binary, otherwise returns null.String
getNormalized()
String
getString()
Get the User Provided value.int
hashCode()
boolean
isHumanReadable()
Tells if the current value is Human Readableboolean
isInstanceOf(AttributeType attributeType)
Check if the value is stored into an instance of the given AttributeType, or one of its ascendant.boolean
isNull()
Check if the contained value is null or notboolean
isSchemaAware()
Tells if the value is schema aware or not.boolean
isValid(SyntaxChecker syntaxChecker)
Uses the syntaxChecker associated with the attributeType to check if the value is valid.int
length()
void
readExternal(ObjectInput in)
int
serialize(byte[] buffer, int pos)
Serialize the Value into a buffer at the given position.String
toString()
void
writeExternal(ObjectOutput out)
-
-
-
Constructor Detail
-
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 ValueupValue
- 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 StringValueupValue
- 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 StringValueupValue
- the value to wrapnormValue
- 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 StringValuevalue
- the original Value- Throws:
LdapInvalidAttributeValueException
- If the value is invalid
-
-
Method Detail
-
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.
-
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
-
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
-
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 StringValuepos
- 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 readClassNotFoundException
- 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 nullin
- The input stream- Returns:
- A new Value instance
- Throws:
IOException
- If the stream can't be readClassNotFoundException
- 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 StringValuepos
- The position in the buffer- Returns:
- The new position
- Throws:
IOException
- If the serialized value is not a StringValueLdapInvalidAttributeValueException
- If the value is invalid
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- 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 interfaceComparable<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 classObject
- See Also:
Object.equals(Object)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classObject
- Returns:
- the instance's hashcode
- See Also:
Object.hashCode()
-
toString
public String toString()
- Overrides:
toString
in classObject
- See Also:
Object.toString()
-
-