use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class XmlSchemaReader method setRelevantElements.
/**
* Set the element names of mapping relevant types.
*
* @param elementNames the element names
*/
public void setRelevantElements(Collection<? extends QName> elementNames) {
ValueList elementList = new ValueList();
for (QName name : elementNames) {
elementList.add(Value.of(name));
}
setParameter(PARAM_RELEVANT_ELEMENTS, elementList.toValue());
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class XmlSchemaReader method getRelevantElements.
/**
* @return the names of the elements configured as relevant
*/
public Set<? extends QName> getRelevantElements() {
Set<QName> result = new HashSet<>();
ValueList elementList = getParameter(PARAM_RELEVANT_ELEMENTS).as(ValueList.class);
if (elementList != null) {
for (Value val : elementList) {
QName name = val.as(QName.class);
if (name != null) {
result.add(name);
}
}
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class ValueListTypeTest method testStringValueListJson.
/**
* Test if a simple list containing only {@link StringValue}s is the same
* when converted to JSON and back again.
*
* @throws Exception if an error occurs
*/
@Test
public void testStringValueListJson() throws Exception {
ValueList values = new ValueList();
values.add(Value.of(1));
values.add(Value.of(2));
values.add(Value.of(3));
values.add(Value.of(4));
values.add(Value.of(5));
// converter
ValueListType vlt = new ValueListType();
// convert to Json
StringWriter writer = new StringWriter();
vlt.toJson(values, writer);
System.out.println(writer.toString());
// convert back
ValueList conv = vlt.fromJson(new StringReader(writer.toString()), null);
assertEquals("List size does not match", values.size(), conv.size());
for (int i = 0; i < values.size(); i++) {
assertEquals(values.get(i), conv.get(i));
}
}
use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.
the class EnumerationValidatorFactory method restore.
@Override
public Validator restore(Value value) throws Exception {
ValueList list = value.as(ValueList.class);
List<String> values = new ArrayList<>();
for (Value val : list) {
String str = val.as(String.class);
if (str != null) {
values.add(str);
} else {
throw new IllegalStateException("Enumeration value for validator could not be read");
}
}
return new EnumerationValidator(values);
}
Aggregations