Apache Tomcat 7.0.4

org.apache.catalina.startup
Class ContextConfig

java.lang.Object
  extended by org.apache.catalina.startup.ContextConfig
All Implemented Interfaces:
LifecycleListener

public class ContextConfig
extends Object
implements LifecycleListener

Startup event listener for a Context that configures the properties of that Context, and the associated defined servlets.

Version:
$Id: ContextConfig.java 1022593 2010-10-14 16:05:55Z markt $
Author:
Craig R. McClanahan, Jean-Francois Arcand

Field Summary
protected static Properties authenticators
          The set of Authenticators that we know how to configure.
protected  Context context
          The Context we are associated with.
protected static Digester contextDigester
          The Digester we will use to process web application context files.
protected  Map<String,Authenticator> customAuthenticators
          Custom mappings of login methods to authenticators
protected  String defaultContextXml
          The default web application's context file location.
protected  String defaultWebXml
          The default web application's deployment descriptor location.
protected static long deploymentCount
          Deployment count.
protected static LoginConfig DUMMY_LOGIN_CONFIG
           
protected  Map<ServletContainerInitializer,Set<Class<?>>> initializerClassMap
          Map of ServletContainerInitializer to classes they expressed interest in.
protected  boolean ok
          Track any fatal errors during startup configuration processing.
protected  String originalDocBase
          Original docBase.
protected static StringManager sm
          The string resources for this package.
protected  Map<Class<?>,Set<ServletContainerInitializer>> typeInitializerMap
          Map of Types to ServletContainerInitializer that are interested in those types.
protected  Digester webDigester
          The Digester we will use to process web application deployment descriptor files.
protected static Digester[] webDigesters
           
protected  Digester webFragmentDigester
          The Digester we will use to process web fragment deployment descriptor files.
protected static Digester[] webFragmentDigesters
          The Digesters available to process web fragment deployment descriptor files.
protected static WebRuleSet webFragmentRuleSet
          The Rules used to parse the web-fragment.xml
protected static WebRuleSet webRuleSet
          The Rules used to parse the web.xml
 
Constructor Summary
ContextConfig()
           
 
Method Summary
protected  void antiLocking()
           
protected  void applicationAnnotationsConfig()
          Process the application classes annotations, if it exists.
protected  void authenticatorConfig()
          Set up an Authenticator automatically if required, and one has not already been configured.
protected  void beforeStart()
          Process a "before start" event for this Context.
protected  void checkHandlesTypes(JavaClass javaClass)
          For classes packaged with the web application, the class and each super class needs to be checked for a match with HandlesTypes or for an annotation that matches HandlesTypes.
protected  void configureStart()
          Process a "contextConfig" event for this Context.
protected  void configureStop()
          Process a "stop" event for this Context.
protected  void contextConfig()
          Process the default configuration file, if it exists.
protected  Digester createContextDigester()
          Create (if necessary) and return a Digester configured to process the context configuration descriptor for an application.
protected  WebXml createWebXml()
           
 void createWebXmlDigester(boolean namespaceAware, boolean validation)
          Create (if necessary) and return a Digester configured to process the web application deployment descriptor (web.xml).
protected  void destroy()
          Process a "destroy" event for this Context.
protected  void fixDocBase()
          Adjust docBase.
protected  String getBaseDir()
           
protected  File getConfigBase()
          Get config base.
protected  InputSource getContextWebXmlSource()
          Identify the application web.xml to be used and obtain an input source for it.
 String getDefaultContextXml()
          Return the location of the default context file
 String getDefaultWebXml()
          Return the location of the default deployment descriptor
protected  InputSource getGlobalWebXmlSource()
          Identify the default web.xml to be used and obtain an input source for it.
protected  String getHostConfigPath(String resourceName)
           
protected  InputSource getHostWebXmlSource()
          Identify the host web.xml to be used and obtain an input source for it.
protected  ServletContainerInitializer getServletContainerInitializer(InputStream is)
          Extract the name of the ServletContainerInitializer.
protected  InputSource getWebXmlSource(String filename, String path)
           
protected  void init()
          Process a "init" event for this Context.
 void lifecycleEvent(LifecycleEvent event)
          Process events for an associated Context.
protected  void parseWebXml(InputSource source, WebXml dest, boolean fragment)
           
protected  void processAnnotations(Set<WebXml> fragments)
           
protected  void processAnnotationsFile(File file, WebXml fragment)
           
protected  void processAnnotationsJar(URL url, WebXml fragment)
           
protected  void processAnnotationsJndi(URL url, WebXml fragment)
           
protected  void processAnnotationsStream(InputStream is, WebXml fragment)
           
protected  String[] processAnnotationsStringArray(ElementValue ev)
           
protected  void processAnnotationsUrl(URL url, WebXml fragment)
           
protected  void processAnnotationWebFilter(String className, AnnotationEntry ae, WebXml fragment)
          process filter annotation and merge with existing one!
protected  Map<String,String> processAnnotationWebInitParams(ElementValue ev)
           
protected  void processAnnotationWebServlet(String className, AnnotationEntry ae, WebXml fragment)
           
protected  void processContextConfig(URL contextXml)
          Process a context.xml.
protected  Map<String,WebXml> processJarsForWebFragments()
          Scan /META-INF/lib for JARs and for each one found add it and any /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files will be parsed before being added to the map.
protected  void processResourceJARs(Set<WebXml> fragments)
          Scan JARs that contain web-fragment.xml files that will be used to configure this application to see if they also contain static resources.
protected  boolean processServletContainerInitializers(Set<WebXml> fragments)
          Scan JARs for ServletContainerInitializer implementations.
 void setCustomAuthenticators(Map<String,Authenticator> customAuthenticators)
          Sets custom mappings of login methods to authenticators.
 void setDefaultContextXml(String path)
          Set the location of the default context file
 void setDefaultWebXml(String path)
          Set the location of the default deployment descriptor
protected  void validateSecurityRoles()
          Validate the usage of security role names in the web application deployment descriptor.
protected  void webConfig()
          Scan the web.xml files that apply to the web application and merge them using the rules defined in the spec.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

customAuthenticators

protected Map<String,Authenticator> customAuthenticators
Custom mappings of login methods to authenticators


authenticators

protected static Properties authenticators
The set of Authenticators that we know how to configure. The key is the name of the implemented authentication method, and the value is the fully qualified Java class name of the corresponding Valve.


context

protected Context context
The Context we are associated with.


defaultContextXml

protected String defaultContextXml
The default web application's context file location.


defaultWebXml

protected String defaultWebXml
The default web application's deployment descriptor location.


ok

protected boolean ok
Track any fatal errors during startup configuration processing.


originalDocBase

protected String originalDocBase
Original docBase.


initializerClassMap

protected Map<ServletContainerInitializer,Set<Class<?>>> initializerClassMap
Map of ServletContainerInitializer to classes they expressed interest in.


typeInitializerMap

protected Map<Class<?>,Set<ServletContainerInitializer>> typeInitializerMap
Map of Types to ServletContainerInitializer that are interested in those types.


sm

protected static final StringManager sm
The string resources for this package.


contextDigester

protected static Digester contextDigester
The Digester we will use to process web application context files.


webDigester

protected Digester webDigester
The Digester we will use to process web application deployment descriptor files.


webFragmentDigester

protected Digester webFragmentDigester
The Digester we will use to process web fragment deployment descriptor files.


webDigesters

protected static Digester[] webDigesters

webFragmentDigesters

protected static Digester[] webFragmentDigesters
The Digesters available to process web fragment deployment descriptor files.


webRuleSet

protected static WebRuleSet webRuleSet
The Rules used to parse the web.xml


webFragmentRuleSet

protected static WebRuleSet webFragmentRuleSet
The Rules used to parse the web-fragment.xml


deploymentCount

protected static long deploymentCount
Deployment count.


DUMMY_LOGIN_CONFIG

protected static final LoginConfig DUMMY_LOGIN_CONFIG
Constructor Detail

ContextConfig

public ContextConfig()
Method Detail

getDefaultWebXml

public String getDefaultWebXml()
Return the location of the default deployment descriptor


setDefaultWebXml

public void setDefaultWebXml(String path)
Set the location of the default deployment descriptor

Parameters:
path - Absolute/relative path to the default web.xml

getDefaultContextXml

public String getDefaultContextXml()
Return the location of the default context file


setDefaultContextXml

public void setDefaultContextXml(String path)
Set the location of the default context file

Parameters:
path - Absolute/relative path to the default context.xml

setCustomAuthenticators

public void setCustomAuthenticators(Map<String,Authenticator> customAuthenticators)
Sets custom mappings of login methods to authenticators.

Parameters:
customAuthenticators - Custom mappings of login methods to authenticators

lifecycleEvent

public void lifecycleEvent(LifecycleEvent event)
Process events for an associated Context.

Specified by:
lifecycleEvent in interface LifecycleListener
Parameters:
event - The lifecycle event that has occurred

applicationAnnotationsConfig

protected void applicationAnnotationsConfig()
Process the application classes annotations, if it exists.


authenticatorConfig

protected void authenticatorConfig()
Set up an Authenticator automatically if required, and one has not already been configured.


createWebXmlDigester

public void createWebXmlDigester(boolean namespaceAware,
                                 boolean validation)
Create (if necessary) and return a Digester configured to process the web application deployment descriptor (web.xml).


createContextDigester

protected Digester createContextDigester()
Create (if necessary) and return a Digester configured to process the context configuration descriptor for an application.


getBaseDir

protected String getBaseDir()

contextConfig

protected void contextConfig()
Process the default configuration file, if it exists.


processContextConfig

protected void processContextConfig(URL contextXml)
Process a context.xml.


fixDocBase

protected void fixDocBase()
                   throws IOException
Adjust docBase.

Throws:
IOException

antiLocking

protected void antiLocking()

init

protected void init()
Process a "init" event for this Context.


beforeStart

protected void beforeStart()
Process a "before start" event for this Context.


configureStart

protected void configureStart()
Process a "contextConfig" event for this Context.


configureStop

protected void configureStop()
Process a "stop" event for this Context.


destroy

protected void destroy()
Process a "destroy" event for this Context.


validateSecurityRoles

protected void validateSecurityRoles()
Validate the usage of security role names in the web application deployment descriptor. If any problems are found, issue warning messages (for backwards compatibility) and add the missing roles. (To make these problems fatal instead, simply set the ok instance variable to false as well).


getConfigBase

protected File getConfigBase()
Get config base.


getHostConfigPath

protected String getHostConfigPath(String resourceName)

webConfig

protected void webConfig()
Scan the web.xml files that apply to the web application and merge them using the rules defined in the spec. For the global web.xml files, where there is duplicate configuration, the most specific level wins. ie an application's web.xml takes precedence over the host level or global web.xml file.


createWebXml

protected WebXml createWebXml()

processServletContainerInitializers

protected boolean processServletContainerInitializers(Set<WebXml> fragments)
Scan JARs for ServletContainerInitializer implementations. Implementations will be added in web-fragment.xml priority order.


getServletContainerInitializer

protected ServletContainerInitializer getServletContainerInitializer(InputStream is)
                                                              throws IOException
Extract the name of the ServletContainerInitializer.

Parameters:
is - The resource where the name is defined
Returns:
The class name
Throws:
IOException

processResourceJARs

protected void processResourceJARs(Set<WebXml> fragments)
Scan JARs that contain web-fragment.xml files that will be used to configure this application to see if they also contain static resources. If static resources are found, add them to the context. Resources are added in web-fragment.xml priority order.


getGlobalWebXmlSource

protected InputSource getGlobalWebXmlSource()
Identify the default web.xml to be used and obtain an input source for it.


getHostWebXmlSource

protected InputSource getHostWebXmlSource()
Identify the host web.xml to be used and obtain an input source for it.


getContextWebXmlSource

protected InputSource getContextWebXmlSource()
Identify the application web.xml to be used and obtain an input source for it.


getWebXmlSource

protected InputSource getWebXmlSource(String filename,
                                      String path)
Parameters:
filename - Name of the file (possibly with one or more leading path segments) to read
path - Location that filename is relative to

parseWebXml

protected void parseWebXml(InputSource source,
                           WebXml dest,
                           boolean fragment)

processJarsForWebFragments

protected Map<String,WebXml> processJarsForWebFragments()
Scan /META-INF/lib for JARs and for each one found add it and any /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files will be parsed before being added to the map. Every JAR will be added and null will be used if no web-fragment.xml was found. Any JARs known not contain fragments will be skipped.

Returns:
A map of JAR name to processed web fragment (if any)

processAnnotations

protected void processAnnotations(Set<WebXml> fragments)

processAnnotationsUrl

protected void processAnnotationsUrl(URL url,
                                     WebXml fragment)

processAnnotationsJar

protected void processAnnotationsJar(URL url,
                                     WebXml fragment)

processAnnotationsJndi

protected void processAnnotationsJndi(URL url,
                                      WebXml fragment)

processAnnotationsFile

protected void processAnnotationsFile(File file,
                                      WebXml fragment)

processAnnotationsStream

protected void processAnnotationsStream(InputStream is,
                                        WebXml fragment)
                                 throws ClassFormatException,
                                        IOException
Throws:
ClassFormatException
IOException

checkHandlesTypes

protected void checkHandlesTypes(JavaClass javaClass)
For classes packaged with the web application, the class and each super class needs to be checked for a match with HandlesTypes or for an annotation that matches HandlesTypes.

Parameters:
javaClass -

processAnnotationWebServlet

protected void processAnnotationWebServlet(String className,
                                           AnnotationEntry ae,
                                           WebXml fragment)

processAnnotationWebFilter

protected void processAnnotationWebFilter(String className,
                                          AnnotationEntry ae,
                                          WebXml fragment)
process filter annotation and merge with existing one! FIXME: refactoring method to long and has redundant subroutines with processAnnotationWebServlet!

Parameters:
className -
ae -
fragment -

processAnnotationsStringArray

protected String[] processAnnotationsStringArray(ElementValue ev)

processAnnotationWebInitParams

protected Map<String,String> processAnnotationWebInitParams(ElementValue ev)

Apache Tomcat 7.0.4

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.