* Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
* @see #createMBeanAttributeInfo
*/
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException
{
if (attribute == null) throw new AttributeNotFoundException("Attribute " + attribute + " not found");
Object resource = null;
MBeanInfo info = null;
synchronized (this)
{
resource = getResourceOrThis();
info = getMBeanInfo();
}
MBeanAttributeInfo[] attrs = info.getAttributes();
if (attrs == null || attrs.length == 0) throw new AttributeNotFoundException("No attributes defined for this MBean");
for (int i = 0; i < attrs.length; ++i)
{
MBeanAttributeInfo attr = attrs[i];
if (attr == null) continue;
if (attribute.equals(attr.getName()))
{
if (!attr.isReadable()) throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));
// Found, invoke via reflection
String prefix = null;
if (attr.isIs())
prefix = "is";
else
prefix = "get";
try
{
return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
}
catch (InvalidAttributeValueException x)
{
throw new ReflectionException(x);
}
}
}
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}