comparison src/org/eclipse/jetty/server/handler/HandlerWrapper.java @ 993:d9d95acded81

remove ScopedHandler
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 18 Oct 2016 15:54:54 -0600
parents 22a4e93ed20e
children 32d4b569567c
comparison
equal deleted inserted replaced
992:0608a6664bee 993:d9d95acded81
34 * {@link LifeCycle life cycle} events to a delegate. This is primarily used to implement the <i>Decorator</i> pattern. 34 * {@link LifeCycle life cycle} events to a delegate. This is primarily used to implement the <i>Decorator</i> pattern.
35 * 35 *
36 */ 36 */
37 public class HandlerWrapper extends AbstractHandlerContainer 37 public class HandlerWrapper extends AbstractHandlerContainer
38 { 38 {
39 protected Handler _handler; 39 protected Handler _handler;
40 40
41 /* ------------------------------------------------------------ */ 41 /* ------------------------------------------------------------ */
42 /** 42 /**
43 * 43 *
44 */ 44 */
45 public HandlerWrapper() 45 public HandlerWrapper()
46 { 46 {
47 } 47 }
48 48
49 /* ------------------------------------------------------------ */ 49 /* ------------------------------------------------------------ */
50 /** 50 /**
51 * @return Returns the handlers. 51 * @return Returns the handlers.
52 */ 52 */
53 public Handler getHandler() 53 public Handler getHandler()
54 { 54 {
55 return _handler; 55 return _handler;
56 } 56 }
57 57
58 /* ------------------------------------------------------------ */ 58 /* ------------------------------------------------------------ */
59 /** 59 /**
60 * @return Returns the handlers. 60 * @return Returns the handlers.
61 */ 61 */
62 public Handler[] getHandlers() 62 public Handler[] getHandlers()
63 { 63 {
64 if (_handler==null) 64 if (_handler==null)
65 return new Handler[0]; 65 return new Handler[0];
66 return new Handler[] {_handler}; 66 return new Handler[] {_handler};
67 } 67 }
68 68
69 /* ------------------------------------------------------------ */ 69 /* ------------------------------------------------------------ */
70 /** 70 /**
71 * @param handler Set the {@link Handler} which should be wrapped. 71 * @param handler Set the {@link Handler} which should be wrapped.
72 */ 72 */
73 public void setHandler(Handler handler) 73 public void setHandler(Handler handler)
74 { 74 {
75 if (isStarted()) 75 if (isStarted())
76 throw new IllegalStateException(STARTED); 76 throw new IllegalStateException(STARTED);
77 77
78 Handler old_handler = _handler; 78 Handler old_handler = _handler;
79 _handler = handler; 79 _handler = handler;
80 if (handler!=null) 80 if (handler!=null)
81 handler.setServer(getServer()); 81 handler.setServer(getServer());
82 } 82 }
83 83
84 /* ------------------------------------------------------------ */ 84 /* ------------------------------------------------------------ */
85 /* 85 /*
86 * @see org.eclipse.thread.AbstractLifeCycle#doStart() 86 * @see org.eclipse.thread.AbstractLifeCycle#doStart()
87 */ 87 */
88 @Override 88 @Override
89 protected void doStart() throws Exception 89 protected void doStart() throws Exception
90 { 90 {
91 if (_handler!=null) 91 if (_handler!=null)
92 _handler.start(); 92 _handler.start();
93 super.doStart(); 93 super.doStart();
94 } 94 }
95 95
96 /* ------------------------------------------------------------ */ 96 /* ------------------------------------------------------------ */
97 /* 97 /*
98 * @see org.eclipse.thread.AbstractLifeCycle#doStop() 98 * @see org.eclipse.thread.AbstractLifeCycle#doStop()
99 */ 99 */
100 @Override 100 @Override
101 protected void doStop() throws Exception 101 protected void doStop() throws Exception
102 { 102 {
103 if (_handler!=null) 103 if (_handler!=null)
104 _handler.stop(); 104 _handler.stop();
105 super.doStop(); 105 super.doStop();
106 } 106 }
107 107
108 /* ------------------------------------------------------------ */ 108 /* ------------------------------------------------------------ */
109 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException 109 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
110 { 110 {
111 if (_handler!=null && isStarted()) 111 if (_handler!=null && isStarted())
112 { 112 {
113 _handler.handle(target,baseRequest, request, response); 113 _handler.handle(target,baseRequest, request, response);
114 } 114 }
115 } 115 }
116 116
117 117
118 /* ------------------------------------------------------------ */ 118 /* ------------------------------------------------------------ */
119 @Override 119 @Override
120 public void setServer(Server server) 120 public void setServer(Server server)
121 { 121 {
122 Server old_server=getServer(); 122 Server old_server=getServer();
123 if (server==old_server) 123 if (server==old_server)
124 return; 124 return;
125 125
126 if (isStarted()) 126 if (isStarted())
127 throw new IllegalStateException(STARTED); 127 throw new IllegalStateException(STARTED);
128 128
129 super.setServer(server); 129 super.setServer(server);
130 130
131 Handler h=getHandler(); 131 Handler h=getHandler();
132 if (h!=null) 132 if (h!=null)
133 h.setServer(server); 133 h.setServer(server);
134 } 134 }
135 135
136 136
137 /* ------------------------------------------------------------ */ 137 /* ------------------------------------------------------------ */
138 @Override 138 @Override
139 protected Object expandChildren(Object list, Class byClass) 139 protected Object expandChildren(Object list, Class byClass)
140 { 140 {
141 return expandHandler(_handler,list,byClass); 141 return expandHandler(_handler,list,byClass);
142 } 142 }
143 143
144 /* ------------------------------------------------------------ */ 144 /* ------------------------------------------------------------ */
145 public <H extends Handler> H getNestedHandlerByClass(Class<H> byclass) 145 public <H extends Handler> H getNestedHandlerByClass(Class<H> byclass)
146 { 146 {
147 HandlerWrapper h=this; 147 HandlerWrapper h=this;
148 while (h!=null) 148 while (h!=null)
149 { 149 {
150 if (byclass.isInstance(h)) 150 if (byclass.isInstance(h))
151 return (H)h; 151 return (H)h;
152 Handler w = h.getHandler(); 152 Handler w = h.getHandler();
153 if (w instanceof HandlerWrapper) 153 if (w instanceof HandlerWrapper)
154 h=(HandlerWrapper)w; 154 h=(HandlerWrapper)w;
155 else break; 155 else break;
156 } 156 }
157 return null; 157 return null;
158 158
159 } 159 }
160 160
161 /* ------------------------------------------------------------ */ 161 /* ------------------------------------------------------------ */
162 @Override 162 @Override
163 public void destroy() 163 public void destroy()
164 { 164 {
165 if (!isStopped()) 165 if (!isStopped())
166 throw new IllegalStateException("!STOPPED"); 166 throw new IllegalStateException("!STOPPED");
167 Handler child=getHandler(); 167 Handler child=getHandler();
168 if (child!=null) 168 if (child!=null)
169 { 169 {
170 setHandler(null); 170 setHandler(null);
171 child.destroy(); 171 child.destroy();
172 } 172 }
173 super.destroy(); 173 super.destroy();
174 } 174 }
175 175
176 } 176 }