Search in sources :

Example 6 with ValueList

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

Example 7 with ValueList

use of eu.esdihumboldt.hale.common.core.io.ValueList in project hale by halestudio.

the class EnumerationFactory method store.

@Override
public Value store(Enumeration<?> constraint, TypeReferenceBuilder typeIndex) {
    ValueProperties props = new ValueProperties(2);
    // values
    if (constraint.getValues() != null) {
        ValueList list = new ValueList();
        for (Object value : constraint.getValues()) {
            list.add(Value.simple(value));
        }
        props.put(P_VALUES, Value.complex(list));
    // XXX also store the value type for reconstruction?
    }
    // allow others?
    props.put(P_ALLOW_OTHERS, Value.of(constraint.isAllowOthers()));
    return Value.complex(props);
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList)

Example 8 with ValueList

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

Example 9 with ValueList

use of eu.esdihumboldt.hale.common.core.io.ValueList 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);
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Value(eu.esdihumboldt.hale.common.core.io.Value) PrimaryKey(eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey)

Example 10 with ValueList

use of eu.esdihumboldt.hale.common.core.io.ValueList 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);
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) ArrayList(java.util.ArrayList) ValidatorValue(eu.esdihumboldt.hale.common.schema.model.validate.factory.ValidatorValue) Value(eu.esdihumboldt.hale.common.core.io.Value) CombinedValidator(eu.esdihumboldt.util.validator.CombinedValidator) Validator(eu.esdihumboldt.util.validator.Validator)

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