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.


Variable Index

 o attrID
Holds the attribute's id.
 o values
Holds the attribute's values.

Constructor Index

 o BasicAttribute(String)
Constructs a new instance of an attribute with no value.
 o BasicAttribute(String, Object)
Constructs a new instance of an attribute with a single value.

Method Index

 o add(Object)
Adds a new value to this attribute.
 o clear()
Removes all values from this attribute.
 o clone()
Makes a copy of this attribute.
 o contains(Object)
Determines whether a value is in this attribute.
 o equals(Object)
Determines whether obj is equal to this attribute.
 o get()
Retrieves one of this attribute's values.
 o getAll()
Retrieves an enumeration of this attribute's values.
 o getAttributeDefinition()
Retrieves this attribute's schema definition.
 o getAttributeSyntaxDefinition()
Retrieves the syntax definition associated with this attribute.
 o getID()
Retrieves the id of this attribute.
 o remove(Object)
Removes a specified value from this attribute.
 o size()
Retrieves the number of values in this attribute.
 o toString()
Generates the string representation of this attribute.

Variables

 o 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.

 o 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.

Constructors

 o 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.
 o 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.

Methods

 o 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
 o 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
 o 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
 o 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.
 o 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.
 o size
 public int size()
Retrieves the number of values in this attribute.

Returns:
The nonnegative number of values in this attribute.
 o getID
 public String getID()
Retrieves the id of this attribute.

Returns:
The id of this attribute. It cannot be null.
 o 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
 o 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.
 o 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.
 o clear
 public void clear()
Removes all values from this attribute.

 o 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.
 o 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