private AttributeInfo(ManagedAttribute attribute, Method getter) { String name = attribute.name(); if ("".equals(name)) name = toAttributeName(getter.getName()); _name = name; _getter = getter; boolean readOnly = attribute.readonly(); _setter = readOnly ? null : findSetter(attribute, getter, name); _proxied = attribute.proxied(); Class<?> returnType = getter.getReturnType(); _convert = isManagedObject(returnType); String signature = _convert ? returnType.isArray() ? ObjectName[].class.getName() : ObjectName.class.getName() : returnType.getName(); String description = attribute.value(); _info = new MBeanAttributeInfo(name, signature, description, true, _setter != null, getter.getName().startsWith("is")); }
void setAttribute(Attribute attribute, ObjectMBean mbean) throws AttributeNotFoundException, ReflectionException, MBeanException { if (attribute == null) return; String name = attribute.getName(); AttributeInfo info = findAttribute(name); if (info == null) throw new AttributeNotFoundException(name); info.setAttribute(attribute.getValue(), mbean); }
private void parseMethods(Class<?>... classes) { for (Class<?> klass : classes) { // Only work on the public method of the class, not of the hierarchy. for (Method method : klass.getDeclaredMethods()) { if (!Modifier.isPublic(method.getModifiers())) continue; ManagedAttribute attribute = method.getAnnotation(ManagedAttribute.class); if (attribute != null) { AttributeInfo info = new AttributeInfo(attribute, method); if (LOG.isDebugEnabled()) LOG.debug("Found attribute {} for {}: {}", info._name, klass.getName(), info); _attributes.put(info._name, info); } ManagedOperation operation = method.getAnnotation(ManagedOperation.class); if (operation != null) { OperationInfo info = new OperationInfo(operation, method); if (LOG.isDebugEnabled()) LOG.debug("Found operation {} for {}: {}", info._name, klass.getName(), info); _operations.put(info._name, info); } } } }
Object getAttribute(String name, ObjectMBean mbean) throws AttributeNotFoundException, ReflectionException, MBeanException { AttributeInfo info = findAttribute(name); if (info == null) throw new AttributeNotFoundException(name); return info.getAttribute(mbean); }