Refine search
@Initializer public static void init() { Stapler.CONVERT_UTILS.register(new Converter() { public Object convert(Class type, Object value) { return Result.fromString(value.toString()); } }, Result.class); } }
/** * Return the value of the specified mapped property of the specified * bean, as a String. The key is specified as a method parameter and * must *not* be included in the property name expression * * @param bean Bean whose property is to be extracted * @param name Simple property name of the property value to be extracted * @param key Lookup key of the property value to be extracted * @return The mapped property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getMappedProperty(final Object bean, final String name, final String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getMappedProperty(bean, name, key); return (getConvertUtils().convert(value)); }
/** * <p>Constructs an instance using new property * and conversion instances.</p> */ public BeanUtilsBean() { this(new ConvertUtilsBean(), new PropertyUtilsBean()); }
/** * <p>Remove any registered {@link Converter} for the specified destination * <code>Class</code>.</p> * * <p>For more details see <code>ConvertUtilsBean</code>.</p> * * @param clazz Class for which to remove a registered Converter * @see ConvertUtilsBean#deregister(Class) */ public static void deregister(final Class<?> clazz) { ConvertUtilsBean.getInstance().deregister(clazz); }
/** * Look up and return any registered {@link Converter} for the specified * source and destination class; if there is no registered Converter, * return <code>null</code>. * * @param sourceType Class of the value being converted * @param targetType Class of the value to be converted to * @return The registered {@link Converter} or <code>null</code> if not found */ public static Converter lookup(final Class<?> sourceType, final Class<?> targetType) { return ConvertUtilsBean.getInstance().lookup(sourceType, targetType); }
/** * <p>Convert the value to an object of the specified class (if * possible).</p> * * @param value Value to be converted (may be null) * @param targetType Class of the value to be converted to (must not be null) * @return The converted value * * @throws ConversionException if thrown by an underlying Converter */ public static Object convert(final Object value, final Class<?> targetType) { return ConvertUtilsBean.getInstance().convert(value, targetType); }
return; // Skip this property setter type = dynaPropertyType(dynaProperty, value); if (index >= 0 && List.class.isAssignableFrom(type)) { type = Object.class; final String[] values = new String[1]; values[0] = null; newValue = getConvertUtils().convert(values, type); } else if (value instanceof String) { newValue = getConvertUtils().convert(value, type); } else if (value instanceof String[]) { newValue = getConvertUtils().convert((String[]) value, type); newValue = getConvertUtils().convert((String) value, type.getComponentType()); } else if (value instanceof String[]) { newValue = getConvertUtils().convert(((String[]) value)[0], type.getComponentType()); } else { newValue = getConvertUtils().convert((String) value, type); } else if (value instanceof String[]) { newValue = getConvertUtils().convert(((String[]) value)[0], type); } else {
/** * Return the value of the specified indexed property of the specified * bean, as a String. The index is specified as a method parameter and * must *not* be included in the property name expression * * @param bean Bean whose property is to be extracted * @param name Simple property name of the property value to be extracted * @param index Index of the property value to be extracted * @return The indexed property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getIndexedProperty(final Object bean, final String name, final int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getIndexedProperty(bean, name, index); return (getConvertUtils().convert(value)); }
NoSuchMethodException { final Object value = getPropertyUtils().getProperty(bean, name); if (value == null) { return (null); } else { values.add(getConvertUtils().convert(item)); } else { results[i] = getConvertUtils().convert(item); } else { final String[] results = new String[1]; results[0] = getConvertUtils().convert(value); return (results);
/** * Return the value of the (possibly nested) property of the specified * name, for the specified bean, as a String. * * @param bean Bean whose property is to be extracted * @param name Possibly nested name of the property to be extracted * @return The nested property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws IllegalArgumentException if a nested reference to a * property returns null * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getNestedProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getNestedProperty(bean, name); return (getConvertUtils().convert(value)); }
/** * Return the value of the specified simple property of the specified * bean, converted to a String. * * @param bean Bean whose property is to be extracted * @param name Name of the property to be extracted * @return The property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getSimpleProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getSimpleProperty(bean, name); return (getConvertUtils().convert(value)); }
ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); convertUtilsBean.deregister(DateTime.class); convertUtilsBean.register(new JodaDateTimeConverter(), DateTime.class); BeanUtilsBean beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean()); try { beanUtilsBean.setProperty(machineInfo, qName, temp); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); }
/** * Creates a BeanUtilsBean that is configured to use * type converters that throw a ConversionException * instead of using the default value when something * goes wrong. * * @return a configured BeanUtilsBean */ private static BeanUtilsBean createBeanUtilsBean() { final ConvertUtilsBean cub = new ConvertUtilsBean(); registerIntegralTypes(cub); registerCustomTypes(cub); return new BeanUtilsBean(cub, new PropertyUtilsBean()); }
/** * Initializes the shared {@code BeanUtilsBean} instance. This method sets * up custom bean introspection in a way that fluent parameter interfaces * are supported. * * @return the {@code BeanUtilsBean} instance to be used for all property * set operations */ private static BeanUtilsBean initBeanUtilsBean() { final PropertyUtilsBean propUtilsBean = new PropertyUtilsBean(); propUtilsBean.addBeanIntrospector(new FluentPropertyBeanIntrospector()); return new BeanUtilsBean(new ConvertUtilsBean(), propUtilsBean); }
.getInstance() .getConvertUtils() .lookup(targetClass); if (null != converter) { return converter.convert(targetClass, source);
public DefaultRequestProcessor() { ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); convertUtilsBean.register(new FormFileConverter(), FormFile.class); convertUtilsBean.register(new FormFileArrayConverter(), FormFile[].class); beanUtilsBean_ = new BeanUtilsBean(convertUtilsBean, propertyUtilsBean_); DisposableUtil.add(new Disposable() { public void dispose() { propertyUtilsBean_.clearDescriptors(); } }); }
public TypeConverterUtil(String[] datePatterns) { convertUtilsBean = new ConvertUtilsBean(); final DateConverter dateConverter = new DateConverter(); dateConverter.setPatterns(datePatterns); dateConverter.setTimeZone(TimeZone.getTimeZone("GMT")); convertUtilsBean.register(dateConverter, Date.class); convertUtilsBean.register(new LocalDateTimeConverter(), LocalDateTime.class); convertUtilsBean.register(new LocalDateConverter(), LocalDate.class); convertUtilsBean.register(new OffsetDateTimeConverter(), OffsetDateTime.class); }
public static void registerConverter(Converter converter, Class type) { synchronized (beanUtils) { beanUtils.getConvertUtils().register(converter, type); } }
BeanUtilsBean beanUtilsBean = new BeanUtilsBean(new ConvertUtilsBean() { @Override public Object convert(String value, Class clazz) { if (clazz.isEnum()){ return Enum.valueOf(clazz, value); }else{ return super.convert(value, clazz); } } });
@Override protected ConvertUtilsBean initialValue() { ConvertUtilsBean ret = BeanUtilsBean2.getInstance().getConvertUtils(); ret.deregister(); ret.register(false, true, 1); return ret; } };