use of org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator in project jo-client-platform by jo-source.
the class BeanLinkCreatorCommand method createDefaultBean.
private <BEAN_TYPE> IBeanProxy<BEAN_TYPE> createDefaultBean(final IBeanFormBluePrint<BEAN_TYPE> formBp, final Object beanTypeId, final Class<? extends BEAN_TYPE> beanType, final List<IBeanPropertyValidator<BEAN_TYPE>> validators) {
if (formBp != null) {
final HashMap<String, Object> defaultValues = new HashMap<String, Object>();
final LinkedList<String> properties = new LinkedList<String>();
final Collection<IAttribute<?>> attributes = formBp.getCreateModeAttributes();
final IAttributeSet attributeSet = AttributeSet.create(attributes);
for (final IAttribute<?> attribute : attributes) {
final String propertyName = attribute.getPropertyName();
properties.add(propertyName);
final Object defaultValue = attribute.getDefaultValue();
if (defaultValue != null) {
defaultValues.put(propertyName, defaultValue);
}
}
final List<IBeanPropertyValidator<BEAN_TYPE>> propertyValidators = createBeanPropertyValidators(attributes);
if (!EmptyCheck.isEmpty(validators)) {
propertyValidators.addAll(validators);
}
@SuppressWarnings("unchecked") final IBeanProxyFactory<BEAN_TYPE> proxyFactory = BeanProxyFactory.builder((Class<BEAN_TYPE>) beanType).setBeanTypeId(beanTypeId).setAttributes(attributeSet).setBeanPropertyValidators(propertyValidators).build();
return proxyFactory.createTransientProxy(defaultValues);
} else {
return null;
}
}
use of org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator in project jo-client-platform by jo-source.
the class BeanProxyImplTest method createValidators.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static <BEAN_TYPE> List<IBeanPropertyValidator<BEAN_TYPE>> createValidators(final IBeanDtoDescriptor descriptor, final Collection<IAttribute<Object>> attributes) {
final List<IBeanPropertyValidator<BEAN_TYPE>> result = new LinkedList<IBeanPropertyValidator<BEAN_TYPE>>();
result.add(new AttributesBeanPropertyValidator<BEAN_TYPE>(attributes));
for (final IBeanValidator beanValidator : descriptor.getValidators()) {
result.add(new BeanPropertyValidatorAdapter<BEAN_TYPE>(beanValidator));
}
return result;
}
Aggregations