Search in sources :

Example 11 with JAXBFeatureTypeReader

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

the class XmlFeatureTypeTest method testReadMultiGeomFeatureType.

@Test
public void testReadMultiGeomFeatureType() throws JAXBException {
    final JAXBFeatureTypeReader reader = getReader(true);
    final List<FeatureType> types = new ArrayList<>(reader.read(XmlFeatureTypeTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/MultiGeomType.xsd")).getValues());
    removeGMLBaseTypes(types);
    assertEquals(1, types.size());
    Collection<? extends PropertyType> expProperties = multiGeomType.getProperties(false);
    Collection<? extends PropertyType> resProperties = types.get(0).getProperties(false);
    assertEquals(diffSizeProperties(expProperties, resProperties), expProperties.size(), resProperties.size());
    FeatureComparator comparator = new FeatureComparator(multiGeomType, types.get(0));
    comparator.ignoredCharacteristics.add("http://www.w3.org/1999/xlink:href");
    comparator.ignoredCharacteristics.add("mapping");
    comparator.compare();
}
Also used : FeatureType(org.opengis.feature.FeatureType) ArrayList(java.util.ArrayList) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) FeatureComparator(org.apache.sis.test.feature.FeatureComparator)

Example 12 with JAXBFeatureTypeReader

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

the class XmlFeatureTypeTest method testReadTypeWithNil.

@Test
public void testReadTypeWithNil() throws JAXBException {
    final JAXBFeatureTypeReader reader = getReader(true);
    final List<FeatureType> types = new ArrayList<>(reader.read(XmlFeatureTypeTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/TypeWithNil.xsd")).getValues());
    removeGMLBaseTypes(types);
    assertEquals(1, types.size());
    final FeatureType readType = types.get(0);
    FeatureComparator comparator = new FeatureComparator(typeWithNil, readType);
    comparator.ignoredCharacteristics.add("http://www.w3.org/1999/xlink:href");
    comparator.ignoredCharacteristics.add("mapping");
    comparator.compare();
}
Also used : FeatureType(org.opengis.feature.FeatureType) ArrayList(java.util.ArrayList) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) FeatureComparator(org.apache.sis.test.feature.FeatureComparator)

Example 13 with JAXBFeatureTypeReader

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

the class WPSIO method getFeatureReader.

/**
 * Get the JAXPStreamFeatureReader to read feature. If there is a schema
 * defined, the JAXPStreamFeatureReader will use it. Otherwise it will try
 * to read it when reading data.
 *
 * @param schema location of the feature type definition.
 * @return
 * @throws MalformedURLException If given schema cannot be translated in a
 * propert URL.
 */
public static XmlFeatureReader getFeatureReader(String schema) throws MalformedURLException {
    final Collection<FeatureType> schemaTypes;
    if (schema == null || (schema = schema.trim()).isEmpty()) {
        schemaTypes = Collections.EMPTY_LIST;
    } else {
        Collection<FeatureType> types = null;
        try {
            final JAXBFeatureTypeReader xsdReader = new JAXBFeatureTypeReader();
            final URL schemaURL = new URL(URLDecoder.decode(schema, StandardCharsets.UTF_8.name()));
            types = xsdReader.read(schemaURL).getValues();
        } catch (JAXBException | UnsupportedEncodingException ex) {
            LOGGER.log(Level.FINE, "Cannot read schema at location " + schema, ex);
        }
        schemaTypes = types;
    }
    final JAXPStreamFeatureReader featureReader;
    if (schemaTypes == null || schemaTypes.isEmpty()) {
        featureReader = new JAXPStreamFeatureReader();
        featureReader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
    } else {
        featureReader = new JAXPStreamFeatureReader(schemaTypes);
    }
    return featureReader;
}
Also used : FeatureType(org.opengis.feature.FeatureType) JAXBException(javax.xml.bind.JAXBException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) URL(java.net.URL)

Example 14 with JAXBFeatureTypeReader

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

the class ComplexToFeatureTypeConverter method convert.

/**
 * {@inheritDoc}
 * @return FeatureType
 */
@Override
public FeatureType convert(final Data source, final Map<String, Object> params) throws UnconvertibleObjectException {
    final List<Object> data = source.getContent();
    if (data.size() > 1) {
        throw new UnconvertibleObjectException("Invalid data input : Only one FeatureType expected.");
    }
    try {
        final JAXBFeatureTypeReader xsdReader = new JAXBFeatureTypeReader();
        final GenericNameIndex<FeatureType> ft = xsdReader.read((Node) data.get(0));
        return ft.getValues().iterator().next();
    } catch (JAXBException ex) {
        throw new UnconvertibleObjectException("Unable to read feature type from xsd.", ex);
    }
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) FeatureType(org.opengis.feature.FeatureType) JAXBException(javax.xml.bind.JAXBException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader)

Example 15 with JAXBFeatureTypeReader

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

the class GMLSparseStore method getType.

@Override
public synchronized FeatureType getType() throws DataStoreException {
    if (featureType == null) {
        final String xsd = parameters.getValue(GMLProvider.XSD);
        final String xsdTypeName = parameters.getValue(GMLProvider.XSD_TYPE_NAME);
        catalog = new GenericNameIndex();
        if (xsd != null) {
            // read types from XSD file
            final JAXBFeatureTypeReader reader = new JAXBFeatureTypeReader();
            try {
                catalog = reader.read(new URL(xsd));
                featureType = catalog.get(xsdTypeName);
            } catch (MalformedURLException | JAXBException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            }
        } else {
            final JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
            reader.getProperties().put(JAXPStreamFeatureReader.LONGITUDE_FIRST, longitudeFirst);
            reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
            try {
                if (Files.isDirectory(file)) {
                    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(file, new PosixDirectoryFilter("*.gml", true))) {
                        final Iterator<Path> gmlPaths = directoryStream.iterator();
                        // get first gml file only
                        if (gmlPaths.hasNext()) {
                            final Path gmlPath = gmlPaths.next();
                            try (FeatureReader ite = reader.readAsStream(gmlPath)) {
                                catalog = reader.getFeatureTypes();
                                featureType = ite.getFeatureType();
                            }
                        }
                    }
                } else {
                    try (FeatureReader ite = reader.readAsStream(file)) {
                        catalog = reader.getFeatureTypes();
                        featureType = ite.getFeatureType();
                    }
                }
            } catch (IOException | XMLStreamException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            } finally {
                reader.dispose();
            }
        }
    }
    return featureType;
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) DataStoreException(org.apache.sis.storage.DataStoreException) PosixDirectoryFilter(org.geotoolkit.nio.PosixDirectoryFilter) JAXBException(javax.xml.bind.JAXBException) GenericNameIndex(org.geotoolkit.storage.feature.GenericNameIndex) IOException(java.io.IOException) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) FeatureReader(org.geotoolkit.storage.feature.FeatureReader)

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