/** * Load metadata of a given bindable class, merged with bindable attributes from * parent classes marked with {@link Bindable} as well. */ public static BindableMetadata forClassWithParents(final Class<?> clazz) { IBindableDescriptor descriptor = BindableDescriptorUtils.getDescriptor(clazz); final BindableMetadata bindable = new BindableMetadata(); bindable.setDescription(descriptor.getDescription()); bindable.setLabel(descriptor.getLabel()); bindable.setTitle(descriptor.getTitle()); bindable.setAttributeMetadata( asAttributeMetadata(descriptor.getAttributes())); return bindable; }
final BindableMetadata metadata = new BindableMetadata(); extractTitleDescription(metadata, javaDoc); metadata.setLabel(label.value()); final List<AttributeFieldInfo> ownFields = new ArrayList<AttributeFieldInfo>(); extractAttributeMetadata(type, ownFields, attributeMetadata); metadata.setAttributeMetadata(attributeMetadata);
/** * Builds {@link AttributeDescriptor} for a field from a {@link Bindable} type. */ private static AttributeDescriptor buildAttributeDescriptor( Object initializedInstance, Field field, BindableMetadata bindableMetadata) { Object defaultValue = null; try { defaultValue = field.get(initializedInstance); } catch (IllegalAccessException e) { throw new AssertionError("An attribute field must be public: " + field.getDeclaringClass().getName() + "#" + field.getName()); } catch (Exception e) { throw new RuntimeException("Could not retrieve default value of attribute: " + BindableUtils.getKey(field), e); } AttributeMetadata attributeMetadata = null; if (bindableMetadata != null) { attributeMetadata = bindableMetadata.getAttributeMetadata().get( field.getName()); } return new AttributeDescriptor(field, defaultValue, getConstraintAnnotations(field), attributeMetadata); }
final BindableMetadata bindableMetadata = BindableMetadata.forClassWithParents(clazz);