Serializable
, Cloneable
, Attribute
public class BasicAttribute extends Object implements Attribute
Attribute
interface. This implementation does not support the schema methods getAttributeDefinition()
and getAttributeSyntaxDefinition()
. They simply throw OperationNotSupportedException
. Subclasses of BasicAttribute
should override these methods if they support them.
The BasicAttribute
class by default uses Object.equals()
to determine equality of attribute values when testing for equality or when searching for values, except when the value is an array. For an array, each element of the array is checked using Object.equals()
. Subclasses of BasicAttribute
can make use of schema information when doing similar equality checks by overriding methods in which such use of schema is meaningful. Similarly, the BasicAttribute
class by default returns the values passed to its constructor and/or manipulated using the add/remove methods. Subclasses of BasicAttribute
can override get()
and getAll()
to get the values dynamically from the directory (or implement the Attribute
interface directly instead of subclassing BasicAttribute
).
Note that updates to BasicAttribute
(such as adding or removing a value) does 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.
A BasicAttribute
instance is not synchronized against concurrent multithreaded access. Multiple threads trying to access and modify a BasicAttribute
should lock the object.
Modifier and Type | Field | Description |
---|---|---|
protected String |
attrID |
Holds the attribute's id. |
protected boolean |
ordered |
A flag for recording whether this attribute's values are ordered. |
protected Vector |
values |
Holds the attribute's values. |
Constructor | Description |
---|---|
BasicAttribute |
Constructs a new instance of an unordered attribute with no value. |
BasicAttribute |
Constructs a new instance of a possibly ordered attribute with no value. |
BasicAttribute |
Constructs a new instance of an unordered attribute with a single value. |
BasicAttribute |
Constructs a new instance of a possibly ordered attribute with a single value. |
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 this attribute. |
void |
clear() |
Removes all values from this attribute. |
Object |
clone() |
Creates and returns a copy of this object. |
boolean |
contains |
Determines whether a value is in this attribute. |
boolean |
equals |
Determines whether obj is equal to this 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 this attribute's values. |
DirContext |
getAttributeDefinition() |
Retrieves this attribute's schema definition. |
DirContext |
getAttributeSyntaxDefinition() |
Retrieves the syntax definition associated with this attribute. |
String |
getID() |
Retrieves the id of this attribute. |
int |
hashCode() |
Calculates the hash code 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 this attribute. |
Object |
set |
Sets an attribute value in the ordered list of attribute values. |
int |
size() |
Retrieves the number of values in this attribute. |
String |
toString() |
Generates the string representation of this attribute. |
protected String attrID
protected transient Vector<Object> values
protected boolean ordered
public BasicAttribute(String id)
id
- The attribute's id. It cannot be null.public BasicAttribute(String id, Object value)
id
- The attribute's id. It cannot be null.value
- The attribute's value. If null, a null value is added to the attribute.public BasicAttribute(String id, boolean ordered)
id
- The attribute's id. It cannot be null.ordered
- true means the attribute's values will be ordered; false otherwise.public BasicAttribute(String id, Object value, boolean ordered)
id
- The attribute's id. It cannot be null.value
- The attribute's value. If null, a null value is added to the attribute.ordered
- true means the attribute's values will be ordered; false otherwise.public Object clone()
Object
x
, the expression: will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements. While it is typically the case that: will bex.clone().equals(x)
true
, this is not an absolute requirement. By convention, the returned object should be obtained by calling super.clone
. If a class and all of its superclasses (except Object
) obey this convention, it will be the case that x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone
before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone
need to be modified.
public boolean equals(Object obj)
By default Object.equals()
is used when comparing the attribute id and its values except when a value is an array. For an array, each element of the array is checked using Object.equals()
. A subclass may override this to make use of schema syntax information and matching rules, which define what it means for two attributes to be equal. How and whether a subclass makes use of the schema information is determined by the subclass. If a subclass overrides equals()
, it should also override hashCode()
such that two attributes that are equal have the same hash code.
public int hashCode()
The hash code is computed by adding the hash code of the attribute's id and that of all of its values except for values that are arrays. For an array, the hash code of each element of the array is summed. If a subclass overrides hashCode()
, it should override equals()
as well so that two attributes that are equal have the same hash code.
public String toString()
public NamingEnumeration<?> getAll() throws NamingException
By default, the values returned are those passed to the constructor and/or manipulated using the add/replace/remove methods. A subclass may override this to retrieve the values dynamically from the directory.
getAll
in interface Attribute
NamingException
- If a naming exception was encountered while retrieving the values.public Object get() throws NamingException
By default, the value returned is one of those passed to the constructor and/or manipulated using the add/replace/remove methods. A subclass may override this to retrieve the value dynamically from the directory.
get
in interface Attribute
NamingException
- If a naming exception was encountered while retrieving the value.public int size()
Attribute
public String getID()
Attribute
public boolean contains(Object attrVal)
By default, Object.equals()
is used when comparing attrVal
with this attribute's values except when attrVal
is an array. For an array, each element of the array is checked using Object.equals()
. A subclass may use schema information to determine equality.
public boolean add(Object attrVal)
By default, Object.equals()
is used when comparing attrVal
with this attribute's values except when attrVal
is an array. For an array, each element of the array is checked using Object.equals()
. A subclass may use schema information to determine equality.
public boolean remove(Object attrval)
By default, Object.equals()
is used when comparing attrVal
with this attribute's values except when attrVal
is an array. For an array, each element of the array is checked using Object.equals()
. A subclass may use schema information to determine equality.
public void clear()
Attribute
public boolean isOrdered()
Attribute
public Object get(int ix) throws NamingException
Attribute
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.get
in interface Attribute
ix
- The index of the value in the ordered list of attribute values. 0 <= ix < size()
.ix
; null if the attribute value is null.NamingException
- If a naming exception was encountered while retrieving the value.public Object remove(int ix)
Attribute
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).public void add(int ix, Object attrVal)
Attribute
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.public Object set(int ix, Object attrVal)
Attribute
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.set
in interface Attribute
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.public DirContext getAttributeSyntaxDefinition() throws NamingException
This method by default throws OperationNotSupportedException. A subclass should override this method if it supports schema.
getAttributeSyntaxDefinition
in interface Attribute
OperationNotSupportedException
- If getting the schema is not supported.NamingException
- If a naming exception occurs while getting the schema.public DirContext getAttributeDefinition() throws NamingException
This method by default throws OperationNotSupportedException. A subclass should override this method if it supports schema.
getAttributeDefinition
in interface Attribute
OperationNotSupportedException
- If getting the schema is not supported.NamingException
- If a naming exception occurs while getting the schema.
© 1993, 2023, 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/21/docs/api/java.naming/javax/naming/directory/BasicAttribute.html