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

com.weisiliang.formui.util.FormUiSpringUtils Maven / Gradle / Ivy

The newest version!
package com.weisiliang.formui.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class FormUiSpringUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    private static Map beansWithFormUiAnnotationMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContextParam) throws BeansException {
        applicationContext=applicationContextParam;
    }
    public static Object getObject(String id) {
        Object object = null;
        object = applicationContext.getBean(id);
        return object;
    }
    public static  T getObject(Class tClass) {
        return applicationContext.getBean(tClass);
    }

    public static Object getBean(String tClass) {
        return applicationContext.getBean(tClass);
    }

    public static  T getBean(Class tClass) {
        return applicationContext.getBean(tClass);
    }

//    public static Object getFormUiColumn(String beanName){
//        if(beansWithFormUiAnnotationMap==null){
//            beansWithFormUiAnnotationMap = applicationContext.getBeansWithAnnotation(FormUiBean.class);
//        }
//        return beansWithFormUiAnnotationMap.get(beanName);
////        return obj;
//    }

//    public static Class getFormUiColumn(String beanName){
//        if(beansWithFormUiAnnotationMap==null){
//            beansWithFormUiAnnotationMap=new HashMap<>();
//            List> list=new ArrayList<>();
//            list.add(FormUiBean.class);
//
//
//            String pkgName = "com";
//            String pkgPath = AnnotationScannerUtils.getPkgPath(pkgName);
//
//            pkgName="";
//
//            Map, Set>> map= AnnotationScannerUtils.scanClassesByAnnotations(pkgName,pkgPath,true,list);
//
//            for(Map.Entry, Set>> entry : map.entrySet()){
////                Class mapKey = entry.getKey();
//                Set> setClass = entry.getValue();
////                System.out.println(mapKey+":"+mapValue);
//                for(Class cc:setClass){
//                    FormUiBean formUiBean=  cc.getDeclaredAnnotation(FormUiBean.class);
//                    beansWithFormUiAnnotationMap.put(formUiBean.value(),cc);
//                }
//            }
////            map.values();
////            beansWithFormUiAnnotationMap = applicationContext.getBeansWithAnnotation(FormUiBean.class);
//        }
//        return beansWithFormUiAnnotationMap.get(beanName);
////        return obj;
//    }

//    public static void main(String[] args){
//        Object ooo=  getFormUiColumn("demoQuery");
//        ooo=ooo;
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy