org.pm4j.core.pm.impl
Class AnnotationUtil

java.lang.Object
  extended by org.pm4j.core.pm.impl.AnnotationUtil

public class AnnotationUtil
extends java.lang.Object


Constructor Summary
AnnotationUtil()
           
 
Method Summary
static
<T extends java.lang.annotation.Annotation>
T
findAnnotation(PmObjectBase pm, java.lang.Class<T> annotationClass)
          Just finds an annotation for this class.
static
<T extends java.lang.annotation.Annotation>
T
findAnnotation(PmObjectBase pm, java.lang.Class<T> annotationClass, java.lang.Class<?> parentClass)
          Provides an annotation that is defined for this presentation model class or the field of the parent presentation model class.
static
<A extends java.lang.annotation.Annotation>
A
findAnnotationInClassTree(java.lang.Class<?> classToAnalyze, java.lang.Class<A> annotationClass)
          Searches for an annotation within the inheritance tree of a class.
static PmCacheCfg.CacheMode getCacheModeFromCacheAnnotations(java.lang.String propertyName, java.util.Collection<PmCacheCfg> annotations, PmCacheCfg.CacheMode defaultValue)
          Searches for the first PmCacheCfg.CacheMode property with the given name within from the given annotation set.
The first annotation property that has not the value PmCacheCfg.CacheMode.NOT_SPECIFIED will be returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationUtil

public AnnotationUtil()
Method Detail

findAnnotationInClassTree

public static <A extends java.lang.annotation.Annotation> A findAnnotationInClassTree(java.lang.Class<?> classToAnalyze,
                                                                                      java.lang.Class<A> annotationClass)
Searches for an annotation within the inheritance tree of a class.

TODO: Annotations declared in interfaces are not yet considered.

Type Parameters:
A - The annotation type.
Parameters:
classToAnalyze - In this class or one of its super classes the annotation will be searched.
annotationClass - The runtime class of the annotation.
Returns:
The found annotation or null.

findAnnotation

public static <T extends java.lang.annotation.Annotation> T findAnnotation(PmObjectBase pm,
                                                                           java.lang.Class<T> annotationClass)
Just finds an annotation for this class.

Subclasses provide different implementations e.g. to find annotations that are attached to a matching field declaration of the parent model.

Type Parameters:
T - The annotation type.
Parameters:
annotationClass - The annotation class to find.
Returns:
The annotation instance of null when not found.

findAnnotation

public static <T extends java.lang.annotation.Annotation> T findAnnotation(PmObjectBase pm,
                                                                           java.lang.Class<T> annotationClass,
                                                                           java.lang.Class<?> parentClass)
Provides an annotation that is defined for this presentation model class or the field of the parent presentation model class.

Type Parameters:
T - The annotation type.
Parameters:
annotationClass - The annotation class to find.
parentClass - The class the contains this presentation model. E.g. the element PM class for an attribute PM class.
Returns:
The annotation instance of null when not found.

getCacheModeFromCacheAnnotations

public static PmCacheCfg.CacheMode getCacheModeFromCacheAnnotations(java.lang.String propertyName,
                                                                    java.util.Collection<PmCacheCfg> annotations,
                                                                    PmCacheCfg.CacheMode defaultValue)
Searches for the first PmCacheCfg.CacheMode property with the given name within from the given annotation set.
The first annotation property that has not the value PmCacheCfg.CacheMode.NOT_SPECIFIED will be returned. When there is no match, the provided default will be returned.

Parameters:
propertyName - name of the PmCacheCfg.CacheMode property to handle. E.g. 'all' or 'title'.
annotations - the set of found found PmCacheCfg.CacheMode annotations to analyze.
defaultValue - the default value to be used in case of not finding a non-default definition.
Returns:
The first found annotation value for the given property or the specified default.