Package org.apache.catalina.startup
Class ContextConfig
- java.lang.Object
- 
- 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.- Author:
- Craig R. McClanahan
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceContextConfig.ContextXml
 - 
Field SummaryFields Modifier and Type Field Description protected static java.util.PropertiesauthenticatorsThe set of Authenticators that we know how to configure.protected ContextcontextThe Context we are associated with.protected java.util.Map<java.lang.String,Authenticator>customAuthenticatorsCustom mappings of login methods to authenticatorsprotected java.lang.StringdefaultWebXmlThe default web application's deployment descriptor location.protected static longdeploymentCountDeployment count.protected static LoginConfigDUMMY_LOGIN_CONFIGprotected booleanhandlesTypesAnnotationsFlag that indicates if at least oneHandlesTypesentry is present that represents an annotation.protected booleanhandlesTypesNonAnnotationsFlag that indicates if at least oneHandlesTypesentry is present that represents a non-annotation.protected static java.util.Map<Host,org.apache.catalina.startup.ContextConfig.DefaultWebXmlCacheEntry>hostWebXmlCacheCache of default web.xml fragments per Hostprotected java.util.Map<ServletContainerInitializer,java.util.Set<java.lang.Class<?>>>initializerClassMapMap of ServletContainerInitializer to classes they expressed interest in.protected booleanokTrack any fatal errors during startup configuration processing.protected java.lang.StringoriginalDocBaseOriginal docBase.protected static StringManagersmThe string resources for this package.protected java.util.Map<java.lang.Class<?>,java.util.Set<ServletContainerInitializer>>typeInitializerMapMap of Types to ServletContainerInitializer that are interested in those types.
 - 
Constructor SummaryConstructors Constructor Description ContextConfig()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidantiLocking()protected voidapplicationAnnotationsConfig()Process the application classes annotations, if it exists.protected voidauthenticatorConfig()Set up an Authenticator automatically if required, and one has not already been configured.protected voidbeforeStart()Process a "before start" event for this Context.protected voidcheckHandlesTypes(JavaClass javaClass, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)For classes packaged with the web application, the class and each super class needs to be checked for a match withHandlesTypesor for an annotation that matchesHandlesTypes.protected voidconfigureStart()Process a "contextConfig" event for this Context.protected voidconfigureStop()Process a "stop" event for this Context.protected voidcontextConfig(Digester digester)Process the default configuration file, if it exists.protected DigestercreateContextDigester()Create (if necessary) and return a Digester configured to process the context configuration descriptor for an application.protected WebXmlcreateWebXml()protected voiddestroy()Process a "destroy" event for this Context.protected voidfixDocBase()Adjust docBase.protected voidgenerateClassFooter(Digester digester)protected voidgenerateClassHeader(Digester digester, java.lang.String packageName, java.lang.String resourceName)java.lang.StringgetConfigBasePath()protected org.xml.sax.InputSourcegetContextWebXmlSource()Identify the application web.xml to be used and obtain an input source for it.protected java.io.FilegetContextXmlJavaSource(java.lang.String contextXmlPackageName, java.lang.String contextXmlSimpleClassName)protected static java.lang.StringgetContextXmlPackageName(java.lang.String generatedCodePackage, Container container)java.lang.StringgetDefaultWebXml()Obtain the location of the default deployment descriptor.protected booleangetGenerateCode()protected java.io.FilegetGeneratedCodeLocation()protected java.lang.StringgetGeneratedCodePackage()protected org.xml.sax.InputSourcegetGlobalWebXmlSource()Identify the default web.xml to be used and obtain an input source for it.protected java.io.FilegetHostConfigBase()protected org.xml.sax.InputSourcegetHostWebXmlSource()Identify the host web.xml to be used and obtain an input source for it.protected booleangetUseGeneratedCode()protected org.xml.sax.InputSourcegetWebXmlSource(java.lang.String filename, boolean global)Utility method to create an input source from the specified XML file.protected voidinit()Process a "init" event for this Context.voidlifecycleEvent(LifecycleEvent event)Process events for an associated Context.protected voidprocessAnnotations(java.util.Set<WebXml> fragments, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)protected voidprocessAnnotationsFile(java.io.File file, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)protected voidprocessAnnotationsInParallel(java.util.Set<WebXml> fragments, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)Parallelized version of processAnnotationsInParallel().protected voidprocessAnnotationsJar(java.net.URL url, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)protected voidprocessAnnotationsStream(java.io.InputStream is, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)protected java.lang.String[]processAnnotationsStringArray(ElementValue ev)protected voidprocessAnnotationsUrl(java.net.URL url, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)protected voidprocessAnnotationsWebResource(WebResource webResource, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)protected voidprocessAnnotationWebFilter(java.lang.String className, AnnotationEntry ae, WebXml fragment)process filter annotation and merge with existing one!protected java.util.Map<java.lang.String,java.lang.String>processAnnotationWebInitParams(ElementValue ev)protected voidprocessAnnotationWebServlet(java.lang.String className, AnnotationEntry ae, WebXml fragment)protected voidprocessClass(WebXml fragment, JavaClass clazz)protected voidprocessClasses(WebXml webXml, java.util.Set<WebXml> orderedFragments)protected voidprocessContextConfig(Digester digester, java.net.URL contextXml, java.io.InputStream stream)Process a context.xml.protected java.util.Map<java.lang.String,WebXml>processJarsForWebFragments(WebXml application, WebXmlParser webXmlParser)Scan /WEB-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 voidprocessResourceJARs(java.util.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 voidprocessServletContainerInitializers()Scan JARs for ServletContainerInitializer implementations.voidsetCustomAuthenticators(java.util.Map<java.lang.String,Authenticator> customAuthenticators)Sets custom mappings of login methods to authenticators.voidsetDefaultWebXml(java.lang.String path)Set the location of the default deployment descriptor.protected voidvalidateSecurityRoles()Validate the usage of security role names in the web application deployment descriptor.protected voidwebConfig()Scan the web.xml files that apply to the web application and merge them using the rules defined in the spec.
 
- 
- 
- 
Field Detail- 
smprotected static final StringManager sm The string resources for this package.
 - 
DUMMY_LOGIN_CONFIGprotected static final LoginConfig DUMMY_LOGIN_CONFIG 
 - 
authenticatorsprotected static final 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.
 - 
deploymentCountprotected static long deploymentCount Deployment count.
 - 
hostWebXmlCacheprotected static final java.util.Map<Host,org.apache.catalina.startup.ContextConfig.DefaultWebXmlCacheEntry> hostWebXmlCache Cache of default web.xml fragments per Host
 - 
customAuthenticatorsprotected java.util.Map<java.lang.String,Authenticator> customAuthenticators Custom mappings of login methods to authenticators
 - 
contextprotected volatile Context context The Context we are associated with.
 - 
defaultWebXmlprotected java.lang.String defaultWebXml The default web application's deployment descriptor location.
 - 
okprotected boolean ok Track any fatal errors during startup configuration processing.
 - 
originalDocBaseprotected java.lang.String originalDocBase Original docBase.
 - 
initializerClassMapprotected final java.util.Map<ServletContainerInitializer,java.util.Set<java.lang.Class<?>>> initializerClassMap Map of ServletContainerInitializer to classes they expressed interest in.
 - 
typeInitializerMapprotected final java.util.Map<java.lang.Class<?>,java.util.Set<ServletContainerInitializer>> typeInitializerMap Map of Types to ServletContainerInitializer that are interested in those types.
 - 
handlesTypesAnnotationsprotected boolean handlesTypesAnnotations Flag that indicates if at least oneHandlesTypesentry is present that represents an annotation.
 - 
handlesTypesNonAnnotationsprotected boolean handlesTypesNonAnnotations Flag that indicates if at least oneHandlesTypesentry is present that represents a non-annotation.
 
- 
 - 
Method Detail- 
getDefaultWebXmlpublic java.lang.String getDefaultWebXml() Obtain the location of the default deployment descriptor.- Returns:
- The path to the default web.xml. If not absolute, it is relative to CATALINA_BASE.
 
 - 
setDefaultWebXmlpublic void setDefaultWebXml(java.lang.String path) Set the location of the default deployment descriptor.- Parameters:
- path- The path to the default web.xml. If not absolute, it is relative to CATALINA_BASE.
 
 - 
setCustomAuthenticatorspublic void setCustomAuthenticators(java.util.Map<java.lang.String,Authenticator> customAuthenticators) Sets custom mappings of login methods to authenticators.- Parameters:
- customAuthenticators- Custom mappings of login methods to authenticators
 
 - 
lifecycleEventpublic void lifecycleEvent(LifecycleEvent event) Process events for an associated Context.- Specified by:
- lifecycleEventin interface- LifecycleListener
- Parameters:
- event- The lifecycle event that has occurred
 
 - 
applicationAnnotationsConfigprotected void applicationAnnotationsConfig() Process the application classes annotations, if it exists.
 - 
authenticatorConfigprotected void authenticatorConfig() Set up an Authenticator automatically if required, and one has not already been configured.
 - 
createContextDigesterprotected Digester createContextDigester() Create (if necessary) and return a Digester configured to process the context configuration descriptor for an application.- Returns:
- the digester for context.xml files
 
 - 
getGenerateCodeprotected boolean getGenerateCode() 
 - 
getUseGeneratedCodeprotected boolean getUseGeneratedCode() 
 - 
getGeneratedCodeLocationprotected java.io.File getGeneratedCodeLocation() 
 - 
getGeneratedCodePackageprotected java.lang.String getGeneratedCodePackage() 
 - 
getContextXmlPackageNameprotected static java.lang.String getContextXmlPackageName(java.lang.String generatedCodePackage, Container container)
 - 
getContextXmlJavaSourceprotected java.io.File getContextXmlJavaSource(java.lang.String contextXmlPackageName, java.lang.String contextXmlSimpleClassName)
 - 
generateClassHeaderprotected void generateClassHeader(Digester digester, java.lang.String packageName, java.lang.String resourceName) 
 - 
generateClassFooterprotected void generateClassFooter(Digester digester) 
 - 
contextConfigprotected void contextConfig(Digester digester) Process the default configuration file, if it exists.- Parameters:
- digester- The digester that will be used for XML parsing
 
 - 
processContextConfigprotected void processContextConfig(Digester digester, java.net.URL contextXml, java.io.InputStream stream) Process a context.xml.- Parameters:
- digester- The digester that will be used for XML parsing
- contextXml- The URL to the context.xml configuration
- stream- The XML resource stream
 
 - 
fixDocBaseprotected void fixDocBase() throws java.io.IOExceptionAdjust docBase.- Throws:
- java.io.IOException- cannot access the context base path
 
 - 
antiLockingprotected void antiLocking() 
 - 
initprotected void init() Process a "init" event for this Context.
 - 
beforeStartprotected void beforeStart() Process a "before start" event for this Context.
 - 
configureStartprotected void configureStart() Process a "contextConfig" event for this Context.
 - 
configureStopprotected void configureStop() Process a "stop" event for this Context.
 - 
destroyprotected void destroy() Process a "destroy" event for this Context.
 - 
validateSecurityRolesprotected 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 theokinstance variable tofalseas well).
 - 
getHostConfigBaseprotected java.io.File getHostConfigBase() 
 - 
webConfigprotected 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.
 - 
processClassesprotected void processClasses(WebXml webXml, java.util.Set<WebXml> orderedFragments) 
 - 
createWebXmlprotected WebXml createWebXml() 
 - 
processServletContainerInitializersprotected void processServletContainerInitializers() Scan JARs for ServletContainerInitializer implementations.
 - 
processResourceJARsprotected void processResourceJARs(java.util.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.- Parameters:
- fragments- The set of fragments that will be scanned for static resources
 
 - 
getGlobalWebXmlSourceprotected org.xml.sax.InputSource getGlobalWebXmlSource() Identify the default web.xml to be used and obtain an input source for it.- Returns:
- an input source to the default web.xml
 
 - 
getHostWebXmlSourceprotected org.xml.sax.InputSource getHostWebXmlSource() Identify the host web.xml to be used and obtain an input source for it.- Returns:
- an input source to the default per host web.xml
 
 - 
getContextWebXmlSourceprotected org.xml.sax.InputSource getContextWebXmlSource() Identify the application web.xml to be used and obtain an input source for it.- Returns:
- an input source to the context web.xml
 
 - 
getConfigBasePathpublic java.lang.String getConfigBasePath() 
 - 
getWebXmlSourceprotected org.xml.sax.InputSource getWebXmlSource(java.lang.String filename, boolean global)Utility method to create an input source from the specified XML file.- Parameters:
- filename- Name of the file (possibly with one or more leading path segments) to read
- global- true if processing a shared resource, false if processing a host based resource
- Returns:
- the input source
 
 - 
processJarsForWebFragmentsprotected java.util.Map<java.lang.String,WebXml> processJarsForWebFragments(WebXml application, WebXmlParser webXmlParser) Scan /WEB-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 andnullwill be used if no web-fragment.xml was found. Any JARs known not contain fragments will be skipped.- Parameters:
- application- The main web.xml metadata
- webXmlParser- The parser to use to process the web.xml file
- Returns:
- A map of JAR name to processed web fragment (if any)
 
 - 
processAnnotationsprotected void processAnnotations(java.util.Set<WebXml> fragments, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) 
 - 
processAnnotationsInParallelprotected void processAnnotationsInParallel(java.util.Set<WebXml> fragments, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) Parallelized version of processAnnotationsInParallel(). Constructs tasks, submits them as they're created, then waits for completion.- Parameters:
- fragments- Set of parallelizable scans
- handlesTypesOnly- Important parameter for the underlying scan
- javaClassCache- The class cache
 
 - 
processAnnotationsWebResourceprotected void processAnnotationsWebResource(WebResource webResource, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) 
 - 
processAnnotationsUrlprotected void processAnnotationsUrl(java.net.URL url, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)
 - 
processAnnotationsJarprotected void processAnnotationsJar(java.net.URL url, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)
 - 
processAnnotationsFileprotected void processAnnotationsFile(java.io.File file, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache)
 - 
processAnnotationsStreamprotected void processAnnotationsStream(java.io.InputStream is, WebXml fragment, boolean handlesTypesOnly, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) throws ClassFormatException, java.io.IOException- Throws:
- ClassFormatException
- java.io.IOException
 
 - 
checkHandlesTypesprotected void checkHandlesTypes(JavaClass javaClass, java.util.Map<java.lang.String,org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) For classes packaged with the web application, the class and each super class needs to be checked for a match withHandlesTypesor for an annotation that matchesHandlesTypes.- Parameters:
- javaClass- the class to check
- javaClassCache- a class cache
 
 - 
processAnnotationWebServletprotected void processAnnotationWebServlet(java.lang.String className, AnnotationEntry ae, WebXml fragment)
 - 
processAnnotationWebFilterprotected void processAnnotationWebFilter(java.lang.String className, AnnotationEntry ae, WebXml fragment)process filter annotation and merge with existing one! FIXME: refactoring method too long and has redundant subroutines with processAnnotationWebServlet!- Parameters:
- className- The filter class name
- ae- The filter annotation
- fragment- The corresponding fragment
 
 - 
processAnnotationsStringArrayprotected java.lang.String[] processAnnotationsStringArray(ElementValue ev) 
 - 
processAnnotationWebInitParamsprotected java.util.Map<java.lang.String,java.lang.String> processAnnotationWebInitParams(ElementValue ev) 
 
- 
 
-