use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class CustomTypeContentConfigurationType method fromDOM.
@Override
public CustomTypeContentConfiguration fromDOM(Element fragment, Void context) {
Value val = DOMValueUtil.fromTag(fragment);
ValueList list = val.as(ValueList.class);
List<CustomTypeContentAssociation> resultList = new ArrayList<>();
if (list != null) {
for (Value value : list) {
CustomTypeContentAssociation assoc = value.as(CustomTypeContentAssociation.class);
if (assoc != null) {
resultList.add(assoc);
}
}
}
return new CustomTypeContentConfiguration(resultList);
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class CustomTypeContentConfigurationType method toDOM.
@Override
public Element toDOM(CustomTypeContentConfiguration value) {
ValueList list = new ValueList();
for (CustomTypeContentAssociation assoc : value.getAssociations()) {
list.add(Value.complex(assoc));
}
Map<String, String> prefixes = new HashMap<>();
prefixes.put("xsd", XMLSchemaIO.NS_HALE_XSD);
NSDOMBuilder builder;
try {
builder = NSDOMBuilder.newBuilder(prefixes);
Element element = DOMValueUtil.valueTag(builder, "xsd:typeContentConfig", Value.complex(list));
return element;
} catch (Exception e) {
throw new IllegalStateException("Error creating validator DOM representation", e);
}
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class XmlElementsFactory method store.
@Override
public Value store(XmlElements constraint, TypeReferenceBuilder refBuilder) throws Exception {
Collection<? extends XmlElement> elements = constraint.getElements();
if (elements == null) {
return null;
}
ValueList result = new ValueList();
for (XmlElement element : elements) {
result.add(elementToValue(element, refBuilder));
}
return result.toValue();
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class CodeListAssocationFactory method restore.
@Override
public CodeListAssociation restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
// is it a simple value? (single String code list reference)
String single = value.as(String.class);
if (single != null) {
return new CodeListAssociation(Collections.singleton(single));
}
// is it a value list? (multiple String code list references)
ValueList list = value.as(ValueList.class);
if (list != null) {
List<String> refList = list.stream().map(val -> val.as(String.class)).filter(val -> val != null).collect(Collectors.toList());
return new CodeListAssociation(refList);
}
// fall-back
return new CodeListAssociation();
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class ReferenceFactory method restore.
@Override
public Reference restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
Reference ref = new Reference(props.get(P_IS_REF).as(Boolean.class, false));
Value types = props.get(P_TYPES);
if (types.isComplex()) {
ValueList list = types.as(ValueList.class);
if (list != null) {
for (Value entry : list) {
Optional<TypeDefinition> type = typeIndex.resolve(entry);
if (type.isPresent()) {
ref.addReferencedType(type.get());
} else {
throw new IllegalStateException("Could not resolve type definition for index " + entry);
}
}
}
}
return ref;
}
Aggregations