|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.unboundid.ldap.sdk.Attribute
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class Attribute
This class provides a data structure for holding information about an LDAP
attribute, which includes an attribute name (which may include a set of
attribute options) and zero or more values. Attribute objects are immutable
and cannot be altered. However, if an attribute is included in an
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.
This class uses the term "attribute name" as an equivalent of what the LDAP
specification refers to as an "attribute description". An attribute
description consists of an attribute type name or object identifier (which
this class refers to as the "base name") followed by zero or more attribute
options, each of which should be prefixed by a semicolon. Attribute options
may be used to provide additional metadata for the attribute and/or its
values, or to indicate special handling for the values. For example,
RFC 3866 describes the use
of attribute options to indicate that a value may be associated with a
particular language (e.g., "cn;lang-en-US" indicates that the values of that
cn attribute should be treated as U.S. English values), and
RFC 4522 describes a binary
encoding option that indicates that the server should only attempt to
interact with the values as binary data (e.g., "userCertificate;binary") and
should not treat them as strings. An attribute name (which is technically
referred to as an "attribute description" in the protocol specification) may
have zero, one, or multiple attribute options. If there are any attribute
options, then a semicolon is used to separate the first option from the base
attribute name, and to separate each subsequent attribute option from the
previous option.
Attribute values can be treated as either strings or byte arrays. In LDAP,
they are always transferred using a binary encoding, but applications
frequently treat them as strings and it is often more convenient to do so.
However, for some kinds of data (e.g., certificates, images, audio clips, and
other "blobs") it may be desirable to only treat them as binary data and only
interact with the values as byte arrays. If you do intend to interact with
string values as byte arrays, then it is important to ensure that you use a
UTF-8 representation for those values unless you are confident that the
directory server will not attempt to treat the value as a string.
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Attribute(java.lang.String name)
name
- The name for this attribute. It must not be null
.public Attribute(java.lang.String name, 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(java.lang.String name, 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(java.lang.String name, 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(java.lang.String name, 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(java.lang.String name, 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(java.lang.String name, 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(java.lang.String name, 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(java.lang.String name, MatchingRule matchingRule, 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(java.lang.String name, MatchingRule matchingRule, 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(java.lang.String name, MatchingRule matchingRule, 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(java.lang.String name, MatchingRule matchingRule, 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(java.lang.String name, MatchingRule matchingRule, 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(java.lang.String name, MatchingRule matchingRule, 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(java.lang.String name, Schema schema, 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(java.lang.String name, Schema schema, 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(java.lang.String name, Schema schema, 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(java.lang.String name, Schema schema, 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
.Method Detail |
---|
public static Attribute mergeAttributes(Attribute attr1, 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
.
public static Attribute removeValues(Attribute attr1, 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
.
public static Attribute removeValues(Attribute attr1, Attribute attr2, 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.
public java.lang.String getName()
public java.lang.String getBaseName()
getName()
method.
public static java.lang.String getBaseName(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(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(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(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(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(java.lang.String name, 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.public java.util.Set<java.lang.String> getOptions()
public static java.util.Set<java.lang.String> getOptions(java.lang.String name)
name
- The name to be examined.
public MatchingRule getMatchingRule()
public java.lang.String getValue()
null
if this attribute
does not have any values.public byte[] getValueByteArray()
null
if this attribute
does not have any values.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.public java.util.Date getValueAsDate()
null
if this
attribute does not have any values or the value cannot be parsed
as a Date.public DN getValueAsDN()
null
if this attribute
does not have any values or the value cannot be parsed as a DN.public java.lang.Integer getValueAsInteger()
null
if this
attribute does not have any values or the value cannot be parsed
as an Integer.public java.lang.Long getValueAsLong()
null
if this
attribute does not have any values or the value cannot be parsed
as a Long.public java.lang.String[] getValues()
public byte[][] getValueByteArrays()
public ASN1OctetString[] getRawValues()
public boolean hasValue()
true
if this attribute has at least one value, or
false
if not.public boolean hasValue(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(java.lang.String value, 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(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(byte[] value, 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(ASN1Buffer buffer)
buffer
- The ASN.1 buffer to which the encoded representation should
be written.public ASN1Sequence encode()
public static Attribute readFrom(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.public static Attribute readFrom(ASN1StreamReader reader, 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.public static Attribute decode(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(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(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(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.public java.lang.String toString()
toString
in class java.lang.Object
public void toString(java.lang.StringBuilder buffer)
buffer
- The buffer to which the string representation of this LDAP
attribute should be appended.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |