Example usage for org.springframework.beans BeanWrapperImpl getDefaultEditor

List of usage examples for org.springframework.beans BeanWrapperImpl getDefaultEditor

Introduction

In this page you can find the example usage for org.springframework.beans BeanWrapperImpl getDefaultEditor.

Prototype

@Nullable
public PropertyEditor getDefaultEditor(Class<?> requiredType) 

Source Link

Document

Retrieve the default editor for the given property type, if any.

Usage

From source file:org.archive.crawler.restlet.BeanBrowseResource.java

/**
 * Constructs a nested Map data structure with the information represented
 * by this Resource. The result is particularly suitable for use with with
 * {@link XmlMarshaller}.//from  w  w  w  . jav  a  2s. c o m
 * 
 * @return the nested Map data structure
 */
protected BeansModel makeDataModel() {
    Object bean = null;
    String problem = null;
    boolean editable = false;
    Object target = null;

    if (StringUtils.isNotBlank(beanPath)) {
        try {
            int firstDot = beanPath.indexOf(".");
            String beanName = firstDot < 0 ? beanPath : beanPath.substring(0, firstDot);
            Object namedBean = appCtx.getBean(beanName);
            if (firstDot < 0) {
                target = namedBean;
                bean = makePresentableMapFor(null, target, beanPath);
            } else {
                BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean);
                String propPath = beanPath.substring(firstDot + 1);
                target = bwrap.getPropertyValue(propPath);

                Class<?> type = bwrap.getPropertyType(propPath);
                if (bwrap.isWritableProperty(propPath)
                        && (bwrap.getDefaultEditor(type) != null || type == String.class)
                        && !Collection.class.isAssignableFrom(type)) {
                    editable = true;
                    bean = makePresentableMapFor(null, target);
                } else {
                    bean = makePresentableMapFor(null, target, beanPath);
                }
            }
        } catch (BeansException e) {
            problem = e.toString();
        }
    }

    Collection<Object> nestedNames = new LinkedList<Object>();
    Set<Object> alreadyWritten = new HashSet<Object>();
    addPresentableNestedNames(nestedNames, appCtx.getBean("crawlController"), alreadyWritten);
    for (String name : appCtx.getBeanDefinitionNames()) {
        addPresentableNestedNames(nestedNames, appCtx.getBean(name), alreadyWritten);
    }

    return new BeansModel(cj.getShortName(),
            new Reference(getRequest().getResourceRef().getBaseRef(), "..").getTargetRef().toString(), beanPath,
            bean, editable, problem, target, nestedNames);

}