Class EnumConverter
- java.lang.Object
-
- net.sf.jguiraffe.di.EnumConverter
-
- All Implemented Interfaces:
org.apache.commons.beanutils.Converter
public final class EnumConverter extends Object implements org.apache.commons.beanutils.Converter
A specialized
Converter
implementation dealing with all types of enumeration classes.The implementation of the
convert(Class, Object)
method expects that the passed in value is a constant as defined for an enumeration class as string. It tries to find the corresponding instance of the enumeration class.An instance of this class is registered per default as base class converter at any new
InvocationHelper
instance. Therefore conversions to parameters or properties ofEnum
types are supported out of the box.Implementation note: This class has no state. So a single instance can be shared between multiple instances. This instance can be obtained using the
getInstance()
factory method; creating new instances is now allowed.- Version:
- $Id: EnumConverter.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
convert(Class type, Object value)
Performs the type conversion to an enumeration constant.static EnumConverter
getInstance()
Returns an instance ofEnumConverter
.
-
-
-
Method Detail
-
getInstance
public static EnumConverter getInstance()
Returns an instance ofEnumConverter
. Use this factory method to obtain a new instance rather than invoking a constructor.- Returns:
- the
EnumConverter
instance
-
convert
public Object convert(Class type, Object value)
Performs the type conversion to an enumeration constant. If this is not possible, aConversionException
is thrown. There are multiple reasons why this could happen, e.g. the value is not an exact string representation of an enumeration constant, or the class might be noEnum
class.- Specified by:
convert
in interfaceorg.apache.commons.beanutils.Converter
- Parameters:
type
- the class to convert tovalue
- the object to be converted- Returns:
- the result of the conversion
-
-