1 //========================================================================
2 //$Id: AbstractHandler.java,v 1.4 2005/11/11 22:55:39 gregwilkins Exp $
3 //Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
4 //------------------------------------------------------------------------
5 //Licensed under the Apache License, Version 2.0 (the "License");
6 //you may not use this file except in compliance with the License.
7 //You may obtain a copy of the License at
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //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
19 import org.mortbay.component.AbstractLifeCycle;
20 import org.mortbay.jetty.Handler;
21 import org.mortbay.jetty.Server;
22 import org.mortbay.log.Log;
23
24
25 /* ------------------------------------------------------------ */
26 /** AbstractHandler.
27 * @author gregw
28 *
29 */
30 public abstract class AbstractHandler extends AbstractLifeCycle implements Handler
31 {
32 protected String _string;
33 private Server _server;
34
35 /* ------------------------------------------------------------ */
36 /**
37 *
38 */
39 public AbstractHandler()
40 {
41 }
42
43 /* ------------------------------------------------------------ */
44 /*
45 * @see org.mortbay.thread.LifeCycle#start()
46 */
47 protected void doStart() throws Exception
48 {
49 Log.debug("starting {}",this);
50 }
51
52 /* ------------------------------------------------------------ */
53 /*
54 * @see org.mortbay.thread.LifeCycle#stop()
55 */
56 protected void doStop() throws Exception
57 {
58 Log.debug("stopping {}",this);
59 }
60
61 /* ------------------------------------------------------------ */
62 public String toString()
63 {
64 if (_string==null)
65 {
66 _string=super.toString();
67 _string=_string.substring(_string.lastIndexOf('.')+1);
68 }
69 return _string;
70 }
71
72 /* ------------------------------------------------------------ */
73 public void setServer(Server server)
74 {
75 Server old_server=_server;
76 if (old_server!=null && old_server!=server)
77 old_server.getContainer().removeBean(this);
78 _server=server;
79 if (_server!=null && _server!=old_server)
80 _server.getContainer().addBean(this);
81 }
82
83 /* ------------------------------------------------------------ */
84 public Server getServer()
85 {
86 return _server;
87 }
88
89
90 /* ------------------------------------------------------------ */
91 public void destroy()
92 {
93 if (!isStopped())
94 throw new IllegalStateException("!STOPPED");
95 if (_server!=null)
96 _server.getContainer().removeBean(this);
97 }
98
99 }