All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class javax.naming.directory.Attribute

java.lang.Object
   |
   +----javax.naming.directory.Attribute

public class Attribute
extends Object
implements Cloneable, Serializable
In a directory, named objects can have associated with them attributes. The Attribute class represents an attribute associated with a named object. An attribute contains 0 or more values. The values are unordered, with no duplicates, and can be null.

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. These methods by default do not return any schema information. Subclasses of Attribute override these methods if they support schemas.

The Attribute class by default use the Object.equals() to determine equality of object values when testing for equality or when searching for values. Subclasses of Attribute can make use of schema information when doing similar equality checks by overriding methods in which such use of schema is meaningful. Similarly, the Attribute class by default returns the values passed to its constructor and/or manipulated using the add/remove methods. Subclasses of Attribute can override get() and getAll() to get the values dynamically from the directory.

Note that updates to Attribute (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.

An Attribute instance is not synchronized against concurrent multithreaded access. Multiple threads trying to access and modify an Attribute should lock the object.

The serialized form of an Attribute 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 Attribute()
Null constructor for subclasses to use in case they do not want to use attrID or values in their implementation Neither of attrID nor values is initialized.
 o Attribute(String)
Constructs a new instance of an attribute with no value.
 o Attribute(String, Object)
Constructs a new instance of an attribute with a single value.

Method Index

 o add(Object)
Adds a new value to 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 Attribute
 protected Attribute()
Null constructor for subclasses to use in case they do not want to use attrID or values in their implementation Neither of attrID nor values is initialized.

 o Attribute
 public Attribute(String id)
Constructs a new instance of an attribute with no value.

Parameters:
id - The attribute's id. It cannot be null.
 o Attribute
 public Attribute(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. Changes to the copy does not affect this Attribute and vice value.

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 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 OperationNotSupported. A subclass should override this method if it supports schema.

Returns:
This attribute's syntax definition. By default null.
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 OperationNotSupported. A subclass should override this method if it supports schema.

Returns:
This attribute's schema definition. Cannot be null.
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