Package es.internna.framework.utils

Source Code of es.internna.framework.utils.ClassUtils

package es.internna.framework.utils;

import java.lang.annotation.Annotation;
import org.springframework.aop.framework.Advised;

public class ClassUtils
{
    public final static Class<?> getTargetClass (Object bean) {
        Class clazz = null;
        if (bean != null) {
            if (Advised.class.isInstance(bean)) {
                Advised advised = (Advised) bean;
                clazz = advised.getTargetSource().getTargetClass();
            } else clazz = bean.getClass();
        }
        return clazz;
    }
   
    public final static <A extends Annotation> A getAnnotation(Class<A> annotationClass, Object bean) {
        A annotation = null;
        if ((annotationClass != null) & (bean != null)) {
            Class<?> clazz = getTargetClass(bean);
            if (clazz.isAnnotationPresent(annotationClass)) annotation = clazz.getAnnotation(annotationClass);
        }
        return annotation;
    }
}
TOP

Related Classes of es.internna.framework.utils.ClassUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.