Class ConverterUtil
ConvertUtils
or trying to get it from this package.- Since:
- 1.0
- Author:
- Tony Chemit - chemit@codelutin.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringDefault package where to find the converter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]convert(char[] chars) Converts a array of char to an array of bytes.static <T> TTry to convert a value.static voidTo remove any registered converter.static <T> org.apache.commons.beanutils.ConvertergetConverter(Class<T> type) Try to find amatching converter for the giventype.static voidTo init default converters (using the service loader mecanism on contractNuitonConverter).static voidregisterConverter(Class<?> type) protected static voidregisterConverter0(Class<?> type) static <E extends Enum>
voidregisterEnumConverter(Class<E> type) Register a new converter for a given enum type, not using any default value.static <E extends Enum>
voidregisterEnumConverter(Class<E> type, Object defaultValue) Register a new converter for a given enum type, using the given default value.
-
Field Details
-
CONVERTER_PACKAGE
Default package where to find the converter.- See Also:
-
-
Constructor Details
-
ConverterUtil
protected ConverterUtil()
-
-
Method Details
-
getConverter
Try to find amatching converter for the giventype.If required, init defaults converters (see
initConverters()).If not found and type is an enum, then will register a enum type converter.
If still not found, try to register a converter having the
NuitonConvertercontract namedtypeConverterin the current package (CONVERTER_PACKAGE).For example with type
MyType, will try to find the converterorg.nuiton.converter.MyTypeConverter.- Type Parameters:
T- type to convert- Parameters:
type- type to convert- Returns:
- the found converter, or
nullif not found
-
convert
Try to convert a value.Will first try to find a matching converter, if not found return then
null.Note: will init default converters or matching data type converter if required.
- Type Parameters:
T- type of data to convert- Parameters:
type- type of data to converttoConvert- data to convert- Returns:
- the converted data or
nullif no converter found for the type of data.
-
registerConverter
public static void registerConverter(Class<?> type) throws IllegalAccessException, InstantiationException, ClassNotFoundException -
registerConverter0
protected static void registerConverter0(Class<?> type) throws IllegalAccessException, InstantiationException, ClassNotFoundException -
registerEnumConverter
-
registerEnumConverter
-
convert
public static byte[] convert(char[] chars) Converts a array of char to an array of bytes.TODO Find out who uses this ?
- Parameters:
chars- array of characters to converter- Returns:
- the array of bytes
-
deregister
public static void deregister()To remove any registered converter.At the next call to method
convert(Class, Object)orgetConverter(Class), default converters will be registred again. -
initConverters
public static void initConverters()To init default converters (using the service loader mecanism on contractNuitonConverter).If was already init, then will do nothing.
Note: the
getConverter(Class)orconvert(Class, Object)methods always invoke this method if the class was not initialized (see thewasInitinternal flag).
-