6.35 - Value

The Value class is used to store an attribute's value. Such a value can be either a String or a byte[], depending on the nature of the AttributeType (the default is that the Value is a String). Each value is associated to an AttributeType, and is used in an Entry or a DN.

We can create a schema aware Value, or just a plain Value. Having a schema aware Value allows further controls to be made on the value injected : its syntax will be checked against the AttributeType syntax.

Value is also a Externalizable class.

Value instances are immutable.

Creating a value

There are two ways to create a value: - using a constructor - using a static factory (useful for deserialization)

You can create the value passing it an AttributeType, or without it. Here are the possible constructors:

| With an AttributeType | Without an attributeType | Description | |:-:|:-:|:-:| | Value( AttributeType, byte[] upValue ) | Value( byte[] upValue ) | Creates a Value with a binary content | | Value( AttributeType, String upValue ) | Value( String upValue ) | Creates a Value with a String content | | Value( AttributeType, Value ) | - | Create a new Value from an existing one, applying the SchemaManager on it |

The third constructor is quite specific, as Value is immutable, and it allows you to associate a SchemaManager to a Value instance (creating a new Value in the process). The new Value instance will be schema aware.

Operations on a Value

There are ways to consult the content of the Value, and its status. Here is the list of common operations:

| Operation | Description | |:-:|:-:| | clone() | Clone the current Value, creating a new instance | | compareTo( byte[] ) | Compare the content of the current value to the given byte[] | | compareTo( String ) | Compare the content of the current value to the given String | | compareTo( Value ) | Compare the content of the current value to the given Value | | deserialize( byte[], int ) | Create a Value deserializing it from the byte[], starting at a given position | | equals( Object ) | Tells if the current Value is equal to the provided object | | getAttributeType() | Get back the AttributeType associated with this value, if any | | getBytes() | Get the byte[] representation of this Value | | getValue() | Get the Value as a String, if the Value is Human Readable | | hashCode() | Compute the Value hashcode | | isHumanReadable() | Tells if the Value is Humane Readable (ie, a String) | | isInstanceOf( AttributeType ) | Tells if the Value is an instance of a given AttributeType, or of one of its parent | | isNull() | Tells if the contained value is null | | isSchemaAware() | Tells if teh Value is schema aware | | isValid( SyntaxChecker ) | Check the contained value | | length() | Returns the contained value's length (number of chars for a String, number of bytes for a byte[]) | | readExternal( ObjectInput ) | Read a new Value from a stream of bytes | | serialize( byte[], int ) | Write the Value into a stream of bytes | | toString() | Returns a String representation of the Value instance | | writeExternal( ObjectOutput ) | Write the Value into a stream | |