LinkedList<String> layerNameList = new LinkedList<String>();
// First we collect all the layers that use this style
Iterator<LayerInfo> liter = cat.getLayers().iterator();
while(liter.hasNext()) {
LayerInfo li = liter.next();
if(li.getDefaultStyle().getName().equals(styleName)) {
String prefixedName = li.getResource().getPrefixedName();
layerNameList.add(prefixedName);
cleanser.deleteLayer(prefixedName);
}
}
// Now we check for layer groups that are affected
Iterator<LayerGroupInfo> lgiter = cat.getLayerGroups().iterator();
while(lgiter.hasNext()) {
LayerGroupInfo lgi = lgiter.next();
boolean truncate = false;
// First we check for referenced to affected layers
liter = lgi.getLayers().iterator();
while(! truncate && liter.hasNext()) {
LayerInfo li = liter.next();
if(layerNameList.contains(li.getResource().getPrefixedName())){
truncate = true;
}
}
// Finally we need to check whether the style is used explicitly
if(! truncate) {
Iterator<StyleInfo> siiter = lgi.getStyles().iterator();
while(! truncate && siiter.hasNext()) {
StyleInfo si2 = siiter.next();
if(si2 != null && si2.getName().equals(si.getName())) {
truncate = true;
}
}
}
if(truncate) {
cleanser.deleteLayer(lgi.getName());
}
// Next layer group
}
} else {
WMSLayer wmsLayer = null; //getLayer(obj);
if(obj instanceof LayerInfo) {
LayerInfo li = (LayerInfo) obj;
wmsLayer = getLayer(li);
} else
if(obj instanceof LayerGroupInfo) {
LayerGroupInfo lgInfo = (LayerGroupInfo) obj;
wmsLayer = getLayer(lgInfo);