Package org.forgerock.opendj.ldap
Class AttributeParser
java.lang.Object
org.forgerock.opendj.ldap.AttributeParser
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();
-
Method Summary
Modifier and TypeMethodDescription<T,
E extends Exception>
Tas
(Function<ByteString, ? extends T, E> f) Returns the first value decoded as aT
using the providedFunction
, ornull
if the attribute does not contain any values.<T,
E extends Exception>
Tas
(Function<ByteString, ? extends T, E> f, T defaultValue) Returns the first value decoded as aT
using the providedFunction
, ordefaultValue
if the attribute does not contain any values.Returns the first value decoded as anAttributeDescription
using the schema associated with this parser, ornull
if the attribute does not contain any values.asAttributeDescription
(String defaultValue) Returns the first value decoded as anAttributeDescription
using the schema associated with this parser, ordefaultValue
if the attribute does not contain any values.asAttributeDescription
(AttributeDescription defaultValue) Returns the first value decoded as anAttributeDescription
using the schema associated with this parser, ordefaultValue
if the attribute does not contain any values.Returns the first value decoded as a boolean, ornull
if the attribute does not contain any values.boolean
asBoolean
(boolean defaultValue) Returns the first value decoded as anBoolean
, ordefaultValue
if the attribute does not contain any values.Returns the first value, ornull
if the attribute does not contain any values.asByteString
(ByteString defaultValue) Returns the first value, ordefaultValue
if the attribute does not contain any values.Returns the first value decoded as aX509Certificate
, ornull
if the attribute does not contain any values.asCertificate
(X509Certificate defaultValue) Returns the first value decoded as aX509Certificate
, ordefaultValue
if the attribute does not contain any values.asDn()
Returns the first value decoded as aDN
using the schema associated with this parser, ornull
if the attribute does not contain any values.Returns the first value decoded as aDN
using the schema associated with this parser, ordefaultValue
if the attribute does not contain any values.Returns the first value decoded as aDN
using the schema associated with this parser, ordefaultValue
if the attribute does not contain any values.asDuration
(Duration defaultValue) Returns the first value decoded as aDuration
ordefaultValue
if the attribute does not contain any values.Returns the first value decoded as aGeneralizedTime
using the generalized time syntax, ornull
if the attribute does not contain any values.asGeneralizedTime
(GeneralizedTime defaultValue) Returns the first value decoded as anGeneralizedTime
using the generalized time syntax, ordefaultValue
if the attribute does not contain any values.Returns the first value decoded as anInteger
, ornull
if the attribute does not contain any values.int
asInteger
(int defaultValue) Returns the first value decoded as anInteger
, ordefaultValue
if the attribute does not contain any values.asLong()
Returns the first value decoded as aLong
, ornull
if the attribute does not contain any values.long
asLong
(long defaultValue) Returns the first value decoded as aLong
, ordefaultValue
if the attribute does not contain any values.asPath()
Returns the first value decoded as aPath
, ornull
if the attribute does not contain any values.Returns the first value decoded as aPath
, or defaultValue if the attribute does not contain any values.asSetOf
(Function<ByteString, ? extends T, E> f, Collection<? extends T> defaultValues) Returns the values decoded as a set ofT
s using the providedFunction
, ordefaultValues
if the attribute does not contain any values.asSetOf
(Function<ByteString, ? extends T, E> f, T... defaultValues) Returns the values decoded as a set ofT
s using the providedFunction
, ordefaultValues
if the attribute does not contain any values.Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, or an empty set if the attribute does not contain any values.asSetOfAttributeDescription
(String... defaultValues) Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, ordefaultValues
if the attribute does not contain any values.asSetOfAttributeDescription
(Collection<AttributeDescription> defaultValues) Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, ordefaultValues
if the attribute does not contain any values.asSetOfAttributeDescription
(AttributeDescription... defaultValues) Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, ordefaultValues
if the attribute does not contain any values.asSetOfBoolean
(Boolean... defaultValues) Returns the values decoded as a set ofBoolean
s, ordefaultValues
if the attribute does not contain any values.asSetOfBoolean
(Collection<Boolean> defaultValues) Returns the values decoded as a set ofBoolean
s, ordefaultValues
if the attribute does not contain any values.asSetOfByteString
(Collection<ByteString> defaultValues) Returns the values contained in the attribute, ordefaultValues
if the attribute does not contain any values.asSetOfByteString
(ByteString... defaultValues) Returns the values contained in the attribute, ordefaultValues
if the attribute does not contain any values.Returns the values decoded as a set ofX509Certificate
s, or an empty set if the attribute does not contain any values.Returns the values decoded as a set ofDN
s 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 ofDN
s using the schema associated with this parser, ordefaultValues
if the attribute does not contain any values.asSetOfDn
(Collection<Dn> defaultValues) Returns the values decoded as a set ofDN
s using the schema associated with this parser, ordefaultValues
if the attribute does not contain any values.Returns the values decoded as a set ofDN
s using the schema associated with this parser, ordefaultValues
if the attribute does not contain any values.asSetOfGeneralizedTime
(Collection<GeneralizedTime> defaultValues) Returns the values decoded as a set ofGeneralizedTime
s using the generalized time syntax, ordefaultValues
if the attribute does not contain any values.asSetOfGeneralizedTime
(GeneralizedTime... defaultValues) Returns the values decoded as a set ofGeneralizedTime
s using the generalized time syntax, ordefaultValues
if the attribute does not contain any values.asSetOfInteger
(Integer... defaultValues) Returns the values decoded as a set ofInteger
s, ordefaultValues
if the attribute does not contain any values.asSetOfInteger
(Collection<Integer> defaultValues) Returns the values decoded as a set ofInteger
s, ordefaultValues
if the attribute does not contain any values.asSetOfLong
(Long... defaultValues) Returns the values decoded as a set ofLong
s, ordefaultValues
if the attribute does not contain any values.asSetOfLong
(Collection<Long> defaultValues) Returns the values decoded as a set ofLong
s, ordefaultValues
if the attribute does not contain any values.asSetOfString
(String... defaultValues) Returns the values decoded as a set ofString
s, ordefaultValues
if the attribute does not contain any values.asSetOfString
(Collection<String> defaultValues) Returns the values decoded as a set ofString
s, ordefaultValues
if the attribute does not contain any values.asSetOfString
(Function<String, ? extends T, E> f, Collection<? extends T> defaultValues) Returns the values decoded as a set ofT
s from their string representations using the providedFunction
, ordefaultValues
if the attribute does not contain any values.asSetOfString
(Function<String, ? extends T, E> f, T... defaultValues) Returns the values decoded as a set ofT
s from their string representations using the providedFunction
, ordefaultValues
if the attribute does not contain any values.asStream()
Returns the values as a stream ofByteString
.asString()
Returns the first value decoded as aString
, ornull
if the attribute does not contain any values.Returns the first value decoded as aString
, ordefaultValue
if the attribute does not contain any values.<T,
E extends Exception>
TReturns the first value decoded as aT
from its string representation using the providedFunction
, ornull
if the attribute does not contain any values.<T,
E extends Exception>
TReturns the first value decoded as aT
from its string representation using the providedFunction
, or thedefaultValue
if the attribute does not contain any values.static AttributeParser
parseAttribute
(Attribute attribute) Returns an attribute parser for the provided attribute.Throws aLocalizedIllegalArgumentException
if the attribute referenced by this parser isnull
or empty.usingSchema
(Schema schema) Sets theSchema
which will be used when parsing schema sensitive values such as DNs and attribute descriptions.
-
Method Details
-
parseAttribute
Returns an attribute parser for the provided attribute.- Parameters:
attribute
- The attribute to be parsed, which must not benull
.- Returns:
- The attribute parser.
- Throws:
NullPointerException
- ifattribute
isnull
.
-
asString
Returns the first value decoded as aT
from its string representation using the providedFunction
, ornull
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 from aString
.- Returns:
- The first value decoded as a
T
, ornull
if there is no value. - Throws:
E
- If an error occurred when parsing the attribute.
-
asString
public <T,E extends Exception> T asString(Function<String, ? extends T, throws EE> f, T defaultValue) Returns the first value decoded as aT
from its string representation using the providedFunction
, or thedefaultValue
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 from aString
.defaultValue
- The default value to return if the attribute is empty.- Returns:
- The first value decoded as a
T
, ordefaultValue
if there is no value. - Throws:
E
- If an error occurred when parsing the attribute.
-
as
Returns the first value decoded as aT
using the providedFunction
, ornull
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
Returns the first value decoded as aT
using the providedFunction
, ordefaultValue
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 anAttributeDescription
using the schema associated with this parser, ornull
if the attribute does not contain any values.- Returns:
- The first value decoded as an
AttributeDescription
.
-
asAttributeDescription
Returns the first value decoded as anAttributeDescription
using the schema associated with this parser, ordefaultValue
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 anAttributeDescription
using the schema associated with this parser, ordefaultValue
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
Returns the first value decoded as a boolean, ornull
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 anBoolean
, ordefaultValue
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, ornull
if the attribute does not contain any values.- Returns:
- The first value.
-
asByteString
Returns the first value, ordefaultValue
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 aX509Certificate
, ornull
if the attribute does not contain any values.- Returns:
- The first value decoded as a
X509Certificate
.
-
asCertificate
Returns the first value decoded as aX509Certificate
, ordefaultValue
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
Returns the first value decoded as aDN
using the schema associated with this parser, ornull
if the attribute does not contain any values.- Returns:
- The first value decoded as a
DN
.
-
asDn
Returns the first value decoded as aDN
using the schema associated with this parser, ordefaultValue
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
Returns the first value decoded as aDN
using the schema associated with this parser, ordefaultValue
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
.
-
asDuration
Returns the first value decoded as aDuration
ordefaultValue
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
Duration
.
-
asGeneralizedTime
Returns the first value decoded as aGeneralizedTime
using the generalized time syntax, ornull
if the attribute does not contain any values.- Returns:
- The first value decoded as a
GeneralizedTime
.
-
asGeneralizedTime
Returns the first value decoded as anGeneralizedTime
using the generalized time syntax, ordefaultValue
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
Returns the first value decoded as anInteger
, ornull
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 anInteger
, ordefaultValue
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
Returns the first value decoded as aLong
, ornull
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 aLong
, ordefaultValue
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
.
-
asPath
Returns the first value decoded as aPath
, ornull
if the attribute does not contain any values.- Returns:
- The first value decoded as a
Path
. - Throws:
LocalizedIllegalArgumentException
- If an invalid value is provided.
-
asPath
Returns the first value decoded as aPath
, 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
Path
. - Throws:
LocalizedIllegalArgumentException
- If an invalid value is provided.
-
asSetOfString
@SafeVarargs public final <T,E extends Exception> Set<T> asSetOfString(Function<String, ? extends T, throws EE> f, T... defaultValues) Returns the values decoded as a set ofT
s from their string representations using the providedFunction
, ordefaultValues
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 fromString
s.defaultValues
- The default values to return if the attribute is empty.- Returns:
- The values decoded as a set of
T
s. - Throws:
E
- If an error occurred when parsing the attribute.
-
asSetOfString
public <T,E extends Exception> Set<T> asSetOfString(Function<String, ? extends T, throws EE> f, Collection<? extends T> defaultValues) Returns the values decoded as a set ofT
s from their string representations using the providedFunction
, ordefaultValues
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 fromString
sdefaultValues
- The default values to return if the attribute is empty.- Returns:
- The values decoded as a set of
T
s. - Throws:
E
- If an error occurred when parsing the attribute.
-
asSetOf
@SafeVarargs public final <T,E extends Exception> Set<T> asSetOf(Function<ByteString, ? extends T, throws EE> f, T... defaultValues) Returns the values decoded as a set ofT
s using the providedFunction
, ordefaultValues
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
T
s. - Throws:
E
- If an error occurred when parsing the attribute.
-
asSetOf
public <T,E extends Exception> Set<T> asSetOf(Function<ByteString, ? extends T, throws EE> f, Collection<? extends T> defaultValues) Returns the values decoded as a set ofT
s using the providedFunction
, ordefaultValues
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
T
s. - Throws:
E
- If an error occurred when parsing the attribute.
-
asStream
Returns the values as a stream ofByteString
. If the attribute is empty, this method will return an empty stream.- Returns:
- The values as a stream of
ByteString
.
-
asSetOfAttributeDescription
Returns the values decoded as a set ofAttributeDescription
s 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
AttributeDescription
s.
-
asSetOfAttributeDescription
Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, ordefaultValues
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
AttributeDescription
s.
-
asSetOfAttributeDescription
public Set<AttributeDescription> asSetOfAttributeDescription(Collection<AttributeDescription> defaultValues) Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, ordefaultValues
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
AttributeDescription
s.
-
asSetOfAttributeDescription
Returns the values decoded as a set ofAttributeDescription
s using the schema associated with this parser, ordefaultValues
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
AttributeDescription
s.
-
asSetOfBoolean
Returns the values decoded as a set ofBoolean
s, ordefaultValues
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
Boolean
s.
-
asSetOfBoolean
Returns the values decoded as a set ofBoolean
s, ordefaultValues
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
Boolean
s.
-
asSetOfByteString
Returns the values contained in the attribute, ordefaultValues
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, ordefaultValues
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 ofX509Certificate
s, or an empty set if the attribute does not contain any values.- Returns:
- The values decoded as a set of
X509Certificate
s.
-
asSetOfDn
Returns the values decoded as a set ofDN
s 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
DN
s.
-
asSetOfDn
Returns the values decoded as a set ofDN
s using the schema associated with this parser, ordefaultValues
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
DN
s.
-
asSetOfDn
Returns the values decoded as a set ofDN
s using the schema associated with this parser, ordefaultValues
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
DN
s.
-
asSetOfDn
Returns the values decoded as a set ofDN
s using the schema associated with this parser, ordefaultValues
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
DN
s.
-
asSetOfGeneralizedTime
Returns the values decoded as a set ofGeneralizedTime
s using the generalized time syntax, ordefaultValues
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
GeneralizedTime
s.
-
asSetOfGeneralizedTime
Returns the values decoded as a set ofGeneralizedTime
s using the generalized time syntax, ordefaultValues
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
GeneralizedTime
s.
-
asSetOfInteger
Returns the values decoded as a set ofInteger
s, ordefaultValues
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
Integer
s.
-
asSetOfInteger
Returns the values decoded as a set ofInteger
s, ordefaultValues
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
Integer
s.
-
asSetOfLong
Returns the values decoded as a set ofLong
s, ordefaultValues
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
Long
s.
-
asSetOfLong
Returns the values decoded as a set ofLong
s, ordefaultValues
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
Long
s.
-
asSetOfString
Returns the values decoded as a set ofString
s, ordefaultValues
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
String
s.
-
asSetOfString
Returns the values decoded as a set ofString
s, ordefaultValues
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
String
s.
-
asString
Returns the first value decoded as aString
, ornull
if the attribute does not contain any values.- Returns:
- The first value decoded as a
String
.
-
asString
Returns the first value decoded as aString
, ordefaultValue
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 aLocalizedIllegalArgumentException
if the attribute referenced by this parser isnull
or empty.- Returns:
- A reference to this attribute parser.
- Throws:
LocalizedIllegalArgumentException
- If the attribute referenced by this parser isnull
or empty.
-
usingSchema
Sets theSchema
which will be used when parsing schema sensitive values such as DNs and attribute descriptions.- Parameters:
schema
- TheSchema
which will be used when parsing schema sensitive values.- Returns:
- This attribute parser.
-