}
public static Configuration convertManagedObjectToConfiguration(
Map<String, ManagedProperty> managedProperties,
Map<String, PropertySimple> customProps, ResourceType resourceType) {
Configuration config = new Configuration();
ConfigurationDefinition configDef = resourceType
.getResourceConfigurationDefinition();
Map<String, PropertyDefinition> propDefs = configDef
.getPropertyDefinitions();
Set<String> propNames = managedProperties.keySet();
for (String propName : propNames) {
PropertyDefinition propertyDefinition = propDefs.get(propName);
ManagedProperty managedProperty = managedProperties.get(propName);
if (propertyDefinition == null) {
if (!managedProperty.hasViewUse(ViewUse.STATISTIC))
LOG
.debug(resourceType
+ " does not define a property corresponding to ManagedProperty '" //$NON-NLS-1$
+ propName + "'."); //$NON-NLS-1$
continue;
}
if (managedProperty == null) {
// This should never happen, but don't let it blow us up.
LOG.error("ManagedProperty '" + propName //$NON-NLS-1$
+ "' has a null value in the ManagedProperties Map."); //$NON-NLS-1$
continue;
}
MetaValue metaValue = managedProperty.getValue();
if (managedProperty.isRemoved() || metaValue == null) {
// Don't even add a Property to the Configuration if the
// ManagedProperty is flagged as removed or has a
// null value.
continue;
}
PropertySimple customProp = customProps.get(propName);
PropertyAdapter<Property, PropertyDefinition> propertyAdapter = PropertyAdapterFactory
.getCustomPropertyAdapter(customProp);
if (propertyAdapter == null)
propertyAdapter = PropertyAdapterFactory
.getPropertyAdapter(metaValue);
if (propertyAdapter == null) {
LOG
.error("Unable to find a PropertyAdapter for ManagedProperty '" //$NON-NLS-1$
+ propName
+ "' with MetaType [" //$NON-NLS-1$
+ metaValue.getMetaType()
+ "] for ResourceType '" //$NON-NLS-1$
+ resourceType.getName() + "'."); //$NON-NLS-1$
continue;
}
Property property = propertyAdapter.convertToProperty(metaValue,
propertyDefinition);
config.put(property);
}
return config;
}