Details
Description
I try to parse following xml with org.geotools.gml3.v3_2.GMLConfiguration(). The problem is with usage of org.geotools.gml3.bindings.DoubleListBinding.
new DoubleListBinding().getTarget() return QName("http://www.opengis.net/gml", "doubleList"). ParseExecutor.java cannot find corresponding SDTypeDefinition. There is used XSDTypeDefinition
. In .v3_2.GMLConfiguration there is used "http://www.opengis.net/gml/3.2" uri. In DoubleListBinding is used "http://www.opengis.net/gml" uri.
XML:
<?xml version='1.0' encoding='UTF-8'?>
<gml:patches xmlns:gml="http://www.opengis.net/gml/3.2">
<gml:PolygonPatch>
<gml:exterior>
<gml:LinearRing>
<gml:pos>-125.451 32.942</gml:pos>
<gml:pos>-125.291 32.947</gml:pos>
<gml:pos>-125.284 32.85</gml:pos>
<gml:pos>-125.434 32.85</gml:pos>
<gml:pos>-125.451 32.942</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:PolygonPatch>
</gml:patches>
Code:
Configuration configurationG = new org.geotools.gml3.v3_2.GMLConfiguration();
Parser parser = new org.geotools.xml.Parser(configurationG);
InputStream xml = this.getClass().getResourceAsStream("gml.xml");
Object o = parser.parse(xml);
Problem:
Exception in thread "main" java.lang.RuntimeException: Parsing failed for pos: java.lang.NullPointerException
at org.geotools.xml.impl.ParseExecutor.visit(ParseExecutor.java:158)
at org.geotools.xml.impl.BindingWalker$BindingExecutionChain.execute(BindingWalker.java:215)
at org.geotools.xml.impl.BindingWalker.walk(BindingWalker.java:181)
at org.geotools.xml.impl.ElementHandlerImpl.endElement(ElementHandlerImpl.java:228)
at org.geotools.xml.impl.ParserHandler.endElement(ParserHandler.java:626)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.geotools.xml.Parser.parse(Parser.java:236)
at org.geotools.xml.Parser.parse(Parser.java:164)
at com.lhsystems.testy.GML2C3_2.parser(GML2C3_2.java:31)
at com.lhsystems.testy.GML2C3_2.main(GML2C3_2.java:16)
Caused by: java.lang.NullPointerException
at org.geotools.gml3.bindings.DoubleListBinding.parse(DoubleListBinding.java:82)
at org.geotools.xml.impl.ParseExecutor.visit(ParseExecutor.java:147)
... 16 more
Sollution:
I have 2 adaptations:
1. rerouted the type binding for generic types like "doubleList" in "org.geotools.xml.impl.ParseExecutor"
2. changed the execution mode of "org.geotools.gml3.bindings.LinearRingTypeBinding" to prevent that the anytype will override the LinearRing result.
addaption nr1:
public void visit(Binding binding) {
...
if (Schemas.nameMatches(instance.getDeclaration(), binding.getTarget()))
{ //instance binding type = instance.getTypeDefinition(); }else {
//type binding
type = Schemas.getBaseTypeDefinition(instance.getTypeDefinition(),
binding.getTarget());
//******** begin addaption **********
if (type == null)
//******** end addaption **********
}
...
}
addaption nr2:
public class LinearRingTypeBinding extends AbstractComplexBinding {
...
//******** begin addaption **********
/**
- Changed BEFORE into OVERRIDE because otherwise the LinearRing will be
overridden by the anytype
*/
public int getExecutionMode() { return OVERRIDE; }//******** end addaption **********
...
}
The junit test does not contain the following jars from Geotools 2.7.3 to keep the upload under 10 MB, they are uploaded in a seperate file:
gt-api-2.7.3.jar
gt-epsg-extension-2.7.3.jar
gt-epsg-wkt-2.7.3.jar
gt-main-2.7.3.jar
gt-metadata-2.7.3.jar
gt-opengis-2.7.3.jar
gt-referencing-2.7.3.jar
gt-referencing3D-2.7.3.jar
gt-render-2.7.3.jar
gt-xsd-core-2.7.3.jar
gt-xsd-gml2-2.7.3.jar
gt-xsd-gml3-2.7.3.jar
Regards,
Hans Wolffenbuttel
Regards,
Hans