01: //========================================================================
02: //$Id: AbstractHandler.java,v 1.4 2005/11/11 22:55:39 gregwilkins Exp $
03: //Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
04: //------------------------------------------------------------------------
05: //Licensed under the Apache License, Version 2.0 (the "License");
06: //you may not use this file except in compliance with the License.
07: //You may obtain a copy of the License at
08: //http://www.apache.org/licenses/LICENSE-2.0
09: //Unless required by applicable law or agreed to in writing, software
10: //distributed under the License is distributed on an "AS IS" BASIS,
11: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: //See the License for the specific language governing permissions and
13: //limitations under the License.
14: //========================================================================
15:
16: package org.mortbay.jetty.handler;
17:
18: import org.mortbay.component.AbstractLifeCycle;
19: import org.mortbay.jetty.Handler;
20: import org.mortbay.jetty.Server;
21: import org.mortbay.log.Log;
22:
23: /* ------------------------------------------------------------ */
24: /** AbstractHandler.
25: * @author gregw
26: *
27: */
28: public abstract class AbstractHandler extends AbstractLifeCycle
29: implements Handler {
30: protected String _string;
31: private Server _server;
32:
33: /* ------------------------------------------------------------ */
34: /**
35: *
36: */
37: public AbstractHandler() {
38: }
39:
40: /* ------------------------------------------------------------ */
41: /*
42: * @see org.mortbay.thread.LifeCycle#start()
43: */
44: protected void doStart() throws Exception {
45: Log.debug("starting {}", this );
46: }
47:
48: /* ------------------------------------------------------------ */
49: /*
50: * @see org.mortbay.thread.LifeCycle#stop()
51: */
52: protected void doStop() throws Exception {
53: Log.debug("stopping {}", this );
54: }
55:
56: /* ------------------------------------------------------------ */
57: public String toString() {
58: if (_string == null) {
59: _string = super .toString();
60: _string = _string.substring(_string.lastIndexOf('.') + 1);
61: }
62: return _string;
63: }
64:
65: /* ------------------------------------------------------------ */
66: public void setServer(Server server) {
67: Server old_server = _server;
68: if (old_server != null && old_server != server)
69: old_server.getContainer().removeBean(this );
70: _server = server;
71: if (_server != null && _server != old_server)
72: _server.getContainer().addBean(this );
73: }
74:
75: /* ------------------------------------------------------------ */
76: public Server getServer() {
77: return _server;
78: }
79:
80: /* ------------------------------------------------------------ */
81: public void destroy() {
82: if (!isStopped())
83: throw new IllegalStateException("!STOPPED");
84: if (_server != null)
85: _server.getContainer().removeBean(this);
86: }
87:
88: }
|