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