All LDAP Classes
Internal LDAP Classes

com.novell.ldap
Class LDAPAttribute

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

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

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

Field Summary
private  java.lang.String baseName
           
private  java.lang.String name
           
private  java.lang.String[] subTypes
           
private  java.lang.Object[] values
           
 
Constructor Summary
LDAPAttribute()
          This constructor was added to support default Serialization
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
private  void add(byte[] bytes)
          Adds an object to this object's list of attribute values
 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.
private  boolean equals(byte[] e1, byte[] e2)
          Returns true if the two specified arrays of bytes are equal to each another.
 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.
private static LDAPXMLHandler getTopXMLHandler(java.lang.String tagname, LDAPXMLHandler parenthandler)
           
(package private) static LDAPXMLHandler getXMLHandler(java.lang.String tagname, LDAPXMLHandler parenthandler)
          This method return the LDAPHandler which handles the XML (DSML) tags for this class
 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.
(package private)  void newLine(int indentTabs, java.io.Writer out)
           
static java.lang.Object readDSML(java.io.InputStream input)
          This method is used to deserialize the DSML encoded representation of this class.
 void readExternal(java.io.ObjectInput in)
          Reads the serialized object from the underlying input stream.
 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 setDeserializedValues(java.io.BufferedInputStream istream)
           
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.
 void writeExternal(java.io.ObjectOutput out)
          Writes the object state to a stream in XML format
protected  void writeValue(java.lang.StringBuffer buff)
           
protected  void writeValue(java.io.Writer out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private java.lang.String name

baseName

private java.lang.String baseName

subTypes

private java.lang.String[] subTypes

values

private java.lang.Object[] values
Constructor Detail

LDAPAttribute

public LDAPAttribute()
This constructor was added to support default Serialization


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.

Overrides:
clone in class java.lang.Object
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.

add

private void add(byte[] bytes)
Adds an object to this object's list of attribute values

Parameters:
bytes - Ultimately all of this attribute's values are treated as binary data so we simplify the process by requiring that all data added to our list is in binary form.

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


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.


equals

private boolean equals(byte[] e1,
                       byte[] e2)
Returns true if the two specified arrays of bytes are equal to each another. Matches the logic of Arrays.equals which is not available in jdk 1.1.x.

Parameters:
e1 - the first array to be tested
e2 - the second array to be tested
Returns:
true if the two arrays are equal

toString

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

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this LDAPAttribute

newLine

void newLine(int indentTabs,
             java.io.Writer out)
       throws java.io.IOException
Throws:
java.io.IOException

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

writeValue

protected void writeValue(java.io.Writer out)
                   throws java.io.IOException
Throws:
java.io.IOException

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.

getTopXMLHandler

private static LDAPXMLHandler getTopXMLHandler(java.lang.String tagname,
                                               LDAPXMLHandler parenthandler)

getXMLHandler

static LDAPXMLHandler getXMLHandler(java.lang.String tagname,
                                    LDAPXMLHandler parenthandler)
This method return the LDAPHandler which handles the XML (DSML) tags for this class

Parameters:
tagname - Name of the Root tag used to represent this class.
parenthandler - Parent LDAPXMLHandler for this tag.
Returns:
LDAPXMLHandler to handle this element.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Writes the object state to a stream in XML format

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - The ObjectOutput stream where the Object in XML format is being written to
Throws:
java.io.IOException - - If I/O errors occur

writeValue

protected void writeValue(java.lang.StringBuffer buff)

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Reads the serialized object from the underlying input stream.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - The ObjectInput stream where the Serialized Object is being read from
Throws:
java.io.IOException - - If I/O errors occur
java.lang.ClassNotFoundException - - If the class for an object being restored cannot be found.

setDeserializedValues

protected void setDeserializedValues(java.io.BufferedInputStream istream)
                              throws java.io.IOException
Throws:
java.io.IOException

All LDAP Classes
Internal LDAP Classes

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