use of org.eclipse.scout.rt.platform.reflect.IPropertyFilter in project scout.rt by eclipse.
the class AbstractForm method storeToXml.
@Override
public void storeToXml(Element root) {
root.setAttribute("formId", getFormId());
root.setAttribute("formQname", getClass().getName());
// add custom properties
Element xProps = root.getOwnerDocument().createElement("properties");
root.appendChild(xProps);
IPropertyFilter filter = new IPropertyFilter() {
@Override
public boolean accept(FastPropertyDescriptor descriptor) {
if (descriptor.getPropertyType().isInstance(IFormField.class)) {
return false;
}
if (!descriptor.getPropertyType().isPrimitive() && !Serializable.class.isAssignableFrom(descriptor.getPropertyType())) {
return false;
}
if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) {
return false;
}
return true;
}
};
Map<String, Object> props = BeanUtility.getProperties(this, AbstractForm.class, filter);
storePropertiesToXml(xProps, props);
// add extension properties
for (IExtension<?> ex : getAllExtensions()) {
Map<String, Object> extensionProps = BeanUtility.getProperties(ex, AbstractFormExtension.class, filter);
if (extensionProps.isEmpty()) {
continue;
}
Element xExtension = root.getOwnerDocument().createElement("extension");
xProps.appendChild(xExtension);
xExtension.setAttribute("extensionId", ex.getClass().getSimpleName());
xExtension.setAttribute("extensionQname", ex.getClass().getName());
storePropertiesToXml(xExtension, extensionProps);
}
// add fields
final Element xFields = root.getOwnerDocument().createElement("fields");
root.appendChild(xFields);
final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class);
final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field.getForm() != AbstractForm.this) {
// field is part of a wrapped form and is handled by the AbstractWrappedFormField
return true;
}
Element xField = xFields.getOwnerDocument().createElement("field");
try {
field.storeToXml(xField);
xFields.appendChild(xField);
} catch (RuntimeException e) {
exceptionHolder.setValue(e);
return false;
} catch (PlatformError e) {
errorHolder.setValue(e);
return false;
}
return true;
}
};
visitFields(v);
if (exceptionHolder.getValue() != null) {
throw exceptionHolder.getValue();
} else if (errorHolder.getValue() != null) {
throw errorHolder.getValue();
}
}
Aggregations