Skip to content

Commit

Permalink
Better target-env filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Staub committed Jun 26, 2012
1 parent 8698345 commit ca0ed6a
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java
Expand Up @@ -84,31 +84,37 @@ public static Configuration filterEnvironment(Configuration repoConfigElement, S
elements = new LinkedList<MutableConfiguration>();
elementsMap.put(name, elements);
}

elements.add(child);
}

for(Map.Entry<String, Queue<MutableConfiguration>> entry : elementsMap.entrySet()) {
// Look at every element we found
Queue<MutableConfiguration> elements = entry.getValue();
int count = elements.size();
boolean needsFiltering = false;

for(MutableConfiguration child : elements) {
try {
String env = child.getAttribute("target-environment");

if(!targetEnvironment.equals(env)) {
// Target env does not match - remove this child.
current.removeChild(child);
}
child.getAttribute("target-environment");
needsFiltering = true;
} catch(ConfigurationException e) {
// No target environment set - keep child, but only
// if there are no others.
if(count > 1 && !"".equals(targetEnvironment)) {
current.removeChild(child);
}
// No target-environment attribute: Exception is
// thrown if attribute is not set.
}
}

if(needsFiltering) {
for(MutableConfiguration child : elements) {
try {
String env = child.getAttribute("target-environment");
if(!targetEnvironment.equals(env)) {
current.removeChild(child);
}
} catch(ConfigurationException e) {
current.removeChild(child);
}
}
}
}

// All remaining children are now root elements
Expand Down

0 comments on commit ca0ed6a

Please sign in to comment.