public final class AttributeParser extends Object
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();
| Modifier and Type | Method and Description |
|---|---|
<T> T |
as(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> f)
Returns the first value decoded as a
T using the provided
Function, or null if the attribute does not contain any
values. |
<T> T |
as(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> 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. |
AttributeDescription |
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. |
AttributeDescription |
asAttributeDescription(AttributeDescription defaultValue)
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. |
AttributeDescription |
asAttributeDescription(String defaultValue)
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. |
Boolean |
asBoolean()
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. |
ByteString |
asByteString()
Returns the first value, or
null if the attribute does not
contain any values. |
ByteString |
asByteString(ByteString defaultValue)
Returns the first value, or
defaultValue if the attribute does
not contain any values. |
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. |
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. |
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. |
GeneralizedTime |
asGeneralizedTime()
Returns the first value decoded as a
GeneralizedTime using the
generalized time syntax, or null if the attribute does not
contain any values. |
GeneralizedTime |
asGeneralizedTime(GeneralizedTime defaultValue)
Returns the first value decoded as an
GeneralizedTime using the
generalized time syntax, or defaultValue if the attribute does
not contain any values. |
Integer |
asInteger()
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. |
Long |
asLong()
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> Set<T> |
asSetOf(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> 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. |
<T> Set<T> |
asSetOf(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> 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. |
Set<AttributeDescription> |
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. |
Set<AttributeDescription> |
asSetOfAttributeDescription(AttributeDescription... defaultValues)
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. |
Set<AttributeDescription> |
asSetOfAttributeDescription(Collection<AttributeDescription> defaultValues)
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. |
Set<AttributeDescription> |
asSetOfAttributeDescription(String... defaultValues)
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. |
Set<Boolean> |
asSetOfBoolean(Boolean... defaultValues)
Returns the values decoded as a set of
Booleans, or
defaultValues if the attribute does not contain any values. |
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. |
Set<ByteString> |
asSetOfByteString(ByteString... defaultValues)
Returns the values contained in the attribute, or
defaultValues
if the attribute does not contain any values. |
Set<ByteString> |
asSetOfByteString(Collection<ByteString> defaultValues)
Returns the values contained in the attribute, or
defaultValues
if the attribute does not contain any values. |
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. |
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. |
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. |
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. |
Set<GeneralizedTime> |
asSetOfGeneralizedTime(Collection<GeneralizedTime> defaultValues)
Returns the values decoded as a set of
GeneralizedTimes using the
generalized time syntax, or defaultValues if the attribute does
not contain any values. |
Set<GeneralizedTime> |
asSetOfGeneralizedTime(GeneralizedTime... defaultValues)
Returns the values decoded as a set of
GeneralizedTimes using the
generalized time syntax, or defaultValues if the attribute does
not contain any values. |
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. |
Set<Integer> |
asSetOfInteger(Integer... defaultValues)
Returns the values decoded as a set of
Integers, or
defaultValues if the attribute does not contain any values. |
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. |
Set<Long> |
asSetOfLong(Long... defaultValues)
Returns the values decoded as a set of
Longs, or
defaultValues if the attribute does not contain any values. |
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. |
Set<String> |
asSetOfString(String... defaultValues)
Returns the values decoded as a set of
Strings, or
defaultValues if the attribute does not contain any values. |
String |
asString()
Returns the first value decoded as a
String, or null if
the attribute does not contain any values. |
String |
asString(String defaultValue)
Returns the first value decoded as a
String, or
defaultValue if the attribute does not contain any values. |
static AttributeParser |
parseAttribute(Attribute attribute)
Returns an attribute parser for the provided attribute.
|
AttributeParser |
requireValue()
Throws a
NoSuchElementException if the attribute referenced by
this parser is null or empty. |
AttributeParser |
usingSchema(Schema schema)
Sets the
Schema which will be used when parsing schema sensitive
values such as DNs and attribute descriptions. |
public static AttributeParser parseAttribute(Attribute attribute)
null
attributes are permitted and will be treated as if an empty attribute was
provided.attribute - The attribute to be parsed, which may be null.public <T> T as(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> f)
T using the provided
Function, or null if the attribute does not contain any
values.T - The type of the value to be decoded.f - The function which should be used to decode the value.T.public <T> T as(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> f, T defaultValue)
T using the provided
Function, or defaultValue if the attribute does not
contain any values.T - The type of the value to be decoded.f - The function which should be used to decode the value.defaultValue - The default value to return if the attribute is empty.T.public AttributeDescription asAttributeDescription()
AttributeDescription using
the schema associated with this parser, or null if the attribute
does not contain any values.AttributeDescription.public AttributeDescription asAttributeDescription(AttributeDescription defaultValue)
AttributeDescription using
the schema associated with this parser, or defaultValue if the
attribute does not contain any values.defaultValue - The default value to return if the attribute is empty.AttributeDescription.public AttributeDescription asAttributeDescription(String defaultValue)
AttributeDescription using
the schema associated with this parser, or defaultValue if the
attribute does not contain any values.defaultValue - The default value to return if the attribute is empty.AttributeDescription.public Boolean asBoolean()
null if the
attribute does not contain any values.public boolean asBoolean(boolean defaultValue)
Boolean, or
defaultValue if the attribute does not contain any values.defaultValue - The default value to return if the attribute is empty.Boolean.public ByteString asByteString()
null if the attribute does not
contain any values.public ByteString asByteString(ByteString defaultValue)
defaultValue if the attribute does
not contain any values.defaultValue - The default value to return if the attribute is empty.public DN asDN()
DN using the schema
associated with this parser, or null if the attribute does not
contain any values.DN.public DN asDN(DN defaultValue)
DN using the schema
associated with this parser, or defaultValue if the attribute
does not contain any values.defaultValue - The default value to return if the attribute is empty.DN.public DN asDN(String defaultValue)
DN using the schema
associated with this parser, or defaultValue if the attribute
does not contain any values.defaultValue - The default value to return if the attribute is empty.DN.public GeneralizedTime asGeneralizedTime()
GeneralizedTime using the
generalized time syntax, or null if the attribute does not
contain any values.GeneralizedTime.public GeneralizedTime asGeneralizedTime(GeneralizedTime defaultValue)
GeneralizedTime using the
generalized time syntax, or defaultValue if the attribute does
not contain any values.defaultValue - The default value to return if the attribute is empty.GeneralizedTime.public Integer asInteger()
Integer, or null if
the attribute does not contain any values.Integer.public int asInteger(int defaultValue)
Integer, or
defaultValue if the attribute does not contain any values.defaultValue - The default value to return if the attribute is empty.Integer.public Long asLong()
Long, or null if the
attribute does not contain any values.Long.public long asLong(long defaultValue)
Long, or
defaultValue if the attribute does not contain any values.defaultValue - The default value to return if the attribute is empty.Long.public <T> Set<T> asSetOf(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> f, Collection<? extends T> defaultValues)
Ts using the provided
Function, or defaultValues if the attribute does not
contain any values.T - The type of the values to be decoded.f - The function which should be used to decode values.defaultValues - The default values to return if the attribute is empty.Ts.public <T> Set<T> asSetOf(org.forgerock.util.Function<ByteString,? extends T,org.forgerock.util.promise.NeverThrowsException> f, T... defaultValues)
Ts using the provided
Function, or defaultValues if the attribute does not
contain any values.T - The type of the values to be decoded.f - The function which should be used to decode values.defaultValues - The default values to return if the attribute is empty.Ts.public Set<AttributeDescription> asSetOfAttributeDescription()
AttributeDescriptions
using the schema associated with this parser, or an empty set if the
attribute does not contain any values.AttributeDescriptions.public Set<AttributeDescription> asSetOfAttributeDescription(AttributeDescription... defaultValues)
AttributeDescriptions
using the schema associated with this parser, or defaultValues if
the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.AttributeDescriptions.public Set<AttributeDescription> asSetOfAttributeDescription(Collection<AttributeDescription> defaultValues)
AttributeDescriptions
using the schema associated with this parser, or defaultValues if
the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.AttributeDescriptions.public Set<AttributeDescription> asSetOfAttributeDescription(String... defaultValues)
AttributeDescriptions
using the schema associated with this parser, or defaultValues if
the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.AttributeDescriptions.public Set<Boolean> asSetOfBoolean(Boolean... defaultValues)
Booleans, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Booleans.public Set<Boolean> asSetOfBoolean(Collection<Boolean> defaultValues)
Booleans, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Booleans.public Set<ByteString> asSetOfByteString(ByteString... defaultValues)
defaultValues
if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.public Set<ByteString> asSetOfByteString(Collection<ByteString> defaultValues)
defaultValues
if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.public Set<DN> asSetOfDN()
DNs using the schema
associated with this parser, or an empty set if the attribute does not
contain any values.DNs.public Set<DN> asSetOfDN(Collection<DN> defaultValues)
DNs using the schema
associated with this parser, or defaultValues if the attribute
does not contain any values.defaultValues - The default values to return if the attribute is empty.DNs.public Set<DN> asSetOfDN(DN... defaultValues)
DNs using the schema
associated with this parser, or defaultValues if the attribute
does not contain any values.defaultValues - The default values to return if the attribute is empty.DNs.public Set<DN> asSetOfDN(String... defaultValues)
DNs using the schema
associated with this parser, or defaultValues if the attribute
does not contain any values.defaultValues - The default values to return if the attribute is empty.DNs.public Set<GeneralizedTime> asSetOfGeneralizedTime(Collection<GeneralizedTime> defaultValues)
GeneralizedTimes using the
generalized time syntax, or defaultValues if the attribute does
not contain any values.defaultValues - The default values to return if the attribute is empty.GeneralizedTimes.public Set<GeneralizedTime> asSetOfGeneralizedTime(GeneralizedTime... defaultValues)
GeneralizedTimes using the
generalized time syntax, or defaultValues if the attribute does
not contain any values.defaultValues - The default values to return if the attribute is empty.GeneralizedTimes.public Set<Integer> asSetOfInteger(Collection<Integer> defaultValues)
Integers, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Integers.public Set<Integer> asSetOfInteger(Integer... defaultValues)
Integers, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Integers.public Set<Long> asSetOfLong(Collection<Long> defaultValues)
Longs, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Longs.public Set<Long> asSetOfLong(Long... defaultValues)
Longs, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Longs.public Set<String> asSetOfString(Collection<String> defaultValues)
Strings, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Strings.public Set<String> asSetOfString(String... defaultValues)
Strings, or
defaultValues if the attribute does not contain any values.defaultValues - The default values to return if the attribute is empty.Strings.public String asString()
String, or null if
the attribute does not contain any values.String.public String asString(String defaultValue)
String, or
defaultValue if the attribute does not contain any values.defaultValue - The default value to return if the attribute is empty.String.public AttributeParser requireValue()
NoSuchElementException if the attribute referenced by
this parser is null or empty.NoSuchElementException - If the attribute referenced by this parser is null or
empty.public AttributeParser usingSchema(Schema schema)
Schema which will be used when parsing schema sensitive
values such as DNs and attribute descriptions.schema - The Schema which will be used when parsing schema
sensitive values.Copyright © 2011-2015 ForgeRock AS. All Rights Reserved.