KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > http > servlet > internal > ServletConfigImpl


1 /*******************************************************************************
2  * Copyright (c) 2005-2007 Cognos Incorporated, IBM Corporation and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Cognos Incorporated - initial API and implementation
10  * IBM Corporation - bug fixes and enhancements
11  *******************************************************************************/

12 package org.eclipse.equinox.http.servlet.internal;
13
14 import java.util.*;
15 import javax.servlet.*;
16
17 public class ServletConfigImpl implements ServletConfig {
18
19     private static final Dictionary EMPTY_PARAMS = new Hashtable(0);
20     private static final String JavaDoc SERVLET_NAME = "servlet-name"; //$NON-NLS-1$
21
private Servlet servlet;
22     private Dictionary initparams;
23     private ServletContext servletContext;
24
25     public ServletConfigImpl(Servlet servlet, Dictionary initparams, ServletContext servletContext) {
26         this.servlet = servlet;
27         this.initparams = (initparams != null) ? initparams : EMPTY_PARAMS;
28         this.servletContext = servletContext;
29     }
30
31     /*
32      * @see javax.servlet.ServletConfig#getServletName()
33      *
34      * The OSGi Http Service does not specify a way to set a servlet name at the API level. This
35      * implementation will try to use the value of the "servlet-name" initial parameter if available.
36      */

37     public String JavaDoc getServletName() {
38         String JavaDoc servletName = (String JavaDoc) initparams.get(SERVLET_NAME);
39         return (servletName != null) ? servletName : servlet.getClass().getName();
40     }
41
42     public ServletContext getServletContext() {
43         return servletContext;
44     }
45
46     public String JavaDoc getInitParameter(String JavaDoc name) {
47         return (String JavaDoc) initparams.get(name);
48     }
49
50     public Enumeration getInitParameterNames() {
51         return initparams.keys();
52     }
53 }
54
Popular Tags