Class AbstractClassInfoStrategy

    • Field Detail

      • GETTER_PATTERN

        private final Pattern GETTER_PATTERN
      • SETTER_PATTERN

        private final Pattern SETTER_PATTERN
      • LOG

        private static final org.slf4j.Logger LOG
        The application logger.
      • excludedAnnotations

        private final Set<Class<? extends Annotation>> excludedAnnotations
        Set of annotations, which mark fields to be skipped from populating.
      • excludedFields

        private Map<Class<?>,​Set<String>> excludedFields
        Set of fields, which mark fields to be skipped from populating.
      • extraMethods

        private final Map<Class<?>,​List<Method>> extraMethods
        Set of extra methods to execute.
        Since:
        5.3.0
    • Constructor Detail

      • AbstractClassInfoStrategy

        public AbstractClassInfoStrategy()
    • Method Detail

      • addExcludedAnnotation

        public AbstractClassInfoStrategy addExcludedAnnotation​(Class<? extends Annotation> annotation)
        Adds the specified Annotation to set of excluded annotations, if it is not already present.
        Parameters:
        annotation - the annotation to use as an exclusion mark
        Returns:
        itself
      • removeExcludedAnnotation

        public AbstractClassInfoStrategy removeExcludedAnnotation​(Class<? extends Annotation> annotation)
        Removes the specified Annotation from set of excluded annotations.
        Parameters:
        annotation - the annotation used as an exclusion mark
        Returns:
        itself
      • addExcludedField

        public AbstractClassInfoStrategy addExcludedField​(Class<?> pojoClass,
                                                          String fieldName)
        Adds the specified field to set of excluded fields, if it is not already present.
        Parameters:
        pojoClass - a class for which fields should be skipped
        fieldName - the field name to use as an exclusion mark
        Returns:
        itself
      • removeExcludedField

        public AbstractClassInfoStrategy removeExcludedField​(Class<?> pojoClass,
                                                             String fieldName)
        Removes the field name from set of excluded fields.
        Parameters:
        pojoClass - a class for which fields should be skipped
        fieldName - the field name used as an exlusion mark
        Returns:
        itself
      • approve

        public boolean approve​(ClassAttribute attribute)
        Override this method to select or reject class attributes
        Specified by:
        approve in interface ClassAttributeApprover
        Parameters:
        attribute - class attribute to analyze for further processing or skipping
        Returns:
        true, if attribute should be kept, false, if it should be skipped
      • getExcludedAnnotations

        public Set<Class<? extends Annotation>> getExcludedAnnotations()
        Identifies 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.

        Specified by:
        getExcludedAnnotations in interface ClassInfoStrategy
        Returns:
        set of annotations, which mark fields to be skipped from populating.
      • getExcludedFields

        public Set<String> getExcludedFields​(Class<?> pojoClass)
        Identifies fields to be skipped.

        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.

        Specified by:
        getExcludedFields in interface ClassInfoStrategy
        Parameters:
        pojoClass - a class for which fields should be skipped
        Returns:
        set of field name, which mark fields to be skipped from populating.
      • getClassInfo

        public 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
        Parameters:
        clazz - The class to retrieve info from
        excludeFieldAnnotations - the fields marked with any of these annotations will not be included in the class info
        excludedFields - the fields matching the given names will not be included in the class info
        attributeApprover - a ClassAttributeApprover implementation, which defines which attributes to skip and which to process
        extraMethods - extra methods to call after object initialization
        Returns:
        a ClassInfo object for the given class
      • containsAnyAnnotation

        private boolean containsAnyAnnotation​(Method method,
                                              Set<Class<? extends Annotation>> annotations)
        Checks if the given method has any one of the annotations
        Parameters:
        method - the method to check for
        annotations - the set of annotations to look for in the field
        Returns:
        true if the field is marked with any of the given annotations
      • containsAnyAnnotation

        private boolean containsAnyAnnotation​(Field field,
                                              Set<Class<? extends Annotation>> annotations)
        Checks if the given field has any one of the annotations
        Parameters:
        field - the field to check for
        annotations - the set of annotations to look for in the field
        Returns:
        true if the field is marked with any of the given annotations
      • findPojoAttributes

        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
        Parameters:
        clazz - The class to analyze for setters
        attributeMap - The Map which will be filled with class' attributes
        excludeAnnotations - The Set containing annotations marking fields to be excluded
        excludedFields - The Set containing field names to be excluded
      • extractFieldNameFromMethod

        protected String extractFieldNameFromMethod​(String methodName,
                                                    Pattern pattern)
        Given a accessor's name, it extracts the field name, according to JavaBean standards

        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.

        Parameters:
        methodName - The accessor method from which the field name is required
        pattern - The pattern to strip from the method name
        Returns:
        The field name corresponding to the setter
      • getGetterPattern

        protected Pattern getGetterPattern()
        Defines a regular expression for a getter's name
        Returns:
        a compiled pattern for the getter's name
      • getSetterPattern

        protected Pattern getSetterPattern()
        Defines a regular expression for a setters name
        Returns:
        a compiled pattern for the setter's name