Hans Wolffenbuttel created GEOT-3974:
----------------------------------------
Summary: GML 3.2 parsing problem in GeoTools 2.7.x : nullpointer
exception because of 'version independant' elements
Key: GEOT-3974
URL: https://jira.codehaus.org/browse/GEOT-3974
Project: GeoTools
Issue Type: Bug
Components: xsd-gml
Affects Versions: 2.7.3
Environment: Windows Vista (64bits) service pack 2, Java version
1.6.0_21
Reporter: Hans Wolffenbuttel
Priority: Critical
Fix For: 2.7.4
Attachments: GeoTools 2.7.3_lib_files.zip, GeotoolsTest.zip
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{"http://www.opengis.net/gml/3.2",
"doubleList"}. 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) {
// when the type is not found, it is probably a generic (version
independant) component
// which can be found by using the namespace of the instance instead
of the generic binding.
QName qName = new QName(instance.getNamespace(),
binding.getTarget().getLocalPart());
type = Schemas.getBaseTypeDefinition(instance.getTypeDefinition(),
qName);
}
//******** 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
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel