Search in sources :

Example 1 with TypeDefinition

use of eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition in project hale by halestudio.

the class ModelAlignmentToModelRifTranslator method canBeSubstitutedBy.

/**
 * Determines if the given type can be substituted by the given element
 *
 * @param type the type definition
 * @param element the element
 * @return if the type can be substituted by the given element
 */
private static boolean canBeSubstitutedBy(TypeDefinition type, SchemaElement element) {
    Queue<TypeDefinition> toTest = new LinkedList<TypeDefinition>();
    toTest.add(type);
    while (!toTest.isEmpty()) {
        TypeDefinition test = toTest.poll();
        if (test.getDeclaringElements().contains(element))
            return true;
        toTest.addAll(test.getSubTypes());
    }
    return false;
}
Also used : LinkedList(java.util.LinkedList) TypeDefinition(eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)

Example 2 with TypeDefinition

use of eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method createAttributePath.

/**
 * Create an attribute path from an {@link IDetailedAbout}
 *
 * @param about the about
 * @param elements the available elements
 * @return the attribute path
 * @throws TranslationException if the attribute path cannot be resolved
 */
private static GmlAttributePath createAttributePath(IDetailedAbout about, Map<String, SchemaElement> elements) throws TranslationException {
    GmlAttributePath binding = new GmlAttributePath();
    // get the parent class for the entity
    // $NON-NLS-1$
    SchemaElement entityParent = elements.get(about.getNamespace() + "/" + about.getFeatureClass());
    if (entityParent == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new TranslationException("Element " + about.getFeatureClass() + " not found");
    }
    TypeDefinition type = entityParent.getType();
    List<String> nestedParts = about.getProperties();
    for (String attributeName : nestedParts) {
        AttributeDefinition attDef = type.getAttribute(attributeName);
        if (attDef == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new TranslationException("Attribute " + attributeName + " not found");
        }
        GmlAttribute attribute = new GmlAttribute(attDef);
        binding.add(attribute);
        type = attDef.getAttributeType();
    }
    return binding;
}
Also used : GmlAttributePath(com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath) AttributeDefinition(eu.esdihumboldt.hale.schemaprovider.model.AttributeDefinition) SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) GmlAttribute(com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute) TypeDefinition(eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)

Example 3 with TypeDefinition

use of eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition in project hale by halestudio.

the class ModelAlignmentToModelRifTranslator method filter.

/**
 * Filter {@link ModelAttributeMappingCell}s to leave only those that can
 * target the specified source and target classes.
 *
 * @param attributeMappings
 *            cells to filter.
 * @param sourceClass
 *            source class that mapping must apply to.
 * @param targetClass
 *            target class that mapping must apply to.
 * @return filtered list of mappings cells.
 */
private static List<ModelAttributeMappingCell> filter(List<ModelAttributeMappingCell> attributeMappings, SchemaElement sourceClass, SchemaElement targetClass) {
    List<ModelAttributeMappingCell> applicableMappings = new ArrayList<ModelAttributeMappingCell>();
    for (ModelAttributeMappingCell candidate : attributeMappings) {
        TypeDefinition sourceElement = candidate.getSourceAttribute().get(0).getDefinition().getDeclaringType();
        TypeDefinition targetElement = candidate.getTargetAttribute().get(0).getDefinition().getDeclaringType();
        if (canBeSubstitutedBy(sourceElement, sourceClass) && canBeSubstitutedBy(targetElement, targetClass)) {
            applicableMappings.add(candidate);
        }
    // also test attributes.
    }
    return applicableMappings;
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ArrayList(java.util.ArrayList) TypeDefinition(eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)3 TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)1 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)1 GmlAttribute (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute)1 GmlAttributePath (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath)1 AttributeDefinition (eu.esdihumboldt.hale.schemaprovider.model.AttributeDefinition)1 SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1