io.github.factoryfx.jetty.builder.ServletBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jettyFactory Show documentation
Show all versions of jettyFactory Show documentation
factoryfx dependency injection framework
The 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 extends Servlet, R> servlet;
private final FactoryTemplateId> templateId;
public ServletBuilder(FactoryTemplateId> templateId, String pathSpec, FactoryBase extends Servlet, R> servlet) {
this.pathSpec = pathSpec;
this.servlet = servlet;
this.templateId = templateId;
}
void build(FactoryTreeBuilder,R> 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;
}
}