Search in sources :

Example 26 with JAXBFeatureTypeReader

use of org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader in project geotoolkit by Geomatys.

the class ReferenceToFeatureTypeConverter method convert.

/**
 * {@inheritDoc}
 * @return FeatureType.
 */
@Override
public FeatureType convert(final Reference source, final Map<String, Object> params) throws UnconvertibleObjectException {
    final String mime = source.getMimeType() != null ? source.getMimeType() : WPSMimeType.TEXT_XML.val();
    final InputStream stream = getInputStreamFromReference(source);
    // XML
    if (mime.equalsIgnoreCase(WPSMimeType.TEXT_XML.val()) || mime.equalsIgnoreCase(WPSMimeType.APP_GML.val()) || mime.equalsIgnoreCase(WPSMimeType.TEXT_GML.val())) {
        try {
            final JAXBFeatureTypeReader xsdReader = new JAXBFeatureTypeReader();
            final GenericNameIndex<FeatureType> ft = xsdReader.read(stream);
            if (ft.getNames().size() != 1) {
                throw new UnconvertibleObjectException("Invalid reference input : More than one FeatureType in schema.");
            }
            return ft.getValues().iterator().next();
        } catch (JAXBException ex) {
            throw new UnconvertibleObjectException("Invalid reference input : can't read reference schema.", ex);
        }
    } else {
        throw new UnconvertibleObjectException("ReferenceType data mime is not supported");
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader)

Aggregations

JAXBFeatureTypeReader (org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader)26 FeatureType (org.opengis.feature.FeatureType)22 ArrayList (java.util.ArrayList)13 FeatureComparator (org.apache.sis.test.feature.FeatureComparator)8 JAXBException (javax.xml.bind.JAXBException)7 IOException (java.io.IOException)4 URL (java.net.URL)4 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)3 JAXPStreamFeatureReader (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader)3 PropertyType (org.opengis.feature.PropertyType)3 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)2 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)2 GenericNameIndex (org.geotoolkit.storage.feature.GenericNameIndex)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1