/** * Evaluates the given object as a String. * * @param value * an object to interpret as a String * @return the String value implied by the given object as returned by the * toString() method, or "null" if the object is null. */ public static String stringValue(Object value) { return stringValue(value, false); }
public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) { return convertValue(context, value, toType); }
private Object getRealValue(Map context, Object value, Class convertToClass) { if (value == null || convertToClass == null) { return value; } return xworkConverter.convertValue(context, value, convertToClass); } }
/** * Replaces the element at the specified position in this list with the specified element. * <p/> * This method is guaranteed to work since it will create empty beans to fill the gap between * the current list size and the requested index to enable the element to be set. This method * also performs any necessary type conversion. * * @param index index of element to replace. * @param element element to be stored at the specified position. * @return the element previously at the specified position. */ @Override public Object set(int index, Object element) { if (index >= this.size()) { get(index); } element = convert(element); return super.set(index, element); }
/** * Determines the key class by looking for the value of @Key annotation for the given class. * If no annotation is found, the key class is determined by using the generic parametrics. * * As fallback, it determines the key class by looking for the value of Key_${property} in the properties * file for the given class. * * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. * @param property the property of the Map or Collection for the given parent class * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getKeyClass(Class, String) */ public Class getKeyClass(Class parentClass, String property) { Key annotation = getAnnotation(parentClass, property, Key.class); if (annotation != null) { return annotation.value(); } Class clazz = getClass(parentClass, property, false); if (clazz != null) { return clazz; } return (Class) xworkConverter.getConverter(parentClass, KEY_PREFIX + property); }
/** * Converts the given object to a given type. How this is to be done is implemented in toClass. The OGNL context, o * and toClass are given. This method should be able to handle conversion in general without any context or object * specified. * * @param context - OGNL context under which the conversion is being done * @param o - the object to be converted * @param toClass - the class that contains the code to convert to enumeration * @return Converted value of type declared in toClass or TypeConverter.NoConversionPossible to indicate that the * conversion was not possible. */ @Override public Object convertValue(Map<String, Object> context, Object o, Class toClass) { if (o instanceof String[]) { return convertFromString(((String[]) o)[0], toClass); } else if (o instanceof String) { return convertFromString((String) o, toClass); } return super.convertValue(context, o, toClass); }
/** * Determines the key property for a Collection by getting it from the @KeyProperty annotation. * * As fallback, it determines the String key property for a Collection by getting it from the conversion properties * file using the KeyProperty_ prefix. KeyProperty_${property}=somePropertyOfBeansInTheSet * * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. * @param property the property of the Map or Collection for the given parent class * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getKeyProperty(Class, String) */ public String getKeyProperty(Class parentClass, String property) { KeyProperty annotation = getAnnotation(parentClass, property, KeyProperty.class); if (annotation != null) { return annotation.value(); } return (String) xworkConverter.getConverter(parentClass, KEY_PROPERTY_PREFIX + property); }
private Map<String, Object> conditionalReload(Class clazz, Map<String, Object> oldValues) throws Exception { Map<String, Object> mapping = oldValues; if (reloadingConfigs) { URL fileUrl = ClassLoaderUtil.getResource(buildConverterFilename(clazz), clazz); if (fileManager.fileNeedsReloading(fileUrl)) { mapping = buildConverterMapping(clazz); } } return mapping; }
@Override public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) { Object result; if (toType == String.class && (value instanceof Double || value instanceof Integer)) { result = convertToString(value); } else if (value instanceof String && (toType == Double.class || toType == double.class || toType == Integer.class || toType == int.class)) { result = convertToNumber((String) value, toType); } else { result = super.convertValue(context, target, member, propertyName, value, toType); } return result; }
public void processRequired(String propsName) { loadConversionProperties(propsName, true); }
@Override public boolean contains(Object element) { element = convert(element); return super.contains(element); } }
private Object doConvertToCalendar(Map<String, Object> context, Object value) { Object result = null; Date dateResult = (Date) doConvertToDate(context, value, Date.class); if (dateResult != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(dateResult); result = calendar; } return result; }
/** * Looks for a TypeConverter in the default mappings. * * @param clazz the class the TypeConverter must handle * @return a TypeConverter to handle the specified class or null if none can be found */ public TypeConverter lookup(Class clazz) { TypeConverter result = lookup(clazz.getName(), clazz.isPrimitive()); if (result == null && clazz.isPrimitive()) { /** * if it is primitive use default converter which allows to define different converters per type * @see XWorkBasicConverter */ return defaultTypeConverter; } return result; }
private Object getRealValue(Map context, Object value, Class convertToClass) { if (value == null || convertToClass == null) { return value; } return xworkConverter.convertValue(context, value, convertToClass); } }
public Object convertValue(Map<String, Object> context, Object value, Class toType) { return convertValue(value, toType); }
public void process(String propsName) { loadConversionProperties(propsName, false); }
/** * Appends the specified element to the end of this list. * <p/> * This method performs any necessary type conversion. * * @param element element to be appended to this list. * @return <tt>true</tt> (as per the general contract of Collection.add). */ @Override public boolean add(Object element) { element = convert(element); return super.add(element); }
@Override public Object convertValue(Map<String, Object> map, Object o, Class aClass) { return convertValue(map, null, null, null, o, aClass); }
private Object getValue(Map context, Object value) { Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED); String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED); if (lastClass == null || lastProperty == null) { return value; } Class elementClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, null); if (elementClass == null) { return value; // nothing is specified, we assume it will be the value passed in. } return xworkConverter.convertValue(context, value, elementClass); }
private Object getKey(Map context, Object name) { Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED); String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED); if (lastClass == null || lastProperty == null) { // return java.lang.String.class; // commented out the above -- it makes absolutely no sense for when setting basic maps! return name; } Class keyClass = objectTypeDeterminer.getKeyClass(lastClass, lastProperty); if (keyClass == null) { keyClass = java.lang.String.class; } return xworkConverter.convertValue(context, name, keyClass); } }