try {
StyleFactory factory = CommonFactoryFinder.getStyleFactory(null);
List<StyledLayer> layers = new ArrayList<StyledLayer>();
for (String layerName : request.getLayers()) {
NamedLayer namedLayer = factory.createNamedLayer();
layers.add(namedLayer);
namedLayer.setName(layerName);
LayerGroupInfo group = wms.getLayerGroupByName(layerName);
LayerInfo layer = wms.getLayerByName(layerName);
if (group != null) {
// nothing to do, groups have no style
} else if (layer != null) {
Style style = layer.getDefaultStyle().getStyle();
// add the default style first
style = cloneStyle(style);
style.setDefault(true);
style.setName(layer.getDefaultStyle().getName());
namedLayer.styles().add(style);
// add alternate styles
for (StyleInfo si : layer.getStyles()) {
style = cloneStyle(si.getStyle());
style.setName(si.getName());
namedLayer.styles().add(style);
}
} else {
// we should really add a code and a locator...
throw new ServiceException("Unknown layer " + layerName);
}