Set<DiscoveredResourceDetails> services = new HashSet<DiscoveredResourceDetails>();
String templates[] = objectNameQueryTemplateOrig.split("\\|");
for (String objectNameQueryTemplate : templates) {
// Get the query template, replacing the parent key variables with the values from the parent configuration
ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(objectNameQueryTemplate,
(this.discoveryContext != null) ? this.discoveryContext.getParentResourceContext()
.getPluginConfiguration() : null);
List<EmsBean> beans = connection.queryBeans(queryUtility.getTranslatedQuery());
if (log.isDebugEnabled()) {
log.debug("Found [" + beans.size() + "] mbeans for query [" + queryUtility.getTranslatedQuery() + "].");
}
for (EmsBean bean : beans) {
if (queryUtility.setMatchedKeyValues(bean.getBeanName().getKeyProperties())) {
// Only use beans that have all the properties we've made variables of
// Don't match beans that have unexpected properties
if (skipUnknownProps
&& queryUtility.isContainsExtraKeyProperties(bean.getBeanName().getKeyProperties().keySet())) {
continue;
}
String resourceKey = bean.getBeanName().getCanonicalName(); // The detected object name
String nameTemplate = (pluginConfiguration.getSimple(PROPERTY_NAME_TEMPLATE) != null) ? pluginConfiguration
.getSimple(PROPERTY_NAME_TEMPLATE).getStringValue() : null;
String descriptionTemplate = (pluginConfiguration.getSimple(PROPERTY_DESCRIPTION_TEMPLATE) != null) ? pluginConfiguration
.getSimple(PROPERTY_DESCRIPTION_TEMPLATE).getStringValue() : null;
String name = resourceKey;
if (nameTemplate != null) {
name = queryUtility.formatMessage(nameTemplate);
}
String description = null;
if (descriptionTemplate != null) {
description = queryUtility.formatMessage(descriptionTemplate);
}
DiscoveredResourceDetails service = new DiscoveredResourceDetails(resourceType, resourceKey, name,
"", description, null, null);
Configuration config = service.getPluginConfiguration();
config.put(new PropertySimple(PROPERTY_OBJECT_NAME, bean.getBeanName().toString()));
Map<String, String> mappedVariableValues = queryUtility.getVariableValues();
for (String key : mappedVariableValues.keySet()) {
config.put(new PropertySimple(key, mappedVariableValues.get(key)));
}
services.add(service);
// Clear out the variables for the next bean detected
queryUtility.resetVariables();
}
}
if (log.isDebugEnabled()) {
log.debug("[" + services.size() + "] services have been added");