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

com.greenhat.loader.ClassLoader Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package com.greenhat.loader;



import com.greenhat.Config;
import com.greenhat.ioc.annotation.Bean;
import com.greenhat.ioc.annotation.Controller;
import com.greenhat.ioc.annotation.Service;
import com.greenhat.util.ClassUtil;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

public final class ClassLoader {

    private static final List> CLASS_LIST;

    static {
        String basePackage= Config.APP_BASE_PACKAGE;
        CLASS_LIST = ClassUtil.getClassList(basePackage);
    }

    public static List> getClassList() {
        return CLASS_LIST;
    }

    public static List>  getServiceClasses(){
        List> classes=new ArrayList>();
        for (Class cls:CLASS_LIST){
            if (cls.isAnnotationPresent(Service.class)){
                classes.add(cls);
            }
        }
        return classes;
    }

    public static List>  getControllerClasses(){
        List> classes=new ArrayList>();
        for (Class cls:CLASS_LIST){
            if (cls.isAnnotationPresent(Controller.class)){
                classes.add(cls);
            }
        }
        return classes;
    }

    public static List>  getBeanClasses(){
        List> classes=new ArrayList>();
        for (Class cls:CLASS_LIST){
            if (cls.isAnnotationPresent(Bean.class)){
                classes.add(cls);
            }
        }
        return classes;
    }

    /**
     * 获取包名下某  父类【或接口】  的所有  子类【或实现类】
     * @param superClass
     * @return
     */
    public static List>  getClassListBySuper(Class superClass){
        List> classes=new ArrayList>();
        for (Class cls:CLASS_LIST){
            if (superClass.isAssignableFrom(cls)&&!superClass.equals(cls)){
                classes.add(cls);
            }
        }
        return classes;
    }

    /**
     * 获取应用包名下带有【某注解】的所有类
     * @param annotationClass
     * @return
     */
    public static List>  getClassListByAnnotation(Class annotationClass){
        List> classes=new ArrayList>();
        for (Class cls:CLASS_LIST){
            if (cls.isAnnotationPresent(annotationClass)){
                classes.add(cls);
            }
        }
        return classes;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy