1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.http.server.glue;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import javax.servlet.Filter;
17 import javax.servlet.http.HttpServlet;
18 import javax.servlet.http.HttpServletResponse;
19
20 import org.eclipse.jgit.http.server.HttpServerText;
21
22 abstract class ServletBinderImpl implements ServletBinder {
23 private final List<Filter> filters;
24
25 private HttpServlet httpServlet;
26
27 ServletBinderImpl() {
28 this.filters = new ArrayList<>();
29 }
30
31
32 @Override
33 public ServletBinder through(Filter filter) {
34 if (filter == null)
35 throw new NullPointerException(HttpServerText.get().filterMustNotBeNull);
36 filters.add(filter);
37 return this;
38 }
39
40
41 @Override
42 public void with(HttpServlet servlet) {
43 if (servlet == null)
44 throw new NullPointerException(HttpServerText.get().servletMustNotBeNull);
45 if (httpServlet != null)
46 throw new IllegalStateException(HttpServerText.get().servletWasAlreadyBound);
47 httpServlet = servlet;
48 }
49
50
51
52
53
54
55 protected HttpServlet getServlet() {
56 if (httpServlet != null) {
57 return httpServlet;
58 }
59 return new ErrorServlet(HttpServletResponse.SC_NOT_FOUND);
60 }
61
62
63
64
65
66
67 protected Filter[] getFilters() {
68 return filters.toArray(new Filter[0]);
69 }
70
71
72 abstract UrlPipeline create();
73 }