use of org.geotoolkit.storage.feature.GenericNameIndex in project geotoolkit by Geomatys.
the class OMFeatureTypes method getFeatureTypes.
public static GenericNameIndex<FeatureType> getFeatureTypes(final String name) {
final GenericNameIndex<FeatureType> types = new GenericNameIndex<>();
final GenericName OM_TN_SAMPLINGPOINT = NamesExt.create(OM_NAMESPACE, name);
final FeatureTypeBuilder featureTypeBuilder = new FeatureTypeBuilder();
featureTypeBuilder.setName(OM_TN_SAMPLINGPOINT);
featureTypeBuilder.setSuperTypes(GMLConvention.ABSTRACTFEATURETYPE_31);
featureTypeBuilder.addAttribute(String.class).setName(ATT_DESC).setMinimumOccurs(0).setMaximumOccurs(1);
featureTypeBuilder.addAttribute(String.class).setName(ATT_NAME).setMinimumOccurs(1).setMaximumOccurs(Integer.MAX_VALUE);
featureTypeBuilder.addAttribute(String.class).setName(ATT_SAMPLED).setMinimumOccurs(0).setMaximumOccurs(Integer.MAX_VALUE).addCharacteristic(GMLConvention.NILLABLE_CHARACTERISTIC);
featureTypeBuilder.addAttribute(Geometry.class).setName(ATT_POSITION).addRole(AttributeRole.DEFAULT_GEOMETRY);
try {
types.add(null, OM_TN_SAMPLINGPOINT, featureTypeBuilder.build());
} catch (IllegalNameException ex) {
// won't happen
throw new FeatureStoreRuntimeException(ex);
}
return types;
}
use of org.geotoolkit.storage.feature.GenericNameIndex 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;
}
use of org.geotoolkit.storage.feature.GenericNameIndex in project geotoolkit by Geomatys.
the class GMLStore method getType.
@Override
public synchronized FeatureType getType() throws DataStoreException {
if (rootType == 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));
rootType = catalog.get(xsdTypeName);
// schemaLocations.put(reader.getTargetNamespace(),xsd); needed?
} 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 (FeatureReader ite = reader.readAsStream(file)) {
catalog = reader.getFeatureTypes();
rootType = ite.getFeatureType();
} catch (IOException | XMLStreamException ex) {
throw new DataStoreException(ex.getMessage(), ex);
} finally {
reader.dispose();
}
}
featureType = getCollectionSubType(rootType);
}
return featureType;
}
Aggregations