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

io.github.factoryfx.jetty.builder.ServletBuilder Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.github.factoryfx.jetty.builder;

import io.github.factoryfx.factory.FactoryBase;
import io.github.factoryfx.factory.builder.FactoryTemplateId;
import io.github.factoryfx.factory.builder.FactoryTreeBuilder;
import io.github.factoryfx.factory.builder.Scope;
import io.github.factoryfx.jetty.ServletAndPathFactory;
import jakarta.servlet.Servlet;

/**
 * builder for a servlet. used internal in {@link JettyServerBuilder#withServlet(FactoryTemplateId, String, FactoryBase)}
 * @param  rootFactory
 */
public class ServletBuilder>{
    private final String pathSpec;
    private final FactoryBase servlet;
    private final FactoryTemplateId> templateId;

    public ServletBuilder(FactoryTemplateId> templateId, String pathSpec, FactoryBase servlet) {
        this.pathSpec = pathSpec;
        this.servlet = servlet;
        this.templateId = templateId;
    }

    void build(FactoryTreeBuilder builder){
        builder.removeFactory(templateId);
        builder.addFactory(templateId, Scope.PROTOTYPE , (ctx)->{
            ServletAndPathFactory servletAndPathFactory = new ServletAndPathFactory<>();
            servletAndPathFactory.pathSpec.set(pathSpec);
            servletAndPathFactory.servlet.set(servlet);
            return servletAndPathFactory;
        });
    }

    FactoryTemplateId> getTemplateId() {
        return this.templateId;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy