
org.directwebremoting.util.FakeServletConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwr Show documentation
Show all versions of dwr Show documentation
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boilerplate code between the web browser and your Java code.
This version 4.0.2 works with Jakarta Servlet 4.0.2.
The newest version!
package org.directwebremoting.util;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
/**
* A fake implementation of ServletConfig for cases (Like inside Spring) when
* you don't have a real one, or when you want to modify the initParameters
* provided by the real {@link ServletConfig}
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class FakeServletConfig implements ServletConfig
{
/**
* @param name The servlet name
* @param servletContext The ServletContext
*/
public FakeServletConfig(String name, ServletContext servletContext)
{
this(name, servletContext, null);
}
/**
* @param name The servlet name
* @param servletContext The ServletContext
* @param initParameters Optional init parameters (can be null)
*/
public FakeServletConfig(String name, ServletContext servletContext, Map initParameters)
{
this.name = name;
this.servletContext = servletContext;
this.initParameters = (initParameters != null) ? initParameters : new HashMap();
}
/**
* Copy the values from another {@link ServletConfig} so we can modify them.
* @param servletConfig ...
*/
public FakeServletConfig(ServletConfig servletConfig)
{
this.name = servletConfig.getServletName();
this.servletContext = servletConfig.getServletContext();
this.initParameters = new HashMap();
for (String key : LocalUtil.iterableizer(servletConfig.getInitParameterNames(), String.class))
{
String value = servletConfig.getInitParameter(key);
initParameters.put(key, value);
}
}
public String getServletName()
{
return name;
}
public ServletContext getServletContext()
{
return servletContext;
}
/**
* Modify an init parameter
* @param name ...
* @param value ...
*/
public void setInitParameter(String name, String value)
{
initParameters.put(name, value);
}
public String getInitParameter(String paramName)
{
Object obj = initParameters.get(paramName);
if (obj instanceof String)
{
return (String) obj;
}
else
{
return null;
}
}
public Enumeration getInitParameterNames()
{
return Collections.enumeration(initParameters.keySet());
}
/**
* The servlet name
*/
private final String name;
/**
* The servlet deployment information
*/
private final ServletContext servletContext;
/**
* Initialization parameters
*/
private final Map initParameters;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy