Search in sources :

Example 26 with Value

use of eu.esdihumboldt.hale.common.core.io.Value 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 27 with Value

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

the class ElementTypeFactory method restore.

@Override
public ElementType restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    ValueProperties props = value.as(ValueProperties.class);
    // try type definition
    Value index = props.getSafe(P_TYPE);
    if (index != null) {
        Optional<TypeDefinition> def = typeIndex.resolve(index);
        if (def.isPresent()) {
            return ElementType.createFromType(def.get());
        }
    }
    // fall back to binding
    String binding = props.getSafe(P_BINDING).as(String.class);
    Class<?> clazz = resolver.loadClass(binding);
    if (clazz == null) {
        throw new IllegalStateException(MessageFormat.format("Could not resolve class {0} for element type binding", binding));
    }
    return ElementType.get(clazz);
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) Value(eu.esdihumboldt.hale.common.core.io.Value) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 28 with Value

use of eu.esdihumboldt.hale.common.core.io.Value 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 29 with Value

use of eu.esdihumboldt.hale.common.core.io.Value 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 30 with Value

use of eu.esdihumboldt.hale.common.core.io.Value 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

Value (eu.esdihumboldt.hale.common.core.io.Value)81 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)12 LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)12 HashMap (java.util.HashMap)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)11 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)11 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 Test (org.junit.Test)6 StyledString (org.eclipse.jface.viewers.StyledString)5 Composite (org.eclipse.swt.widgets.Composite)5 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)4 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 IOException (java.io.IOException)4 Locale (java.util.Locale)4