Search in sources :

Example 6 with DefinitionPath

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

the class PatternTest method testDescent.

/**
 * Test a descending match
 */
@Ignore
@Test
public void testDescent() {
    // $NON-NLS-1$
    Pattern pattern = Pattern.parse("**/LineStringSegment");
    TypeDefinition start = createCurveType();
    DefinitionPath path = pattern.match(start, new DefinitionPath(start, CURVE_ELEMENT, false), GML_NS);
    // $NON-NLS-1$
    assertNotNull("A match should have been found", path);
    // $NON-NLS-1$
    assertFalse("Path should not be empty", path.isEmpty());
    List<PathElement> steps = path.getSteps();
    assertEquals(2, steps.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    String[] names = new String[] { "segments", "LineStringSegment" };
    // check path elements
    for (int i = 0; i < steps.size(); i++) {
        assertEquals(names[i], steps.get(i).getName().getLocalPart());
    }
}
Also used : PathElement(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement) DefinitionPath(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with DefinitionPath

use of eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath 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 8 with DefinitionPath

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

the class GmlWriterUtil method collectPropertyPaths.

/**
 * Collect all the paths to all child properties, even those contained in
 * groups.
 *
 * @param children the children
 * @param basePath the base path
 * @param elementsOnly if only properties representing an XML element should
 *            be considered
 * @return the child paths, each ending with a property element
 */
public static Collection<DefinitionPath> collectPropertyPaths(Iterable<? extends ChildDefinition<?>> children, DefinitionPath basePath, boolean elementsOnly) {
    List<DefinitionPath> result = new ArrayList<DefinitionPath>();
    for (ChildDefinition<?> child : children) {
        if (child.asProperty() != null) {
            if (!elementsOnly || !child.asProperty().getConstraint(XmlAttributeFlag.class).isEnabled()) {
                DefinitionPath path = new DefinitionPath(basePath);
                path.addProperty(child.asProperty());
                result.add(path);
            }
        } else if (child.asGroup() != null) {
            DefinitionPath path = new DefinitionPath(basePath);
            path.addGroup(child.asGroup());
            result.addAll(collectPropertyPaths(child.asGroup().getDeclaredChildren(), path, elementsOnly));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) XmlAttributeFlag(eu.esdihumboldt.hale.io.xsd.constraint.XmlAttributeFlag) DefinitionPath(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath)

Example 9 with DefinitionPath

use of eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath 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)

Example 10 with DefinitionPath

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

the class XsltGenerator method pathInsertForEach.

/**
 * Inserts a <code>xsl:for-each</code> element in the path before the
 * element that may be repeated. Also removes the last path element.
 *
 * @param path the path where target instances should be written to
 * @param variable the variable name of the xsl:variable holding the
 *            instances
 * @param targetElements an empty map that is populated with variable names
 *            mapped to target element names
 * @return the adapted path including the for-each instruction and w/o the
 *         last path element
 */
private DefinitionPath pathInsertForEach(DefinitionPath path, String variable, Map<String, QName> targetElements) {
    List<PathElement> elements = new ArrayList<PathElement>(path.getSteps());
    int index = elements.size() - 1;
    PathElement lastNonUniqueElement = null;
    while (lastNonUniqueElement == null && index >= 0) {
        PathElement element = elements.get(index);
        if (!element.isUnique()) {
            lastNonUniqueElement = element;
        } else {
            index--;
        }
    }
    if (lastNonUniqueElement == null) {
        // TODO instead some fall-back?
        throw new IllegalStateException("No element in member path repeatable");
    }
    /*
		 * Store last element name for variable, this information is needed for
		 * the type transformation.
		 */
    targetElements.put(variable, elements.get(elements.size() - 1).getName());
    // remove last element
    elements.remove(elements.size() - 1);
    if (index == elements.size()) {
        /*
			 * There seems to be a problem with compiling the XSLT if the
			 * for-each is the last element in the path. Then insert the whole
			 * variable in once piece.
			 */
        elements.add(index, new XslForEach("$" + variable));
    } else {
        // loop for each element in the variable
        elements.add(index, new XslForEach("$" + variable + "/*"));
    }
    return new DefinitionPath(elements);
}
Also used : PathElement(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement) ArrayList(java.util.ArrayList) DefinitionPath(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath)

Aggregations

DefinitionPath (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.DefinitionPath)10 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)3 PathElement (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement)3 QName (javax.xml.namespace.QName)3 Test (org.junit.Test)3 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)2 AbstractTypeMatcher (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher)2 Descent (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.Descent)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 SubtaskProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator)1 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)1 XmlAttributeFlag (eu.esdihumboldt.hale.io.xsd.constraint.XmlAttributeFlag)1 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)1 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)1