* @param object the object
*/
@SuppressWarnings("unchecked")
protected void populateValues(ManagedObjectImpl managedObject, Serializable object)
{
InstanceClassFactory icf = getInstanceClassFactory(object.getClass());
Class moClass;
try
{
moClass = icf.getManagedObjectClass(object);
}
catch(ClassNotFoundException e)
{
throw new IllegalStateException(e);
}
BeanInfo beanInfo = configuration.getBeanInfo(moClass);
Object componentName = null;
Map<String, ManagedProperty> properties = managedObject.getProperties();
if (properties != null && properties.size() > 0)
{
for (ManagedProperty property : properties.values())
{
MetaValue value = icf.getValue(beanInfo, property, object);
if (value != null)
property.setField(Fields.VALUE, value);
/* Need to look for a ManagementObjectID at the property level which
defines the ManagedObject id name from the property value.
*/
Map<String, Annotation> annotations = property.getAnnotations();
if (annotations == null)
continue;
ManagementObjectID id = (ManagementObjectID) annotations.get(ManagementObjectID.class.getName());
if (id != null)
{
if (value == null || value.getMetaType().isSimple() == false)
{
log.warn("Cannot create String name from non-Simple property: "
+property+", value="+value);
continue;
}
SimpleValue svalue = (SimpleValue) value;
String name = "" + svalue.getValue();
managedObject.setName(name);
}
ManagementRuntimeRef runtimeRef = (ManagementRuntimeRef) annotations.get(ManagementRuntimeRef.class.getName());
if (runtimeRef != null)
{
componentName = icf.getComponentName(beanInfo, property, object, value);
// let's try this as well
if (componentName == null && icf != this)
componentName = getComponentName(beanInfo, property, object, value);
}
}
}
if (componentName == null)
componentName = icf.getComponentName(null, null, object, null);
// set it, even if it's null
managedObject.setComponentName(componentName);
}