1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.server.handler;
15
16
17 import java.io.IOException;
18
19 import org.eclipse.jetty.server.Handler;
20 import org.eclipse.jetty.server.HandlerContainer;
21 import org.eclipse.jetty.util.LazyList;
22 import org.eclipse.jetty.util.TypeUtil;
23
24
25
26
27
28
29
30 public abstract class AbstractHandlerContainer extends AbstractHandler implements HandlerContainer
31 {
32
33 public AbstractHandlerContainer()
34 {
35 }
36
37
38 public Handler[] getChildHandlers()
39 {
40 Object list = expandChildren(null,null);
41 return (Handler[])LazyList.toArray(list, Handler.class);
42 }
43
44
45 public Handler[] getChildHandlersByClass(Class<?> byclass)
46 {
47 Object list = expandChildren(null,byclass);
48 return (Handler[])LazyList.toArray(list, byclass);
49 }
50
51
52 public <T extends Handler> T getChildHandlerByClass(Class<T> byclass)
53 {
54
55 Object list = expandChildren(null,byclass);
56 if (list==null)
57 return null;
58 return (T)LazyList.get(list, 0);
59 }
60
61
62 protected Object expandChildren(Object list, Class<?> byClass)
63 {
64 return list;
65 }
66
67
68 protected Object expandHandler(Handler handler, Object list, Class<Handler> byClass)
69 {
70 if (handler==null)
71 return list;
72
73 if (byClass==null || byClass.isAssignableFrom(handler.getClass()))
74 list=LazyList.add(list, handler);
75
76 if (handler instanceof AbstractHandlerContainer)
77 list=((AbstractHandlerContainer)handler).expandChildren(list, byClass);
78 else if (handler instanceof HandlerContainer)
79 {
80 HandlerContainer container = (HandlerContainer)handler;
81 Handler[] handlers=byClass==null?container.getChildHandlers():container.getChildHandlersByClass(byClass);
82 list=LazyList.addArray(list, handlers);
83 }
84
85 return list;
86 }
87
88
89 public void dump(Appendable out,String indent) throws IOException
90 {
91 dumpThis(out);
92 dump(out,indent,TypeUtil.asList(getHandlers()),getBeans());
93 }
94 }