* @return the meta value
*/
public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property, Serializable object)
{
String name = getPropertyName(property);
PropertyInfo propertyInfo = beanInfo.getProperty(name);
Object value;
try
{
value = propertyInfo.get(object);
}
catch (RuntimeException e)
{
throw e;
}
catch (Error e)
{
throw e;
}
catch (Throwable t)
{
throw new RuntimeException("Error getting property " + name + " for " + object.getClass().getName(), t);
}
if (value == null)
return null;
MetaType propertyType = property.getMetaType();
if (MANAGED_OBJECT_META_TYPE == propertyType)
{
if (value instanceof Serializable == false)
throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
// Look for a ManagementObjectRef
ManagementObjectRef ref = (ManagementObjectRef) property.getAnnotations().get(ManagementObjectRef.class.getName());
String moName = (ref != null ? ref.name() : value.getClass().getName());
String moNameType = (ref != null ? ref.type() : "");
ManagedObject mo = initManagedObject((Serializable) value, moName, moNameType);
return new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo);
}
else if (propertyType.isArray())
{
ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
if (MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
{
Collection cvalue = getAsCollection(value);
// todo - AJ: changed some generics by best guess
ArrayMetaType<GenericValueSupport> moType = new ArrayMetaType<GenericValueSupport>(1, MANAGED_OBJECT_META_TYPE);
ArrayValueSupport<GenericValueSupport> moArrayValue = new ArrayValueSupport<GenericValueSupport>(moType);
ArrayList<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
for(Object element : cvalue)
{
ManagedObject mo = initManagedObject((Serializable) element, null, null);
tmp.add(new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo));
}
GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
tmp.toArray(mos);
moArrayValue.setValue(mos);
return moArrayValue;
}
}
return metaValueFactory.create(value, propertyInfo.getType());
}