use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class ReferenceFactory method store.
@Override
public Value store(Reference constraint, TypeReferenceBuilder typeIndex) {
ValueProperties props = new ValueProperties();
props.put(P_IS_REF, Value.of(constraint.isReference()));
if (constraint.getReferencedTypes() == null) {
// referenced types are unknown
props.put(P_TYPES, Value.of(V_TYPES_UNKNOWN));
} else {
// store type list
ValueList types = new ValueList();
for (TypeDefinition type : constraint.getReferencedTypes()) {
// add each type index
Optional<Value> ref = typeIndex.createReference(type);
if (ref.isPresent()) {
types.add(ref.get());
} else {
throw new IllegalStateException(MessageFormat.format("Type {0} could not be resolved in type index", type.getName()));
}
}
props.put(P_TYPES, types.toValue());
}
return props.toValue();
}
use of eu.esdihumboldt.hale.common.core.io.ValueList 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.ValueList 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);
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class PrimaryKeyFactory method restore.
@Override
public PrimaryKey restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueList list = value.as(ValueList.class);
List<QName> names = new ArrayList<>();
for (Value val : list) {
QName name = val.as(QName.class);
if (name != null) {
names.add(name);
} else {
throw new IllegalStateException("Failed to read name for primary key path");
}
}
return new PrimaryKey(names);
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class AbstractCombinedValidatorFactory method restore.
@Override
public Validator restore(Value value) throws Exception {
ValueList list = value.as(ValueList.class);
List<Validator> children = new ArrayList<>();
for (Value childVal : list) {
children.add(childVal.as(ValidatorValue.class).toValidator());
}
return createValidator(children);
}
Aggregations