Java Reflection Annotation getAnnotationFromEntityOrInterface( Class annotationType, Class entity)

Here you can find the source of getAnnotationFromEntityOrInterface( Class annotationType, Class entity)

Description

Given an array and a typed predicate, determines if the array has an object that matches the condition of the predicate.

License

Open Source License

Parameter

Parameter Description
annotationType a parameter
entity a parameter

Return

the annotation of annotationType if it can be found

Declaration

public static Annotation getAnnotationFromEntityOrInterface(
        Class annotationType, Class entity) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .j ava 2  s .com*/
 * #%L
 * BroadleafCommerce Common Libraries
 * %%
 * Copyright (C) 2009 - 2016 Broadleaf Commerce
 * %%
 * Licensed under the Broadleaf Fair Use License Agreement, Version 1.0
 * (the "Fair Use License" located  at http://license.broadleafcommerce.org/fair_use_license-1.0.txt)
 * unless the restrictions on use therein are violated and require payment to Broadleaf in which case
 * the Broadleaf End User License Agreement (EULA), Version 1.1
 * (the "Commercial License" located at http://license.broadleafcommerce.org/commercial_license-1.1.txt)
 * shall apply.
 * 
 * Alternatively, the Commercial License may be replaced with a mutually agreed upon license (the "Custom License")
 * between you and Broadleaf Commerce. You may not use this file except in compliance with the applicable license.
 * #L%
 */

import java.lang.annotation.Annotation;

public class Main {
    /**
     * Given an array and a typed predicate, determines if the array has an object that matches the condition of the
     * predicate. The predicate should evaluate to true when a match occurs.
     * 
     * @param annotationType
     * @param entity
     * @return the annotation of annotationType if it can be found
     */
    public static Annotation getAnnotationFromEntityOrInterface(
            Class annotationType, Class entity) {
        Annotation result = entity.getAnnotation(annotationType);
        if (result == null) {
            for (Class inter : entity.getInterfaces()) {
                result = inter.getAnnotation(annotationType);
                if (result != null) {
                    break;
                }
            }
        }
        return result;
    }
}

Related

  1. getAnnotationFields(Class clazz, Class annotationClass)
  2. getAnnotationForMethodOrContainingClass(Method m, Class annotationType)
  3. getAnnotationForProperty(Class cls, String name, Class anno)
  4. getAnnotationFromAnnotation(Annotation annotation, Class annotationClass)
  5. getAnnotationFromEntityFields(Class entity, Class annotation)
  6. getAnnotationFromField(Object object, Class annotationClass)
  7. getAnnotationFromJoinpointMethod(ProceedingJoinPoint joinpoint, Class annotationClass)
  8. getAnnotationFromStackTrace(Class annotationClass)
  9. getAnnotationFromWeldBean(Object target, Class annotation)