CoverageInfo cvInfo = (CoverageInfo) layer.getResource();
if (cvInfo == null)
throw new ServiceException("Unable to acquire coverage resource for layer: "
+ layer.getName());
DimensionInfo timeInfo = null;
DimensionInfo elevInfo = null;
Map<String, DimensionInfo> customDimensions = new HashMap<String, DimensionInfo>();
GridCoverage2DReader reader = null;
for (Map.Entry<String, Serializable> e : cvInfo.getMetadata().entrySet()) {
String key = e.getKey();
Object value = e.getValue();
if (key.equals(ResourceInfo.TIME)) {
timeInfo = Converters.convert(value, DimensionInfo.class);
} else if (key.equals(ResourceInfo.ELEVATION)) {
elevInfo = Converters.convert(value, DimensionInfo.class);
} else if (value instanceof DimensionInfo) {
DimensionInfo dimInfo = (DimensionInfo) value;
if (dimInfo.isEnabled()) {
if (key.startsWith(ResourceInfo.CUSTOM_DIMENSION_PREFIX)) {
String dimensionName = key.substring(ResourceInfo.CUSTOM_DIMENSION_PREFIX
.length());
customDimensions.put(dimensionName, dimInfo);
} else {
LOGGER.log(Level.SEVERE, "Skipping custom dimension with key " + key
+ " since it does not start with "
+ ResourceInfo.CUSTOM_DIMENSION_PREFIX);
}
}
}
}
boolean hasTime = timeInfo != null && timeInfo.isEnabled();
boolean hasElevation = elevInfo != null && elevInfo.isEnabled();
boolean hasCustomDimensions = !customDimensions.isEmpty();
// skip if nothing is configured
if (!hasTime && !hasElevation && !hasCustomDimensions) {
return;
}
Catalog catalog = cvInfo.getCatalog();
if (catalog == null)
throw new ServiceException("Unable to acquire catalog resource for layer: "
+ layer.getName());
CoverageStoreInfo csinfo = cvInfo.getStore();
if (csinfo == null)
throw new ServiceException("Unable to acquire coverage store resource for layer: "
+ layer.getName());
try {
reader = (GridCoverage2DReader) cvInfo.getGridCoverageReader(null, null);
} catch (Throwable t) {
LOGGER.log(Level.SEVERE, "Unable to acquire a reader for this coverage with format: "
+ csinfo.getFormat().getName(), t);
}
if (reader == null) {
throw new ServiceException("Unable to acquire a reader for this coverage with format: "
+ csinfo.getFormat().getName());
}
ReaderDimensionsAccessor dimensions = new ReaderDimensionsAccessor(reader);
// Process only custom dimensions supported by the reader
if (hasCustomDimensions) {
for (String key : customDimensions.keySet()) {
if (!dimensions.hasDomain(key)) customDimensions.remove(key);
}
}
if (mode == Mode.WMS11) {
String elevUnits = hasElevation ? elevInfo.getUnits() : "";
String elevUnitSymbol = hasElevation ? elevInfo.getUnitSymbol() : "";
declareWMS11Dimensions(hasTime, hasElevation, elevUnits, elevUnitSymbol, customDimensions);
}
// timeDimension
if (hasTime && dimensions.hasTime()) {
handleTimeDimensionRaster(cvInfo, timeInfo, dimensions);
}
// elevationDomain
if (hasElevation && dimensions.hasElevation()) {
handleElevationDimensionRaster(cvInfo, elevInfo, dimensions);
}
// custom dimensions
if (hasCustomDimensions) {
for (String key : customDimensions.keySet()) {
DimensionInfo dimensionInfo = customDimensions.get(key);
handleCustomDimensionRaster(cvInfo, key, dimensionInfo, dimensions);
}
}
}