servletconfigimpl.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 963 行 · 第 1/2 页

JAVA
963
字号
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * *   Free Software Foundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Scott Ferguson */package com.caucho.server.dispatch;import com.caucho.config.*;import com.caucho.config.program.ConfigProgram;import com.caucho.config.program.ContainerProgram;import com.caucho.config.program.NodeBuilderProgram;import com.caucho.config.types.InitParam;import com.caucho.jmx.Jmx;import com.caucho.jsp.Page;import com.caucho.jsp.QServlet;import com.caucho.naming.Jndi;import com.caucho.remote.server.*;import com.caucho.server.connection.StubServletRequest;import com.caucho.server.connection.StubServletResponse;import com.caucho.server.webapp.WebApp;import com.caucho.servlet.comet.CometServlet;import com.caucho.util.*;import com.caucho.webbeans.component.*;import com.caucho.webbeans.manager.*;import javax.annotation.PostConstruct;import javax.naming.NamingException;import javax.servlet.*;import java.lang.reflect.Constructor;import java.lang.reflect.Modifier;import java.util.Collections;import java.util.Enumeration;import java.util.HashMap;import java.util.Hashtable;import java.util.Map;import java.util.logging.Level;import java.util.logging.Logger;/** * Configuration for a servlet. */public class ServletConfigImpl implements ServletConfig, AlarmListener{  static L10N L = new L10N(ServletConfigImpl.class);  protected static final Logger log    = Logger.getLogger(ServletConfigImpl.class.getName());  private String _location;  private String _jndiName;  private String _var;    private String _servletName;  private String _servletNameDefault;    private String _servletClassName;  private Class _servletClass;  private String _jspFile;  private String _displayName;  private int _loadOnStartup = Integer.MIN_VALUE;  private boolean _allowEL = true;  private HashMap<String,String> _initParams = new HashMap<String,String>();  private HashMap<String,String> _roleMap;  private ContainerProgram _init;  private RunAt _runAt;  private ServletProtocolConfig _protocolConfig;  private ProtocolServletFactory _protocolFactory;    private Alarm _alarm;  private ComponentImpl _comp;  private ServletContext _servletContext;  private ServletManager _servletManager;  private ServletException _initException;  private long _nextInitTime;  private Object _servlet;  private FilterChain _servletChain;  /**   * Creates a new servlet configuration object.   */  public ServletConfigImpl()  {  }  /**   * Sets the config location.   */  public void setConfigLocation(String location, int line)  {    _location = location + ":" + line + ": ";  }  /**   * Sets the id attribute   */  public void setId(String id)  {  }  /**   * Sets the servlet name.   */  public void setServletName(String name)  {    _servletName = name;  }  /**   * Gets the servlet name.   */  public String getServletName()  {    return _servletName;  }  /**   * Sets the servlet name default when not specified   */  public void setServletNameDefault(String name)  {    _servletNameDefault = name;  }  /**   * Gets the servlet name default.   */  public String getServletNameDefault()  {    return _servletNameDefault;  }  /**   * Gets the servlet name.   */  public String getServletClassName()  {    return _servletClassName;  }  /**   * Sets the servlet class.   */  public void setServletClass(String servletClassName)  {    _servletClassName = servletClassName;    // JSF is special    if ("javax.faces.webapp.FacesServlet".equals(_servletClassName)) {      if (_loadOnStartup < 0)	_loadOnStartup = 1;      if (_servletContext instanceof WebApp)	((WebApp) _servletContext).createJsp().setLoadTldOnInit(true);    }  }  /**   * Gets the servlet name.   */  public Class getServletClass()  {    if (_servletClassName == null)      return null;        if (_servletClass == null) {      try {	Thread thread = Thread.currentThread();	ClassLoader loader = thread.getContextClassLoader();        _servletClass = Class.forName(_servletClassName, false, loader);      } catch (Exception e) {	throw error(L.l("'{0}' is not a known servlet class.  Servlets belong in the classpath, for example WEB-INF/classes.",			_servletClassName),		    e);      }    }          return _servletClass;  }  /**   * Sets the JSP file   */  public void setJspFile(String jspFile)  {    _jspFile = jspFile;  }  /**   * Gets the JSP file   */  public String getJspFile()  {    return _jspFile;  }  /**   * Sets the allow value.   */  public void setAllowEL(boolean allowEL)  {    _allowEL = allowEL;  }  /**   * Sets an init-param   */  public void setInitParam(String param, String value)  {    _initParams.put(param, value);  }  /**   * Sets an init-param   */  public InitParam createInitParam()  {    InitParam initParam = new InitParam();    initParam.setAllowEL(_allowEL);    return initParam;  }  /**   * Sets an init-param   */  public void setInitParam(InitParam initParam)  {    _initParams.putAll(initParam.getParameters());  }  /**   * Gets the init params   */  public Map getInitParamMap()  {    return _initParams;  }  /**   * Gets the init params   */  public String getInitParameter(String name)  {    return _initParams.get(name);  }  /**   * Gets the init params   */  public Enumeration getInitParameterNames()  {    return Collections.enumeration(_initParams.keySet());  }  /**   * Returns the servlet context.   */  public ServletContext getServletContext()  {    return _servletContext;  }  /**   * Sets the servlet context.   */  public void setServletContext(ServletContext app)  {    _servletContext = app;  }  /**   * Returns the servlet manager.   */  public ServletManager getServletManager()  {    return _servletManager;  }  /**   * Sets the servlet manager.   */  public void setServletManager(ServletManager manager)  {    _servletManager = manager;  }  /**   * Sets the init block   */  public void setInit(ContainerProgram init)  {    _init = init;  }  /**   * Gets the init block   */  public ContainerProgram getInit()  {    return _init;  }  /**   * Sets the load-on-startup   */  public void setLoadOnStartup(int loadOnStartup)  {    _loadOnStartup = loadOnStartup;  }  /**   * Gets the load-on-startup value.   */  public int getLoadOnStartup()  {    if (_loadOnStartup > Integer.MIN_VALUE)      return _loadOnStartup;    else if (_runAt != null)      return 0;    else      return Integer.MIN_VALUE;  }  /**   * Creates the run-at configuration.   */  public RunAt createRunAt()  {    if (_runAt == null)      _runAt = new RunAt();    return _runAt;  }  public void setJndiName(String jndiName)  {    _jndiName = jndiName;  }  public void setVar(String var)  {    _var = var;  }  /**   * Returns the run-at configuration.   */  public RunAt getRunAt()  {    return _runAt;  }  /**   * Adds a security role reference.   */  public void addSecurityRoleRef(SecurityRoleRef ref)  {    if (_roleMap == null)      _roleMap = new HashMap<String,String>(8);    // server/12h2    // server/12m0    _roleMap.put(ref.getRoleName(), ref.getRoleLink());  }  /**   * Adds a security role reference.   */  public HashMap<String,String> getRoleMap()  {    return _roleMap;  }  /**   * Sets the display name   */  public void setDisplayName(String displayName)  {    _displayName = displayName;  }  /**   * Gets the display name   */  public String getDisplayName()  {    return _displayName;  }  /**   * Sets the description   */  public void setDescription(String description)  {  }  /**   * Sets the icon   */  public void setIcon(com.caucho.config.types.Icon icon)  {  }  /**   * Sets the web service protocol.   */  public void setProtocol(ServletProtocolConfig protocol)  {    _protocolConfig = protocol;  }  /**   * Sets the init exception   */  public void setInitException(ServletException exn)  {    _initException = exn;    _nextInitTime = Long.MAX_VALUE / 2;    if (exn instanceof UnavailableException) {      UnavailableException unExn = (UnavailableException) exn;      if (! unExn.isPermanent())        _nextInitTime = (Alarm.getCurrentTime() +                         1000L * unExn.getUnavailableSeconds());    }  }  /**   * Returns the servlet.   */  public Object getServlet()  {    return _servlet;  }  /**   * Initialize the servlet config.   */  @PostConstruct  public void init()    throws ServletException  {    if (_runAt != null) {      _alarm = new Alarm(this);    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?