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

com.github.hammelion.JRamlBootstrap Maven / Gradle / Ivy

Go to download

Jraml helps you build your java implementation of REST API, based on specification, described by raml file.

There is a newer version: 0.3
Show newest version
package com.github.hammelion;

import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.github.hammelion.parsers.RAMLParserFacade;
import com.github.hammelion.processors.ResourceProcessor;
import org.reflections.Reflections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
public class JRamlBootstrap implements ServletContextListener {
    private static final Logger LOG = LoggerFactory.getLogger(JRamlBootstrap.class);

    private final RAMLParserFacade ramlParserFacade;

    private final ResourceProcessor resourceProcessor;

    @Inject
    public JRamlBootstrap(RAMLParserFacade ramlParserFacade, ResourceProcessor resourceProcessor) {
        this.ramlParserFacade = ramlParserFacade;
        this.resourceProcessor = resourceProcessor;
    }

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        Reflections reflections = new Reflections();
        final Set> classes = reflections.getTypesAnnotatedWith(RAMLConfig.class);
        for (Class originalClass : classes) {
            applyConfig(originalClass);
        }
        System.out.println("JRaml was successfully initialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }

    public void applyConfig(Class originalClass) {
        applyConfig(originalClass, ClassLoader.getSystemClassLoader());
    }

    public void applyConfig(Class originalClass, ClassLoader classLoader) {
        try {
            this.resourceProcessor.process(ramlParserFacade, originalClass, classLoader);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy