|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectilog.views.util.convert.IlvConvert
public class IlvConvert
The class IlvConvert is used to convert a value from one type
to another. All methods are static.
Conversions are handled by a table of IlvConverter
objects. Each converter handles one or several "from" types and one
or several "to" types. The conversion is actually performed by
the convert() method of IlvConverter.
A number of predefined filters are provided:
String to/from localized Number, Byte, Short, Integer, Long, Float,
Double, BigDecimal, BigInteger, and Boolean String to/from Color String to/from Fontfloat to int)String to localized Date, see SimpleDateFormat,
e.g. "mm/dd/yy,02/21/03" String to/from localized Currency/Percent (use
IlvLocalizedConverter.CURRENCY_AS_NUMBER_CLASS and
IlvLocalizedConverter.PERCENT_AS_NUMBER_CLASS
as type. More filters supplied by other packages or by the application can be added.
It is also possible to register a PropertyEditor which converts value from/to String
through its get/setAsText() methods.
This is a bit different from IlvConvertForSetters, which converts a value
from a PropertyDescriptor.
The code comes mainly from BGO (IlvValueConverter)
IlvConverter,
IlvLocalizedConverter,
IlvConvertForSetters,
Serialized Form| Method Summary | |
|---|---|
static void |
addConverter(IlvConverter converter)
Adds a converter to the global list of converters used to convert values. |
static void |
addConverter(PropertyEditor pe,
Class type)
Adds a converter to the global list of converters used to convert values. |
static Object |
convert(Object value,
Class toType)
Converts the type of a value to a new type. |
static Object |
convert(Object value,
Class toType,
Locale locale)
Converts the type of a value to a new type. |
static boolean |
convertToBoolean(Object value)
Converts a value from its current type to a boolean value. |
static byte |
convertToByte(Object value)
Converts a value from its current type to a byte. |
static double |
convertToDouble(Object value)
Converts a value from its current type to a double. |
static float |
convertToFloat(Object value)
Converts a value from its current type to a float. |
static int |
convertToInt(Object value)
Converts a value from its current type to an integer. |
static long |
convertToLong(Object value)
Converts a value from its current type to a long integer. |
static short |
convertToShort(Object value)
Converts a value from its current type to a short. |
static String |
convertToString(Object value)
Converts a value from its current type to a string. |
static IlvConverter |
getConverter(Class from,
Class to)
Returns the converter which can handle given parameters |
static boolean |
isConverterLocalized(Class from,
Class to)
Returns true whether the converter which can handle given parameters is localized. |
static boolean |
isConvertible(Class fromType,
Class toType)
Returns true if a values from type fromType can
be converted to a value of type toType. |
static void |
removeConverter(Class from,
Class to)
Removes the converter between given types. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static final void addConverter(IlvConverter converter)
converter - the new value converter. The source and target types
handled by the converter are determined by the result of the
methods fromTypes and toTypes of the
converter.
public static final void addConverter(PropertyEditor pe,
Class type)
pe - the new value converter which must implement its getAsTex() and setAsText() methods.type - the type of the property associated to the given property editor.
public static IlvConverter getConverter(Class from,
Class to)
from - the source typeto - the target type
public static boolean isConverterLocalized(Class from,
Class to)
from - the source typeto - the target type
public static void removeConverter(Class from,
Class to)
from - the source typeto - the target type
public static final Object convert(Object value,
Class toType)
throws IlvConvertException
value - the value to be converted.toType - the type to which the value must be converted.
toType.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.
public static boolean isConvertible(Class fromType,
Class toType)
true if a values from type fromType can
be converted to a value of type toType.
fromType - the source typetoType - the destination type
public static final Object convert(Object value,
Class toType,
Locale locale)
throws IlvConvertException
value - the value to be converted.toType - the type to which the value must be converted.locale - the locale used for the conversion
toType.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.
public static final String convertToString(Object value)
throws IlvConvertException
(String)convert(value, String.class)
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final int convertToInt(Object value)
throws IlvConvertException
((Integer)convert(value, Integer.class)).intValue()
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final long convertToLong(Object value)
throws IlvConvertException
((Long)convert(value, Long.class)).longValue()
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final boolean convertToBoolean(Object value)
throws IlvConvertException
((Boolean)convert(value, Boolean.class)).booleanValue()
value - the value to convert
IlvConvertException - if not converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final float convertToFloat(Object value)
throws IlvConvertException
((Float)convert(value, Float.class)).floatValue()
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final double convertToDouble(Object value)
throws IlvConvertException
((Double)convert(value, Double.class)).doubleValue()
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final short convertToShort(Object value)
throws IlvConvertException
((Short)convert(value, Short.class)).shortValue()
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
public static final byte convertToByte(Object value)
throws IlvConvertException
value - the value to be converted.
IlvConvertException - if no converter was registered for the
requested conversion or if the value could not be converted
to the requested type.convert(java.lang.Object, java.lang.Class)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||