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();
}
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();
}
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;
}
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);
}
}
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;
}
Aggregations