org.jmeterplugins.repository.util.ComponentFinder Maven / Gradle / Ivy
package org.jmeterplugins.repository.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.*;
public class ComponentFinder {
private static final Logger log = LoggerFactory.getLogger(ComponentFinder.class);
private final Class search;
public ComponentFinder(Class cls) {
search = cls;
}
public T findComponentIn(Container container) {
log.debug("Searching in " + container);
for (Component a : container.getComponents()) {
if (search.isAssignableFrom(a.getClass())) {
log.debug("Found " + a);
return (T) a;
}
if (a instanceof Container) {
T res = findComponentIn((Container) a);
if (res != null) {
return res;
}
}
}
return null;
}
}