org.apache.catalina.startup
Class ContextConfig

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

public class ContextConfig
extends java.lang.Object
implements LifecycleListener

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

Version:
$Revision: 1329 $ $Date: 2009-12-09 18:11:00 +0100 (Wed, 09 Dec 2009) $
Author:
Craig R. McClanahan, Jean-Francois Arcand

Nested Class Summary
protected  class ContextConfig.ContextErrorHandler
           
protected  class ContextConfig.ServletContainerInitializerInfo
           
 
Field Summary
protected static java.util.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  java.util.Map customAuthenticators
          Custom mappings of login methods to authenticators
protected  java.lang.String defaultContextXml
          The default web application's context file location.
protected  java.lang.String defaultWebXml
          The default web application's deployment descriptor location.
protected static long deploymentCount
          Deployment count.
protected static LoginConfig DUMMY_LOGIN_CONFIG
           
protected static Digester fragmentOrderingDigester
          The Digester we will use to parse fragment ordering.
protected  java.util.Map<java.lang.Class<?>,ContextConfig.ServletContainerInitializerInfo> handlesTypes
           
protected  java.lang.Class<?>[] handlesTypesArray
          Used to speed up scanning for the services interest classes.
protected static org.jboss.logging.Logger log
           
protected  boolean ok
          Track any fatal errors during startup configuration processing.
protected  java.util.LinkedList<java.lang.String> order
           
protected static Digester orderingDigester
          The Digester we will use to parse absolute ordering in web.xml.
protected  java.lang.String originalDocBase
          Original docBase.
protected  java.util.ArrayList<java.lang.String> overlays
           
protected  org.xml.sax.SAXParseException parseException
          Any parse error which occurred while parsing XML descriptors.
protected  java.util.Map<java.lang.String,ContextConfig.ServletContainerInitializerInfo> servletContainerInitializerInfos
           
protected static StringManager sm
          The string resources for this package.
protected static Digester tldDigester
          The Digester we will use to process tag library descriptor files.
protected  java.util.Map<java.lang.String,java.util.Set<java.lang.String>> TLDs
           
protected static Digester webDigester
          The Digester we will use to process web application deployment descriptor files.
protected static Digester webFragmentDigester
          The Digester we will use to process web application fragment descriptor files.
protected static WebRuleSet webFragmentRuleSet
          The Rule used to parse web-fragment.xml files.
protected  java.util.ArrayList<java.lang.String> webFragments
           
protected static WebRuleSet webRuleSet
          The Rule used to parse the web.xml.
 
Constructor Summary
ContextConfig()
           
 
Method Summary
protected  void antiLocking()
           
protected  void applicationExtraDescriptorsConfig()
          Process additional descriptors: TLDs, web fragments, and map overlays.
 void applicationServletContainerInitializerConfig()
          Find and parse ServletContainerInitializer service in specified JAR.
protected  void applicationTldConfig()
          Parse TLDs.
protected  void applicationWebConfig()
          Process the application configuration file, 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 completeConfig()
          Process a "start" event for this Context.
protected  void contextConfig()
          Process the default configuration file, if it exists.
protected static Digester createContextDigester()
          Create (if necessary) and return a Digester configured to process the context configuration descriptor for an application.
protected static Digester createFragmentOrderingDigester()
          Create (if necessary) and return a Digester configured to process web fragments ordering.
protected  void createFragmentsOrder()
          Parse fragments order.
protected static Digester createTldDigester()
          Create (if necessary) and return a Digester configured to process tag library descriptors.
protected static Digester createWebDigester()
          Create (if necessary) and return a Digester configured to process the web application deployment descriptor (web.xml).
protected static Digester createWebFragmentDigester()
          Create (if necessary) and return a Digester configured to process the web application fragment descriptors (web-fragment.xml).
protected  void defaultWebConfig()
          Process the default configuration file, if it exists.
protected  void destroy()
          Process a "destroy" event for this Context.
protected  void fixDocBase()
          Adjust docBase.
protected  java.lang.String getBaseDir()
           
protected  java.lang.String getClassName(java.lang.String filePath)
          Get class name given a path to a classfile.
protected  java.io.File getConfigBase()
          Get config base.
 java.lang.String getDefaultContextXml()
          Return the location of the default context file
 java.lang.String getDefaultWebXml()
          Return the location of the default deployment descriptor
protected  java.lang.String getHostConfigPath(java.lang.String resourceName)
           
protected  java.lang.String getJarName(java.util.List<WebOrdering> orderings, java.lang.String name)
          Get the jar name corresponding to the ordering name.
 java.util.Iterator<java.lang.String> getOverlays()
           
 java.util.Map<java.lang.String,ContextConfig.ServletContainerInitializerInfo> getServletContainerInitializerInfo()
           
 java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getTLDs()
           
 java.util.Iterator<java.lang.String> getWebFragments()
           
protected  void init()
          Process a "init" event for this Context.
 void lifecycleEvent(LifecycleEvent event)
          Process events for an associated Context.
protected  void processConfigAnnotations(java.lang.Class<?> clazz)
          Process the application classes annotations, if it exists.
protected  void processContextConfig(java.io.File baseDir, java.lang.String resourceName)
          Process a context.xml.
protected  void processDefaultWebConfig(Digester digester, java.io.InputStream stream, org.xml.sax.InputSource source)
          Process a default web.xml.
protected  void resolveServletSecurity()
          Translate servlet security associated with Servlets to security constraints.
protected  void scanClass(java.lang.String className, boolean annotations)
           
protected  void scanClasses(java.io.File folder, java.lang.String path, boolean annotations)
          Scan folder containing class files.
protected  void scanJar(java.util.jar.JarFile jarFile, boolean annotations)
           
 void scanJarForServletContainerInitializer(java.util.jar.JarFile file)
          Find and parse ServletContainerInitializer service in specified JAR.
 void setCustomAuthenticators(java.util.Map customAuthenticators)
          Sets custom mappings of login methods to authenticators.
 void setDefaultContextXml(java.lang.String path)
          Set the location of the default context file
 void setDefaultWebXml(java.lang.String path)
          Set the location of the default deployment descriptor
protected  void start()
          Process a "start" event for this Context.
protected  void stop()
          Process a "stop" event for this Context.
protected  void tldScanResourcePathsWebInf(javax.naming.directory.DirContext resources, java.lang.String rootPath, java.util.HashSet<java.lang.String> tldPaths)
          Scans the web application's subdirectory identified by rootPath, along with its subdirectories, for TLDs.
protected  java.lang.String toHttpMethod(java.lang.String method)
          Although this does not comply with the spec, it is likely Java method names will be used in the annotations.
protected  void validateSecurityRoles()
          Validate the usage of security role names in the web application deployment descriptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.jboss.logging.Logger log

customAuthenticators

protected java.util.Map customAuthenticators
Custom mappings of login methods to authenticators


authenticators

protected static java.util.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 java.lang.String defaultContextXml
The default web application's context file location.


defaultWebXml

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


ok

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


parseException

protected org.xml.sax.SAXParseException parseException
Any parse error which occurred while parsing XML descriptors.


originalDocBase

protected java.lang.String originalDocBase
Original docBase.


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 static Digester webDigester
The Digester we will use to process web application deployment descriptor files.


webFragmentDigester

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


tldDigester

protected static Digester tldDigester
The Digester we will use to process tag library descriptor files.


fragmentOrderingDigester

protected static Digester fragmentOrderingDigester
The Digester we will use to parse fragment ordering.


orderingDigester

protected static Digester orderingDigester
The Digester we will use to parse absolute ordering in web.xml.


webRuleSet

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


webFragmentRuleSet

protected static WebRuleSet webFragmentRuleSet
The Rule used to parse web-fragment.xml files.


deploymentCount

protected static long deploymentCount
Deployment count.


DUMMY_LOGIN_CONFIG

protected static final LoginConfig DUMMY_LOGIN_CONFIG

overlays

protected java.util.ArrayList<java.lang.String> overlays

webFragments

protected java.util.ArrayList<java.lang.String> webFragments

TLDs

protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> TLDs

servletContainerInitializerInfos

protected java.util.Map<java.lang.String,ContextConfig.ServletContainerInitializerInfo> servletContainerInitializerInfos

order

protected java.util.LinkedList<java.lang.String> order

handlesTypesArray

protected java.lang.Class<?>[] handlesTypesArray
Used to speed up scanning for the services interest classes.


handlesTypes

protected java.util.Map<java.lang.Class<?>,ContextConfig.ServletContainerInitializerInfo> handlesTypes
Constructor Detail

ContextConfig

public ContextConfig()
Method Detail

getDefaultWebXml

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


setDefaultWebXml

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

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

getDefaultContextXml

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


setDefaultContextXml

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

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

setCustomAuthenticators

public void setCustomAuthenticators(java.util.Map customAuthenticators)
Sets custom mappings of login methods to authenticators.

Parameters:
customAuthenticators - Custom mappings of login methods to authenticators

getOverlays

public java.util.Iterator<java.lang.String> getOverlays()

getWebFragments

public java.util.Iterator<java.lang.String> getWebFragments()

getTLDs

public java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getTLDs()

getServletContainerInitializerInfo

public java.util.Map<java.lang.String,ContextConfig.ServletContainerInitializerInfo> getServletContainerInitializerInfo()

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

processConfigAnnotations

protected void processConfigAnnotations(java.lang.Class<?> clazz)
Process the application classes annotations, if it exists.


applicationWebConfig

protected void applicationWebConfig()
Process the application configuration file, if it exists.


applicationTldConfig

protected void applicationTldConfig()
Parse TLDs. This is separate, and is not subject to the order defined. Also, all TLDs from all JARs are parsed.


authenticatorConfig

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


createWebDigester

protected static Digester createWebDigester()
Create (if necessary) and return a Digester configured to process the web application deployment descriptor (web.xml).


createWebFragmentDigester

protected static Digester createWebFragmentDigester()
Create (if necessary) and return a Digester configured to process the web application fragment descriptors (web-fragment.xml).


createTldDigester

protected static Digester createTldDigester()
Create (if necessary) and return a Digester configured to process tag library descriptors.


createFragmentOrderingDigester

protected static Digester createFragmentOrderingDigester()
Create (if necessary) and return a Digester configured to process web fragments ordering.


createContextDigester

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


getBaseDir

protected java.lang.String getBaseDir()

defaultWebConfig

protected void defaultWebConfig()
Process the default configuration file, if it exists. The default config must be read with the container loader - so container servlets can be loaded


processDefaultWebConfig

protected void processDefaultWebConfig(Digester digester,
                                       java.io.InputStream stream,
                                       org.xml.sax.InputSource source)
Process a default web.xml.


createFragmentsOrder

protected void createFragmentsOrder()
Parse fragments order.


getJarName

protected java.lang.String getJarName(java.util.List<WebOrdering> orderings,
                                      java.lang.String name)
Get the jar name corresponding to the ordering name.


applicationExtraDescriptorsConfig

protected void applicationExtraDescriptorsConfig()
Process additional descriptors: TLDs, web fragments, and map overlays.


scanJar

protected void scanJar(java.util.jar.JarFile jarFile,
                       boolean annotations)

tldScanResourcePathsWebInf

protected void tldScanResourcePathsWebInf(javax.naming.directory.DirContext resources,
                                          java.lang.String rootPath,
                                          java.util.HashSet<java.lang.String> tldPaths)
Scans the web application's subdirectory identified by rootPath, along with its subdirectories, for TLDs. Initially, rootPath equals /WEB-INF. The /WEB-INF/classes and /WEB-INF/lib subdirectories are excluded from the search, as per the JSP 2.0 spec.

Parameters:
resources - The web application's resources
rootPath - The path whose subdirectories are to be searched for TLDs
tldPaths - The set of TLD resource paths to add to

scanClasses

protected void scanClasses(java.io.File folder,
                           java.lang.String path,
                           boolean annotations)
Scan folder containing class files.


scanClass

protected void scanClass(java.lang.String className,
                         boolean annotations)

getClassName

protected java.lang.String getClassName(java.lang.String filePath)
Get class name given a path to a classfile. /my/class/MyClass.class -> my.class.MyClass


applicationServletContainerInitializerConfig

public void applicationServletContainerInitializerConfig()
Find and parse ServletContainerInitializer service in specified JAR.


scanJarForServletContainerInitializer

public void scanJarForServletContainerInitializer(java.util.jar.JarFile file)
Find and parse ServletContainerInitializer service in specified JAR.


contextConfig

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


processContextConfig

protected void processContextConfig(java.io.File baseDir,
                                    java.lang.String resourceName)
Process a context.xml.


fixDocBase

protected void fixDocBase()
                   throws java.io.IOException
Adjust docBase.

Throws:
java.io.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.


start

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


completeConfig

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


stop

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


destroy

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


resolveServletSecurity

protected void resolveServletSecurity()
Translate servlet security associated with Servlets to security constraints.


toHttpMethod

protected java.lang.String toHttpMethod(java.lang.String method)
Although this does not comply with the spec, it is likely Java method names will be used in the annotations. Since it is not possible to validate, this would be an error that is invisible for the user.

Parameters:
method -
Returns:

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 java.io.File getConfigBase()
Get config base.


getHostConfigPath

protected java.lang.String getHostConfigPath(java.lang.String resourceName)


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