use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class NumberValidatorFactory method restore.
@Override
public Validator restore(Value value) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
Type type = Type.valueOf(props.getSafe(P_TYPE).as(String.class));
BigDecimal val = props.getSafe(P_VALUE).as(BigDecimal.class);
return new NumberValidator(type, val);
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class DigitCountValidatorFactory method restore.
@Override
public Validator restore(Value value) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
Type type = Type.valueOf(props.getSafe(P_TYPE).as(String.class));
int length = props.getSafe(P_LENGTH).as(Integer.class);
return new DigitCountValidator(type, length);
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class DigitCountValidatorFactory method store.
@Override
public Value store(DigitCountValidator validator) throws Exception {
ValueProperties props = new ValueProperties();
props.put(P_TYPE, Value.of(validator.getType().name()));
props.put(P_LENGTH, Value.of(validator.getLength()));
return props.toValue();
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class EnumerationFactory method store.
@Override
public Value store(Enumeration<?> constraint, TypeReferenceBuilder typeIndex) {
ValueProperties props = new ValueProperties(2);
// values
if (constraint.getValues() != null) {
ValueList list = new ValueList();
for (Object value : constraint.getValues()) {
list.add(Value.simple(value));
}
props.put(P_VALUES, Value.complex(list));
// XXX also store the value type for reconstruction?
}
// allow others?
props.put(P_ALLOW_OTHERS, Value.of(constraint.isAllowOthers()));
return Value.complex(props);
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class EnumerationFactory method restore.
@Override
public Enumeration<?> restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
boolean allowOthers = props.get(P_ALLOW_OTHERS).as(Boolean.class, true);
Collection<Object> values = null;
if (props.containsKey(P_VALUES)) {
values = new ArrayList<>();
ValueList list = props.get(P_VALUES).as(ValueList.class);
for (Value val : list) {
// XXX determine value type?
// XXX for now just use string
String str = val.as(String.class);
if (str != null) {
values.add(str);
} else {
// TODO warn?
}
}
}
return new Enumeration<Object>(values, allowOthers);
}
Aggregations