* Sets the value of the manageable attribute, as specified by the DynamicMBean interface.
* @see #createMBeanAttributeInfo
*/
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, 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.getName().equals(attr.getName()))
{
if (!attr.isWritable()) throw new ReflectionException(new NoSuchMethodException("No setter defined for attribute: " + attribute));
try
{
String signature = attr.getType();
Class cls = Utils.loadClass(resource.getClass().getClassLoader(), signature);
invoke(resource, "set" + attr.getName(), new Class[]{cls}, new Object[]{attribute.getValue()});
return;
}
catch (ClassNotFoundException x)
{
throw new ReflectionException(x);
}
}
}
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}