Search in sources :

Example 1 with AbstractTypeMatcher

use of eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher in project hale by halestudio.

the class CityGMLInstanceWriter method findMemberAttribute.

/**
 * @see StreamGmlWriter#findMemberAttribute(TypeDefinition, QName,
 *      TypeDefinition)
 */
@Override
protected DefinitionPath findMemberAttribute(TypeDefinition container, QName containerName, final TypeDefinition memberType) {
    AbstractTypeMatcher<TypeDefinition> matcher = new AbstractTypeMatcher<TypeDefinition>() {

        @Override
        protected DefinitionPath matchPath(TypeDefinition type, TypeDefinition matchParam, DefinitionPath path) {
            PathElement firstProperty = null;
            for (PathElement step : path.getSteps()) {
                if (step.isProperty()) {
                    firstProperty = step;
                    break;
                }
            }
            if (firstProperty != null && firstProperty.getName().getLocalPart().equals(CITY_OBJECT_MEMBER_ELEMENT) && type.equals(memberType)) {
                return path;
            }
            return null;
        }
    };
    // candidate match
    List<DefinitionPath> candidates = matcher.findCandidates(container, containerName, true, memberType);
    if (candidates != null && !candidates.isEmpty()) {
        // FIXME how to decide between candidates?
        return candidates.get(0);
    }
    return null;
}
Also used : PathElement(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement) DefinitionPath(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath) AbstractTypeMatcher(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 2 with AbstractTypeMatcher

use of eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher in project hale by halestudio.

the class StreamGmlWriter method findMemberAttribute.

/**
 * Find a matching attribute for the given member type in the given
 * container type
 *
 * @param container the container type
 * @param containerName the container element name
 * @param memberType the member type
 *
 * @return the attribute definition or <code>null</code>
 */
protected DefinitionPath findMemberAttribute(TypeDefinition container, QName containerName, final TypeDefinition memberType) {
    // XXX not working if property is no substitution of the property type -
    // use matching instead
    // for (PropertyDefinition property : GmlWriterUtil.collectProperties(container.getChildren())) {
    // // direct match -
    // if (property.getPropertyType().equals(memberType)) {
    // long max = property.getConstraint(Cardinality.class).getMaxOccurs();
    // return new DefinitionPath(
    // property.getPropertyType(),
    // property.getName(),
    // max != Cardinality.UNBOUNDED && max <= 1);
    // }
    // }
    AbstractTypeMatcher<TypeDefinition> matcher = new AbstractTypeMatcher<TypeDefinition>() {

        @Override
        protected DefinitionPath matchPath(TypeDefinition type, TypeDefinition matchParam, DefinitionPath path) {
            if (type.equals(memberType)) {
                return path;
            }
            // XXX special case: FeatureCollection from foreign schema
            Collection<? extends XmlElement> elements = matchParam.getConstraint(XmlElements.class).getElements();
            Collection<? extends XmlElement> containerElements = type.getConstraint(XmlElements.class).getElements();
            if (!elements.isEmpty() && !containerElements.isEmpty()) {
                TypeDefinition parent = matchParam.getSuperType();
                while (parent != null) {
                    if (parent.equals(type)) {
                    // FIXME will not work with separately loaded
                    // schemas because e.g. the choice allowing the
                    // specific type is missing
                    // FIXME add to path
                    // return new DefinitionPath(path).addSubstitution(elements.iterator().next());
                    }
                    parent = parent.getSuperType();
                }
            }
            return null;
        }
    };
    // candidate match (go down at maximum ten levels)
    List<DefinitionPath> candidates = matcher.findCandidates(container, containerName, true, memberType, 10);
    if (candidates != null && !candidates.isEmpty()) {
        // TODO notification? FIXME will this
        return candidates.get(0);
    // work? possible problem: attribute is
    // selected even though better candidate
    // is in other attribute
    }
    return null;
}
Also used : XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) DefinitionPath(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath) AbstractTypeMatcher(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 AbstractTypeMatcher (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher)2 DefinitionPath (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath)2 PathElement (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement)1 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)1