org.pf.directory
Class MultiValueAttributes

java.lang.Object
  extended by org.pf.directory.MultiValueAttributes
All Implemented Interfaces:
AttributeReadAccess
Direct Known Subclasses:
DirectoryObject

public class MultiValueAttributes
extends java.lang.Object
implements AttributeReadAccess

Holds many attribute names with associated multiple values under. Access to attributes by their name is case-insensitive.

Version:
1.2
Author:
M.Duchrow

Constructor Summary
MultiValueAttributes()
          Initialize the new instance with default values.
 
Method Summary
 void addAttribute(MultiValueAttribute attribute)
          Adds the given attribute.
 void addValue(java.lang.String attrName, java.lang.Object value)
          Adds the given value to the attribute with the given name.
 void addValue(java.lang.String attrName, java.lang.Object value, boolean encoded)
          Adds the given value to the attribute with the given name.
 MultiValueAttribute getAttribute(java.lang.String attrName)
          Returns the attribute with the specified name or null if not found
 java.lang.String getAttributeAsString(java.lang.String attrName)
          Returns the first value of the specified attribute as String.
 java.lang.String[] getAttributeAsStringArray(java.lang.String attrName)
          Returns the values of the specified attribute as String array.
 java.lang.String[] getAttributeNames()
          Returns the names of all attributes.
 java.lang.Object getAttributeValue(java.lang.String attrName)
          Returns the current value of the attribute with the given name.
 MultiValueAttributes getCopyOfAttributes(java.lang.String[] attrNames)
          Returns a copy of all those attributes that are specified by the given name array and that exist in this object.
 AttributesMetaData getMetaData()
           
 java.lang.Object getValue(java.lang.String attrName)
          Returns the first value of the attribute with the given name.
 java.util.List getValues(java.lang.String attrName)
          Returns the values of the attribute with the given name.
 boolean hasAttribute(java.lang.String attrName)
          Returns if this object contains an attribute with the specified name.
 boolean isEmpty()
          Returns true if this object currently contains no attribute at all
 void removeAttribute(java.lang.String attrName)
          Removes the attribute with the given name and of course also all its associated values.
 void removeValue(java.lang.String attrName, java.lang.Object value)
          Removes the given value from the specified attribute.
 void setMetaData(AttributesMetaData newValue)
           
 int size()
          Returns the current number of attributes in this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiValueAttributes

public MultiValueAttributes()
Initialize the new instance with default values.

Method Detail

getMetaData

public AttributesMetaData getMetaData()

setMetaData

public void setMetaData(AttributesMetaData newValue)

getValue

public java.lang.Object getValue(java.lang.String attrName)
Returns the first value of the attribute with the given name. If the attribute is not known it returns null.

Parameters:
attrName - The name of the attribute of which the first associated value should be returned

getValues

public java.util.List getValues(java.lang.String attrName)
Returns the values of the attribute with the given name. If the attribute is not known it returns null.

Parameters:
attrName - The name of the attribute of which the associated values should be returned

addValue

public void addValue(java.lang.String attrName,
                     java.lang.Object value)
Adds the given value to the attribute with the given name. If the attribute not yet exists it will be automatically added as well.

Parameters:
attrName - The name of the attribute
value - The value to be added to the attribute's values

addValue

public void addValue(java.lang.String attrName,
                     java.lang.Object value,
                     boolean encoded)
Adds the given value to the attribute with the given name. If the attribute not yet exists it will be automatically added as well.

Parameters:
attrName - The name of the attribute
value - The value to be added to the attribute's values
encoded - An indicator that defines whether the values of this attribute have to be encoded

addAttribute

public void addAttribute(MultiValueAttribute attribute)
Adds the given attribute. If an attribute with the same name already exists then it will be replaced.

Parameters:
attribute - The attribute to add

removeAttribute

public void removeAttribute(java.lang.String attrName)
Removes the attribute with the given name and of course also all its associated values.

Parameters:
attrName - The name of the attribute to remove

removeValue

public void removeValue(java.lang.String attrName,
                        java.lang.Object value)
Removes the given value from the specified attribute. If the value is not yet associated with the attribute nothing happens. If the attribute has no values after removing this one, the attribute will be removed as well.

Parameters:
attrName - The name of the attribute
value - The value to remove from the attribute

getAttributeNames

public java.lang.String[] getAttributeNames()
Returns the names of all attributes.

Specified by:
getAttributeNames in interface AttributeReadAccess

getAttributeValue

public java.lang.Object getAttributeValue(java.lang.String attrName)
                                   throws java.lang.NoSuchFieldException
Returns the current value of the attribute with the given name.

Specified by:
getAttributeValue in interface AttributeReadAccess
Parameters:
attrName - The attribute's name ( case sensitive )
Throws:
java.lang.NoSuchFieldException - If there is no attribute with the given name

getAttribute

public MultiValueAttribute getAttribute(java.lang.String attrName)
Returns the attribute with the specified name or null if not found

Parameters:
attrName - The name of the attribute

hasAttribute

public boolean hasAttribute(java.lang.String attrName)
Returns if this object contains an attribute with the specified name.


size

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


isEmpty

public boolean isEmpty()
Returns true if this object currently contains no attribute at all


getCopyOfAttributes

public MultiValueAttributes getCopyOfAttributes(java.lang.String[] attrNames)
Returns a copy of all those attributes that are specified by the given name array and that exist in this object. If the name array is null or empty all attributes will be copied.

Parameters:
attrNames - The names of all attributes to copy (null means to copy all attributes)

getAttributeAsString

public java.lang.String getAttributeAsString(java.lang.String attrName)
                                      throws java.lang.NoSuchFieldException
Returns the first value of the specified attribute as String.

Parameters:
attrName - The name of the attribute
Returns:
null if the attribute was found but has no value
Throws:
java.lang.NoSuchFieldException - If no attribute with the specified name can be found

getAttributeAsStringArray

public java.lang.String[] getAttributeAsStringArray(java.lang.String attrName)
                                             throws java.lang.NoSuchFieldException
Returns the values of the specified attribute as String array.

Parameters:
attrName - The name of the attribute
Returns:
An empty array if the attribute was found but has no values
Throws:
java.lang.NoSuchFieldException - If no attribute with the specified name can be found
java.lang.ClassCastException - If any value of the attribute is not of type String