blob: e4dba28dc595ff71f411e5770e49d951cf1d634b [file] [log] [blame]
Richard S. Hallfe8e5602006-04-19 15:23:22 +00001/*
2 * Copyright 2006 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.mortbay.jetty.servlet;
18
19
20import java.util.Dictionary;
21import java.util.Enumeration;
22
23import javax.servlet.Servlet;
24import javax.servlet.ServletConfig;
25import javax.servlet.UnavailableException;
26
27public class OsgiServletHolder
28 extends
29 ServletHolder
30{
31 private Servlet m_servlet;
32 private ServletConfig m_config;
33
34
35 public OsgiServletHolder(ServletHandler handler, Servlet servlet,
36 String name, Dictionary params)
37 {
38 super(handler,name,servlet.getClass().getName());
39 m_servlet = servlet;
40
41 // Seemed safer to copy params into parent holder, rather than override
42 // the getInitxxx methods.
43 if (params != null)
44 {
45 Enumeration e = params.keys();
46 while (e.hasMoreElements())
47 {
48 Object key = e.nextElement();
49 super.put(key, params.get(key));
50 }
51 }
52 }
53
54 public synchronized Servlet getServlet()
55 throws UnavailableException
56 {
57 return m_servlet;
58 }
59
60 public Servlet getOsgiServlet()
61 {
62 return m_servlet;
63 }
64
65
66 // override "Holder" method to prevent instantiation
67 public synchronized Object newInstance()
68 throws InstantiationException,
69 IllegalAccessException
70 {
71 return getOsgiServlet();
72 }
73
74 // override "Holder" method to prevent attempt to load
75 // the servlet class.
76 public void start()
77 throws Exception
78 {
79 _class=m_servlet.getClass();
80
81 m_config=new Config();
82 m_servlet.init(m_config);
83 }
84
85 // override "Holder" method to prevent destroy, which is only called
86 // when a bundle manually unregisters
87 public void stop()
88 {
89 }
90}
91