Class AttributeParser

java.lang.Object
org.forgerock.opendj.ldap.AttributeParser

public final class AttributeParser extends Object
A fluent API for parsing attributes as different types of object. An attribute parser is obtained from an entry using the method Entry.parseAttribute(org.forgerock.opendj.ldap.AttributeDescription) or from an attribute using Attribute.parse().

Methods throw an IllegalArgumentException when a value cannot be parsed (e.g. because its syntax is invalid). Methods which return a Set always return a modifiable non-null result, even if the attribute is null or empty.

Examples:

 Entry entry = ...;

 Calendar timestamp = entry.parseAttribute("createTimestamp").asCalendar();
 boolean isEnabled = entry.parseAttribute("enabled").asBoolean(false);

 Entry group = ...;
 Schema schema = ...;

 Set<DN> members = group.parseAttribute("member").usingSchema(schema).asSetOfDN();
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T, E extends Exception>
    T
    as(org.forgerock.util.Function<ByteString,? extends T,E> f)
    Returns the first value decoded as a T using the provided Function, or null if the attribute does not contain any values.
    <T, E extends Exception>
    T
    as(org.forgerock.util.Function<ByteString,? extends T,E> f, T defaultValue)
    Returns the first value decoded as a T using the provided Function, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as an AttributeDescription using the schema associated with this parser, or null if the attribute does not contain any values.
    Returns the first value decoded as an AttributeDescription using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as an AttributeDescription using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as a boolean, or null if the attribute does not contain any values.
    boolean
    asBoolean(boolean defaultValue)
    Returns the first value decoded as an Boolean, or defaultValue if the attribute does not contain any values.
    Returns the first value, or null if the attribute does not contain any values.
    asByteString(ByteString defaultValue)
    Returns the first value, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as a X509Certificate, or null if the attribute does not contain any values.
    Returns the first value decoded as a X509Certificate, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as a DN using the schema associated with this parser, or null if the attribute does not contain any values.
    asDN(String defaultValue)
    Returns the first value decoded as a DN using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
    asDN(DN defaultValue)
    Returns the first value decoded as a DN using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as a GeneralizedTime using the generalized time syntax, or null if the attribute does not contain any values.
    Returns the first value decoded as an GeneralizedTime using the generalized time syntax, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as an Integer, or null if the attribute does not contain any values.
    int
    asInteger(int defaultValue)
    Returns the first value decoded as an Integer, or defaultValue if the attribute does not contain any values.
    Returns the first value decoded as a Long, or null if the attribute does not contain any values.
    long
    asLong(long defaultValue)
    Returns the first value decoded as a Long, or defaultValue if the attribute does not contain any values.
    <T, E extends Exception>
    Set<T>
    asSetOf(org.forgerock.util.Function<ByteString,? extends T,E> f, Collection<? extends T> defaultValues)
    Returns the values decoded as a set of Ts using the provided Function, or defaultValues if the attribute does not contain any values.
    final <T, E extends Exception>
    Set<T>
    asSetOf(org.forgerock.util.Function<ByteString,? extends T,E> f, T... defaultValues)
    Returns the values decoded as a set of Ts using the provided Function, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or an empty set if the attribute does not contain any values.
    Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
    asSetOfBoolean(Boolean... defaultValues)
    Returns the values decoded as a set of Booleans, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of Booleans, or defaultValues if the attribute does not contain any values.
    Returns the values contained in the attribute, or defaultValues if the attribute does not contain any values.
    asSetOfByteString(ByteString... defaultValues)
    Returns the values contained in the attribute, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of X509Certificates, or an empty set if the attribute does not contain any values.
    Returns the values decoded as a set of DNs using the schema associated with this parser, or an empty set if the attribute does not contain any values.
    asSetOfDN(String... defaultValues)
    Returns the values decoded as a set of DNs using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
    asSetOfDN(Collection<DN> defaultValues)
    Returns the values decoded as a set of DNs using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
    asSetOfDN(DN... defaultValues)
    Returns the values decoded as a set of DNs using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of GeneralizedTimes using the generalized time syntax, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of GeneralizedTimes using the generalized time syntax, or defaultValues if the attribute does not contain any values.
    asSetOfInteger(Integer... defaultValues)
    Returns the values decoded as a set of Integers, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of Integers, or defaultValues if the attribute does not contain any values.
    asSetOfLong(Long... defaultValues)
    Returns the values decoded as a set of Longs, or defaultValues if the attribute does not contain any values.
    asSetOfLong(Collection<Long> defaultValues)
    Returns the values decoded as a set of Longs, or defaultValues if the attribute does not contain any values.
    asSetOfString(String... defaultValues)
    Returns the values decoded as a set of Strings, or defaultValues if the attribute does not contain any values.
    Returns the values decoded as a set of Strings, or defaultValues if the attribute does not contain any values.
    Returns the first value decoded as a String, or null if the attribute does not contain any values.
    asString(String defaultValue)
    Returns the first value decoded as a String, or defaultValue if the attribute does not contain any values.
    Returns an attribute parser for the provided attribute.
    Throws a LocalizedIllegalArgumentException if the attribute referenced by this parser is null or empty.
    Sets the Schema which will be used when parsing schema sensitive values such as DNs and attribute descriptions.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parseAttribute

      public static AttributeParser parseAttribute(Attribute attribute)
      Returns an attribute parser for the provided attribute. null attributes are permitted and will be treated as if an empty attribute was provided.
      Parameters:
      attribute - The attribute to be parsed, which may be null.
      Returns:
      The attribute parser.
    • as

      public <T, E extends Exception> T as(org.forgerock.util.Function<ByteString,? extends T,E> f) throws E
      Returns the first value decoded as a T using the provided Function, or null if the attribute does not contain any values.
      Type Parameters:
      T - The type of the value to be decoded.
      E - The type of exception thrown by the function.
      Parameters:
      f - The function which should be used to decode the value.
      Returns:
      The first value decoded as a T.
      Throws:
      E - If an error occurred when parsing the attribute.
    • as

      public <T, E extends Exception> T as(org.forgerock.util.Function<ByteString,? extends T,E> f, T defaultValue) throws E
      Returns the first value decoded as a T using the provided Function, or defaultValue if the attribute does not contain any values.
      Type Parameters:
      T - The type of the value to be decoded.
      E - The type of exception thrown by the function.
      Parameters:
      f - The function which should be used to decode the value.
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as a T.
      Throws:
      E - If an error occurred when parsing the attribute.
    • asAttributeDescription

      Returns the first value decoded as an AttributeDescription using the schema associated with this parser, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as an AttributeDescription.
    • asAttributeDescription

      Returns the first value decoded as an AttributeDescription using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as an AttributeDescription.
    • asAttributeDescription

      Returns the first value decoded as an AttributeDescription using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as an AttributeDescription.
    • asBoolean

      public Boolean asBoolean()
      Returns the first value decoded as a boolean, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as a boolean.
    • asBoolean

      public boolean asBoolean(boolean defaultValue)
      Returns the first value decoded as an Boolean, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as an Boolean.
    • asByteString

      Returns the first value, or null if the attribute does not contain any values.
      Returns:
      The first value.
    • asByteString

      public ByteString asByteString(ByteString defaultValue)
      Returns the first value, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value.
    • asCertificate

      Returns the first value decoded as a X509Certificate, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as a X509Certificate.
    • asCertificate

      Returns the first value decoded as a X509Certificate, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as a X509Certificate.
    • asDN

      public DN asDN()
      Returns the first value decoded as a DN using the schema associated with this parser, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as a DN.
    • asDN

      public DN asDN(DN defaultValue)
      Returns the first value decoded as a DN using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as a DN.
    • asDN

      public DN asDN(String defaultValue)
      Returns the first value decoded as a DN using the schema associated with this parser, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as a DN.
    • asGeneralizedTime

      Returns the first value decoded as a GeneralizedTime using the generalized time syntax, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as a GeneralizedTime.
    • asGeneralizedTime

      Returns the first value decoded as an GeneralizedTime using the generalized time syntax, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as an GeneralizedTime.
    • asInteger

      public Integer asInteger()
      Returns the first value decoded as an Integer, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as an Integer.
    • asInteger

      public int asInteger(int defaultValue)
      Returns the first value decoded as an Integer, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as an Integer.
    • asLong

      public Long asLong()
      Returns the first value decoded as a Long, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as a Long.
    • asLong

      public long asLong(long defaultValue)
      Returns the first value decoded as a Long, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as a Long.
    • asSetOf

      public <T, E extends Exception> Set<T> asSetOf(org.forgerock.util.Function<ByteString,? extends T,E> f, Collection<? extends T> defaultValues) throws E
      Returns the values decoded as a set of Ts using the provided Function, or defaultValues if the attribute does not contain any values.
      Type Parameters:
      T - The type of the values to be decoded.
      E - The type of exception thrown by the function.
      Parameters:
      f - The function which should be used to decode values.
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Ts.
      Throws:
      E - If an error occurred when parsing the attribute.
    • asSetOf

      @SafeVarargs public final <T, E extends Exception> Set<T> asSetOf(org.forgerock.util.Function<ByteString,? extends T,E> f, T... defaultValues) throws E
      Returns the values decoded as a set of Ts using the provided Function, or defaultValues if the attribute does not contain any values.
      Type Parameters:
      T - The type of the values to be decoded.
      E - The type of exception thrown by the function.
      Parameters:
      f - The function which should be used to decode values.
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Ts.
      Throws:
      E - If an error occurred when parsing the attribute.
    • asSetOfAttributeDescription

      Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or an empty set if the attribute does not contain any values.
      Returns:
      The values decoded as a set of AttributeDescriptions.
    • asSetOfAttributeDescription

      Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of AttributeDescriptions.
    • asSetOfAttributeDescription

      Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of AttributeDescriptions.
    • asSetOfAttributeDescription

      Returns the values decoded as a set of AttributeDescriptions using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of AttributeDescriptions.
    • asSetOfBoolean

      public Set<Boolean> asSetOfBoolean(Boolean... defaultValues)
      Returns the values decoded as a set of Booleans, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Booleans.
    • asSetOfBoolean

      public Set<Boolean> asSetOfBoolean(Collection<Boolean> defaultValues)
      Returns the values decoded as a set of Booleans, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Booleans.
    • asSetOfByteString

      public Set<ByteString> asSetOfByteString(ByteString... defaultValues)
      Returns the values contained in the attribute, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values contained in the attribute.
    • asSetOfByteString

      Returns the values contained in the attribute, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values contained in the attribute.
    • asSetOfCertificate

      Returns the values decoded as a set of X509Certificates, or an empty set if the attribute does not contain any values.
      Returns:
      The values decoded as a set of X509Certificates.
    • asSetOfDN

      public Set<DN> asSetOfDN()
      Returns the values decoded as a set of DNs using the schema associated with this parser, or an empty set if the attribute does not contain any values.
      Returns:
      The values decoded as a set of DNs.
    • asSetOfDN

      public Set<DN> asSetOfDN(Collection<DN> defaultValues)
      Returns the values decoded as a set of DNs using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of DNs.
    • asSetOfDN

      public Set<DN> asSetOfDN(DN... defaultValues)
      Returns the values decoded as a set of DNs using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of DNs.
    • asSetOfDN

      public Set<DN> asSetOfDN(String... defaultValues)
      Returns the values decoded as a set of DNs using the schema associated with this parser, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of DNs.
    • asSetOfGeneralizedTime

      Returns the values decoded as a set of GeneralizedTimes using the generalized time syntax, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of GeneralizedTimes.
    • asSetOfGeneralizedTime

      Returns the values decoded as a set of GeneralizedTimes using the generalized time syntax, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of GeneralizedTimes.
    • asSetOfInteger

      public Set<Integer> asSetOfInteger(Collection<Integer> defaultValues)
      Returns the values decoded as a set of Integers, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Integers.
    • asSetOfInteger

      public Set<Integer> asSetOfInteger(Integer... defaultValues)
      Returns the values decoded as a set of Integers, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Integers.
    • asSetOfLong

      public Set<Long> asSetOfLong(Collection<Long> defaultValues)
      Returns the values decoded as a set of Longs, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Longs.
    • asSetOfLong

      public Set<Long> asSetOfLong(Long... defaultValues)
      Returns the values decoded as a set of Longs, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Longs.
    • asSetOfString

      public Set<String> asSetOfString(Collection<String> defaultValues)
      Returns the values decoded as a set of Strings, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Strings.
    • asSetOfString

      public Set<String> asSetOfString(String... defaultValues)
      Returns the values decoded as a set of Strings, or defaultValues if the attribute does not contain any values.
      Parameters:
      defaultValues - The default values to return if the attribute is empty.
      Returns:
      The values decoded as a set of Strings.
    • asString

      public String asString()
      Returns the first value decoded as a String, or null if the attribute does not contain any values.
      Returns:
      The first value decoded as a String.
    • asString

      public String asString(String defaultValue)
      Returns the first value decoded as a String, or defaultValue if the attribute does not contain any values.
      Parameters:
      defaultValue - The default value to return if the attribute is empty.
      Returns:
      The first value decoded as a String.
    • requireValue

      Throws a LocalizedIllegalArgumentException if the attribute referenced by this parser is null or empty.
      Returns:
      A reference to this attribute parser.
      Throws:
      org.forgerock.i18n.LocalizedIllegalArgumentException - If the attribute referenced by this parser is null or empty.
    • usingSchema

      Sets the Schema which will be used when parsing schema sensitive values such as DNs and attribute descriptions.
      Parameters:
      schema - The Schema which will be used when parsing schema sensitive values.
      Returns:
      This attribute parser.