@Override
public List<ImportTask> list(ImportData data, Catalog catalog, ProgressMonitor monitor) throws IOException {
DataStore dataStore = createDataStore(data);
try {
CatalogBuilder cb = new CatalogBuilder(catalog);
//create a dummy datastore
DataStoreInfo store = cb.buildDataStore("dummy");
cb.setStore(store);
List<ImportTask> tasks = new ArrayList<ImportTask>();
for (String typeName : dataStore.getTypeNames()) {
if (monitor.isCanceled()) {
break;
}
monitor.setTask("Processing " + typeName);
// warning - this will log a scary exception if SRS cannot be found
try {
FeatureTypeInfo featureType =
cb.buildFeatureType(dataStore.getFeatureSource(typeName));
featureType.setStore(null);
featureType.setNamespace(null);
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
cb.setupBounds(featureType, featureSource);
//add attributes
CatalogFactory factory = catalog.getFactory();
SimpleFeatureType schema = featureSource.getSchema();
for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
AttributeTypeInfo att = factory.createAttribute();
att.setName(ad.getLocalName());
att.setBinding(ad.getType().getBinding());
featureType.getAttributes().add(att);
}
LayerInfo layer = cb.buildLayer((ResourceInfo)featureType);
ImportTask task = new ImportTask(data.part(typeName));
task.setLayer(layer);
task.getMetadata().put(FeatureType.class, schema);