Example usage for org.springframework.beans BeanWrapperImpl getWrappedClass

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

Introduction

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

Prototype

public final Class<?> getWrappedClass() 

Source Link

Usage

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

/**
 * Get and modify the PropertyDescriptors associated with the BeanWrapper.
 * @param bwrap/*  w w w  .  ja  va2s.  c  o  m*/
 * @return
 */
protected PropertyDescriptor[] getPropertyDescriptors(BeanWrapperImpl bwrap) {
    PropertyDescriptor[] descriptors = bwrap.getPropertyDescriptors();
    for (PropertyDescriptor pd : descriptors) {
        if (DescriptorUpdater.class.isAssignableFrom(bwrap.getWrappedClass())) {
            ((DescriptorUpdater) bwrap.getWrappedInstance()).updateDescriptor(pd);
        } else {
            defaultUpdateDescriptor(pd);
        }
    }
    return descriptors;
}

From source file:org.gvnix.web.datatables.util.DatatablesUtils.java

/**
 * Convert a field value to string/*ww  w  .ja  v a2 s  . co  m*/
 * 
 * @param datePatterns
 * @param dateFormatters
 * @param conversionService
 * @param entityBean
 * @param entity
 * @param fieldName
 * @param unescapedFieldName
 * @return
 */
private static <T> String convertFieldValueToString(Map<String, Object> datePatterns,
        Map<String, SimpleDateFormat> dateFormatters, ConversionService conversionService,
        BeanWrapperImpl entityBean, T entity, String fieldName, String unescapedFieldName) {
    try {
        Object value = null;
        TypeDescriptor fieldDesc = entityBean.getPropertyTypeDescriptor(unescapedFieldName);
        TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
        value = entityBean.getPropertyValue(unescapedFieldName);
        if (value == null) {
            return "";
        }

        // For dates
        if (Date.class.isAssignableFrom(value.getClass())
                || Calendar.class.isAssignableFrom(value.getClass())) {
            SimpleDateFormat formatter = getDateFormatter(datePatterns, dateFormatters,
                    entityBean.getWrappedClass(), unescapedFieldName);
            if (formatter != null) {
                if (Calendar.class.isAssignableFrom(value.getClass())) {
                    // Gets Date instance as SimpleDateFormat
                    // doesn't works with Calendar
                    value = ((Calendar) value).getTime();
                }
                return formatter.format(value);
            }
        }
        String stringValue;
        // Try to use conversion service (uses field descrition
        // to handle field format annotations)
        if (conversionService.canConvert(fieldDesc, strDesc)) {
            stringValue = (String) conversionService.convert(value, fieldDesc, strDesc);
            if (stringValue == null) {
                stringValue = "";
            }
        } else {
            stringValue = ObjectUtils.getDisplayString(value);
        }
        return stringValue;
    } catch (Exception ex) {
        LOGGER.error(String.format("Error getting value of property [%s] in bean %s [%s]", unescapedFieldName,
                entity.getClass().getSimpleName(),
                org.apache.commons.lang3.ObjectUtils.firstNonNull(entity.toString(), "{unknow}")), ex);
        return "";
    }
}

From source file:org.gvnix.web.datatables.util.impl.DatatablesUtilsBeanImpl.java

/**
 * Convert a field value to string//w  w  w  . j  a v  a 2 s .  c  o  m
 * 
 * @param datePatterns
 * @param dateFormatters
 * @param conversionService
 * @param entityBean
 * @param entity
 * @param fieldName
 * @param unescapedFieldName
 * @return
 */
private <T> String convertFieldValueToString(Map<String, Object> datePatterns,
        Map<String, SimpleDateFormat> dateFormatters, BeanWrapperImpl entityBean, T entity, String fieldName,
        String unescapedFieldName) {
    try {
        Object value = null;
        TypeDescriptor fieldDesc = entityBean.getPropertyTypeDescriptor(unescapedFieldName);
        TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
        value = entityBean.getPropertyValue(unescapedFieldName);
        if (value == null) {
            return "";
        }

        // For dates
        if (Date.class.isAssignableFrom(value.getClass())
                || Calendar.class.isAssignableFrom(value.getClass())) {
            SimpleDateFormat formatter = getDateFormatter(datePatterns, dateFormatters,
                    entityBean.getWrappedClass(), unescapedFieldName);
            if (formatter != null) {
                if (Calendar.class.isAssignableFrom(value.getClass())) {
                    // Gets Date instance as SimpleDateFormat
                    // doesn't works with Calendar
                    value = ((Calendar) value).getTime();
                }
                return formatter.format(value);
            }
        }
        String stringValue;
        // Try to use conversion service (uses field descrition
        // to handle field format annotations)
        if (conversionService.canConvert(fieldDesc, strDesc)) {
            stringValue = (String) conversionService.convert(value, fieldDesc, strDesc);
            if (stringValue == null) {
                stringValue = "";
            }
        } else {
            stringValue = ObjectUtils.getDisplayString(value);
        }
        return stringValue;
    } catch (Exception ex) {
        LOGGER.error(String.format("Error getting value of property [%s] in bean %s [%s]", unescapedFieldName,
                entity.getClass().getSimpleName(),
                org.apache.commons.lang3.ObjectUtils.firstNonNull(entity.toString(), "{unknow}")), ex);
        return "";
    }
}

From source file:org.kuali.rice.krad.web.bind.UifViewBeanWrapper.java

/**
 * Checks whether the given property is secure.
 *
 * @param wrappedClass class the property is associated with
 * @param propertyPath path to the property
 * @return boolean true if the property is secure, false if not
 *//*from w  ww  . ja  v  a2 s .com*/
protected boolean isSecure(Class<?> wrappedClass, String propertyPath) {
    if (KRADServiceLocatorWeb.getDataObjectAuthorizationService()
            .attributeValueNeedsToBeEncryptedOnFormsAndLinks(wrappedClass, propertyPath)) {
        return true;
    }

    BeanWrapperImpl beanWrapper;
    try {
        beanWrapper = getBeanWrapperForPropertyPath(propertyPath);
    } catch (NotReadablePropertyException nrpe) {
        LOG.debug("Bean wrapper was not found for " + propertyPath
                + ", but since it cannot be accessed it will not be set as secure.", nrpe);
        return false;
    }

    if (org.apache.commons.lang.StringUtils.isNotBlank(beanWrapper.getNestedPath())) {
        PropertyTokenHolder tokens = getPropertyNameTokens(propertyPath);
        String nestedPropertyPath = org.apache.commons.lang.StringUtils.removeStart(tokens.canonicalName,
                beanWrapper.getNestedPath());

        return isSecure(beanWrapper.getWrappedClass(), nestedPropertyPath);
    }

    return false;
}