001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.core.servletwrapper.servlet;
017
018import java.util.Enumeration;
019import java.util.Map;
020
021import javax.servlet.ServletConfig;
022import javax.servlet.ServletContext;
023
024/**
025 * The wrapped servlet configuration based on configuration parameters (as if there were a web.xml)
026 */
027public class ServletWrapperConfig implements ServletConfig
028{
029    private String _servletName;
030    private ServletContext _servletContext;
031    private Map<String, String> _parameters;
032    private Enumeration<String> _enumParameters;
033    
034    /**
035     * set the configuration
036     * @param servletName servlet-name
037     * @param servletContext Context
038     * @param parameters init-param
039     */
040    public ServletWrapperConfig(String servletName, ServletContext servletContext, Map<String, String> parameters)
041    {
042        this._servletName = servletName;
043        this._servletContext = servletContext;
044        this._parameters = parameters;
045        this._enumParameters = java.util.Collections.enumeration(parameters.keySet());
046    }
047
048    public String getServletName()
049    {
050        return this._servletName;
051    }
052
053    public ServletContext getServletContext()
054    {
055        return this._servletContext;
056    }
057
058    public String getInitParameter(String name)
059    {
060        return this._parameters.get(name);
061    }
062
063    public Enumeration<String> getInitParameterNames()
064    {
065        return this._enumParameters;
066    }
067
068}