Class DefaultTypeConverter
java.lang.Object
org.apache.struts2.conversion.impl.DefaultTypeConverter
- All Implemented Interfaces:
TypeConverter
- Direct Known Subclasses:
ArrayConverter
,CollectionConverter
,DateConverter
,NumberConverter
,StringConverter
,StrutsTypeConverter
,UploadedFileConverter
,XWorkBasicConverter
,XWorkConverter
Default type conversion. Converts among numeric types and also strings. Contains the basic
type mapping code from OGNL.
- Author:
- Luke Blanshard (blanshlu@netscape.net), Drew Davidson (drew@ognl.org)
-
Field Summary
FieldsFields inherited from interface org.apache.struts2.conversion.TypeConverter
NO_CONVERSION_POSSIBLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimal
bigDecValue
(Object value) Evaluates the given object as a BigDecimal.static BigInteger
bigIntValue
(Object value) Evaluates the given object as a BigInteger.static boolean
booleanValue
(Object value) Evaluates the given object as a boolean: if it is a Boolean object, it's easy; if it's a Number or a Character, returns true for non-zero objects; and otherwise returns true for non-null objects.convertValue
(Object value, Class toType) Returns the value converted numerically to the given class type This method also detects when arrays are being converted and converts the components of one array to the type of the other.convertValue
(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) Converts the given value to a given type.static double
doubleValue
(Object value) Evaluates the given object as a double-precision floating-point number.Enum<?>
protected Locale
getTypeConverter
(Map<String, Object> context) static long
Evaluates the given object as a long integer.void
setContainer
(Container container) static String
stringValue
(Object value) Evaluates the given object as a String.static String
stringValue
(Object value, boolean trim) Evaluates the given object as a String and trims it if the trim flag is true.
-
Field Details
-
MILLISECOND_FORMAT
- See Also:
-
-
Constructor Details
-
DefaultTypeConverter
public DefaultTypeConverter()
-
-
Method Details
-
setContainer
-
convertValue
-
convertValue
public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) Description copied from interface:TypeConverter
Converts the given value to a given type. The OGNL context, target, member and name of property being set are given. This method should be able to handle conversion in general without any context, target, member or property name specified.- Specified by:
convertValue
in interfaceTypeConverter
- Parameters:
context
- context under which the conversion is being donetarget
- target object in which the property is being setmember
- member (Constructor, Method or Field) being setpropertyName
- property name being setvalue
- value to be convertedtoType
- type to which value is converted- Returns:
- Converted value of type toType or TypeConverter.NoConversionPossible to indicate that the conversion was not possible.
-
getTypeConverter
-
convertValue
Returns the value converted numerically to the given class type This method also detects when arrays are being converted and converts the components of one array to the type of the other.- Parameters:
value
- an object to be converted to the given typetoType
- class type to be converted to- Returns:
- converted value of the type given, or value if the value cannot be converted to the given type.
-
booleanValue
Evaluates the given object as a boolean: if it is a Boolean object, it's easy; if it's a Number or a Character, returns true for non-zero objects; and otherwise returns true for non-null objects.- Parameters:
value
- an object to interpret as a boolean- Returns:
- the boolean value implied by the given object
-
enumValue
-
longValue
Evaluates the given object as a long integer.- Parameters:
value
- an object to interpret as a long integer- Returns:
- the long integer value implied by the given object
-
doubleValue
Evaluates the given object as a double-precision floating-point number.- Parameters:
value
- an object to interpret as a double- Returns:
- the double value implied by the given object
-
bigIntValue
Evaluates the given object as a BigInteger.- Parameters:
value
- an object to interpret as a BigInteger- Returns:
- the BigInteger value implied by the given object
-
bigDecValue
Evaluates the given object as a BigDecimal.- Parameters:
value
- an object to interpret as a BigDecimal- Returns:
- the BigDecimal value implied by the given object
-
stringValue
Evaluates the given object as a String and trims it if the trim flag is true.- Parameters:
value
- an object to interpret as a Stringtrim
- trims the result if true- Returns:
- the String value implied by the given object as returned by the toString() method, or "null" if the object is null.
-
stringValue
Evaluates the given object as a String.- Parameters:
value
- an object to interpret as a String- Returns:
- the String value implied by the given object as returned by the toString() method, or "null" if the object is null.
-
getLocale
-