LDAP Classes
Implements Java LDAP

com.novell.ldap
Class LDAPAttributeSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended bycom.novell.ldap.LDAPAttributeSet
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.io.Serializable, java.util.Set

public class LDAPAttributeSet
extends java.util.AbstractSet
implements java.lang.Cloneable, java.util.Set, java.io.Serializable

A set of LDAPAttribute objects.

An LDAPAttributeSet is a collection of LDAPAttribute classes as returned from an LDAPEntry on a search or read operation. LDAPAttributeSet may be also used to contruct an entry to be added to a directory. If the add() or addAll() methods are called and one or more of the objects to be added is not an LDAPAttribute, ClassCastException is thrown (as discussed in the documentation for java.util.Collection).

Sample Code: AddEntry.java

See Also:
LDAPAttribute, LDAPEntry, Serialized Form

Constructor Summary
LDAPAttributeSet()
          Constructs an empty set of attributes.
 
Method Summary
 boolean add(java.lang.Object attr)
          Adds the specified attribute to this set if it is not already present.
 boolean addAll(java.util.Collection c)
          Adds all LDAPAttribute objects in the specified collection to this collection.
 void clear()
          Removes all of the elements from this set.
 java.lang.Object clone()
          Returns a deep copy of this attribute set.
 boolean contains(java.lang.Object attr)
          Returns true if this set contains an attribute of the same name as the specified attribute.
 LDAPAttribute getAttribute(java.lang.String attrName)
          Returns the attribute matching the specified attrName.
 LDAPAttribute getAttribute(java.lang.String attrName, java.lang.String lang)
          Returns a single best-match attribute, or null if no match is available in the entry.
 LDAPAttributeSet getSubset(java.lang.String subtype)
          Creates a new attribute set containing only the attributes that have the specified subtypes.
 boolean isEmpty()
          Returns true if this set contains no elements
 java.util.Iterator iterator()
          Returns an iterator over the attributes in this set.
static java.lang.Object readDSML(java.io.InputStream input)
          This method is used to deserialize the DSML encoded representation of this class.
 boolean remove(java.lang.Object object)
          Removes the specified object from this set if it is present.
 int size()
          Returns the number of attributes in this set.
 java.lang.String toString()
          Returns a string representation of this LDAPAttributeSet
 void writeDSML(java.io.OutputStream oout)
          This method does DSML serialization of the instance.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

LDAPAttributeSet

public LDAPAttributeSet()
Constructs an empty set of attributes.

Method Detail

clone

public java.lang.Object clone()
Returns a deep copy of this attribute set.

Returns:
A deep copy of this attribute set.

getAttribute

public LDAPAttribute getAttribute(java.lang.String attrName)
Returns the attribute matching the specified attrName.

For example:

In both cases, null is returned if there is no exact match to the specified attrName.

Note: Novell eDirectory does not currently support language subtypes. It does support the "binary" subtype.

Parameters:
attrName - The name of an attribute to retrieve, with or without subtype specifications. For example, "cn", "cn;phonetic", and "cn;binary" are valid attribute names.
Returns:
The attribute matching the specified attrName, or null if there is no exact match.

getAttribute

public LDAPAttribute getAttribute(java.lang.String attrName,
                                  java.lang.String lang)
Returns a single best-match attribute, or null if no match is available in the entry.

LDAP version 3 allows adding a subtype specification to an attribute name. For example, "cn;lang-ja" indicates a Japanese language subtype of the "cn" attribute and "cn;lang-ja-JP-kanji" may be a subtype of "cn;lang-ja". This feature may be used to provide multiple localizations in the same directory. For attributes which do not vary among localizations, only the base attribute may be stored, whereas for others there may be varying degrees of specialization.

For example, getAttribute(attrName,lang) returns the LDAPAttribute that exactly matches attrName and that best matches lang.

If there are subtypes other than "lang" subtypes included in attrName, for example, "cn;binary", only attributes with all of those subtypes are returned. If lang is null or empty, the method behaves as getAttribute(attrName). If there are no matching attributes, null is returned.

Assume the entry contains only the following attributes:

Examples:

Note: Novell eDirectory does not currently support language subtypes. It does support the "binary" subtype.

Parameters:
attrName - The name of an attribute to retrieve, with or without subtype specifications. For example, "cn", "cn;phonetic", and cn;binary" are valid attribute names.

lang - A language specification with optional subtypes appended using "-" as separator. For example, "lang-en", "lang-en-us", "lang-ja", and "lang-ja-JP-kanji" are valid language specification.
Returns:
A single best-match LDAPAttribute, or null if no match is found in the entry.

getSubset

public LDAPAttributeSet getSubset(java.lang.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:

Calling the getSubset method and passing lang-ja as the argument, the method returns an attribute set containing the following attributes:

Parameters:
subtype - Semi-colon delimited list of subtypes to include. For example:
  • "lang-ja" specifies only Japanese language subtypes
  • "binary" specifies only binary subtypes
  • "binary;lang-ja" specifies only Japanese language subtypes which also are binary

Note: Novell eDirectory does not currently support language subtypes. It does support the "binary" subtype.

Returns:
An attribute set containing the attributes that match the specified subtype.

iterator

public java.util.Iterator iterator()
Returns an iterator over the attributes in this set. The attributes returned from this iterator are not in any particular order.

Specified by:
iterator in interface java.util.Set
Returns:
iterator over the attributes in this set

size

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

Specified by:
size in interface java.util.Set
Returns:
number of attributes in this set.

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements

Specified by:
isEmpty in interface java.util.Set
Returns:
true if this set contains no elements

contains

public boolean contains(java.lang.Object attr)
Returns true if this set contains an attribute of the same name as the specified attribute.

Specified by:
contains in interface java.util.Set
Parameters:
attr - Object of type LDAPAttribute
Returns:
true if this set contains the specified attribute
Throws:
java.lang.ClassCastException - occurs the specified Object is not of type LDAPAttribute.

add

public boolean add(java.lang.Object attr)
Adds the specified attribute to this set if it is not already present.

If an attribute with the same name already exists in the set then the specified attribute will not be added.

Specified by:
add in interface java.util.Set
Parameters:
attr - Object of type LDAPAttribute
Returns:
true if the attribute was added.
Throws:
java.lang.ClassCastException - occurs the specified Object is not of type LDAPAttribute.

remove

public boolean remove(java.lang.Object object)
Removes the specified object from this set if it is present.

If the specified object is of type LDAPAttribute, the specified attribute will be removed. If the specified object is of type String, the attribute with a name that matches the string will be removed.

Specified by:
remove in interface java.util.Set
Parameters:
object - LDAPAttribute to be removed or String naming the attribute to be removed.
Returns:
true if the object was removed.
Throws:
java.lang.ClassCastException - occurs the specified Object is not of type LDAPAttribute or of type String.

clear

public void clear()
Removes all of the elements from this set.

Specified by:
clear in interface java.util.Set

addAll

public boolean addAll(java.util.Collection c)
Adds all LDAPAttribute objects in the specified collection to this collection.

Specified by:
addAll in interface java.util.Set
Parameters:
c - Collection of LDAPAttribute objects.
Returns:
true if this set changed as a result of the call.
Throws:
java.lang.ClassCastException - occurs when an element in the collection is not of type LDAPAttribute.

toString

public java.lang.String toString()
Returns a string representation of this LDAPAttributeSet

Returns:
a string representation of this LDAPAttributeSet

writeDSML

public void writeDSML(java.io.OutputStream oout)
               throws java.io.IOException
This method does DSML serialization of the instance.

Parameters:
oout - Outputstream where the serialzed data has to be written
Throws:
java.io.IOException - if write fails on OutputStream

readDSML

public static java.lang.Object readDSML(java.io.InputStream input)
                                 throws java.io.IOException
This method is used to deserialize the DSML encoded representation of this class.

Parameters:
input - InputStream for the DSML formatted data.
Returns:
Deserialized form of this class.
Throws:
java.io.IOException - when serialization fails.

LDAP Classes
Implements Java LDAP

Copyright © 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000