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());
}
}
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;
}
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);
}
Aggregations