public abstract class AbstractClassInfoStrategy extends Object implements ClassInfoStrategy, ClassAttributeApprover
ClassInfoStrategy
This default implementation is based on field introspection.
| Modifier and Type | Field and Description |
|---|---|
private Set<Class<? extends Annotation>> |
excludedAnnotations
Set of annotations, which mark fields to be skipped from populating.
|
private Map<Class<?>,Set<String>> |
excludedFields
Set of fields, which mark fields to be skipped from populating.
|
private Map<Class<?>,List<Method>> |
extraMethods
Set of extra methods to execute.
|
private Pattern |
GETTER_PATTERN |
private static org.slf4j.Logger |
LOG
The application logger.
|
private Pattern |
SETTER_PATTERN |
| Constructor and Description |
|---|
AbstractClassInfoStrategy() |
| Modifier and Type | Method and Description |
|---|---|
AbstractClassInfoStrategy |
addExcludedAnnotation(Class<? extends Annotation> annotation)
Adds the specified
Annotation to set of excluded annotations,
if it is not already present. |
AbstractClassInfoStrategy |
addExcludedField(Class<?> pojoClass,
String fieldName)
Adds the specified field to set of excluded fields,
if it is not already present.
|
AbstractClassInfoStrategy |
addExtraMethod(Class<?> pojoClass,
String methodName,
Class<?>... methodArgs)
It adds an extra method to execute
|
boolean |
approve(ClassAttribute attribute)
Override this method to select or reject class attributes
|
private boolean |
containsAnyAnnotation(Field field,
Set<Class<? extends Annotation>> annotations)
Checks if the given field has any one of the annotations
|
private boolean |
containsAnyAnnotation(Method method,
Set<Class<? extends Annotation>> annotations)
Checks if the given method has any one of the annotations
|
protected String |
extractFieldNameFromMethod(String methodName,
Pattern pattern)
Given a accessor's name, it extracts the field name, according to
JavaBean standards
|
protected void |
findPojoAttributes(Class<?> clazz,
Map<String,ClassAttribute> attributeMap,
Set<Class<? extends Annotation>> excludeAnnotations,
Set<String> excludedFields)
Given a class and a set of class declared fields it returns a map of
setters, getters and fields defined for this class
|
ClassAttributeApprover |
getClassAttributeApprover(Class<?> pojoClass) |
ClassInfo |
getClassInfo(Class<?> pojoClass) |
ClassInfo |
getClassInfo(Class<?> clazz,
Set<Class<? extends Annotation>> excludeFieldAnnotations,
Set<String> excludedFields,
ClassAttributeApprover attributeApprover,
Collection<Method> extraMethods)
It returns a
ClassInfo object for the given class |
Set<Class<? extends Annotation>> |
getExcludedAnnotations()
Identifies
Annotations for fields to be skipped. |
Set<String> |
getExcludedFields(Class<?> pojoClass)
Identifies fields to be skipped.
|
Collection<Method> |
getExtraMethods(Class<?> pojoClass)
It returns the collection of extra methods to execute.
|
protected Pattern |
getGetterPattern()
Defines a regular expression for a getter's name
|
protected Pattern |
getSetterPattern()
Defines a regular expression for a setters name
|
AbstractClassInfoStrategy |
removeExcludedAnnotation(Class<? extends Annotation> annotation)
Removes the specified
Annotation from set of excluded annotations. |
AbstractClassInfoStrategy |
removeExcludedField(Class<?> pojoClass,
String fieldName)
Removes the field name from set of excluded fields.
|
private final Pattern GETTER_PATTERN
private final Pattern SETTER_PATTERN
private static final org.slf4j.Logger LOG
private final Set<Class<? extends Annotation>> excludedAnnotations
private Map<Class<?>,Set<String>> excludedFields
public AbstractClassInfoStrategy addExcludedAnnotation(Class<? extends Annotation> annotation)
Annotation to set of excluded annotations,
if it is not already present.annotation - the annotation to use as an exclusion markpublic AbstractClassInfoStrategy addExtraMethod(Class<?> pojoClass, String methodName, Class<?>... methodArgs) throws NoSuchMethodException, SecurityException
pojoClass - The pojo class where to execute the methodmethodName - name to be scheduled for executionmethodArgs - list of method argumentsSecurityException - If a security exception occurred while retrieving the methodNoSuchMethodException - If pojoClass doesn't declare the required methodpublic AbstractClassInfoStrategy removeExcludedAnnotation(Class<? extends Annotation> annotation)
Annotation from set of excluded annotations.annotation - the annotation used as an exclusion markpublic AbstractClassInfoStrategy addExcludedField(Class<?> pojoClass, String fieldName)
pojoClass - a class for which fields should be skippedfieldName - the field name to use as an exclusion markpublic AbstractClassInfoStrategy removeExcludedField(Class<?> pojoClass, String fieldName)
pojoClass - a class for which fields should be skippedfieldName - the field name used as an exlusion markpublic boolean approve(ClassAttribute attribute)
approve in interface ClassAttributeApproverattribute - class attribute to analyze for further processing or skippingpublic Set<Class<? extends Annotation>> getExcludedAnnotations()
Annotations for fields to be skipped.
Should return set of annotations, which will be treated as notion for
PodamFactory to skip production of these particular fields.
getExcludedAnnotations in interface ClassInfoStrategypublic Set<String> getExcludedFields(Class<?> pojoClass)
Should return set of field names as case-sensitive string, which will
be treated as notion for PodamFactory to skip production of
these particular fields.
getExcludedFields in interface ClassInfoStrategypojoClass - a class for which fields should be skippedpublic ClassInfo getClassInfo(Class<?> pojoClass)
getClassInfo in interface ClassInfoStrategypojoClass - a class to introspect and fetch attributesClassInfopublic ClassAttributeApprover getClassAttributeApprover(Class<?> pojoClass)
getClassAttributeApprover in interface ClassInfoStrategypublic Collection<Method> getExtraMethods(Class<?> pojoClass)
ClassInfoStrategygetExtraMethods in interface ClassInfoStrategypojoClass - The pojo classpublic ClassInfo getClassInfo(Class<?> clazz, Set<Class<? extends Annotation>> excludeFieldAnnotations, Set<String> excludedFields, ClassAttributeApprover attributeApprover, Collection<Method> extraMethods)
ClassInfo object for the given classclazz - The class to retrieve info fromexcludeFieldAnnotations - the fields marked with any of these annotations will not be
included in the class infoexcludedFields - the fields matching the given names will not be included in the class infoattributeApprover - a ClassAttributeApprover implementation,
which defines which attributes to skip and which to processextraMethods - extra methods to call after object initializationClassInfo object for the given classprivate boolean containsAnyAnnotation(Method method, Set<Class<? extends Annotation>> annotations)
method - the method to check forannotations - the set of annotations to look for in the fieldprivate boolean containsAnyAnnotation(Field field, Set<Class<? extends Annotation>> annotations)
field - the field to check forannotations - the set of annotations to look for in the fieldprotected void findPojoAttributes(Class<?> clazz, Map<String,ClassAttribute> attributeMap, Set<Class<? extends Annotation>> excludeAnnotations, Set<String> excludedFields)
protected String extractFieldNameFromMethod(String methodName, Pattern pattern)
This method, given a accessor method's name, it returns the corresponding attribute name. For example: given setIntField the method would return intField. given getIntField the method would return intField; given isBoolField the method would return boolField.The correctness of the return value depends on the adherence to JavaBean standards.
methodName - The accessor method from which the field name is requiredpattern - The pattern to strip from the method nameprotected Pattern getGetterPattern()
protected Pattern getSetterPattern()
Copyright © 2016. All rights reserved.