Package org.coliper.ibean.beanstyle
Class ClassicBeanStyle
- java.lang.Object
-
- org.coliper.ibean.BeanStyle
-
- org.coliper.ibean.beanstyle.ClassicBeanStyle
-
- Direct Known Subclasses:
ClassicBeanStyleWithOptionalSupport
public class ClassicBeanStyle extends BeanStyle
ABeanStyle
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
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 inClassicBeanStyleWithOptionalSupport
.
-
-
Field Summary
Fields Modifier and Type Field Description static ClassicBeanStyle
INSTANCE
-
Fields inherited from class org.coliper.ibean.BeanStyle
CLASSIC, CLASSIC_WITH_OPTIONAL, MODERN
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ClassicBeanStyle()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
convertGetterNameToFieldName(String getterName)
Cuts off "get" and decapitalizes the first character of the remaining.String
convertSetterNameToFieldName(String setterName)
Cuts off "set" and decapitalizes the first character of the remaining.Class<?>
determineFieldTypeFromGetterAndSetter(Class<?> beanType, Method getterMethod, Method setterMethod)
Determines the type of a bean field from given corresponding getter and setter method.protected boolean
hasGetterMethodSignature(Method method)
protected boolean
hasSetterMethodSignature(Method method)
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 propertiesboolean
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"-
Methods inherited from class org.coliper.ibean.BeanStyle
assertForBeanType, equals, hashCode, isNoParameterInMethod, isOneParameterInMethod
-
-
-
-
Field Detail
-
INSTANCE
public static final ClassicBeanStyle INSTANCE
-
-
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 classBeanStyle
- Parameters:
method
- theMethod
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 classBeanStyle
- Parameters:
method
- theMethod
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)
-
convertGetterNameToFieldName
public String convertGetterNameToFieldName(String getterName)
Cuts off "get" and decapitalizes the first character of the remaining.- Specified by:
convertGetterNameToFieldName
in classBeanStyle
- Parameters:
getterName
- the name of a method that has been identified as a potential getter- Returns:
- the name of the bean field; names are case sensitive
- See Also:
BeanStyle.convertGetterNameToFieldName(java.lang.String)
-
convertSetterNameToFieldName
public String convertSetterNameToFieldName(String setterName)
Cuts off "set" and decapitalizes the first character of the remaining.- Specified by:
convertSetterNameToFieldName
in classBeanStyle
- Parameters:
setterName
- the name of a method that has been identified as a potential setter- Returns:
- the name of the bean field; names are case sensitive
- See Also:
BeanStyle.convertSetterNameToFieldName(java.lang.String)
-
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 classBeanStyle
- Parameters:
beanType
- the examined bean classgetterMethod
- a method of thebeanType
that is proven to be a potential gettersetterMethod
- a method of thebeanType
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
-
-