com.ca.commons.jndi.beans
Class MultiValuedAttribHandler

java.lang.Object
  extended by com.ca.commons.jndi.beans.MultiValuedAttribHandler
All Implemented Interfaces:
JNDIBeanPropertyHandler
Direct Known Subclasses:
ByteDataPropertyHandler, DataModelBinaryPropertyHandler, EnumPropertyHandler, LdapNamePropertyHandler, NumberPropertyHandler, StringPropertyHandler

public class MultiValuedAttribHandler
extends Object
implements JNDIBeanPropertyHandler

A JNDI bean handler implementation to assist processing of multi-valued JNDI attributes. This class handles a common case where a multivalued JNDI attribute is to have all its values placed into a Collection. For multivalued attributes that have a more complicated mapping, the JNDIBeanPropertyHandler interface must be implemented directly. This class is designed to be used as a super class, with subclasses overriding attrib2Property and property2Attrib to convert each value as appropriate. This class provides implementations of these methods that simply return the values unchanged, so it can be used as is to aggregate attribute values into a Collection without converting them.

This class does not accept any initialization properties, but its subclasses may do so.

Author:
Lachlan O'Dea (odela01)

Field Summary
 
Fields inherited from interface com.ca.commons.jndi.beans.JNDIBeanPropertyHandler
logger
 
Constructor Summary
MultiValuedAttribHandler()
           
 
Method Summary
protected  Object attrib2Property(Object attrValue)
          Converts a single attribute value to a value to be included in the Collection result.
 List<?> getAttributeValues(Object value)
          Converts elements of a Collection into a values of a multivalued JNDI attribute.
 Object getPropertyValue(Attribute[] attr)
          Places all values of a multivalued JNDI attribute into a Collection, optionally performing a conversion on each individual action.
 void init(Properties props)
          Provides a set of properties to initialize the handler.
protected  Object property2Attrib(Object propValue)
          Converts a single property value to an attribute value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiValuedAttribHandler

public MultiValuedAttribHandler()
Method Detail

init

public void init(Properties props)
          throws JNDIBeanStoreConfigException
Description copied from interface: JNDIBeanPropertyHandler
Provides a set of properties to initialize the handler. A handler implementation may alter aspects of its behaviour based on these properties. Each implementation must document what properties it expects (if any). This method is called once on each handler instance by JNDIBeanStoreFactory with the properties listed by its XML configuration data.

Specified by:
init in interface JNDIBeanPropertyHandler
Parameters:
props - The properties to use for initialization.
Throws:
JNDIBeanStoreConfigException - If any of the properties were invalid in any way.

getPropertyValue

public Object getPropertyValue(Attribute[] attr)
                        throws NamingException
Places all values of a multivalued JNDI attribute into a Collection, optionally performing a conversion on each individual action. Each value of the attribute is converted via the attrib2Property(java.lang.Object) method before being placed in the result Collection.

Specified by:
getPropertyValue in interface JNDIBeanPropertyHandler
Parameters:
attr - An array containing the multivalued attribute to convert. This array should have a length of 1.
Returns:
A Collection containing all of the attribute's values after conversion by attrib2Property.
Throws:
NamingException - If the attribute's values could not be read.
JNDIBeanStoreException - If thrown by attrib2Property.

getAttributeValues

public List<?> getAttributeValues(Object value)
                           throws JNDIBeanStoreException
Converts elements of a Collection into a values of a multivalued JNDI attribute. The value parameter must by a Collection. Each element in value is converted via the property2Attrib(java.lang.Object) method. The returned List will contain a single element, a Collection containing all the converted values.

Specified by:
getAttributeValues in interface JNDIBeanPropertyHandler
Parameters:
value - A Collection containing the values to convert.
Returns:
A list with one element, which is a collection of JNDI attribute values of size equal to the size of the input collection.
Throws:
JNDIBeanStoreException - If thrown by property2Attrib.

attrib2Property

@Nullable
protected Object attrib2Property(@Nullable
                                          Object attrValue)
                          throws JNDIBeanStoreException
Converts a single attribute value to a value to be included in the Collection result. This is called by getPropertyValue(javax.naming.directory.Attribute[]) for each value of the multivalued attribute. The default implementation simply returns the same reference it was passed.

Parameters:
attrValue - An attribute value.
Returns:
The converted value.
Throws:
JNDIBeanStoreException - If the value could not be converted.

property2Attrib

@Nullable
protected Object property2Attrib(@Nullable
                                          Object propValue)
                          throws JNDIBeanStoreException
Converts a single property value to an attribute value. This is called by getAttributeValues(java.lang.Object) for each element of the input Collection. The default implementation simply returns the same reference it was passed.

Parameters:
propValue - A property value.
Returns:
The converted attribute value.
Throws:
JNDIBeanStoreException - If the value could not be converted.


Created 2011-07-14 13:27 EST