Permalink
Browse files

GEOT-4288: "Unsupported GML version" error when specifying swe schema in

second schemaURI entry
  • Loading branch information...
1 parent 61724bd commit bb351713c0c6cfd5dfd4b8a33c84228120ff109c @riniangreani riniangreani committed Oct 15, 2012
@@ -22,9 +22,11 @@
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.logging.Logger;
import javax.xml.namespace.QName;
+import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDTypeDefinition;
import org.geotools.gml3.ApplicationSchemaConfiguration;
import org.geotools.gml3.GML;
@@ -125,7 +127,21 @@ public SchemaIndex parse(Configuration configuration) throws IOException {
public SchemaIndex parse(String nameSpace, String schemaLocation) throws IOException {
AppSchemaConfiguration configuration = new AppSchemaConfiguration(nameSpace,
schemaLocation, resolver);
- configuration.addDependency(findGmlConfiguration(configuration));
+ Configuration gmlConfig = findGmlConfiguration(configuration);
+ if (gmlConfig != null) {
+ configuration.addDependency(gmlConfig);
+ } else {
+ // No GML configuration found.. could be deliberate
+ // where there is no direct connection between the primary schema
+ // (GML based)
+ // and secondary schemaUri.. but possible by using anyType
+ // will warn in AppSchemaDataAccessConfiguration
+ Logger LOGGER = org.geotools.util.logging.Logging
+ .getLogger(EmfAppSchemaReader.class.getPackage().getName());
+ LOGGER.warning("Non GML based schema found in schemaURI: "
+ + schemaLocation
+ + "! This may result in corrupted data as some types may not be encoded correctly.");
+ }
return parse(configuration);
}
@@ -230,13 +246,20 @@ public static Configuration findGmlConfiguration(AppSchemaConfiguration configur
}
}
}
- throw new RuntimeException("Unsupported GML version for schema at "
- + configuration.getSchemaLocation());
- } finally {
- if (index != null) {
- index.destroy();
- }
+ for (XSDSchema schema : index.getSchemas()) {
+ String ns = schema.getTargetNamespace();
+ if (ns != null && ns.startsWith("http://www.opengis.net/gml")) {
+ throw new RuntimeException(
+ "Unsupported GML version for schema at "
+ + configuration.getSchemaLocation());
+ }
+ }
+ } finally {
+ if (index != null) {
+ index.destroy();
+ }
}
+ return null;
}
}
@@ -29,6 +29,7 @@
import org.geotools.gml3.GML;
import org.geotools.gml3.GMLConfiguration;
import org.geotools.test.AppSchemaTestSupport;
+import org.geotools.xml.AppSchemaCatalog;
import org.geotools.xml.AppSchemaConfiguration;
import org.geotools.xml.AppSchemaResolver;
import org.geotools.xml.Configuration;
@@ -274,5 +275,23 @@ public void findGml32Configuration() {
Assert.assertNotNull(gmlConfiguration);
Assert.assertEquals(new org.geotools.gml3.v3_2.GMLConfiguration(), gmlConfiguration);
}
+
+ /**
+ * Test when secondary schemaUri contains non GML schema used in anyType from primary schema.
+ */
+ @Test
+ public void testNonGMLConfiguration() {
+ AppSchemaCatalog catalog = AppSchemaCatalog.build(getClass()
+ .getResource("/test-data/mappedPolygons.oasis.xml"));
+ AppSchemaConfiguration configuration = new AppSchemaConfiguration(
+ "http://www.opengis.net/swe/2.0",
+ "http://schemas.opengis.net/sweCommon/2.0/swe.xsd",
+ new AppSchemaResolver(catalog));
+ Configuration gmlConfiguration = EmfAppSchemaReader
+ .findGmlConfiguration(configuration);
+ // Null should be returned, not exception
+ // Warning message should be in the log
+ Assert.assertNull(gmlConfiguration);
+ }
}
@@ -0,0 +1,186 @@
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:swe="http://www.opengis.net/swe/2.0" targetNamespace="http://www.opengis.net/swe/2.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.0.1">
+ <annotation>
+ <documentation>SWE Common Data Model schema for specifying parameters of advanced encoding methods (Raw Binary, Base64 Binary, Compressed Binary). See requirements class http://www.opengis.net/spec/SWE/2.0/req/xsd-advanced-encodings/
+
+ SWE Common is an OGC Standard.
+ Copyright (c) 2010 Open Geospatial Consortium.
+ To obtain additional rights of use, visit http://www.opengeospatial.org/legal/ .
+ </documentation>
+ </annotation>
+ <include schemaLocation="swe.xsd"/>
+ <include schemaLocation="simple_encodings.xsd"/>
+ <!-- ================================================= -->
+ <element name="Block" substitutionGroup="swe:AbstractSWE" type="swe:BlockType">
+ <annotation>
+ <documentation>Binary encoding parameters used to encode a block of values at once. This is used for encrypting or compressing a complete array of values for instance</documentation>
+ </annotation>
+ </element>
+ <complexType name="BlockType">
+ <complexContent>
+ <extension base="swe:AbstractSWEType">
+ <attribute name="compression" type="anyURI" use="optional">
+ <annotation>
+ <documentation>Name of the compression method used to encrypt the block of values described by the referenced data component</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="encryption" type="anyURI" use="optional">
+ <annotation>
+ <documentation>Name of the encryption method used to encrypt the block of values described by the referenced data component</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="paddingBytes-after" type="integer" use="optional">
+ <annotation>
+ <documentation>Number of padding bytes present in the stream after this binary block</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="paddingBytes-before" type="integer" use="optional">
+ <annotation>
+ <documentation>Number of padding bytes present in the stream before this binary block</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="byteLength" type="integer" use="optional">
+ <annotation>
+ <documentation>Length in byte of this binary block (if known in advance)</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="ref" type="string" use="required">
+ <annotation>
+ <documentation>Reference to the aggregate data component that this binary block encoding settings apply to</documentation>
+ </annotation>
+ </attribute>
+ </extension>
+ </complexContent>
+ </complexType>
+ <complexType name="BlockPropertyType">
+ <sequence minOccurs="0">
+ <element ref="swe:Block"/>
+ </sequence>
+ <attributeGroup ref="swe:AssociationAttributeGroup"/>
+ </complexType>
+ <complexType name="BlockPropertyByValueType">
+ <sequence>
+ <element ref="swe:Block"/>
+ </sequence>
+ </complexType><!-- ================================================= -->
+ <element name="BinaryEncoding" substitutionGroup="swe:AbstractEncoding" type="swe:BinaryEncodingType">
+ <annotation>
+ <documentation>Parameters of the binary encoding method</documentation>
+ </annotation>
+ </element>
+ <complexType name="BinaryEncodingType">
+ <complexContent>
+ <extension base="swe:AbstractEncodingType">
+ <sequence>
+ <element maxOccurs="unbounded" minOccurs="1" name="member">
+ <annotation>
+ <documentation>Each member contains detailed parameters for encoding a scalar value or a block of values</documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <group ref="swe:ComponentOrBlock"/>
+ </sequence>
+ </complexType>
+ </element>
+ </sequence>
+ <attribute name="byteOrder" type="swe:ByteOrderType" use="required">
+ <annotation>
+ <documentation>Byte order convention used to encode this binary data (big endian = most significant byte first, MSB or little endian = least significant byte first, LSB)</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="byteEncoding" type="swe:ByteEncodingType" use="required">
+ <annotation>
+ <documentation>Byte encoding method used to encode the binary data (raw or base 64)</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="byteLength" type="integer" use="optional">
+ <annotation>
+ <documentation>Total length in bytes of the binary stream (if known in advance)</documentation>
+ </annotation>
+ </attribute>
+ </extension>
+ </complexContent>
+ </complexType>
+ <complexType name="BinaryEncodingPropertyType">
+ <sequence minOccurs="0">
+ <element ref="swe:BinaryEncoding"/>
+ </sequence>
+ <attributeGroup ref="swe:AssociationAttributeGroup"/>
+ </complexType>
+ <complexType name="BinaryEncodingPropertyByValueType">
+ <sequence>
+ <element ref="swe:BinaryEncoding"/>
+ </sequence>
+ </complexType><!-- ================================================= -->
+ <element name="Component" substitutionGroup="swe:AbstractSWE" type="swe:ComponentType">
+ <annotation>
+ <documentation>Binary encoding parameters used for encoding a single data component</documentation>
+ </annotation>
+ </element>
+ <complexType name="ComponentType">
+ <complexContent>
+ <extension base="swe:AbstractSWEType">
+ <attribute name="encryption" type="anyURI" use="optional">
+ <annotation>
+ <documentation>Name of the encryption method used to encrypt the value of this field</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="significantBits" type="integer" use="optional">
+ <annotation>
+ <documentation>Number of significant bits actually used for a binary encoded numerical value (all remaining bits shall be set to 0)</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="bitLength" type="integer" use="optional"/>
+ <attribute name="byteLength" type="integer" use="optional">
+ <annotation>
+ <documentation>Byte length of this field when a custom data type is used</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="dataType" type="anyURI" use="required">
+ <annotation>
+ <documentation>Binary data type used to encode the value(s) of the referenced data component</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="ref" type="string" use="required">
+ <annotation>
+ <documentation>Reference to the data component that these binary encoding settings apply to</documentation>
+ </annotation>
+ </attribute>
+ </extension>
+ </complexContent>
+ </complexType>
+ <complexType name="ComponentPropertyType">
+ <sequence minOccurs="0">
+ <element ref="swe:Component"/>
+ </sequence>
+ <attributeGroup ref="swe:AssociationAttributeGroup"/>
+ </complexType>
+ <complexType name="ComponentPropertyByValueType">
+ <sequence>
+ <element ref="swe:Component"/>
+ </sequence>
+ </complexType><!-- ================================================= -->
+ <group name="ComponentOrBlock">
+ <choice>
+ <element ref="swe:Component"/>
+ <element ref="swe:Block"/>
+ </choice>
+ </group>
+ <complexType name="ComponentOrBlockPropertyType">
+ <sequence minOccurs="0">
+ <group ref="swe:ComponentOrBlock"/>
+ </sequence>
+ <attributeGroup ref="swe:AssociationAttributeGroup"/>
+ </complexType>
+ <simpleType name="ByteEncodingType">
+ <restriction base="string">
+ <enumeration value="base64"/>
+ <enumeration value="raw"/>
+ </restriction>
+ </simpleType>
+ <simpleType name="ByteOrderType">
+ <restriction base="string">
+ <enumeration value="bigEndian"/>
+ <enumeration value="littleEndian"/>
+ </restriction>
+ </simpleType>
+</schema>
Oops, something went wrong.

0 comments on commit bb35171

Please sign in to comment.