public interface Attribute extends Cloneable, Serializable
In a directory, named objects can have associated with them attributes. The Attribute interface represents an attribute associated with a named object. An attribute contains 0 or more, possibly null, values. The attribute values can be ordered or unordered (see isOrdered()). If the values are unordered, no duplicates are allowed. If the values are ordered, duplicates are allowed.
The content and representation of an attribute and its values is defined by the attribute's schema. The schema contains information about the attribute's syntax and other properties about the attribute. See getAttributeDefinition() and getAttributeSyntaxDefinition() for details regarding how to get schema information about an attribute if the underlying directory service supports schemas.
Equality of two attributes is determined by the implementation class. A simple implementation can use Object.equals() to determine equality of attribute values, while a more sophisticated implementation might make use of schema information to determine equality. Similarly, one implementation might provide a static storage structure which simply returns the values passed to its constructor, while another implementation might define get() and getAll(). to get the values dynamically from the directory.
Note that updates to Attribute (such as adding or removing a value) do not affect the corresponding representation of the attribute in the directory. Updates to the directory can only be effected using operations in the DirContext interface.
BasicAttribute
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID
Use serialVersionUID from JNDI 1.1.1 for interoperability.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int ix,
Object attrVal)
Adds an attribute value to the ordered list of attribute values.
|
boolean |
add(Object attrVal)
Adds a new value to the attribute.
|
void |
clear()
Removes all values from this attribute.
|
Object |
clone()
Makes a copy of the attribute.
|
boolean |
contains(Object attrVal)
Determines whether a value is in the attribute.
|
Object |
get()
Retrieves one of this attribute's values.
|
Object |
get(int ix)
Retrieves the attribute value from the ordered list of attribute values.
|
NamingEnumeration<?> |
getAll()
Retrieves an enumeration of the attribute's values.
|
DirContext |
getAttributeDefinition()
Retrieves the attribute's schema definition.
|
DirContext |
getAttributeSyntaxDefinition()
Retrieves the syntax definition associated with the attribute.
|
String |
getID()
Retrieves the id of this attribute.
|
boolean |
isOrdered()
Determines whether this attribute's values are ordered.
|
Object |
remove(int ix)
Removes an attribute value from the ordered list of attribute values.
|
boolean |
remove(Object attrval)
Removes a specified value from the attribute.
|
Object |
set(int ix,
Object attrVal)
Sets an attribute value in the ordered list of attribute values.
|
int |
size()
Retrieves the number of values in this attribute.
|
static final long serialVersionUID
NamingEnumeration<?> getAll() throws NamingException
NamingException
- If a naming exception was encountered while retrieving
the values.isOrdered()
Object get() throws NamingException
NamingException
- If a naming exception was encountered while retrieving
the value.NoSuchElementException
- If this attribute has no values.int size()
String getID()
boolean contains(Object attrVal)
attrVal
- The possibly null value to check. If null, check
whether the attribute has an attribute value whose value is null.Object.equals(java.lang.Object)
,
BasicAttribute.equals(java.lang.Object)
boolean add(Object attrVal)
Equality is determined by the implementation, which may use Object.equals() or schema information to determine equality.
attrVal
- The new possibly null value to add. If null, null
is added as an attribute value.boolean remove(Object attrval)
Equality is determined by the implementation, which may use Object.equals() or schema information to determine equality.
attrval
- The possibly null value to remove from this attribute.
If null, remove the attribute value that is null.void clear()
DirContext getAttributeSyntaxDefinition() throws NamingException
For example, even though a value might be a Java String object, its directory syntax might be "Printable String" or "Telephone Number". Or a value might be a byte array, and its directory syntax is "JPEG" or "Certificate". For example, if this attribute's syntax is "JPEG", this method would return the syntax definition for "JPEG".
The information that you can retrieve from a syntax definition is directory-dependent.
If an implementation does not support schemas, it should throw OperationNotSupportedException. If an implementation does support schemas, it should define this method to return the appropriate information.
OperationNotSupportedException
- If getting the schema
is not supported.NamingException
- If a naming exception occurs while getting
the schema.DirContext getAttributeDefinition() throws NamingException
If an implementation does not support schemas, it should throw OperationNotSupportedException. If an implementation does support schemas, it should define this method to return the appropriate information.
OperationNotSupportedException
- If getting the schema
is not supported.NamingException
- If a naming exception occurs while getting
the schema.Object clone()
boolean isOrdered()
get(int)
,
remove(int)
,
add(int, java.lang.Object)
,
set(int, java.lang.Object)
Object get(int ix) throws NamingException
ix
- The index of the value in the ordered list of attribute values.
0 <= ix < size().NamingException
- If a naming exception was encountered while
retrieving the value.IndexOutOfBoundsException
- If ix is outside the specified range.Object remove(int ix)
ix
- The index of the value to remove.
0 <= ix < size().IndexOutOfBoundsException
- If ix is outside the specified range.void add(int ix, Object attrVal)
ix
- The index in the ordered list of attribute values to add the new value.
0 <= ix <= size().attrVal
- The possibly null attribute value to add; if null, null is
the value added.IndexOutOfBoundsException
- If ix is outside the specified range.IllegalStateException
- If the attribute values are unordered and
attrVal is one of those values.Object set(int ix, Object attrVal)
ix
- The index of the value in the ordered list of attribute values.
0 <= ix < size().attrVal
- The possibly null attribute value to use.
If null, 'null' replaces the old value.IndexOutOfBoundsException
- If ix is outside the specified range.IllegalStateException
- If attrVal already exists and the
attribute values are unordered. Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2020, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.