Search in sources :

Example 1 with ValueList

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

Example 2 with ValueList

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);
    }
}
Also used : CustomTypeContentAssociation(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentAssociation) NSDOMBuilder(eu.esdihumboldt.util.groovy.xml.NSDOMBuilder) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) HashMap(java.util.HashMap) Element(org.w3c.dom.Element)

Example 3 with ValueList

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();
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Example 4 with ValueList

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();
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) List(java.util.List) ClassResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ClassResolver) TypeResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeResolver) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation) StreamSupport(java.util.stream.StreamSupport) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeReferenceBuilder(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeReferenceBuilder) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Value(eu.esdihumboldt.hale.common.core.io.Value) ValueConstraintFactory(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ValueConstraintFactory) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation)

Example 5 with ValueList

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;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Reference(eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference) Value(eu.esdihumboldt.hale.common.core.io.Value) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

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