Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * JBoss, Home of Professional Open Source.
    * Copyright 2012 Red Hat, Inc., and individual contributors
    * as indicated by the @author tags.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.catalina.core;
  
  
  import static org.jboss.web.CatalinaMessages.MESSAGES;
  
  import java.io.File;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  
  
Standard implementation of ServletContext that represents a web application's execution environment. An instance of this class is associated with each instance of StandardContext.

Author(s):
Craig R. McClanahan
Remy Maucherat
Version:
$Revision: 1263 $ $Date: 2009-11-11 04:29:33 +0100 (Wed, 11 Nov 2009) $
  
  
  public class ApplicationContext
      implements ServletContext {
  
      // ----------------------------------------------------------- Constructors
  

    
Construct a new instance of this class, associated with the specified Context instance.

Parameters:
context The associated Context instance
 
     public ApplicationContext(String basePathStandardContext context) {
         super();
         this. = context;
         this. = basePath;
     }
 
 
     // ----------------------------------------------------- Instance Variables
 

    
The context attributes for this context.
 
     protected Map attributes = new ConcurrentHashMap();


    
List of read only attributes for this context.
 
     private Map readOnlyAttributes = new ConcurrentHashMap();


    
The Context instance with which we are associated.
 
     private StandardContext context = null;


    
Empty collection to serve as the basis for empty enumerations. DO NOT ADD ANY ELEMENTS TO THIS COLLECTION!
 
     private static final ArrayList empty = new ArrayList();


    
The facade around this object.
 
     private ServletContext facade = new ApplicationContextFacade(this);


    
The merged context initialization parameters for this Context.
 
     private Map parameters = null;


    
Base path.
 
     private String basePath = null;


    
Thread local data used during request dispatch.
 
     private ThreadLocal<DispatchDatadispatchData =
         new ThreadLocal<DispatchData>();

    
    
The restricted flag.
 
     private boolean restricted = false;
     
 
     // --------------------------------------------------------- Public Methods
 

    
Return the resources object that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.
 
     public DirContext getResources() {
 
         return .getResources();
 
     }
 
 
     public boolean isRestricted() {
         return ;
     }
 
 
     public void setRestricted(boolean restricted) {
         this. = restricted;
     }
 
 
     // ------------------------------------------------- ServletContext Methods
 

    
Return the value of the specified context attribute, if any; otherwise return null.

Parameters:
name Name of the context attribute to return
 
     public Object getAttribute(String name) {
 
         return (.get(name));
 
     }


    
Return an enumeration of the names of the context attributes associated with this context.
 
     public Enumeration getAttributeNames() {
 
         return new Enumerator(.keySet(), true);
 
     }


    
Return a ServletContext object that corresponds to a specified URI on the server. This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects or resources from the context. The given path must be absolute (beginning with a "/"), and is interpreted based on our virtual host's document root.

Parameters:
uri Absolute URI of a resource on the server
 
     public ServletContext getContext(String uri) {
 
         // Validate the format of the specified argument
         if ((uri == null) || (!uri.startsWith("/")))
             return (null);
 
         Context child = null;
         try {
             Host host = (Host.getParent();
             String mapuri = uri;
             while (true) {
                 child = (Contexthost.findChild(mapuri);
                 if (child != null)
                     break;
                 int slash = mapuri.lastIndexOf('/');
                 if (slash < 0)
                     break;
                 mapuri = mapuri.substring(0, slash);
             }
         } catch (Throwable t) {
             return (null);
         }
 
         if (child == null)
             return (null);
 
         if (.getCrossContext()) {
             // If crossContext is enabled, can always return the context
             return child.getServletContext();
         } else if (child == ) {
             // Can still return the current context
             return .getServletContext();
         } else {
             // Nothing to return
             return (null);
         }
     }

    
    
Return the main path associated with this context.
 
     public String getContextPath() {
         return .getPath();
     }
    

    
Return the value of the specified initialization parameter, or null if this parameter does not exist.

Parameters:
name Name of the initialization parameter to retrieve
 
     public String getInitParameter(final String name) {
 
         mergeParameters();
         return ((String.get(name));
 
     }


    
Return the names of the context's initialization parameters, or an empty enumeration if the context has no initialization parameters.
 
     public Enumeration getInitParameterNames() {
 
         mergeParameters();
         return (new Enumerator(.keySet()));
 
     }


    
Return the major version of the Java Servlet API that we implement.
 
     public int getMajorVersion() {
 
         return (.);
 
     }


    
Return the minor version of the Java Servlet API that we implement.
 
     public int getMinorVersion() {
 
         return (.);
 
     }


    
Return the MIME type of the specified file, or null if the MIME type cannot be determined.

Parameters:
file Filename for which to identify a MIME type
 
     public String getMimeType(String file) {
 
         if (file == null)
             return (null);
         int period = file.lastIndexOf(".");
         if (period < 0)
             return (null);
         String extension = file.substring(period + 1);
         if (extension.length() < 1)
             return (null);
         return (.findMimeMapping(extension));
 
     }


    
Return a RequestDispatcher object that acts as a wrapper for the named servlet.

Parameters:
name Name of the servlet for which a dispatcher is requested
 
     public RequestDispatcher getNamedDispatcher(String name) {
 
         // Validate the name argument
         if (name == null)
             return (null);
 
         // Create and return a corresponding request dispatcher
         Wrapper wrapper = (Wrapper.findChild(name);
         if (wrapper == null)
             return (null);
         
         return new ApplicationDispatcher(wrappernullnullnullnullnullname);
 
     }


    
Return the real path for a given virtual path, if possible; otherwise return null.

Parameters:
path The path to the desired resource
 
     public String getRealPath(String path) {
 
         if (!.isFilesystemBased())
             return null;
 
         if (path == null) {
             return null;
         }
 
         File file = new File(path);
         return (file.getAbsolutePath());
 
     }


    
Return a RequestDispatcher instance that acts as a wrapper for the resource at the given path. The path must begin with a "/" and is interpreted as relative to the current context root.

Parameters:
path The path to the desired resource.
 
     public RequestDispatcher getRequestDispatcher(String path) {
 
         // Validate the path argument
         if (path == null)
             return (null);
         if (path.equals(""))
             path = "/";
         if (path.startsWith("?"))
             path = "/" + path;
         if (!path.startsWith("/"))
             throw .invalidDispatcherPath(path);
 
         // Get query string
         String queryString = null;
         int pos = path.indexOf('?');
         if (pos >= 0) {
             queryString = path.substring(pos + 1);
             path = path.substring(0, pos);
         }
  
         path = RequestUtil.normalize(path);
         if (path == null)
             return (null);
 
         pos = path.length();
 
         // Use the thread local URI and mapping data
         DispatchData dd = .get();
         if (dd == null) {
             dd = new DispatchData();
             .set(dd);
         }
 
         MessageBytes uriMB = dd.uriMB;
         uriMB.recycle();
 
         // Use the thread local mapping data
         MappingData mappingData = dd.mappingData;
 
         // Map the URI
         CharChunk uriCC = uriMB.getCharChunk();
         try {
             uriCC.append(.getPath(), 0, .getPath().length());
             /*
              * Ignore any trailing path params (separated by ';') for mapping
              * purposes
              */
             int semicolon = path.indexOf(';');
             if (pos >= 0 && semicolon > pos) {
                 semicolon = -1;
             }
             uriCC.append(path, 0, semicolon > 0 ? semicolon : pos);
             .getMapper().map(uriMBmappingData);
             if (mappingData.wrapper == null) {
                 return (null);
             }
             /*
              * Append any trailing path params (separated by ';') that were
              * ignored for mapping purposes, so that they're reflected in the
              * RequestDispatcher's requestURI
              */
             if (semicolon > 0) {
                 uriCC.append(pathsemicolonpos - semicolon);
             }
         } catch (Exception e) {
             // Should never happen
             log(.dispatcherMappingError(), e);
             return (null);
         }
 
         Wrapper wrapper = (WrappermappingData.wrapper;
         String requestPath = mappingData.requestPath.toString();
         String wrapperPath = mappingData.wrapperPath.toString();
         String pathInfo = mappingData.pathInfo.toString();
 
         mappingData.recycle();
         
         // Construct a RequestDispatcher to process this request
         return new ApplicationDispatcher
             (wrapperuriCC.toString(), requestPathwrapperPathpathInfo
              queryStringnull);
 
     }



    
Return the URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

Parameters:
path The path to the desired resource
Throws:
java.net.MalformedURLException if the path is not given in the correct form
 
     public URL getResource(String path)
         throws MalformedURLException {
 
         if (path == null || (. && !path.startsWith("/"))) {
             throw new MalformedURLException(.invalidDispatcherPathString(path));
         }
         
         path = RequestUtil.normalize(path);
         if (path == null)
             return (null);
 
         String libPath = "/WEB-INF/lib/";
         if ((path.startsWith(libPath)) && (path.endsWith(".jar"))) {
             File jarFile = null;
             if (.isFilesystemBased()) {
                 jarFile = new File(path);
             } else {
                 jarFile = new File(.getWorkPath(), path);
             }
             if (jarFile.exists()) {
                 return jarFile.toURL();
             } else {
                 return null;
             }
         } else {
 
             DirContext resources = .getResources();
             if (resources != null) {
                 String fullPath = .getName() + path;
                 String hostName = .getParent().getName();
                 try {
                     resources.lookup(path);
                     return new URL
                         ("jndi""", 0, getJNDIUri(hostNamefullPath),
                          new DirContextURLStreamHandler(resources));
                 } catch (Exception e) {
                     // Ignore
                 }
             }
         }
 
         return (null);
 
     }


    
Return the requested resource as an InputStream. The path must be specified according to the rules described under getResource. If no such resource can be identified, return null.

Parameters:
path The path to the desired resource.
 
     public InputStream getResourceAsStream(String path) {
 
         if (path == null || (. && !path.startsWith("/")))
             return (null);
 
         path = RequestUtil.normalize(path);
         if (path == null)
             return (null);
 
         DirContext resources = .getResources();
         if (resources != null) {
             try {
                 Object resource = resources.lookup(path);
                 if (resource instanceof Resource)
                     return (((Resourceresource).streamContent());
             } catch (Exception e) {
             }
         }
         return (null);
 
     }


    
Return a Set containing the resource paths of resources member of the specified collection. Each path will be a String starting with a "/" character. The returned set is immutable.

Parameters:
path Collection path
 
     public Set getResourcePaths(String path) {
 
         // Validate the path argument
         if (path == null) {
             return null;
         }
         if (!path.startsWith("/")) {
             throw .invalidDispatcherPath(path);
         }
 
         path = RequestUtil.normalize(path);
         if (path == null)
             return (null);
 
         DirContext resources = .getResources();
         if (resources != null) {
             return (getResourcePathsInternal(resourcespath));
         }
         return (null);
 
     }


    
Internal implementation of getResourcesPath() logic.

Parameters:
resources Directory context to search
path Collection path
 
     private Set getResourcePathsInternal(DirContext resourcesString path) {
 
         ResourceSet set = new ResourceSet();
         try {
             listCollectionPaths(setresourcespath);
         } catch (NamingException e) {
             return (null);
         }
         set.setLocked(true);
         return (set);
 
     }


    
Return the name and version of the servlet container.
 
     public String getServerInfo() {
 
         return (ServerInfo.getServerInfo());
 
     }


    

Deprecated:
As of Java Servlet API 2.1, with no direct replacement.
 
     public Servlet getServlet(String name) {
 
         return (null);
 
     }


    
Return the display name of this web application.
 
     public String getServletContextName() {
 
         return (.getDisplayName());
 
     }


    

Deprecated:
As of Java Servlet API 2.1, with no direct replacement.
 
     public Enumeration getServletNames() {
         return (new Enumerator());
     }


    

Deprecated:
As of Java Servlet API 2.1, with no direct replacement.
 
     public Enumeration getServlets() {
         return (new Enumerator());
     }


    
Writes the specified message to a servlet log file.

Parameters:
message Message to be written
 
     public void log(String message) {
 
         .getLogger().info(message);
 
     }


    
Writes the specified exception and message to a servlet log file.

Deprecated:
As of Java Servlet API 2.1, use log(String, Throwable) instead
Parameters:
exception Exception to be reported
message Message to be written
 
     public void log(Exception exceptionString message) {
         
         .getLogger().error(messageexception);
 
     }


    
Writes the specified message and exception to a servlet log file.

Parameters:
message Message to be written
throwable Exception to be reported
 
     public void log(String messageThrowable throwable) {
         
         .getLogger().error(messagethrowable);
 
     }


    
Remove the context attribute with the specified name, if any.

Parameters:
name Name of the context attribute to be removed
 
     public void removeAttribute(String name) {
 
         Object value = null;
         boolean found = false;
 
         // Remove the specified attribute
         // Check for read only attribute
         if (.containsKey(name))
             return;
         found = .containsKey(name);
         if (found) {
             value = .get(name);
             .remove(name);
         } else {
             return;
         }
 
         // Notify interested application event listeners
         Object listeners[] = .getApplicationEventListeners();
         if ((listeners == null) || (listeners.length == 0))
             return;
         ServletContextAttributeEvent event =
                                             namevalue);
         for (int i = 0; i < listeners.lengthi++) {
             if (!(listeners[iinstanceof ServletContextAttributeListener))
                 continue;
             ServletContextAttributeListener listener =
                 (ServletContextAttributeListenerlisteners[i];
             try {
                 .fireContainerEvent("beforeContextAttributeRemoved",
                                            listener);
                 listener.attributeRemoved(event);
                 .fireContainerEvent("afterContextAttributeRemoved",
                                            listener);
             } catch (Throwable t) {
                 .fireContainerEvent("afterContextAttributeRemoved",
                                            listener);
                 // FIXME - should we do anything besides log these?
                 log(.servletContextAttributeListenerException(), t);
             }
         }
 
     }


    
Bind the specified value with the specified context attribute name, replacing any existing value for that name.

Parameters:
name Attribute name to be bound
value New attribute value to be bound
 
     public void setAttribute(String nameObject value) {
 
         // Name cannot be null
         if (name == null)
 
         // Null value is the same as removeAttribute()
         if (value == null) {
             removeAttribute(name);
             return;
         }
 
         Object oldValue = null;
         boolean replaced = false;
 
         // Add or replace the specified attribute
         // Check for read only attribute
         if (.containsKey(name))
             return;
         oldValue = .get(name);
         if (oldValue != null)
             replaced = true;
         .put(namevalue);
 
         // Notify interested application event listeners
         Object listeners[] = .getApplicationEventListeners();
         if ((listeners == null) || (listeners.length == 0))
             return;
         ServletContextAttributeEvent event = null;
         if (replaced)
             event =
                 new ServletContextAttributeEvent(.getServletContext(),
                                                  nameoldValue);
         else
             event =
                 new ServletContextAttributeEvent(.getServletContext(),
                                                  namevalue);
 
         for (int i = 0; i < listeners.lengthi++) {
             if (!(listeners[iinstanceof ServletContextAttributeListener))
                 continue;
             ServletContextAttributeListener listener =
                 (ServletContextAttributeListenerlisteners[i];
             try {
                 if (replaced) {
                     .fireContainerEvent
                         ("beforeContextAttributeReplaced"listener);
                     listener.attributeReplaced(event);
                     .fireContainerEvent("afterContextAttributeReplaced",
                                                listener);
                 } else {
                     .fireContainerEvent("beforeContextAttributeAdded",
                                                listener);
                     listener.attributeAdded(event);
                     .fireContainerEvent("afterContextAttributeAdded",
                                                listener);
                 }
             } catch (Throwable t) {
                 if (replaced)
                     .fireContainerEvent("afterContextAttributeReplaced",
                                                listener);
                 else
                     .fireContainerEvent("afterContextAttributeAdded",
                                                listener);
                 // FIXME - should we do anything besides log these?
                 log(.servletContextAttributeListenerException(), t);
             }
         }
 
     }
 
 
     public FilterRegistration.Dynamic addFilter(String filterNameString className)
             throws IllegalArgumentExceptionIllegalStateException {
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         if (!.isStarting()) {
             throw .contextAlreadyInitialized(getContextPath());
         }
         if (.findFilterDef(filterName) != null) {
             return null;
         }
         FilterDef filterDef = new FilterDef();
         filterDef.setFilterName(filterName);
         filterDef.setFilterClass(className);
         .addFilterDef(filterDef);
         ApplicationFilterConfig filterConfig = new ApplicationFilterConfig(filterDef);
         filterConfig.setDynamic(true);
         .addApplicationFilterConfig(filterConfig);
         return (FilterRegistration.DynamicfilterConfig.getFacade();
     }
 
 
     public FilterRegistration.Dynamic addFilter(String filterNameFilter filter) {
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         if (!.isStarting()) {
             throw .contextAlreadyInitialized(getContextPath());
         }
         if (.findFilterDef(filterName) != null) {
             return null;
         }
         // Filter instance unicity
         for (Container container : .getParent().findChildren()) {
             if (container instanceof StandardContext) {
                 for (ApplicationFilterConfig filterConfig : ((StandardContextcontainer).findApplicationFilterConfigs()) {
                     if (filterConfig.getFilterInstance() == filter) {
                         return null;
                     }
                 }
             }
         }
         FilterDef filterDef = new FilterDef();
         filterDef.setFilterName(filterName);
         filterDef.setFilterClass(filter.getClass().getName());
         .addFilterDef(filterDef);
         ApplicationFilterConfig filterConfig = new ApplicationFilterConfig(filterDef);
         filterConfig.setDynamic(true);
         filterConfig.setFilter(filter);
         .addApplicationFilterConfig(filterConfig);
         return (FilterRegistration.DynamicfilterConfig.getFacade();
     }
 
 
     public FilterRegistration.Dynamic addFilter(String filterName,
             Class<? extends FilterfilterClass) {
         return addFilter(filterNamefilterClass.getName());
     }
 
 
     public ServletRegistration.Dynamic addServlet(String servletNameString className)
             throws IllegalArgumentExceptionIllegalStateException {
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         if (!.isStarting()) {
             throw .contextAlreadyInitialized(getContextPath());
         }
         if (.findChild(servletName) != null) {
             return null;
         }
         Wrapper wrapper = .createWrapper();
         wrapper.setDynamic(true);
         wrapper.setName(servletName);
         wrapper.setServletClass(className);
         .addChild(wrapper);
         return (ServletRegistration.Dynamicwrapper.getFacade();
     }
 
 
     public ServletRegistration.Dynamic addServlet(String servletName,
             Class<? extends Servletclazzthrows IllegalArgumentException,
             IllegalStateException {
         return addServlet(servletNameclazz.getName());
     }
 
 
     public ServletRegistration.Dynamic addServlet(String servletNameServlet servlet) {
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         if (!.isStarting()) {
             throw .contextAlreadyInitialized(getContextPath());
         }
         if (.findChild(servletName) != null) {
             return null;
         }
         // Servlet instance unicity
         for (Container container : .getParent().findChildren()) {
             for (Container wrapper : container.findChildren()) {
                 if (((Wrapperwrapper).getServlet() == servlet) {
                     return null;
                 }
             }
         }
         Wrapper wrapper = .createWrapper();
         wrapper.setDynamic(true);
         wrapper.setName(servletName);
         wrapper.setServletClass(servlet.getClass().getName());
         wrapper.setServlet(servlet);
         .addChild(wrapper);
         return (ServletRegistration.Dynamicwrapper.getFacade();
     }
 
 
     public FilterRegistration getFilterRegistration(String filterName) {
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         ApplicationFilterConfig filterConfig = .findApplicationFilterConfig(filterName);
         if (filterConfig == null) {
             FilterDef filterDef = .findFilterDef(filterName);
             if (filterDef == null) {
                 return null;
             } else {
                 filterConfig = new ApplicationFilterConfig(filterDef);
                 .addApplicationFilterConfig(filterConfig);
             }
         }
         return filterConfig.getFacade();
     }
 
 
     public ServletRegistration getServletRegistration(String servletName) {
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         Wrapper wrapper = (Wrapper.findChild(servletName);
         if (wrapper != null) {
             return wrapper.getFacade();
         } else {
             return null;
         }
     }
 
 
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         HashMap<StringFilterRegistrationresult = 
             new HashMap<StringFilterRegistration>();
         ApplicationFilterConfig[] filterConfigs = .findApplicationFilterConfigs();
         for (int i = 0; i < filterConfigs.lengthi++) {
             result.put(filterConfigs[i].getFilterName(), filterConfigs[i].getFacade());
         }
         return Collections.unmodifiableMap(result);
     }
 
 
         if () {
             throw .restrictedListenerCannotCallMethod();
         }
         HashMap<StringServletRegistrationresult = 
            new HashMap<StringServletRegistration>();
        Container[] wrappers = .findChildren();
        for (int i = 0; i < wrappers.lengthi++) {
            Wrapper wrapper = (Wrapperwrappers[i];
            result.put(wrapper.getName(), wrapper.getFacade());
        }
        return Collections.unmodifiableMap(result);
    }
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        return .getDefaultSessionTrackingModes();
    }
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        return .getSessionTrackingModes();
    }
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        return .getSessionCookie();
    }
    public <T extends Filter> T createFilter(Class<T> c)
            throws ServletException {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        try {
            return (T) .getInstanceManager().newInstance(c);
        } catch (Throwable e) {
            throw new ServletException(.contextObjectCreationError(), e);
        }
    }
    public <T extends Servlet> T createServlet(Class<T> c)
            throws ServletException {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        try {
            return (T) .getInstanceManager().newInstance(c);
        } catch (Throwable e) {
            throw new ServletException(.contextObjectCreationError(), e);
        }
    }
    public boolean setInitParameter(String nameString value) {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        if (!.isStarting()) {
            throw .contextAlreadyInitialized(getContextPath());
        }
        mergeParameters();
        if (.get(name) != null) {
            return false;
        } else {
            .put(namevalue);
            return true;
        }
    }
    public void setSessionTrackingModes(Set<SessionTrackingModesessionTrackingModes) {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        if (!.isStarting()) {
            throw .contextAlreadyInitialized(getContextPath());
        }
        // Check that only supported tracking modes have been requested
        for (SessionTrackingMode sessionTrackingMode : sessionTrackingModes) {
            if (!getDefaultSessionTrackingModes().contains(sessionTrackingMode)) {
                throw .unsupportedSessionTrackingMode(sessionTrackingMode.toString(), getContextPath());
            }
        }
        // If SSL is specified, it should be the only one used
        if (sessionTrackingModes.contains(.) && sessionTrackingModes.size() > 1) {
        }
        .setSessionTrackingModes(sessionTrackingModes);
    }
    public void addListener(String className) {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        if (!.isStarting()) {
            throw .contextAlreadyInitialized(getContextPath());
        }
        EventListener listenerInstance = null;
        try {
            Class<?> clazz = .getLoader().getClassLoader().loadClass(className);
            listenerInstance = (EventListener.getInstanceManager().newInstance(clazz);
        } catch (Throwable t) {
            throw .invalidContextListenerWithException(classNamegetContextPath(), t);
        }
        checkListenerType(listenerInstance);
        if (.getApplicationLifecycleListeners() != null && listenerInstance instanceof ServletContextListener) {
            throw .invalidContextListener(classNamegetContextPath());
        }
        .addApplicationListenerInstance(listenerInstance);
    }
    public <T extends EventListenervoid addListener(T listener) {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        if (!.isStarting()) {
            throw .contextAlreadyInitialized(getContextPath());
        }
        checkListenerType(listener);
        if (.getApplicationLifecycleListeners() != null && listener instanceof ServletContextListener) {
            throw .invalidContextListener(listener.getClass().getName(), getContextPath());
        }
        .addApplicationListenerInstance(listener);
    }
    public void addListener(Class<? extends EventListenerlistenerClass) {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        if (!.isStarting()) {
            throw .contextAlreadyInitialized(getContextPath());
        }
        EventListener listenerInstance = null;
        try {
            listenerInstance = (EventListener.getInstanceManager().newInstance(listenerClass);
        } catch (Exception e) {
            throw .invalidContextListenerWithException(listenerClass.getName(), getContextPath(), e);
        }
        checkListenerType(listenerInstance);
        if (.getApplicationLifecycleListeners() != null && listenerInstance instanceof ServletContextListener) {
            throw .invalidContextListener(listenerClass.getName(), getContextPath());
        }
        .addApplicationListenerInstance(listenerInstance);
    }
    public <T extends EventListener> T createListener(Class<T> clazz)
            throws ServletException {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        if (!.isStarting()) {
            throw .contextAlreadyInitialized(getContextPath());
        }
        T listenerInstance = null;
        try {
            listenerInstance = (T) .getInstanceManager().newInstance(clazz);
        } catch (Throwable t) {
            throw new ServletException(.contextObjectCreationError(), t);
        }
        checkListenerType(listenerInstance);
        return listenerInstance;
    }
    public ClassLoader getClassLoader() {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        return .getLoader().getClassLoader();
    }
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        ArrayList<TaglibDescriptortaglibDescriptors = new ArrayList<TaglibDescriptor>();
        String[] taglibURIs = .findTaglibs();
        for (int i = 0; i < taglibURIs.lengthi++) {
            String taglibLocation = .findTaglib(taglibURIs[i]);
            TaglibDescriptor taglibDescriptor = 
                new TaglibDescriptorImpl(taglibURIs[i], taglibLocation);
            taglibDescriptors.add(taglibDescriptor);
        }
        ArrayList<JspPropertyGroupDescriptorjspPropertyGroupDescriptors = 
            new ArrayList<JspPropertyGroupDescriptor>();
        JspPropertyGroup[] jspPropertyGroups = .findJspPropertyGroups();
        for (int i = 0; i < jspPropertyGroups.lengthi++) {
            jspPropertyGroupDescriptors.add(jspPropertyGroups[i]);
        }
        return new JspConfigDescriptorImpl(jspPropertyGroupDescriptorstaglibDescriptors);
    }
    public int getEffectiveMajorVersion() {
        if () {
            throw .restrictedListenerCannotCallMethod();
        }
        return .getVersionMajor();
    }