LDAP Classes
Implements Java LDAP

com.novell.ldap
Class LDAPAttribute

java.lang.Object
  extended bycom.novell.ldap.LDAPAttribute
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
LDAPSchemaElement

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

The name and values of one attribute of a directory entry.

LDAPAttribute objects are used when searching for, adding, modifying, and deleting attributes from the directory. LDAPAttributes are often used in conjunction with an LDAPAttributeSet when retrieving or adding multiple attributes to an entry.

Sample Code: AddEntry.java

See Also:
LDAPEntry, LDAPAttributeSet, LDAPModification, Serialized Form

Constructor Summary
LDAPAttribute(LDAPAttribute attr)
          Constructs an attribute with copies of all values of the input attribute.
LDAPAttribute(java.lang.String attrName)
          Constructs an attribute with no values.
LDAPAttribute(java.lang.String attrName, byte[] attrBytes)
          Constructs an attribute with a byte-formatted value.
LDAPAttribute(java.lang.String attrName, java.lang.String attrString)
          Constructs an attribute with a single string value.
LDAPAttribute(java.lang.String attrName, java.lang.String[] attrStrings)
          Constructs an attribute with an array of string values.
 
Method Summary
 void addBase64Value(char[] attrChars)
          Adds a base64 encoded value to the attribute.
 void addBase64Value(java.lang.String attrString)
          Adds a base64 encoded value to the attribute.
 void addBase64Value(java.lang.StringBuffer attrString, int start, int end)
          Adds a base64 encoded value to the attribute.
 void addURLValue(java.lang.String url)
          Adds a URL, indicating a file or other resource that contains the value of the attribute.
 void addURLValue(java.net.URL url)
          Adds a URL, indicating a file or other resource that contains the value of the attribute.
 void addValue(byte[] attrBytes)
          Adds a byte-formatted value to the attribute.
 void addValue(java.lang.String attrString)
          Adds a string value to the attribute.
 java.lang.Object clone()
          Returns a clone of this LDAPAttribute.
 int compareTo(java.lang.Object attribute)
          Compares this object with the specified object for order.
 java.lang.String getBaseName()
          Returns the base name of the attribute.
static java.lang.String getBaseName(java.lang.String attrName)
          Returns the base name of the specified attribute name.
 byte[] getByteValue()
          Returns the the first value of the attribute as a byte array.
 byte[][] getByteValueArray()
          Returns the values of the attribute as an array of bytes.
 java.util.Enumeration getByteValues()
          Returns an enumerator for the values of the attribute in byte format.
 java.lang.String getLangSubtype()
          Returns the language subtype of the attribute, if any.
 java.lang.String getName()
          Returns the name of the attribute.
 java.lang.String getStringValue()
          Returns the the first value of the attribute as a String.
 java.lang.String[] getStringValueArray()
          Returns the values of the attribute as an array of strings.
 java.util.Enumeration getStringValues()
          Returns an enumerator for the string values of an attribute.
 java.lang.String[] getSubtypes()
          Extracts the subtypes from the attribute name.
static java.lang.String[] getSubtypes(java.lang.String attrName)
          Extracts the subtypes from the specified attribute name.
 boolean hasSubtype(java.lang.String subtype)
          Reports if the attribute name contains the specified subtype.
 boolean hasSubtypes(java.lang.String[] subtypes)
          Reports if the attribute name contains all the specified subtypes.
static java.lang.Object readDSML(java.io.InputStream input)
          This method is used to deserialize the DSML encoded representation of this class.
 void removeValue(byte[] attrBytes)
          Removes a byte-formatted value from the attribute.
 void removeValue(java.lang.String attrString)
          Removes a string value from the attribute.
protected  void setValue(java.lang.String value)
          Replaces all values with the specified value.
 int size()
          Returns the number of values in the attribute.
 java.lang.String toString()
          Returns a string representation of this LDAPAttribute
 void writeDSML(java.io.OutputStream oout)
          This method does DSML serialization of the instance.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LDAPAttribute

public LDAPAttribute(LDAPAttribute attr)
Constructs an attribute with copies of all values of the input attribute.

Parameters:
attr - An LDAPAttribute to use as a template.
Throws:
java.lang.IllegalArgumentException - if attr is null

LDAPAttribute

public LDAPAttribute(java.lang.String attrName)
Constructs an attribute with no values.

Parameters:
attrName - Name of the attribute.
Throws:
java.lang.IllegalArgumentException - if attrName is null

LDAPAttribute

public LDAPAttribute(java.lang.String attrName,
                     byte[] attrBytes)
Constructs an attribute with a byte-formatted value.

Parameters:
attrName - Name of the attribute.

attrBytes - Value of the attribute as raw bytes.

Note: If attrBytes represents a string it should be UTF-8 encoded.

Throws:
java.lang.IllegalArgumentException - if attrName or attrBytes is null

LDAPAttribute

public LDAPAttribute(java.lang.String attrName,
                     java.lang.String attrString)
Constructs an attribute with a single string value.

Parameters:
attrName - Name of the attribute.

attrString - Value of the attribute as a string.
Throws:
java.lang.IllegalArgumentException - if attrName or attrString is null

LDAPAttribute

public LDAPAttribute(java.lang.String attrName,
                     java.lang.String[] attrStrings)
Constructs an attribute with an array of string values.

Parameters:
attrName - Name of the attribute.

attrStrings - Array of values as strings.
Throws:
java.lang.IllegalArgumentException - if attrName, attrStrings, or a member of attrStrings is null
Method Detail

clone

public java.lang.Object clone()
Returns a clone of this LDAPAttribute.

Returns:
clone of this LDAPAttribute.

addValue

public void addValue(java.lang.String attrString)
Adds a string value to the attribute.

Parameters:
attrString - Value of the attribute as a String.
Throws:
java.lang.IllegalArgumentException - if attrString is null

addValue

public void addValue(byte[] attrBytes)
Adds a byte-formatted value to the attribute.

Parameters:
attrBytes - Value of the attribute as raw bytes.

Note: If attrBytes represents a string it should be UTF-8 encoded.

Throws:
java.lang.IllegalArgumentException - if attrBytes is null

addBase64Value

public void addBase64Value(java.lang.String attrString)
Adds a base64 encoded value to the attribute. The value will be decoded and stored as bytes. String data encoded as a base64 value must be UTF-8 characters.

Parameters:
attrString - The base64 value of the attribute as a String.
Throws:
java.lang.IllegalArgumentException - if attrString is null

addBase64Value

public void addBase64Value(java.lang.StringBuffer attrString,
                           int start,
                           int end)
Adds a base64 encoded value to the attribute. The value will be decoded and stored as bytes. Character data encoded as a base64 value must be UTF-8 characters.

Parameters:
attrString - The base64 value of the attribute as a StringBuffer.
start - The start index of base64 encoded part, inclusive.
end - The end index of base encoded part, exclusive.
Throws:
java.lang.IllegalArgumentException - if attrString is null

addBase64Value

public void addBase64Value(char[] attrChars)
Adds a base64 encoded value to the attribute. The value will be decoded and stored as bytes. Character data encoded as a base64 value must be UTF-8 characters.

Parameters:
attrChars - The base64 value of the attribute as an array of characters.
Throws:
java.lang.IllegalArgumentException - if attrString is null

addURLValue

public void addURLValue(java.lang.String url)
                 throws java.net.MalformedURLException,
                        java.io.IOException
Adds a URL, indicating a file or other resource that contains the value of the attribute.

Parameters:
url - String value of a URL pointing to the resource containing the value of the attribute.
Throws:
java.lang.IllegalArgumentException - if url is null
java.net.MalformedURLException
java.io.IOException

addURLValue

public void addURLValue(java.net.URL url)
                 throws java.net.MalformedURLException,
                        java.io.IOException
Adds a URL, indicating a file or other resource that contains the value of the attribute.

Parameters:
url - A URL class pointing to the resource containing the value of the attribute.
Throws:
java.lang.IllegalArgumentException - if url is null
java.net.MalformedURLException
java.io.IOException

getByteValues

public java.util.Enumeration getByteValues()
Returns an enumerator for the values of the attribute in byte format.

Returns:
The values of the attribute in byte format.

Note: All string values will be UTF-8 encoded. To decode use the String constructor. Example: new String( byteArray, "UTF-8" );


getStringValues

public java.util.Enumeration getStringValues()
Returns an enumerator for the string values of an attribute.

Returns:
The string values of an attribute.

getByteValueArray

public byte[][] getByteValueArray()
Returns the values of the attribute as an array of bytes.

Returns:
The values as an array of bytes or an empty array if there are no values.

getStringValueArray

public java.lang.String[] getStringValueArray()
Returns the values of the attribute as an array of strings.

Returns:
The values as an array of strings or an empty array if there are no values

getStringValue

public java.lang.String getStringValue()
Returns the the first value of the attribute as a String.

Returns:
The UTF-8 encodedString value of the attribute's value. If the value wasn't a UTF-8 encoded String to begin with the value of the returned String is non deterministic.

If this attribute has more than one value the first value is converted to a UTF-8 encoded String and returned. It should be noted, that the directory may return attribute values in any order, so that the first value may vary from one call to another.

If the attribute has no values null is returned


getByteValue

public byte[] getByteValue()
Returns the the first value of the attribute as a byte array.

Returns:
The binary value of this attribute or null if this attribute doesn't have a value.

If the attribute has no values null is returned


getLangSubtype

public java.lang.String getLangSubtype()
Returns the language subtype of the attribute, if any.

For example, if the attribute name is cn;lang-ja;phonetic, this method returns the string, lang-ja.

Returns:
The language subtype of the attribute or null if the attribute has none.

getBaseName

public java.lang.String getBaseName()
Returns the base name of the attribute.

For example, if the attribute name is cn;lang-ja;phonetic, this method returns cn.

Returns:
The base name of the attribute.

getBaseName

public static java.lang.String getBaseName(java.lang.String attrName)
Returns the base name of the specified attribute name.

For example, if the attribute name is cn;lang-ja;phonetic, this method returns cn.

Parameters:
attrName - Name of the attribute from which to extract the base name.
Returns:
The base name of the attribute.
Throws:
java.lang.IllegalArgumentException - if attrName is null

getName

public java.lang.String getName()
Returns the name of the attribute.

Returns:
The name of the attribute.

getSubtypes

public java.lang.String[] getSubtypes()
Extracts the subtypes from the attribute name.

For example, if the attribute name is cn;lang-ja;phonetic, this method returns an array containing lang-ja and phonetic.

Returns:
An array subtypes or null if the attribute has none.

getSubtypes

public static java.lang.String[] getSubtypes(java.lang.String attrName)
Extracts the subtypes from the specified attribute name.

For example, if the attribute name is cn;lang-ja;phonetic, this method returns an array containing lang-ja and phonetic.

Parameters:
attrName - Name of the attribute from which to extract the subtypes.
Returns:
An array subtypes or null if the attribute has none.
Throws:
java.lang.IllegalArgumentException - if attrName is null

hasSubtype

public boolean hasSubtype(java.lang.String subtype)
Reports if the attribute name contains the specified subtype.

For example, if you check for the subtype lang-en and the attribute name is cn;lang-en, this method returns true.

Parameters:
subtype - The single subtype to check for.
Returns:
True, if the attribute has the specified subtype; false, if it doesn't.
Throws:
java.lang.IllegalArgumentException - if subtype is null

hasSubtypes

public boolean hasSubtypes(java.lang.String[] subtypes)
Reports if the attribute name contains all the specified subtypes.

For example, if you check for the subtypes lang-en and phonetic and if the attribute name is cn;lang-en;phonetic, this method returns true. If the attribute name is cn;phonetic or cn;lang-en, this method returns false.

Parameters:
subtypes - An array of subtypes to check for.
Returns:
True, if the attribute has all the specified subtypes; false, if it doesn't have all the subtypes.
Throws:
java.lang.IllegalArgumentException - if subtypes is null or if array member is null.

removeValue

public void removeValue(java.lang.String attrString)
Removes a string value from the attribute.

Parameters:
attrString - Value of the attribute as a string.

Note: Removing a value which is not present in the attribute has no effect.

Throws:
java.lang.IllegalArgumentException - if attrString is null

removeValue

public void removeValue(byte[] attrBytes)
Removes a byte-formatted value from the attribute.

Parameters:
attrBytes - Value of the attribute as raw bytes.

Note: If attrBytes represents a string it should be UTF-8 encoded. Example: String.getBytes("UTF-8");

Note: Removing a value which is not present in the attribute has no effect.

Throws:
java.lang.IllegalArgumentException - if attrBytes is null

size

public int size()
Returns the number of values in the attribute.

Returns:
The number of values in the attribute.

compareTo

public int compareTo(java.lang.Object attribute)
Compares this object with the specified object for order.

Ordering is determined by comparing attribute names (see getName()) using the method compareTo() of the String class.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
attribute - The LDAPAttribute to be compared to this object.
Returns:
Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

setValue

protected void setValue(java.lang.String value)
Replaces all values with the specified value. This protected method is used by sub-classes of LDAPSchemaElement because the value cannot be set with a contructor.


toString

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

Returns:
a string representation of this LDAPAttribute

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