/**
   * Adds descriptor fields from the <code>ManagedAttribute</code> attribute to the attribute
   * descriptor. Specifically, adds the <code>currencyTimeLimit</code>, <code>default</code>, <code>
   * persistPolicy</code> and <code>persistPeriod</code> descriptor fields if they are present in
   * the metadata.
   */
  protected void populateAttributeDescriptor(
      Descriptor desc, Method getter, Method setter, String beanKey) {
    ManagedAttribute gma =
        (getter == null)
            ? ManagedAttribute.EMPTY
            : this.attributeSource.getManagedAttribute(getter);
    ManagedAttribute sma =
        (setter == null)
            ? ManagedAttribute.EMPTY
            : this.attributeSource.getManagedAttribute(setter);

    applyCurrencyTimeLimit(
        desc, resolveIntDescriptor(gma.getCurrencyTimeLimit(), sma.getCurrencyTimeLimit()));

    Object defaultValue = resolveObjectDescriptor(gma.getDefaultValue(), sma.getDefaultValue());
    desc.setField(FIELD_DEFAULT, defaultValue);

    String persistPolicy = resolveStringDescriptor(gma.getPersistPolicy(), sma.getPersistPolicy());
    if (StringUtils.hasLength(persistPolicy)) {
      desc.setField(FIELD_PERSIST_POLICY, persistPolicy);
    }
    int persistPeriod = resolveIntDescriptor(gma.getPersistPeriod(), sma.getPersistPeriod());
    if (persistPeriod >= 0) {
      desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(persistPeriod));
    }
  }
 @Override
 public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException {
   org.springframework.jmx.export.annotation.ManagedAttribute ann =
       AnnotationUtils.findAnnotation(
           method, org.springframework.jmx.export.annotation.ManagedAttribute.class);
   if (ann == null) {
     return null;
   }
   ManagedAttribute managedAttribute = new ManagedAttribute();
   AnnotationBeanUtils.copyPropertiesToBean(ann, managedAttribute, "defaultValue");
   if (ann.defaultValue().length() > 0) {
     managedAttribute.setDefaultValue(ann.defaultValue());
   }
   return managedAttribute;
 }
 /**
  * Retrieves the description for the supplied <code>Method</code> from the metadata. Uses the
  * method name is no description is present in the metadata.
  */
 protected String getOperationDescription(Method method, String beanKey) {
   PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
   if (pd != null) {
     ManagedAttribute ma = this.attributeSource.getManagedAttribute(method);
     if (ma != null && StringUtils.hasText(ma.getDescription())) {
       return ma.getDescription();
     }
     return method.getName();
   } else {
     ManagedOperation mo = this.attributeSource.getManagedOperation(method);
     if (mo != null && StringUtils.hasText(mo.getDescription())) {
       return mo.getDescription();
     }
     return method.getName();
   }
 }
  /**
   * Creates a description for the attribute corresponding to this property descriptor. Attempts to
   * create the description using metadata from either the getter or setter attributes, otherwise
   * uses the property name.
   */
  protected String getAttributeDescription(PropertyDescriptor propertyDescriptor, String beanKey) {
    Method readMethod = propertyDescriptor.getReadMethod();
    Method writeMethod = propertyDescriptor.getWriteMethod();

    ManagedAttribute getter =
        (readMethod != null) ? this.attributeSource.getManagedAttribute(readMethod) : null;
    ManagedAttribute setter =
        (writeMethod != null) ? this.attributeSource.getManagedAttribute(writeMethod) : null;

    if (getter != null && StringUtils.hasText(getter.getDescription())) {
      return getter.getDescription();
    } else if (setter != null && StringUtils.hasText(setter.getDescription())) {
      return setter.getDescription();
    }
    return propertyDescriptor.getDisplayName();
  }