Class Value
java.lang.Object
org.apache.directory.api.ldap.model.entry.Value
- All Implemented Interfaces:
Externalizable, Serializable, Cloneable, 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 Summary
ConstructorsConstructorDescriptionValue(byte[] value) Creates a Value with an initial user provided binary value.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
Modifier and TypeMethodDescriptionclone()Clone a ValueintcompareTo(byte[] other) Compare two values.intCompare the current value with a String.intCompare two values.static ValuecreateValue(AttributeType attributeType) Create a Value with an AttributeType.intdeserialize(byte[] buffer, int pos) Deserialize a StringValue from a byte[], starting at a given positionstatic ValueDeserialize a Value.static Valuedeserialize(AttributeType attributeType, ObjectInput in) Deserialize a Value.booleanWe compare two values using their Comparator, if any.Get the associated AttributeTypebyte[]getBytes()Get the wrapped value as a byte[], if and only if the Value is binary, otherwise returns null.Get the User Provided value.inthashCode()booleanTells if the current value is Human ReadablebooleanisInstanceOf(AttributeType attributeType) Check if the value is stored into an instance of the given AttributeType, or one of its ascendant.booleanisNull()Check if the contained value is null or notbooleanTells if the value is schema aware or not.final booleanisValid(SyntaxChecker syntaxChecker) Uses the syntaxChecker associated with the attributeType to check if the value is valid.intlength()voidintserialize(byte[] buffer, int pos) Serialize the Value into a buffer at the given position.toString()void
-
Constructor Details
-
Value
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
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
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
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 Details
-
createValue
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
-
isNull
public boolean isNull()Check if the contained value is null or not- Returns:
trueif the inner value is null.
-
getAttributeType
-
isInstanceOf
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:
trueif the value is associated with the given attributeType or one of its ascendant
-
getEscaped
- Returns:
- The value as an escaped 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
- Returns:
- The normalized value
-
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:
trueif the value is sxhema aware
-
isValid
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:
trueif 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:
trueif the value is a String,falseotherwise
-
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
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
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
compareTo
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
Compare two values. We either compare the stored bytes, or we use the AttributeType Comparator, if we have an Ordered MatchingRule.- Specified by:
compareToin 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
-
hashCode
-
toString
-