{
MBeanServer server = getMBeanServer();
ObjectName objName = new ObjectName(name);
MBeanInfo info = server.getMBeanInfo(objName);
MBeanAttributeInfo[] attributesInfo = info.getAttributes();
AttributeList newAttributes = new AttributeList();
for(int a = 0; a < attributesInfo.length; a ++)
{
MBeanAttributeInfo attrInfo = attributesInfo[a];
String attrName = attrInfo.getName();
if( attributes.containsKey(attrName) == false )
continue;
String value = (String) attributes.get(attrName);
if (value.equals("null") && server.getAttribute(objName, attrName) == null) {
log.trace("ignoring 'null' for " + attrName);
continue;
}
String attrType = attrInfo.getType();
Attribute attr = null;
try
{
Object realValue = PropertyEditors.convertValue(value, attrType);
attr = new Attribute(attrName, realValue);
}
catch(ClassNotFoundException e)
{
String s = (attr != null) ? attr.getName() : attrType;
log.trace("Failed to load class for attribute: " + s, e);
throw new ReflectionException(e, "Failed to load class for attribute: " + s);
}
catch(IntrospectionException e)
{
log.trace("Skipped setting attribute: " + attrName +
", cannot find PropertyEditor for type: " + attrType);
continue;
}
server.setAttribute(objName, attr);
newAttributes.add(attr);
}
return newAttributes;
}