@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class Attribute extends java.lang.Object implements java.io.Serializable
Entry
object, then it is possible to add and remove attribute values
from the entry (which will actually create new Attribute object instances),
although this is not allowed for instances of ReadOnlyEntry
and its
subclasses.
Constructor and Description |
---|
Attribute(java.lang.String name)
Creates a new LDAP attribute with the specified name and no values.
|
Attribute(java.lang.String name,
ASN1OctetString... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
byte[]... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
byte[] value)
Creates a new LDAP attribute with the specified name and value.
|
Attribute(java.lang.String name,
java.util.Collection<java.lang.String> values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
MatchingRule matchingRule)
Creates a new LDAP attribute with the specified name and no values.
|
Attribute(java.lang.String name,
MatchingRule matchingRule,
ASN1OctetString[] values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
MatchingRule matchingRule,
byte[]... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
MatchingRule matchingRule,
byte[] value)
Creates a new LDAP attribute with the specified name and value.
|
Attribute(java.lang.String name,
MatchingRule matchingRule,
java.util.Collection<java.lang.String> values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
MatchingRule matchingRule,
java.lang.String... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
MatchingRule matchingRule,
java.lang.String value)
Creates a new LDAP attribute with the specified name and value.
|
Attribute(java.lang.String name,
Schema schema,
ASN1OctetString[] values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
Schema schema,
byte[]... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
Schema schema,
java.util.Collection<java.lang.String> values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
Schema schema,
java.lang.String... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
java.lang.String... values)
Creates a new LDAP attribute with the specified name and set of values.
|
Attribute(java.lang.String name,
java.lang.String value)
Creates a new LDAP attribute with the specified name and value.
|
Modifier and Type | Method and Description |
---|---|
static Attribute |
decode(ASN1Sequence encodedAttribute)
Decodes the provided ASN.1 sequence as an LDAP attribute.
|
ASN1Sequence |
encode()
Encodes this attribute into a form suitable for use in the LDAP protocol.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is equal to this LDAP attribute.
|
java.lang.String |
getBaseName()
Retrieves the base name for this attribute, which is the name or OID of the
attribute type, without any attribute options.
|
static java.lang.String |
getBaseName(java.lang.String name)
Retrieves the base name for an attribute with the given name, which will be
the provided name without any attribute options.
|
MatchingRule |
getMatchingRule()
Retrieves the matching rule instance used by this attribute.
|
java.lang.String |
getName()
Retrieves the name for this attribute (i.e., the attribute description),
which may include zero or more attribute options.
|
java.util.Set<java.lang.String> |
getOptions()
Retrieves the set of options for this attribute.
|
static java.util.Set<java.lang.String> |
getOptions(java.lang.String name)
Retrieves the set of options for the provided attribute name.
|
ASN1OctetString[] |
getRawValues()
Retrieves the set of values for this attribute as an array of ASN.1 octet
strings.
|
java.lang.String |
getValue()
Retrieves the value for this attribute as a string.
|
java.lang.Boolean |
getValueAsBoolean()
Retrieves the value for this attribute as a Boolean.
|
java.util.Date |
getValueAsDate()
Retrieves the value for this attribute as a Date, formatted using the
generalized time syntax.
|
DN |
getValueAsDN()
Retrieves the value for this attribute as a DN.
|
java.lang.Integer |
getValueAsInteger()
Retrieves the value for this attribute as an Integer.
|
java.lang.Long |
getValueAsLong()
Retrieves the value for this attribute as a Long.
|
byte[] |
getValueByteArray()
Retrieves the value for this attribute as a byte array.
|
byte[][] |
getValueByteArrays()
Retrieves the set of values for this attribute as byte arrays.
|
java.lang.String[] |
getValues()
Retrieves the set of values for this attribute as strings.
|
int |
hashCode()
Generates a hash code for this LDAP attribute.
|
boolean |
hasOption(java.lang.String option)
Indicates whether this attribute has the specified attribute option.
|
static boolean |
hasOption(java.lang.String name,
java.lang.String option)
Indicates whether the provided attribute name has the specified attribute
option.
|
boolean |
hasOptions()
Indicates whether this attribute has any attribute options.
|
static boolean |
hasOptions(java.lang.String name)
Indicates whether the provided attribute name contains any options.
|
boolean |
hasValue()
Indicates whether this attribute contains at least one value.
|
boolean |
hasValue(byte[] value)
Indicates whether this attribute contains the specified value.
|
boolean |
hasValue(byte[] value,
MatchingRule matchingRule)
Indicates whether this attribute contains the specified value.
|
boolean |
hasValue(java.lang.String value)
Indicates whether this attribute contains the specified value.
|
boolean |
hasValue(java.lang.String value,
MatchingRule matchingRule)
Indicates whether this attribute contains the specified value.
|
static Attribute |
mergeAttributes(Attribute attr1,
Attribute attr2)
Creates a new attribute containing the merged values of the provided
attributes.
|
static Attribute |
mergeAttributes(Attribute attr1,
Attribute attr2,
MatchingRule matchingRule)
Creates a new attribute containing the merged values of the provided
attributes.
|
boolean |
nameIsValid()
Indicates whether the name of this attribute is valid as per RFC 4512.
|
static boolean |
nameIsValid(java.lang.String s)
Indicates whether the provided string represents a valid attribute name as
per RFC 4512.
|
static boolean |
nameIsValid(java.lang.String s,
boolean allowOptions)
Indicates whether the provided string represents a valid attribute name as
per RFC 4512.
|
boolean |
needsBase64Encoding()
Indicates whether any of the values of this attribute need to be
base64-encoded when represented as LDIF.
|
static boolean |
needsBase64Encoding(byte[] v)
Indicates whether the provided value needs to be base64-encoded when
represented as LDIF.
|
static boolean |
needsBase64Encoding(java.lang.String v)
Indicates whether the provided value needs to be base64-encoded when
represented as LDIF.
|
static Attribute |
readFrom(ASN1StreamReader reader)
Reads and decodes an attribute from the provided ASN.1 stream reader.
|
static Attribute |
readFrom(ASN1StreamReader reader,
Schema schema)
Reads and decodes an attribute from the provided ASN.1 stream reader.
|
static Attribute |
removeValues(Attribute attr1,
Attribute attr2)
Creates a new attribute containing all of the values of the first attribute
that are not contained in the second attribute.
|
static Attribute |
removeValues(Attribute attr1,
Attribute attr2,
MatchingRule matchingRule)
Creates a new attribute containing all of the values of the first attribute
that are not contained in the second attribute.
|
int |
size()
Retrieves the number of values for this attribute.
|
java.lang.String |
toString()
Retrieves a string representation of this LDAP attribute.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP attribute to the provided
buffer.
|
void |
writeTo(ASN1Buffer buffer)
Writes an ASN.1-encoded representation of this attribute to the provided
ASN.1 buffer.
|
public Attribute(@NotNull java.lang.String name)
name
- The name for this attribute. It must not be null
.public Attribute(@NotNull java.lang.String name, @NotNull java.lang.String value)
name
- The name for this attribute. It must not be null
.value
- The value for this attribute. It must not be null
.public Attribute(@NotNull java.lang.String name, @NotNull byte[] value)
name
- The name for this attribute. It must not be null
.value
- The value for this attribute. It must not be null
.public Attribute(@NotNull java.lang.String name, @NotNull java.lang.String... values)
name
- The name for this attribute. It must not be null
.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull byte[]... values)
name
- The name for this attribute. It must not be null
.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull ASN1OctetString... values)
name
- The name for this attribute. It must not be null
.values
- The set of raw values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull java.util.Collection<java.lang.String> values)
name
- The name for this attribute. It must not be null
.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule)
name
- The name for this attribute. It must not be
null
.matchingRule
- The matching rule to use when comparing values. It
must not be null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule, @NotNull java.lang.String value)
name
- The name for this attribute. It must not be
null
.matchingRule
- The matching rule to use when comparing values. It
must not be null
.value
- The value for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule, @NotNull byte[] value)
name
- The name for this attribute. It must not be
null
.matchingRule
- The matching rule to use when comparing values. It
must not be null
.value
- The value for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule, @NotNull java.lang.String... values)
name
- The name for this attribute. It must not be
null
.matchingRule
- The matching rule to use when comparing values. It
must not be null
.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule, @NotNull byte[]... values)
name
- The name for this attribute. It must not be
null
.matchingRule
- The matching rule to use when comparing values. It
must not be null
.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule, @NotNull java.util.Collection<java.lang.String> values)
name
- The name for this attribute. It must not be
null
.matchingRule
- The matching rule to use when comparing values. It
must not be null
.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @NotNull MatchingRule matchingRule, @NotNull ASN1OctetString[] values)
name
- The name for this attribute.matchingRule
- The matching rule for this attribute.values
- The set of values for this attribute.public Attribute(@NotNull java.lang.String name, @Nullable Schema schema, @NotNull java.lang.String... values)
name
- The name for this attribute. It must not be null
.schema
- The schema to use to select the matching rule for this
attribute. It may be null
if the default matching
rule should be used.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @Nullable Schema schema, @NotNull byte[]... values)
name
- The name for this attribute. It must not be null
.schema
- The schema to use to select the matching rule for this
attribute. It may be null
if the default matching
rule should be used.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @Nullable Schema schema, @NotNull java.util.Collection<java.lang.String> values)
name
- The name for this attribute. It must not be null
.schema
- The schema to use to select the matching rule for this
attribute. It may be null
if the default matching
rule should be used.values
- The set of values for this attribute. It must not be
null
.public Attribute(@NotNull java.lang.String name, @Nullable Schema schema, @NotNull ASN1OctetString[] values)
name
- The name for this attribute. It must not be null
.schema
- The schema to use to select the matching rule for this
attribute. It may be null
if the default matching
rule should be used.values
- The set of values for this attribute. It must not be
null
.@NotNull public static Attribute mergeAttributes(@NotNull Attribute attr1, @NotNull Attribute attr2)
attr1
- The first attribute containing the values to merge. It must
not be null
.attr2
- The second attribute containing the values to merge. It
must not be null
.@NotNull public static Attribute mergeAttributes(@NotNull Attribute attr1, @NotNull Attribute attr2, @Nullable MatchingRule matchingRule)
attr1
- The first attribute containing the values to merge.
It must not be null
.attr2
- The second attribute containing the values to merge.
It must not be null
.matchingRule
- The matching rule to use to locate matching values.
It may be null
if the matching rule
associated with the first attribute should be used.@NotNull public static Attribute removeValues(@NotNull Attribute attr1, @NotNull Attribute attr2)
attr1
- The attribute from which to remove the values. It must not
be null
.attr2
- The attribute containing the values to remove. It must not
be null
.@NotNull public static Attribute removeValues(@NotNull Attribute attr1, @NotNull Attribute attr2, @Nullable MatchingRule matchingRule)
attr1
- The attribute from which to remove the values. It
must not be null
.attr2
- The attribute containing the values to remove. It
must not be null
.matchingRule
- The matching rule to use to locate matching values.
It may be null
if the matching rule
associated with the first attribute should be used.@NotNull public java.lang.String getName()
@NotNull public java.lang.String getBaseName()
getName()
method.@NotNull public static java.lang.String getBaseName(@NotNull java.lang.String name)
name
- The name to be processed.public boolean nameIsValid()
true
if this attribute has a valid name, or false
if not.public static boolean nameIsValid(@NotNull java.lang.String s)
s
- The name for which to make the determination.true
if this attribute has a valid name, or false
if not.public static boolean nameIsValid(@NotNull java.lang.String s, boolean allowOptions)
s
- The name for which to make the determination.allowOptions
- Indicates whether the provided name will be allowed
to contain attribute options.true
if this attribute has a valid name, or false
if not.public boolean hasOptions()
true
if this attribute has at least one attribute option,
or false
if not.public static boolean hasOptions(@NotNull java.lang.String name)
name
- The name for which to make the determination.true
if the provided attribute name has at least one
attribute option, or false
if not.public boolean hasOption(@NotNull java.lang.String option)
option
- The attribute option for which to make the determination.true
if this attribute has the specified attribute option,
or false
if not.public static boolean hasOption(@NotNull java.lang.String name, @NotNull java.lang.String option)
name
- The name to be examined.option
- The attribute option for which to make the determination.true
if the provided attribute name has the specified
attribute option, or false
if not.@NotNull public java.util.Set<java.lang.String> getOptions()
@NotNull public static java.util.Set<java.lang.String> getOptions(@NotNull java.lang.String name)
name
- The name to be examined.@NotNull public MatchingRule getMatchingRule()
@Nullable public java.lang.String getValue()
null
if this attribute
does not have any values.@Nullable public byte[] getValueByteArray()
null
if this attribute
does not have any values.@Nullable public java.lang.Boolean getValueAsBoolean()
TRUE
. Values
of "false", "f", "no", "n", "off", and "0" will be interpreted as
FALSE
.null
if this
attribute does not have any values or the value cannot be parsed
as a Boolean.@Nullable public java.util.Date getValueAsDate()
null
if this
attribute does not have any values or the value cannot be parsed
as a Date.@Nullable public DN getValueAsDN()
null
if this attribute
does not have any values or the value cannot be parsed as a DN.@Nullable public java.lang.Integer getValueAsInteger()
null
if this
attribute does not have any values or the value cannot be parsed
as an Integer.@Nullable public java.lang.Long getValueAsLong()
null
if this
attribute does not have any values or the value cannot be parsed
as a Long.@NotNull public java.lang.String[] getValues()
@NotNull public byte[][] getValueByteArrays()
@NotNull public ASN1OctetString[] getRawValues()
public boolean hasValue()
true
if this attribute has at least one value, or
false
if not.public boolean hasValue(@NotNull java.lang.String value)
value
- The value for which to make the determination. It must not
be null
.true
if this attribute has the specified value, or
false
if not.public boolean hasValue(@NotNull java.lang.String value, @NotNull MatchingRule matchingRule)
value
- The value for which to make the determination. It
must not be null
.matchingRule
- The matching rule to use when making the
determination. It must not be null
.true
if this attribute has the specified value, or
false
if not.public boolean hasValue(@NotNull byte[] value)
value
- The value for which to make the determination. It must not
be null
.true
if this attribute has the specified value, or
false
if not.public boolean hasValue(@NotNull byte[] value, @NotNull MatchingRule matchingRule)
value
- The value for which to make the determination. It
must not be null
.matchingRule
- The matching rule to use when making the
determination. It must not be null
.true
if this attribute has the specified value, or
false
if not.public int size()
public void writeTo(@NotNull ASN1Buffer buffer)
buffer
- The ASN.1 buffer to which the encoded representation should
be written.@NotNull public ASN1Sequence encode()
@NotNull public static Attribute readFrom(@NotNull ASN1StreamReader reader) throws LDAPException
reader
- The ASN.1 stream reader from which to read the attribute.LDAPException
- If a problem occurs while trying to read or decode
the attribute.@NotNull public static Attribute readFrom(@NotNull ASN1StreamReader reader, @Nullable Schema schema) throws LDAPException
reader
- The ASN.1 stream reader from which to read the attribute.schema
- The schema to use to select the appropriate matching rule
for this attribute. It may be null
if the default
matching rule should be selected.LDAPException
- If a problem occurs while trying to read or decode
the attribute.@NotNull public static Attribute decode(@NotNull ASN1Sequence encodedAttribute) throws LDAPException
encodedAttribute
- The ASN.1 sequence to be decoded as an LDAP
attribute. It must not be null
.LDAPException
- If a problem occurs while attempting to decode the
provided ASN.1 sequence as an LDAP attribute.public boolean needsBase64Encoding()
true
if any of the values of this attribute need to be
base64-encoded when represented as LDIF, or false
if not.public static boolean needsBase64Encoding(@NotNull java.lang.String v)
v
- The value for which to make the determination. It must not be
null
.true
if the provided value needs to be base64-encoded when
represented as LDIF, or false
if not.public static boolean needsBase64Encoding(@NotNull byte[] v)
v
- The value for which to make the determination. It must not be
null
.true
if the provided value needs to be base64-encoded when
represented as LDIF, or false
if not.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
o
- The object for which to make the determination.true
if the provided object may be considered equal to
this LDAP attribute, or false
if not.@NotNull public java.lang.String toString()
toString
in class java.lang.Object