Search in sources :

Example 11 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class SimpleTypeUtil method convertFromXml.

/**
 * Convert a string belonging to a XML simple type to the binding specified
 * by the given type definition.
 *
 * @param value the string value
 * @param type the type definition
 * @return <code>null</code> if the string was <code>null</code>, the
 *         converted object with the binding type if possible, otherwise the
 *         original string
 */
public static Object convertFromXml(String value, TypeDefinition type) {
    if (value == null) {
        return null;
    }
    Class<? extends XmlAnySimpleType> simpleType = getSimpleType(type);
    Class<?> binding = type.getConstraint(Binding.class).getBinding();
    if (List.class.isAssignableFrom(binding)) {
        // XXX also for collection
        // binding?
        // we are dealing with a simple type list
        // items separated by whitespace
        String[] elements = value.trim().split("\\s+");
        ElementType elementType = type.getConstraint(ElementType.class);
        Class<? extends XmlAnySimpleType> elementSimpleType = null;
        if (elementType.getDefinition() != null) {
            elementSimpleType = getSimpleType(elementType.getDefinition());
        }
        Class<?> elementBinding = elementType.getBinding();
        List<Object> result = new ArrayList<Object>();
        for (String element : elements) {
            Object convElement = convertFromXml(element, elementSimpleType, elementBinding);
            result.add(convElement);
        }
        return result;
    }
    // convert ordinary value
    return convertFromXml(value, simpleType, binding);
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) ElementType(eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType) ArrayList(java.util.ArrayList)

Example 12 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class DefaultAttributeEditorFactory method createEditor.

@Override
public AttributeEditor<?> createEditor(Composite parent, PropertyDefinition property, EntityDefinition entityDef, boolean allowScripts) {
    TypeDefinition type = property.getPropertyType();
    if (!type.getConstraint(HasValueFlag.class).isEnabled())
        return null;
    else {
        if (allowScripts) {
            EditorChooserEditor<Object> result = new PropertyEditorChooserEditor(parent, property, entityDef);
            result.selectDefaultEditor();
            return result;
        } else {
            Class<?> binding = type.getConstraint(Binding.class).getBinding();
            if (Boolean.class.equals(binding))
                return new BooleanEditor(parent);
            else
                return new DefaultPropertyEditor(parent, property, entityDef);
        }
    }
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) BooleanEditor(eu.esdihumboldt.hale.ui.common.editors.BooleanEditor) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 13 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class TypeDefinitionElementTypeBindingSection method refresh.

/**
 * @see AbstractPropertySection#refresh()
 */
@Override
public void refresh() {
    Binding bind = getDefinition().getConstraint(Binding.class);
    if (Collection.class.isAssignableFrom(bind.getBinding())) {
        ElementType element = getDefinition().getConstraint(ElementType.class);
        elementType.setText(element.getBinding().getName());
    } else {
        // XXX should not be displayed
        elementType.setText("");
    }
    binding.setText(bind.getBinding().getName());
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) ElementType(eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType)

Example 14 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class GeometryCondition method accept.

/**
 * @see EntityCondition#accept(Entity)
 */
@Override
public boolean accept(Type entity) {
    TypeDefinition type = entity.getDefinition().getDefinition();
    if (!type.getConstraint(HasValueFlag.class).isEnabled() && !type.getConstraint(AugmentedValueFlag.class).isEnabled()) {
        // whether defined in the schema or augmented
        return false;
    }
    GeometryType geometryType = entity.getDefinition().getDefinition().getConstraint(GeometryType.class);
    if (!geometryType.isGeometry()) {
        // is no geometry type
        return false;
    }
    Collection<Class<? extends Geometry>> tmpBindings = bindings;
    if (tmpBindings == null) {
        // check only if it is a geometry
        tmpBindings = new HashSet<Class<? extends Geometry>>();
        tmpBindings.add(Geometry.class);
    }
    // otherwise check the allowed bindings
    // default
    boolean to = true;
    switch(entity.getDefinition().getSchemaSpace()) {
        case SOURCE:
            to = false;
            break;
        case TARGET:
            to = true;
            break;
    }
    for (Class<? extends Geometry> compatibleClass : tmpBindings) {
        Binding binding = type.getConstraint(Binding.class);
        boolean isCollection = Collection.class.isAssignableFrom(binding.getBinding());
        // check binding
        if (isCompatibleClass(geometryType.getBinding(), to, compatibleClass, allowConversion) && (!isCollection || allowCollection)) {
            return true;
        }
    }
    // no check succeeded
    return false;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) GeometryType(eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryType) AugmentedValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.AugmentedValueFlag) HasValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 15 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class BindingCondition method accept.

/**
 * @see EntityCondition#accept(Entity)
 */
@Override
public boolean accept(Type entity) {
    // default
    boolean to = true;
    switch(entity.getDefinition().getSchemaSpace()) {
        case SOURCE:
            to = false;
            break;
        case TARGET:
            to = true;
            break;
    }
    TypeDefinition type = entity.getDefinition().getDefinition();
    if (!type.getConstraint(HasValueFlag.class).isEnabled() && !type.getConstraint(AugmentedValueFlag.class).isEnabled()) {
        // whether defined in the schema or augmented
        return false;
    }
    // check binding
    Binding binding = type.getConstraint(Binding.class);
    if (isCompatibleClass(binding.getBinding(), to)) {
        return true;
    }
    // check element type
    if (allowCollection) {
        ElementType elementType = type.getConstraint(ElementType.class);
        if (isCompatibleClass(elementType.getBinding(), to)) {
            return true;
        }
    }
    // no check succeeded
    return false;
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) ElementType(eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType) AugmentedValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.AugmentedValueFlag) HasValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)17 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)12 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 ElementType (eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType)4 Geometry (org.locationtech.jts.geom.Geometry)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)3 Test (org.junit.Test)3 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)2 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)2 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)2 AugmentedValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.AugmentedValueFlag)2 GeometryType (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryType)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 MultiValue (eu.esdihumboldt.cst.MultiValue)1 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)1 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1