use of eu.esdihumboldt.hale.common.core.io.Value 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.Value in project hale by halestudio.
the class ElementTypeFactory method restore.
@Override
public ElementType restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
// try type definition
Value index = props.getSafe(P_TYPE);
if (index != null) {
Optional<TypeDefinition> def = typeIndex.resolve(index);
if (def.isPresent()) {
return ElementType.createFromType(def.get());
}
}
// fall back to binding
String binding = props.getSafe(P_BINDING).as(String.class);
Class<?> clazz = resolver.loadClass(binding);
if (clazz == null) {
throw new IllegalStateException(MessageFormat.format("Could not resolve class {0} for element type binding", binding));
}
return ElementType.get(clazz);
}
use of eu.esdihumboldt.hale.common.core.io.Value 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.Value 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.Value 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