public GBeanData findGBeanData(Set<AbstractNameQuery> patterns) throws GBeanNotFoundException {
if (patterns == null) throw new NullPointerException("patterns is null");
Set<GBeanData> result = findGBeanDatas(this, patterns);
if (result.size() > 1) {
throw new GBeanNotFoundException("More than one match to referencePatterns in local configuration", patterns, mapToNames(result));
} else if (result.size() == 1) {
return result.iterator().next();
}
// search all parents
for (Configuration configuration : allServiceParents) {
result.addAll(findGBeanDatas(configuration, patterns));
}
// if we already found a match we have an ambiguous query
if (result.size() > 1) {
List<AbstractName> names = new ArrayList<AbstractName>(result.size());
for (GBeanData gBeanData : result) {
names.add(gBeanData.getAbstractName());
}
throw new GBeanNotFoundException("More than one match to referencePatterns in parent configurations: " + names.toString(), patterns, mapToNames(result));
}
if (result.isEmpty()) {
throw new GBeanNotFoundException("No matches for referencePatterns", patterns, null);
}
return result.iterator().next();
}