Search in sources :

Example 1 with PathElement

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

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

use of eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement 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)3 PathElement (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.PathElement)3 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)1 AbstractTypeMatcher (eu.esdihumboldt.hale.io.gml.writer.internal.geometry.AbstractTypeMatcher)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1