Search in sources :

Example 1 with BeanModelImpl

use of org.apache.tapestry5.beanmodel.internal.beanmodel.BeanModelImpl in project tapestry-5 by apache.

the class BeanModelSourceImpl method create.

public <T> BeanModel<T> create(Class<T> beanClass, boolean filterReadOnlyProperties, Messages messages) {
    assert beanClass != null;
    assert messages != null;
    ClassPropertyAdapter adapter = propertyAccess.getAdapter(beanClass);
    BeanModel<T> model = new BeanModelImpl<T>(beanClass, propertyConduitSource, typeCoercer, messages, locator);
    for (final String propertyName : adapter.getPropertyNames()) {
        PropertyAdapter pa = adapter.getPropertyAdapter(propertyName);
        if (!pa.isRead()) {
            continue;
        }
        if (isStaticFieldProperty(pa)) {
            continue;
        }
        if (pa.getAnnotation(NonVisual.class) != null) {
            continue;
        }
        if (filterReadOnlyProperties && !pa.isUpdate()) {
            continue;
        }
        final String dataType = dataTypeAnalyzer.identifyDataType(pa);
        if (dataType == null) {
            continue;
        }
        model.add(propertyName).dataType(dataType);
    }
    // First, order the properties based on the location of the getter method
    // within the class.
    List<String> propertyNames = model.getPropertyNames();
    orderProperties(adapter, propertyNames);
    model.reorder(propertyNames.toArray(new String[propertyNames.size()]));
    // Next, check for an annotation with specific ordering information.
    ReorderProperties reorderAnnotation = beanClass.getAnnotation(ReorderProperties.class);
    if (reorderAnnotation != null) {
        BeanModelUtils.reorder(model, reorderAnnotation.value());
    }
    return model;
}
Also used : BeanModelImpl(org.apache.tapestry5.beanmodel.internal.beanmodel.BeanModelImpl) NonVisual(org.apache.tapestry5.beaneditor.NonVisual) ReorderProperties(org.apache.tapestry5.beaneditor.ReorderProperties) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) PropertyAdapter(org.apache.tapestry5.commons.services.PropertyAdapter)

Aggregations

NonVisual (org.apache.tapestry5.beaneditor.NonVisual)1 ReorderProperties (org.apache.tapestry5.beaneditor.ReorderProperties)1 BeanModelImpl (org.apache.tapestry5.beanmodel.internal.beanmodel.BeanModelImpl)1 ClassPropertyAdapter (org.apache.tapestry5.commons.services.ClassPropertyAdapter)1 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)1