- java.lang.Object
-
- com.github.robtimus.servlet.ServletConfigWrapper
-
- All Implemented Interfaces:
ServletConfig
public class ServletConfigWrapper extends Object implements ServletConfig
A wrapper around an existingServletConfig
instance. By default it delegates all methods. However, it also allows initialization parameters to be added or overwritten. This can be useful when a sub class of some servlet needs to provide hard-coded or calculated initialization parameter values to its parent class. For instance:public void init(ServletConfig servletConfig) { super.init(new ServletConfigWrapper(servletConfig) .withInitParameter("booleanParameter", true) .withInitParameter("intParameter", 100)); }
- Author:
- Rob Spoor
-
-
Constructor Summary
Constructors Constructor Description ServletConfigWrapper(ServletConfig servletConfig)
Creates a newServletConfig
wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getInitParameter(String name)
Enumeration<String>
getInitParameterNames()
ServletContext
getServletContext()
String
getServletName()
ServletConfigWrapper
withInitParameter(String name, Object value)
Adds or overwrites an initialization parameter.
-
-
-
Constructor Detail
-
ServletConfigWrapper
public ServletConfigWrapper(ServletConfig servletConfig)
Creates a newServletConfig
wrapper.- Parameters:
servletConfig
- TheServletConfig
object to wrap.- Throws:
NullPointerException
- If the givenServletConfig
object isnull
.
-
-
Method Detail
-
getServletName
public String getServletName()
- Specified by:
getServletName
in interfaceServletConfig
-
getServletContext
public ServletContext getServletContext()
- Specified by:
getServletContext
in interfaceServletConfig
-
getInitParameter
public String getInitParameter(String name)
- Specified by:
getInitParameter
in interfaceServletConfig
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
- Specified by:
getInitParameterNames
in interfaceServletConfig
-
withInitParameter
public ServletConfigWrapper withInitParameter(String name, Object value)
Adds or overwrites an initialization parameter.- Parameters:
name
- The name of the initialization parameter.value
- The value for the initialization parameter. Itsstring representation
will be used.- Returns:
- This object.
- Throws:
NullPointerException
- If the given name or value isnull
.
-
-