Example usage for org.apache.commons.beanutils Converter Converter

List of usage examples for org.apache.commons.beanutils Converter Converter

Introduction

In this page you can find the example usage for org.apache.commons.beanutils Converter Converter.

Prototype

Converter

Source Link

Usage

From source file:info.magnolia.jcr.node2bean.impl.Node2BeanTransformerImpl.java

public Node2BeanTransformerImpl(Class<?> defaultListImpl, Class<?> defaultSetImpl, Class<?> defaultQueueImpl) {
    this.defaultListImpl = defaultListImpl;
    this.defaultSetImpl = defaultSetImpl;
    this.defaultQueueImpl = defaultQueueImpl;

    // We use non-static BeanUtils conversion, so we can
    // * use our custom ConvertUtilsBean
    // * control converters (convertUtilsBean.register()) - we can register them here, locally, as opposed to a
    // global ConvertUtils.register()
    final EnumAwareConvertUtilsBean convertUtilsBean = new EnumAwareConvertUtilsBean();

    // de-register the converter for Class, we do our own conversion in convertPropertyValue()
    convertUtilsBean.deregister(Class.class);

    convertUtilsBean.register(new Converter() {
        @Override//from  w w w  . j  av  a 2s .  c o m
        public Object convert(Class type, Object value) {
            return new MessageFormat((String) value);
        }
    }, MessageFormat.class);

    convertUtilsBean.register(new Converter() {
        @Override
        public Object convert(Class type, Object value) {
            return Pattern.compile((String) value);
        }
    }, Pattern.class);

    this.beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean());
}

From source file:hudson.model.Result.java

@Initializer
public static void init() {
    Stapler.CONVERT_UTILS.register(new Converter() {
        public Object convert(Class type, Object value) {
            return Result.fromString(value.toString());
        }/*  w  w  w  . ja  v  a  2  s. com*/
    }, Result.class);
}