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

public abstract class DefaultTypeConverter extends Object implements TypeConverter
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 Details

  • Constructor Details

    • DefaultTypeConverter

      public DefaultTypeConverter()
  • Method Details

    • setContainer

      public void setContainer(Container container)
    • convertValue

      public Object convertValue(Map<String,Object> context, Object value, Class toType)
    • 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 interface TypeConverter
      Parameters:
      context - context under which the conversion is being done
      target - target object in which the property is being set
      member - member (Constructor, Method or Field) being set
      propertyName - property name being set
      value - value to be converted
      toType - type to which value is converted
      Returns:
      Converted value of type toType or TypeConverter.NoConversionPossible to indicate that the conversion was not possible.
    • getTypeConverter

      public TypeConverter getTypeConverter(Map<String,Object> context)
    • convertValue

      public Object 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.
      Parameters:
      value - an object to be converted to the given type
      toType - 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

      public 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.
      Parameters:
      value - an object to interpret as a boolean
      Returns:
      the boolean value implied by the given object
    • enumValue

      public Enum<?> enumValue(Class toClass, Object o)
    • longValue

      public static long longValue(Object value)
      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

      public static double doubleValue(Object value)
      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

      public static BigInteger bigIntValue(Object value)
      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

      public static BigDecimal bigDecValue(Object value)
      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

      public static String stringValue(Object value, boolean trim)
      Evaluates the given object as a String and trims it if the trim flag is true.
      Parameters:
      value - an object to interpret as a String
      trim - 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

      public static String stringValue(Object value)
      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

      protected Locale getLocale(Map<String,Object> context)