All Packages Class Hierarchy This Package Previous Next Index
Class javax.naming.directory.BasicAttribute
java.lang.Object
|
+----javax.naming.directory.BasicAttribute
- public class BasicAttribute
- extends Object
- implements Attribute
This class provides a basic implementation of the Attribute interface.
This implementation does not support schema.
The schema methods, getAttributeDefinition() and getAttributeSyntaxDefinition(),
simply throw OperationNotSupportedException.
Subclasses of BasicAttribute should override these methods if they
support schemas.
The BasicAttribute class by default uses the Object.equals() to
determine equality of attribute values when testing for equality or
when searching for values.
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.
The serialized form of a BasicAttribute object consists of the
attribute ID (a String), the number of values (an int), and the
individual values.
-
attrID
- Holds the attribute's id.
-
values
- Holds the attribute's values.
-
BasicAttribute(String)
- Constructs a new instance of an attribute with no value.
-
BasicAttribute(String, Object)
- Constructs a new instance of an attribute with a single value.
-
add(Object)
- Adds a new value to this attribute.
-
clear()
- Removes all values from this attribute.
-
clone()
- Makes a copy of this attribute.
-
contains(Object)
- Determines whether a value is in this attribute.
-
equals(Object)
- Determines whether obj is equal to this attribute.
-
get()
- Retrieves one of this attribute's values.
-
getAll()
- Retrieves an enumeration of this attribute's values.
-
getAttributeDefinition()
- Retrieves this attribute's schema definition.
-
getAttributeSyntaxDefinition()
- Retrieves the syntax definition associated with this attribute.
-
getID()
- Retrieves the id of this attribute.
-
remove(Object)
- Removes a specified value from this attribute.
-
size()
-
Retrieves the number of values in this attribute.
-
toString()
- Generates the string representation of this attribute.
attrID
protected String attrID
- Holds the attribute's id. It is initialized by the public constructor and
cannot be null unless methods in Attribute that use attrID
have been overridden.
values
protected transient Vector values
- Holds the attribute's values. Initialized by public constructors.
Cannot be null unless methods in Attribute that use
values have been overridden.
BasicAttribute
public BasicAttribute(String id)
- Constructs a new instance of an attribute with no value.
- Parameters:
- id - The attribute's id. It cannot be null.
BasicAttribute
public BasicAttribute(String id,
Object value)
- Constructs a new instance of an attribute with a single value.
- Parameters:
- id - The attribute's id. It cannot be null.
- value - The attribute's value. If null, a null
value is added to the attribute.
clone
public Object clone()
- Makes a copy of this attribute.
The copy contains the same attribute values as the original attribute:
the attribute values are not themselves cloned.
Changes to the copy does not affect the original and vice versa.
- Returns:
- A non-null copy of this attribute.
- Overrides:
- clone in class Object
equals
public boolean equals(Object obj)
- Determines whether obj is equal to this attribute.
Two attributes are equal if their attribute-ids, syntaxes
and values are equal. The order that the values were added
are irrelevant. If obj is null or not an Attribute, false is returned.
By default Object.equals() is used when comparing the attribute
id and its values. 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.
- Parameters:
- obj - The possibly null object to check.
- Returns:
- true if obj is equal to this attribute; false otherwise.
- Overrides:
- equals in class Object
toString
public String toString()
- Generates the string representation of this attribute.
The string consists of the attribute's id and its values.
This string is meant for debuggin and not meant to be
interpreted programmatically.
- Returns:
- The non-null string representation of this attribute.
- Overrides:
- toString in class Object
getAll
public NamingEnumeration getAll() throws NamingException
- Retrieves an enumeration of this attribute's values.
The behaviour of this enumeration is unspecified
if the this attribute's values are added, changed,
or removed.
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.
- Returns:
- A non-null enumeration of this attribute's values.
Each element of the enumeration an Object. The object's
class is the class of the attribute value.
If the attribute has zero values, an empty enumeration
is returned.
- Throws: NamingException
- If a naming exception was encountered while retrieving
the values.
get
public Object get() throws NamingException
- Retrieves one of this attribute's values.
If the attribute has more than one value, any of
the values are returned.
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.
- Returns:
- A possibly null object representing one of
the attribute's value.
- Throws: NamingException
- If a naming exception was encountered while retrieving
the value.
- Throws: NoSuchElementException
- If this attribute has no values.
size
public int size()
- Retrieves the number of values in this attribute.
- Returns:
- The nonnegative number of values in this attribute.
getID
public String getID()
- Retrieves the id of this attribute.
- Returns:
- The id of this attribute. It cannot be null.
contains
public boolean contains(Object attrVal)
- Determines whether a value is in this attribute.
By default, Object.equals() is used when comparing attrVal
with this attribute's values. A subclass may use schema
information to determine equality.
- Parameters:
- attrVal - The possibly null value to check.
- Returns:
- true if attrVal is one of this attribute's values; false otherwise.
- See Also:
- equals
add
public boolean add(Object attrVal)
- Adds a new value to this attribute. If attrVal is already in the
attribute, this method does nothing.
By default, Object.equals() is used when comparing attrVal
with this attribute's values. A subclass may use schema
information to determine equality.
- Parameters:
- attrVal - The new possibly null value to add.
- Returns:
- true If this attribute did not already have attrVal.
remove
public boolean remove(Object attrval)
- Removes a specified value from this attribute.
If attrval is not in this attribute, just ignore.
By default, Object.equals() is used when comparing attrVal
with this attribute's values. A subclass may use schema
information to determine equality.
- Parameters:
- attrVal - The possibly null value to remove from this attribute.
- Returns:
- true if the value was removed; false otherwise.
clear
public void clear()
- Removes all values from this attribute.
getAttributeSyntaxDefinition
public DirContext getAttributeSyntaxDefinition() throws NamingException
- Retrieves the syntax definition associated with this attribute.
An attribute's syntax definition specifies the format
of the attribute's value(s). Note that this is different from
the attribute value's representation as a Java object. Syntax
definition refers to the directory's notion of syntax.
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.
This method by default throws OperationNotSupportedException. A subclass
should override this method if it supports schema.
- Returns:
- This attribute's syntax definition.
- Throws: OperationNotSupportedException
- If getting the schema
is not supported.
- Throws: NamingException
- If a naming exception occurs while getting
the schema.
getAttributeDefinition
public DirContext getAttributeDefinition() throws NamingException
- Retrieves this attribute's schema definition.
An attribute's schema definition contains information
such as whether the attribute is multivalued or single-valued,
the matching rules to use when comparing this attribiute's values.
The information that you can retrieve from an attribute definition
is directory-dependent.
This method by default throws OperationNotSupportedException. A subclass
should override this method if it supports schema.
- Returns:
- This attribute's schema definition.
- Throws: OperationNotSupportedException
- If getting the schema
is not supported.
- Throws: NamingException
- If a naming exception occurs while getting
the schema.
All Packages Class Hierarchy This Package Previous Next Index