Search in sources :

Example 21 with ValueList

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());
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) QName(javax.xml.namespace.QName)

Example 22 with ValueList

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;
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) QName(javax.xml.namespace.QName) Value(eu.esdihumboldt.hale.common.core.io.Value) HasNotInheritableValue(eu.esdihumboldt.hale.io.xsd.model.HasNotInheritableValue) HashSet(java.util.HashSet)

Example 23 with ValueList

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));
    }
}
Also used : StringWriter(java.io.StringWriter) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 24 with ValueList

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);
}
Also used : EnumerationValidator(eu.esdihumboldt.util.validator.EnumerationValidator) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) ArrayList(java.util.ArrayList) Value(eu.esdihumboldt.hale.common.core.io.Value)

Aggregations

ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)24 Value (eu.esdihumboldt.hale.common.core.io.Value)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Element (org.w3c.dom.Element)4 QName (javax.xml.namespace.QName)3 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 CustomTypeContentAssociation (eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentAssociation)2 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 Function (com.google.common.base.Function)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 ClassResolver (eu.esdihumboldt.hale.common.schema.model.constraint.factory.ClassResolver)1 TypeReferenceBuilder (eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeReferenceBuilder)1 TypeResolver (eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeResolver)1 ValueConstraintFactory (eu.esdihumboldt.hale.common.schema.model.constraint.factory.ValueConstraintFactory)1 CodeListAssociation (eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation)1 Reference (eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference)1