6.5 - Ava

An Ava is used to store an Attribute value associated to an AttributeType.

It describes a container holding an AttributeType associated with a Value in a Rdn. An example would be:

    dc=example

where ‘dc’ is the AttributeType and ‘example’ its associated value.

The value can be a binary or a String value, depending on the AttributeType.

We can create a schema aware Ava, or just a plain Ava. Having a schema aware Ava allows further controls to be made on the value we inject. Is syntax will be checked against the AttributeType syntax.

Most of the time, one will not need to create or manipulate an Ava, as it’s an internal element of a Rdn.

Ava is also a Externalizable class.

Ava instances are immutable.

Usage

As for the Dn and Rdn classes, we have to hold two representations of its internal AttributeType and Value. The User Provided form, and the escaped form (which are used inside filters). If the AVA is schema aware, the escaped form will be computed, otherwise we store the user provided form. Let’s see some examples.

Schema Aware Ava

Here we will create an AVA and check that the user provided values are preserved. The getName() and getString() methods will give back this user provided form, in a form that allows it to be used in a Filter.

    Ava atav = new Ava( schemaManager, " CommonName ", " This is    a TEST " );
    System.out.println( "toString     : '" + atav.toString() + "'" );
    System.out.println( "Escaped      : '" + atav.getEscaped() + "'" );
    System.out.println( "UserProvided : '" + atav.getName() + "'" );

will produce :

    toString     : ' CommonName =\ This is    a TEST\ '
    Escaped      : ' CommonName =\ This is    a TEST\ '
    UserProvided : ' CommonName =\ This is    a TEST\ '

Not Schema Aware

The biggest difference in this case is that the AttributeType will not be replaced by its Oid, but instead by a lowercase form of the provided ID. We also escape the leading and trailing spaces in the value.

public void testAvaSimpleNorm() throws LdapException
{
    Ava atav = new Ava( null, " CommonName ", " This is    a TEST " );
    assertEquals( " CommonName = This is    a TEST ", atav.toString() );
    assertEquals( "commonname=\\ This is    a TEST\\ ", atav.getNormName() );
    assertEquals( " CommonName = This is    a TEST ", atav.getUpName() );
}