Class ClassicBeanStyle

  • Direct Known Subclasses:
    ClassicBeanStyleWithOptionalSupport

    public class ClassicBeanStyle
    extends BeanStyle
    A BeanStyle implementation that reflects beans of traditional Java bean style as defined in the Java Bean Specification.

    For each property for a bean you basically have

    • a no-argument getter method starting with "get" and returning the property type
    • a setter method starting with "set", returning void and having one parameter with type of the property
    After the "set" respectively "get" prefix both methods would have the capitalized property name in their name.
    For example a property with name "zipCode" and type String would have following setter and getter: void setZipCode(String c); String getZipCode();

    This bean style also exists with Optional support in ClassicBeanStyleWithOptionalSupport.

    • Constructor Detail

      • ClassicBeanStyle

        protected ClassicBeanStyle()
    • Method Detail

      • isGetterMethod

        public boolean isGetterMethod​(Method method)
        Checks if the given method
        • does not return void
        • has no arguments
        • and has a name that has at least four characters and starts with "get" or "is" for boolean properties
        Specified by:
        isGetterMethod in class BeanStyle
        Parameters:
        method - the Method to test
        Returns:
        true if the method matches the requirements for a getter
        See Also:
        BeanStyle.isGetterMethod(java.lang.reflect.Method)
      • isSetterMethod

        public boolean isSetterMethod​(Method method)
        Checks if the given method
        • returns void
        • has exactly one arguments
        • and has a name that has at least four characters and starts with "set"
        Specified by:
        isSetterMethod in class BeanStyle
        Parameters:
        method - the Method to test
        Returns:
        true if the method matches the requirements for a setter
        See Also:
        BeanStyle.isSetterMethod(java.lang.reflect.Method)
      • hasGetterMethodSignature

        protected boolean hasGetterMethodSignature​(Method method)
      • hasSetterMethodSignature

        protected boolean hasSetterMethodSignature​(Method method)
      • determineFieldTypeFromGetterAndSetter

        public Class<?> determineFieldTypeFromGetterAndSetter​(Class<?> beanType,
                                                              Method getterMethod,
                                                              Method setterMethod)
                                                       throws InvalidIBeanTypeException
        Description copied from class: BeanStyle
        Determines the type of a bean field from given corresponding getter and setter method. Implementations of this method can assume that both given methods have been checked for getter and setter compliance and that both methods match in terms of method names. Implementations need to determine the type of the field and need to check if both getter and setter match to the type. That means that for example not only the given setter should be looked at to find out the field type.
        Specified by:
        determineFieldTypeFromGetterAndSetter in class BeanStyle
        Parameters:
        beanType - the examined bean class
        getterMethod - a method of the beanType that is proven to be a potential getter
        setterMethod - a method of the beanType that is proven to be a potential setter
        Returns:
        the type of the bean field
        Throws:
        InvalidIBeanTypeException - if either the type cannot be determined for any reason or if the concluded types of setter and getter do not match