Search in sources :

Example 1 with PropertyInfo

use of com.canoo.dp.impl.remoting.info.PropertyInfo in project dolphin-platform by canoo.

the class ClassRepositoryImpl method createClassInfoForClass.

private ClassInfo createClassInfoForClass(final Class<?> beanClass) {
    final List<PropertyInfo> propertyInfos = new ArrayList<>();
    final List<PropertyInfo> observableListInfos = new ArrayList<>();
    for (Field field : ReflectionHelper.getInheritedDeclaredFields(beanClass)) {
        PropertyType type = null;
        if (Property.class.isAssignableFrom(field.getType())) {
            type = PropertyType.PROPERTY;
        } else if (ObservableList.class.isAssignableFrom(field.getType())) {
            type = PropertyType.OBSERVABLE_LIST;
        }
        final Class<?> parameterType = ReflectionHelper.getTypeParameter(field);
        if (type != null && parameterType != null) {
            final String attributeName = DolphinUtils.getDolphinAttributePropertyNameForField(field);
            final Converter converter = converters.getConverter(parameterType);
            final PropertyInfo propertyInfo = new ClassPropertyInfo(attributeName, converter, field);
            if (type == PropertyType.PROPERTY) {
                propertyInfos.add(propertyInfo);
            } else {
                observableListInfos.add(propertyInfo);
            }
        }
    }
    return new ClassInfo(beanClass, propertyInfos, observableListInfos);
}
Also used : Field(java.lang.reflect.Field) ObservableList(com.canoo.platform.remoting.ObservableList) ArrayList(java.util.ArrayList) Converter(com.canoo.platform.remoting.spi.converter.Converter) PropertyInfo(com.canoo.dp.impl.remoting.info.PropertyInfo) ClassInfo(com.canoo.dp.impl.remoting.info.ClassInfo)

Example 2 with PropertyInfo

use of com.canoo.dp.impl.remoting.info.PropertyInfo in project dolphin-platform by canoo.

the class AbstractBeanBuilder method buildPresentationModel.

private PresentationModel buildPresentationModel(final ClassInfo classInfo) {
    try {
        Assert.requireNonNull(classInfo, "classInfo");
        final PresentationModelBuilder builder = builderFactory.createBuilder().withType(classInfo.getModelType());
        classInfo.forEachProperty(new ClassInfo.PropertyIterator() {

            @Override
            public void call(final PropertyInfo propertyInfo) {
                Assert.requireNonNull(propertyInfo, "propertyInfo");
                builder.withAttribute(propertyInfo.getAttributeName());
            }
        });
        return builder.create();
    } catch (Exception e) {
        throw new DolphinRuntimeException("Cannot create presentation model for type " + classInfo.getBeanClass(), e);
    }
}
Also used : DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) PropertyInfo(com.canoo.dp.impl.remoting.info.PropertyInfo) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) ClassInfo(com.canoo.dp.impl.remoting.info.ClassInfo)

Aggregations

ClassInfo (com.canoo.dp.impl.remoting.info.ClassInfo)2 PropertyInfo (com.canoo.dp.impl.remoting.info.PropertyInfo)2 DolphinRuntimeException (com.canoo.platform.core.DolphinRuntimeException)1 ObservableList (com.canoo.platform.remoting.ObservableList)1 Converter (com.canoo.platform.remoting.spi.converter.Converter)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1