com.opensymphony.xwork2.conversion.impl
Class XWorkBasicConverter

java.lang.Object
  extended by com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter
      extended by com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter
All Implemented Interfaces:
TypeConverter

public class XWorkBasicConverter
extends DefaultTypeConverter

XWork will automatically handle the most common type conversion for you. This includes support for converting to and from Strings for each of the following:

Note that with arrays the type conversion will defer to the type of the array elements and try to convert each item individually. As with any other type conversion, if the conversion can't be performed the standard type conversion error reporting is used to indicate a problem occured while processing the type conversion.

Author:
Pat Lightbody, Mike Mosiewicz, Rainer Hermanns, Alexandru Popescu

Field Summary
private static String MILLISECOND_FORMAT
           
private  ObjectFactory objectFactory
           
private  ObjectTypeDeterminer objectTypeDeterminer
           
private  XWorkConverter xworkConverter
           
 
Fields inherited from interface com.opensymphony.xwork2.conversion.TypeConverter
NO_CONVERSION_POSSIBLE, TYPE_CONVERTER_CONTEXT_KEY
 
Constructor Summary
XWorkBasicConverter()
           
 
Method Summary
 Object convertValue(Map<String,Object> context, Object o, Member member, String s, Object value, Class toType)
          Converts the given value to a given type.
private  Collection createCollection(Object fromObject, String propertyName, Class toType, Class memberType, int size)
          Creates a Collection of the specified type.
private  String doConvertFromNumberToString(Map<String,Object> context, Object value, Class toType)
          Converts the input as a number using java's number formatter to a string output.
private  Object doConvertToArray(Map<String,Object> context, Object o, Member member, String s, Object value, Class toType)
           
private  Object doConvertToBoolean(Object value)
           
private  Object doConvertToCharacter(Object value)
           
private  Class doConvertToClass(Object value)
           
private  Collection doConvertToCollection(Map<String,Object> context, Object o, Member member, String prop, Object value, Class toType)
           
private  Object doConvertToDate(Map<String,Object> context, Object value, Class toType)
           
private  Object doConvertToNumber(Map<String,Object> context, Object value, Class toType)
           
private  String doConvertToString(Map<String,Object> context, Object value)
           
private  DateFormat[] getDateFormats(Locale locale)
           
private  Locale getLocale(Map<String,Object> context)
           
protected  boolean isInRange(Number value, String stringValue, Class toType)
           
protected  boolean isIntegerType(Class type)
           
 void setObjectFactory(ObjectFactory fac)
           
 void setObjectTypeDeterminer(ObjectTypeDeterminer det)
           
 void setXWorkConverter(XWorkConverter conv)
           
 
Methods inherited from class com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter
bigDecValue, bigIntValue, booleanValue, convertValue, convertValue, doubleValue, enumValue, getTypeConverter, longValue, stringValue, stringValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MILLISECOND_FORMAT

private static String MILLISECOND_FORMAT

objectTypeDeterminer

private ObjectTypeDeterminer objectTypeDeterminer

xworkConverter

private XWorkConverter xworkConverter

objectFactory

private ObjectFactory objectFactory
Constructor Detail

XWorkBasicConverter

public XWorkBasicConverter()
Method Detail

setObjectTypeDeterminer

public void setObjectTypeDeterminer(ObjectTypeDeterminer det)

setXWorkConverter

public void setXWorkConverter(XWorkConverter conv)

setObjectFactory

public void setObjectFactory(ObjectFactory fac)

convertValue

public Object convertValue(Map<String,Object> context,
                           Object o,
                           Member member,
                           String s,
                           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
Overrides:
convertValue in class DefaultTypeConverter
Parameters:
context - context under which the conversion is being done
o - target object in which the property is being set
member - member (Constructor, Method or Field) being set
s - 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.

getLocale

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

createCollection

private Collection createCollection(Object fromObject,
                                    String propertyName,
                                    Class toType,
                                    Class memberType,
                                    int size)
Creates a Collection of the specified type.

Parameters:
fromObject -
propertyName -
toType - the type of Collection to create
memberType - the type of object elements in this collection must be
size - the initial size of the collection (ignored if 0 or less)
Returns:
a Collection of the specified type

doConvertToArray

private Object doConvertToArray(Map<String,Object> context,
                                Object o,
                                Member member,
                                String s,
                                Object value,
                                Class toType)

doConvertToCharacter

private Object doConvertToCharacter(Object value)

doConvertToBoolean

private Object doConvertToBoolean(Object value)

doConvertToClass

private Class doConvertToClass(Object value)

doConvertToCollection

private Collection doConvertToCollection(Map<String,Object> context,
                                         Object o,
                                         Member member,
                                         String prop,
                                         Object value,
                                         Class toType)

doConvertToDate

private Object doConvertToDate(Map<String,Object> context,
                               Object value,
                               Class toType)

getDateFormats

private DateFormat[] getDateFormats(Locale locale)

doConvertToNumber

private Object doConvertToNumber(Map<String,Object> context,
                                 Object value,
                                 Class toType)

isInRange

protected boolean isInRange(Number value,
                            String stringValue,
                            Class toType)

isIntegerType

protected boolean isIntegerType(Class type)

doConvertFromNumberToString

private String doConvertFromNumberToString(Map<String,Object> context,
                                           Object value,
                                           Class toType)
Converts the input as a number using java's number formatter to a string output.


doConvertToString

private String doConvertToString(Map<String,Object> context,
                                 Object value)


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.