Search in sources :

Example 1 with ClassInfo

use of com.canoo.dp.impl.remoting.info.ClassInfo 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 ClassInfo

use of com.canoo.dp.impl.remoting.info.ClassInfo 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)

Example 3 with ClassInfo

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

the class AbstractBeanBuilder method create.

public <T> T create(final Class<T> beanClass) {
    final ClassInfo classInfo = classRepository.getOrCreateClassInfo(beanClass);
    final PresentationModel model = buildPresentationModel(classInfo);
    return createInstanceForClass(classInfo, beanClass, model, UpdateSource.SELF);
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClassInfo(com.canoo.dp.impl.remoting.info.ClassInfo)

Example 4 with ClassInfo

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

the class ClassRepositoryImpl method getOrCreateClassInfo.

@Override
public ClassInfo getOrCreateClassInfo(final Class<?> beanClass) {
    final ClassInfo existingClassInfo = classToClassInfoMap.get(beanClass);
    if (existingClassInfo != null) {
        return existingClassInfo;
    }
    createPresentationModelForClass(beanClass);
    return classToClassInfoMap.get(beanClass);
}
Also used : ClassInfo(com.canoo.dp.impl.remoting.info.ClassInfo)

Aggregations

ClassInfo (com.canoo.dp.impl.remoting.info.ClassInfo)4 PropertyInfo (com.canoo.dp.impl.remoting.info.PropertyInfo)2 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)1 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