}
}
private static ObjectName getObjectName(Object obj, String name)
throws MalformedObjectNameException {
MBean resource = obj.getClass().getAnnotation(MBean.class);
if (name != null && name.length() > 0) {
return new ObjectName(name);
} else if (resource.objectName() != null && resource.objectName().length() > 0) {
return new ObjectName(resource.objectName());
} else {
throw new MalformedObjectNameException("Instance " + obj + " of a class "
+ obj.getClass() + " does not have a valid object name");
}
}