Exemple #1
0
  /**
   * Returns whether the given method is a 'getter' method.
   *
   * @param method a parameterless method that returns a non-void
   * @return the property name
   */
  protected String isGetter(final Method<?> method) {

    String methodName = method.getName();
    String propertyName;

    if (methodName.startsWith(ClassUtils.JAVABEAN_GET_PREFIX)) {
      propertyName = methodName.substring(ClassUtils.JAVABEAN_GET_PREFIX.length());

    } else if (methodName.startsWith(ClassUtils.JAVABEAN_IS_PREFIX)
        && boolean.class.equals(method.getQualifiedReturnType())) {

      // As per section 8.3.2 (Boolean properties) of The JavaBeans API specification, 'is'
      // only applies to boolean (little 'b')

      propertyName = methodName.substring(ClassUtils.JAVABEAN_IS_PREFIX.length());
    } else {
      return null;
    }

    if (!StringUtils.isCapitalized(propertyName)) {
      return null;
    }

    return StringUtils.decapitalize(propertyName);
  }
  /**
   * Returns whether the given method is a 'setter' method.
   *
   * @param method a single-parametered method. May return non-void (ie. for Fluent interfaces)
   * @return the property name
   */
  protected String isSetter(final Method<?> method) {
    String methodName = method.getName();

    if (!methodName.startsWith(ClassUtils.JAVABEAN_SET_PREFIX)) {
      return null;
    }

    String propertyName = methodName.substring(ClassUtils.JAVABEAN_SET_PREFIX.length());

    return StringUtils.decapitalize(propertyName);
  }