All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.quartz.utils.ClassUtils Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.quartz.utils;

import java.lang.annotation.Annotation;

public class ClassUtils {

    
    public static boolean isAnnotationPresent(Class clazz, Class a) {

        if (clazz == null) 
            return false;

        if(clazz.isAnnotationPresent(a))
            return true;
        
        if(isAnnotationPresentOnSuperClasses(clazz, a))
            return true;

        if(isAnnotationPresentOnInterfaces(clazz, a))
            return true;
        
        return false;
    }
    
    private static boolean isAnnotationPresentOnSuperClasses(Class clazz, Class a) {
        
        if (clazz == null) 
            return false;

        Class c = clazz.getSuperclass();
        while(c != null && !c.equals(Object.class)) {
            if( c.isAnnotationPresent(a) )
                return true;
            if(isAnnotationPresentOnInterfaces(c, a))
                return true;
            c = c.getSuperclass();
        }
        
        if(isAnnotationPresentOnInterfaces(clazz.getSuperclass(), a))
            return true;
        
        return false;
    }

    private static boolean isAnnotationPresentOnInterfaces(Class clazz, Class a) {
        
        if (clazz == null) 
            return false;

        for(Class i : clazz.getInterfaces()) {
            if( i.isAnnotationPresent(a) )
                return true;
            if(isAnnotationPresentOnInterfaces(i, a))
                return true;
        }
        
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy