LayerInfo createLayerFromResource(JSONObj ref, WorkspaceInfo ws, Catalog cat) throws IOException {
String storeName = ref.str("store");
Name resourceName = new NameImpl(ref.str("name"));
CatalogBuilder builder = new CatalogBuilder(cat);
StoreInfo store = findStore(ws.getName(), storeName, cat);
if( store instanceof DataStoreInfo){
DataStoreInfo dataStore = (DataStoreInfo) store;
builder.setStore(dataStore);
// create from the resource
FeatureTypeInfo ft = null;
try {
ft = builder.buildFeatureType(resourceName);
}
catch(Exception e) {
Throwables.propagateIfInstanceOf(e, IOException.class);
Throwables.propagate(e);
}
DataAccess data = dataStore.getDataStore(null);
FeatureSource source = data.getFeatureSource(resourceName);
builder.setupBounds(ft, source);
return builder.buildLayer(ft);
}
else if (store instanceof CoverageStoreInfo) {
CoverageStoreInfo covStore = (CoverageStoreInfo) store;
builder.setStore(covStore);
CoverageInfo cov = null;
try {
cov = builder.buildCoverage(resourceName.getLocalPart());
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, IOException.class);
Throwables.propagate(e);
}
return builder.buildLayer(cov);
}
else {
throw new UnsupportedOperationException("Copy for non vector/raster layer currently unsupported");
}
}