netscape.ldap

Class LDAPAttributeSet

Implemented Interfaces:
Cloneable, java.io.Serializable

public class LDAPAttributeSet
extends java.lang.Object
implements Cloneable, java.io.Serializable

Represents a set of attributes (for example, the set of attributes in an entry).
Version:
1.0
See Also:
LDAPAttribute, Serialized Form

Constructor Summary

LDAPAttributeSet()
Constructs a new set of attributes.
LDAPAttributeSet(LDAPAttribute[] attrs)
Constructs an attribute set.

Method Summary

void
add(LDAPAttribute attr)
Adds the specified attribute to this attribute set.
Object
clone()
LDAPAttribute
elementAt(int index)
Returns the attribute at the position specified by the index.
LDAPAttribute
getAttribute(String attrName)
Returns a single attribute that exactly matches the specified attribute name.
LDAPAttribute
getAttribute(String attrName, String lang)
Returns the subtype that matches the attribute name specified by attrName and the language specificaton identified by lang.
Enumeration
getAttributes()
Returns an enumeration of the attributes in this attribute set.
LDAPAttributeSet
getSubset(String subtype)
Creates a new attribute set containing only the attributes that have the specified subtypes.
void
remove(String name)
Removes the specified attribute from the set.
void
removeElementAt(int index)
Removes the attribute at the position specified by the index.
int
size()
Returns the number of attributes in this set.
String
toString()
Retrieves the string representation of all attributes in the attribute set.

Constructor Details

LDAPAttributeSet

public LDAPAttributeSet()
Constructs a new set of attributes. This set is initially empty.

LDAPAttributeSet

public LDAPAttributeSet(LDAPAttribute[] attrs)
Constructs an attribute set.
Parameters:
attrs - the list of attributes

Method Details

add

public void add(LDAPAttribute attr)
Adds the specified attribute to this attribute set.
Parameters:
attr - attribute to add to this set

clone

public Object clone()

elementAt

public LDAPAttribute elementAt(int index)
Returns the attribute at the position specified by the index. For example, if you specify the index 0, the method returns the first attribute in the set. The index is 0-based.
Parameters:
index - index of the attribute to obtain
Returns:
attribute at the position specified by the index.

getAttribute

public LDAPAttribute getAttribute(String attrName)
Returns a single attribute that exactly matches the specified attribute name.
Parameters:
attrName - name of attribute to return For example:
"cn"            // Only a non-subtyped version of cn
"cn;lang-ja"    // Only a Japanese version of cn
Returns:
attribute that has exactly the same name, or null (if no attribute in the set matches the specified name).
See Also:
LDAPAttribute

getAttribute

public LDAPAttribute getAttribute(String attrName,
                                  String lang)
Returns the subtype that matches the attribute name specified by attrName and the language specificaton identified by lang.

If no attribute in the set has the specified name and subtype, the method returns null. Attributes containing subtypes other than lang (for example, cn;binary) are returned only if they contain the specified lang subtype and if the set contains no attribute having only the lang subtype. (For example, getAttribute( "cn", "lang-ja" ) returns cn;lang-ja;phonetic only if the cn;lang-ja attribute does not exist.)

If null is specified for the lang argument, calling this method is the same as calling the getAttribute(attrName) method.

For example, suppose an entry contains only the following attributes:

  • cn;lang-en
  • cn;lang-ja-JP-kanji
  • sn

Calling the following methods will return the following values:

  • getAttribute( "cn" ) returns null.
  • getAttribute( "sn" ) returns the "sn" attribute.
  • getAttribute( "cn", "lang-en-us" ) returns the "cn;lang-en" attribute.
  • getAttribute( "cn", "lang-en" ) returns the "cn;lang-en" attribute.
  • getAttribute( "cn", "lang-ja" ) returns null.
  • getAttribute( "sn", "lang-en" ) returns the "sn" attribute.

Parameters:
attrName - name of attribute to find in the entry
lang - a language specification
Returns:
the attribute that matches the base name and that best matches any specified language subtype.
See Also:
LDAPAttribute

getAttributes

public Enumeration getAttributes()
Returns an enumeration of the attributes in this attribute set.
Returns:
enumeration of the attributes in this set.

getSubset

public LDAPAttributeSet getSubset(String subtype)
Creates a new attribute set containing only the attributes that have the specified subtypes.

For example, suppose an attribute set contains the following attributes:

 cn
 cn;lang-ja
 sn;phonetic;lang-ja
 sn;lang-us
 
If you call the getSubset method and pass lang-ja as the argument, the method returns an attribute set containing the following attributes:

 cn;lang-ja
 sn;phonetic;lang-ja
 
Parameters:
subtype - semi-colon delimited list of subtypes to find within attribute names. For example:
"lang-ja"        // Only Japanese language subtypes
"binary"         // Only binary subtypes
"binary;lang-ja" // Only Japanese language subtypes
which also are binary
Returns:
attribute set containing the attributes that have the specified subtypes.
See Also:
LDAPAttribute, netscape.ldap.LDAPAttributeSet.getAttribute, netscape.ldap.LDAPEntry.getAttributeSet

remove

public void remove(String name)
Removes the specified attribute from the set.
Parameters:
name - name of the attribute to remove

removeElementAt

public void removeElementAt(int index)
Removes the attribute at the position specified by the index. For example, if you specify the index 0, the method removes the first attribute in the set. The index is 0-based.
Parameters:
index - index of the attribute to remove

size

public int size()
Returns the number of attributes in this set.
Returns:
number of attributes in this attribute set.

toString

public String toString()
Retrieves the string representation of all attributes in the attribute set. For example:
 LDAPAttributeSet: LDAPAttribute {type='cn', values='Barbara Jensen,Babs
 Jensen'}LDAPAttribute {type='sn', values='Jensen'}LDAPAttribute {type='
 givenname', values='Barbara'}LDAPAttribute {type='objectclass', values=
 'top,person,organizationalPerson,inetOrgPerson'}LDAPAttribute {type='ou',
 values='Product Development,People'}
 
Returns:
string representation of all attributes in the set.