public static void convertSubTree(HashTree tree) {
Iterator<Object> iter = new LinkedList<Object>(tree.list()).iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof TestElement) {
TestElement item = (TestElement) o;
if (item.isEnabled()) {
if (item instanceof ReplaceableController) {
ReplaceableController rc;
// TODO this bit of code needs to be tidied up
// Unfortunately ModuleController is in components, not core
if (item.getClass().getName().equals("org.apache.jmeter.control.ModuleController")){ // Bug 47165
rc = (ReplaceableController) item;
} else {
// HACK: force the controller to load its tree
rc = (ReplaceableController) item.clone();
}
HashTree subTree = tree.getTree(item);
if (subTree != null) {
HashTree replacementTree = rc.getReplacementSubTree();
if (replacementTree != null) {
convertSubTree(replacementTree);
tree.replace(item, rc);
tree.set(rc, replacementTree);
}
} else { // null subTree
convertSubTree(tree.getTree(item));
}
} else { // not Replaceable Controller
convertSubTree(tree.getTree(item));
}
} else { // Not enabled
tree.remove(item);
}
} else { // Not a TestElement
JMeterTreeNode item = (JMeterTreeNode) o;
if (item.isEnabled()) {
// Replacement only needs to occur when starting the engine
// @see StandardJMeterEngine.run()
if (item.getUserObject() instanceof ReplaceableController) {
ReplaceableController rc =
(ReplaceableController) item.getTestElement();
HashTree subTree = tree.getTree(item);
if (subTree != null) {
HashTree replacementTree = rc.getReplacementSubTree();
if (replacementTree != null) {
convertSubTree(replacementTree);
tree.replace(item, rc);
tree.set(rc, replacementTree);
}
}
} else { // Not a ReplaceableController
convertSubTree(tree.getTree(item));
TestElement testElement = item.getTestElement();
tree.replace(item, testElement);
}
} else { // Not enabled
tree.remove(item);
}