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

run.facet.agent.java.Frameworks Maven / Gradle / Ivy

package run.facet.agent.java;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class Frameworks {
    private String id = "JAVA~1";
    private String property = "FRAMEWORK~";
    private List frameworks;
    private Map frameworkAnnotationMap;

    private WebRequest webRequest;

    @Autowired
    private Frameworks(WebRequest webRequest) {
        this.webRequest = webRequest;
        fetchFrameworks();
    }

    private void fetchFrameworks() {
        Framework framework = (Framework) webRequest.fetchConfiguration(this.property, this.id,"attribute", Framework.class);
        List frameworks = new ArrayList<>(){{add(framework);}};
        this.frameworks = frameworks;
        this.frameworkAnnotationMap = generateMap(frameworks);
    }
    
    public Map  generateMap(List frameworks) {
        Map frameworkAnnotationMap = new HashMap<>();
        for (Framework framework : frameworks) {
            for (Sensor sensor : framework.getSensors()) {
                for(Annotation annotation : sensor.getAnnotations())
                frameworkAnnotationMap.put(annotation.getClassName(), framework);
            }
        }
        return frameworkAnnotationMap;
    }

    public boolean isFramework(Annotation annotation) {
        return frameworkAnnotationMap.containsKey(annotation.getClassName());
    }

    public boolean isFramework(List annotations) {
        for(Annotation annotation : annotations) {
            if(isFramework(annotation)) {
                return true;
            }
        }
        return false;
    }

    public Framework getFramework(Annotation annotation) {
        return frameworkAnnotationMap.get(annotation.getClassName());
    }

    public Framework getFramework(List annotations) {
        for(Annotation annotation : annotations) {
            if(isFramework(annotation)) {
                return getFramework(annotation);
            }
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy