Search in sources :

Example 1 with Component

use of io.nuls.kernel.lite.annotation.Component in project nuls by nuls-io.

the class SpringLiteContext method checkBeanClass.

/**
 * 检查一个类型,如果这个类型上被注释了我们关心的注解,如:Service/Component/Interceptor,就对这个对象进行加载,并放入bean管理器中
 * Check a type, if this is commented on the type annotation, we care about, such as: (Service/Component/Interceptor), is to load the object, and in the bean manager
 *
 * @param clazz class type
 */
private static void checkBeanClass(Class clazz) {
    Annotation[] anns = clazz.getDeclaredAnnotations();
    if (anns == null || anns.length == 0) {
        return;
    }
    Annotation ann = getFromArray(anns, Service.class);
    String beanName = null;
    boolean aopProxy = false;
    if (null == ann) {
        ann = getFromArray(anns, Component.class);
        if (null != ann) {
            beanName = ((Component) ann).value();
        }
    } else {
        beanName = ((Service) ann).value();
    }
    if (ann != null) {
        if (beanName == null || beanName.trim().length() == 0) {
            beanName = getBeanName(clazz);
        }
        try {
            loadBean(beanName, clazz, aopProxy);
        } catch (NulsException e) {
            Log.error(e);
            return;
        }
    }
    Annotation interceptorAnn = getFromArray(anns, Interceptor.class);
    if (null != interceptorAnn) {
        BeanMethodInterceptor interceptor = null;
        try {
            Constructor constructor = clazz.getDeclaredConstructor();
            interceptor = (BeanMethodInterceptor) constructor.newInstance();
        } catch (Exception e) {
            Log.error(e);
            return;
        }
        BeanMethodInterceptorManager.addBeanMethodInterceptor(((Interceptor) interceptorAnn).value(), interceptor);
    }
}
Also used : NulsException(io.nuls.kernel.exception.NulsException) Constructor(java.lang.reflect.Constructor) BeanMethodInterceptor(io.nuls.kernel.lite.core.interceptor.BeanMethodInterceptor) Component(io.nuls.kernel.lite.annotation.Component) Annotation(java.lang.annotation.Annotation) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException)

Aggregations

NulsException (io.nuls.kernel.exception.NulsException)1 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)1 Component (io.nuls.kernel.lite.annotation.Component)1 BeanMethodInterceptor (io.nuls.kernel.lite.core.interceptor.BeanMethodInterceptor)1 Annotation (java.lang.annotation.Annotation)1 Constructor (java.lang.reflect.Constructor)1