Example usage for org.springframework.core.convert TypeDescriptor getAnnotation

List of usage examples for org.springframework.core.convert TypeDescriptor getAnnotation

Introduction

In this page you can find the example usage for org.springframework.core.convert TypeDescriptor getAnnotation.

Prototype

@Nullable
public <T extends Annotation> T getAnnotation(Class<T> annotationType) 

Source Link

Document

Obtain the annotation of the specified annotationType that is on this type descriptor.

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  .j  a va 2s  .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);
            }
        }
    }
}