Interface Attribute
- All Superinterfaces:
-
Cloneable
,Serializable
- All Known Implementing Classes:
BasicAttribute
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.
- Since:
- 1.3
- See Also:
Field Summary
Modifier and Type | Field | Description |
---|---|---|
static final long |
serialVersionUID |
Deprecated. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void |
add |
Adds an attribute value to the ordered list of attribute values. |
boolean |
add |
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 |
Determines whether a value is in the attribute. |
Object |
get() |
Retrieves one of this attribute's values. |
Object |
get |
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 |
Removes an attribute value from the ordered list of attribute values. |
boolean |
remove |
Removes a specified value from the attribute. |
Object |
set |
Sets an attribute value in the ordered list of attribute values. |
int |
size() |
Retrieves the number of values in this attribute. |
Field Details
serialVersionUID
@Deprecated static final long serialVersionUID
serialVersionUID
field in an interface is ineffectual. Do not use; no replacement.- See Also:
Method Details
getAll
NamingEnumeration<?> getAll() throws NamingException
- Returns:
- A non-null enumeration of the attribute's values. Each element of the enumeration is a possibly null Object. The object's class is the class of the attribute value. The element is null if the attribute's value is null. If the attribute has zero values, an empty enumeration is returned.
- Throws:
-
NamingException
- If a naming exception was encountered while retrieving the values. - See Also:
get
Object get() throws NamingException
- Returns:
- A possibly null object representing one of the attribute's value. It is null if the attribute's value is null.
- Throws:
-
NamingException
- If a naming exception was encountered while retrieving the value. -
NoSuchElementException
- If this attribute has no values.
size
int size()
- Returns:
- The nonnegative number of values in this attribute.
getID
String getID()
- Returns:
- The id of this attribute. It cannot be null.
contains
boolean contains(Object attrVal)
Object.equals()
or schema information to determine equality.- Parameters:
-
attrVal
- The possibly null value to check. If null, check whether the attribute has an attribute value whose value is null. - Returns:
- true if attrVal is one of this attribute's values; false otherwise.
- See Also:
add
boolean add(Object attrVal)
attrVal
is already in the attribute, this method does nothing. If the attribute values are ordered, attrVal
is added to the end of the list of attribute values. Equality is determined by the implementation, which may use Object.equals()
or schema information to determine equality.
- Parameters:
-
attrVal
- The new possibly null value to add. If null, null is added as an attribute value. - Returns:
- true if a value was added; false otherwise.
remove
boolean remove(Object attrval)
attrval
is not in the attribute, this method does nothing. If the attribute values are ordered, the first occurrence of attrVal
is removed and attribute values at indices greater than the removed value are shifted up towards the head of the list (and their indices decremented by one). Equality is determined by the implementation, which may use Object.equals()
or schema information to determine equality.
- Parameters:
-
attrval
- The possibly null value to remove from this attribute. If null, remove the attribute value that is null. - Returns:
- true if the value was removed; false otherwise.
clear
void clear()
getAttributeSyntaxDefinition
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.
- Returns:
- The attribute's syntax definition. Null if the implementation supports schemas but this particular attribute does not have any schema information.
- Throws:
-
OperationNotSupportedException
- If getting the schema is not supported. -
NamingException
- If a naming exception occurs while getting the schema.
getAttributeDefinition
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.
- Returns:
- This attribute's schema definition. Null if the implementation supports schemas but this particular attribute does not have any schema information.
- Throws:
-
OperationNotSupportedException
- If getting the schema is not supported. -
NamingException
- If a naming exception occurs while getting the schema.
clone
Object clone()
- Returns:
- A non-null copy of the attribute.
isOrdered
boolean isOrdered()
- Returns:
- true if this attribute's values are ordered; false otherwise.
- See Also:
get
Object get(int ix) throws NamingException
ix
index of the list of attribute values. If the attribute values are unordered, this method returns the value that happens to be at that index.- Parameters:
-
ix
- The index of the value in the ordered list of attribute values.0 <= ix < size()
. - Returns:
- The possibly null attribute value at index
ix
; null if the attribute value is null. - Throws:
-
NamingException
- If a naming exception was encountered while retrieving the value. -
IndexOutOfBoundsException
- Ifix
is outside the specified range.
remove
Object remove(int ix)
ix
index of the list of attribute values. If the attribute values are unordered, this method removes the value that happens to be at that index. Values located at indices greater than ix
are shifted up towards the front of the list (and their indices decremented by one).- Parameters:
-
ix
- The index of the value to remove.0 <= ix < size()
. - Returns:
- The possibly null attribute value at index
ix
that was removed; null if the attribute value is null. - Throws:
-
IndexOutOfBoundsException
- Ifix
is outside the specified range.
add
void add(int ix, Object attrVal)
attrVal
to the list of attribute values at index ix
. Values located at indices at or greater than ix
are shifted down towards the end of the list (and their indices incremented by one). If the attribute values are unordered and already have attrVal
, IllegalStateException
is thrown.- Parameters:
-
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. - Throws:
-
IndexOutOfBoundsException
- Ifix
is outside the specified range. -
IllegalStateException
- If the attribute values are unordered andattrVal
is one of those values.
set
Object set(int ix, Object attrVal)
ix
index of the list of attribute values to be attrVal
. The old value is removed. If the attribute values are unordered, this method sets the value that happens to be at that index to attrVal
, unless attrVal
is already one of the values. In that case, IllegalStateException
is thrown.- Parameters:
-
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. - Returns:
- The possibly null attribute value at index ix that was replaced. Null if the attribute value was null.
- Throws:
-
IndexOutOfBoundsException
- Ifix
is outside the specified range. -
IllegalStateException
- IfattrVal
already exists and the attribute values are unordered.
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.naming/javax/naming/directory/Attribute.html
serialVersionUID
field in an interface is ineffectual.