Search in sources :

Example 1 with GeometryType

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryType 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(com.vividsolutions.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)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 AugmentedValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.AugmentedValueFlag)1 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)1 GeometryType (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryType)1 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)1