Example usage for org.springframework.beans PropertyAccessor getPropertyTypeDescriptor

List of usage examples for org.springframework.beans PropertyAccessor getPropertyTypeDescriptor

Introduction

In this page you can find the example usage for org.springframework.beans PropertyAccessor getPropertyTypeDescriptor.

Prototype

@Nullable
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;

Source Link

Document

Return a type descriptor for the specified property: preferably from the read method, falling back to the write method.

Usage

From source file:org.jdal.ui.ViewSupport.java

/**
 * Bind controls following the same name convention or annotated with Property annotation.
 *//*from  w  w w .ja  va2  s  .  c o m*/
public void autobind() {
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(getModel());
    PropertyAccessor viewPropertyAccessor = new DirectFieldAccessor(this);

    // Parse Property annotations
    List<AnnotatedElement> elements = AnnotatedElementAccessor.findAnnotatedElements(Property.class,
            getClass());

    for (AnnotatedElement ae : elements) {
        Property p = ae.getAnnotation(Property.class);
        InitializationConfig config = getInitializationConfig(ae.getAnnotation(Initializer.class));
        bindAndInitializeControl(p.value(), viewPropertyAccessor.getPropertyValue(((Field) ae).getName()),
                config);
        this.ignoredProperties.add(p.value());
    }

    // Iterate on model properties
    for (PropertyDescriptor pd : bw.getPropertyDescriptors()) {
        String propertyName = pd.getName();
        if (!ignoredProperties.contains(propertyName)
                && viewPropertyAccessor.isReadableProperty(propertyName)) {
            Object control = viewPropertyAccessor.getPropertyValue(propertyName);

            if (control != null) {
                if (log.isDebugEnabled())
                    log.debug("Found control: " + control.getClass().getSimpleName() + " for property: "
                            + propertyName);
                TypeDescriptor descriptor = viewPropertyAccessor.getPropertyTypeDescriptor(propertyName);
                InitializationConfig config = getInitializationConfig(
                        descriptor.getAnnotation(Initializer.class));
                // do bind
                bindAndInitializeControl(propertyName, control, config);
            }
        }
    }
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Write object to the entity//w  w w. j ava  2s .  c  o m
 *
 * @param accessor The accessor for the existing entity
 * @param key      The fields name we are overwriting
 * @param value    The new value
 * @throws JSONException the json exception
 */
private void writeObjectToEntity(final PropertyAccessor accessor, final String key, final JSONObject value)
        throws JSONException {
    final ResolvableType type = accessor.getPropertyTypeDescriptor(key).getResolvableType();

    accessor.setPropertyValue(key, parseObject(value, type));
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Write an array map to an entity//ww  w.  j  a va  2  s  .  com
 * an array map is an object, but is meant to represent an array
 *
 * @param accessor The accessor for the existing entity
 * @param key      The fields name we are overwriting
 * @param value    The new value
 * @throws JSONException the json exception
 */
private void writeArrayMapToEntity(final PropertyAccessor accessor, final String key, final JSONObject value)
        throws JSONException {
    final ResolvableType type = accessor.getPropertyTypeDescriptor(key).getResolvableType();

    accessor.setPropertyValue(key, parseArrayMap(value, type));
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Write array to entity./*from www . j  a v  a2  s . c o  m*/
 *
 * @param accessor The accessor for the existing entity
 * @param key      The fields name we are overwriting
 * @param value    The new value
 * @throws JSONException the json exception
 */
private void writeArrayToEntity(final PropertyAccessor accessor, final String key, final JSONArray value)
        throws JSONException {
    final ResolvableType type = accessor.getPropertyTypeDescriptor(key).getResolvableType();

    accessor.setPropertyValue(key, parseArray(value, type));
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Write normal value to entity./*w  w w.  j a va  2s  . co m*/
 *
 * @param accessor The accessor for the existing entity
 * @param key      The fields name we are overwriting
 * @param value    The new value
 */
private void writeValueToEntity(final PropertyAccessor accessor, final String key, final Object value) {
    final ResolvableType type = accessor.getPropertyTypeDescriptor(key).getResolvableType();

    accessor.setPropertyValue(key, parseValue(value, type));
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Is the field editable according to the SchemaView annotation
 *
 * @param accessor the accessor/*from  ww w  .  j  a  v  a 2s  . c om*/
 * @param key      the key
 * @return boolean boolean
 */
private Boolean isFieldEditable(final PropertyAccessor accessor, final String key) {
    final SchemaView schemaView = accessor.getPropertyTypeDescriptor(key).getAnnotation(SchemaView.class);

    if (schemaView != null) {
        final boolean isLocked = schemaView.locked() && accessor.getPropertyValue(key) != null;
        final boolean isVisible = schemaView.visible();

        return !isLocked && isVisible;
    }

    return false;
}

From source file:org.springframework.flex.core.io.SpringPropertyProxy.java

/**
 * {@inheritDoc}//from w  ww  .j  a  v a  2s  .  co  m
 * 
 * Delegates to the configured {@link ConversionService} to potentially convert the current value to the actual type of the property.
 */
@Override
public Object getValue(Object instance, String propertyName) {
    PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService,
            this.useDirectFieldAccess, instance);
    Object value = accessor.getPropertyValue(propertyName);
    if (log.isDebugEnabled()) {
        getType(instance, propertyName);
        log.debug("Actual type of value for property '" + propertyName + "' on instance " + instance + " is "
                + (value != null ? value.getClass() : null));
    }

    TypeDescriptor targetType = accessor.getPropertyTypeDescriptor(propertyName);
    TypeDescriptor sourceType = value == null ? targetType : TypeDescriptor.valueOf(value.getClass());
    if (this.conversionService.canConvert(sourceType, targetType)) {
        value = this.conversionService.convert(value, sourceType, targetType);
    }
    return value;
}

From source file:org.springframework.flex.core.io.SpringPropertyProxy.java

private boolean isReadIgnored(Object instance, String propertyName) {
    PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService,
            this.useDirectFieldAccess, instance);
    if (!accessor.isReadableProperty(propertyName)) {
        return true;
    }//  w  w  w.java 2  s .c  o  m
    if (this.useDirectFieldAccess) {
        AmfIgnoreField ignoreField = accessor.getPropertyTypeDescriptor(propertyName)
                .getAnnotation(AmfIgnoreField.class);
        return ignoreField != null && ignoreField.onSerialization();
    } else {
        PropertyDescriptor pd = ((BeanWrapper) accessor).getPropertyDescriptor(propertyName);
        return pd.getReadMethod().getAnnotation(AmfIgnore.class) != null;
    }
}

From source file:org.springframework.flex.core.io.SpringPropertyProxy.java

private boolean isWriteIgnored(Object instance, String propertyName) {
    PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService,
            this.useDirectFieldAccess, instance);
    if (!accessor.isWritableProperty(propertyName)) {
        return true;
    }/*  w  w  w .  j a  v  a  2  s. c o  m*/
    if (this.useDirectFieldAccess) {
        AmfIgnoreField ignoreField = accessor.getPropertyTypeDescriptor(propertyName)
                .getAnnotation(AmfIgnoreField.class);
        return ignoreField != null && ignoreField.onDeserialization();
    } else {
        PropertyDescriptor pd = ((BeanWrapper) accessor).getPropertyDescriptor(propertyName);
        return pd.getWriteMethod().getAnnotation(AmfIgnore.class) != null;
    }
}