public void contextInitialized()

in web/src/main/java/org/apache/commons/chain2/web/ChainListener.java [157:212]


    public void contextInitialized(ServletContextEvent event) {
        Log log = LogFactory.getLog(ChainListener.class);
        if (log.isInfoEnabled()) {
            log.info("Initializing chain listener");
        }
        ServletContext context = event.getServletContext();

        // Retrieve context init parameters that we need
        String attr = context.getInitParameter(CONFIG_ATTR);
        String classResources =
            context.getInitParameter(CONFIG_CLASS_RESOURCE);
        String ruleSet = context.getInitParameter(RULE_SET);
        String webResources = context.getInitParameter(CONFIG_WEB_RESOURCE);

        // Retrieve or create the Catalog instance we may be updating
        Catalog<String, Object, ServletWebContext<String, Object>> catalog = null;
        if (attr != null) {
            Object catalogRef = context.getAttribute(attr);

            if (catalogRef == null || !(catalogRef instanceof Catalog) ) {
                catalog = new CatalogBase<String, Object, ServletWebContext<String, Object>>();
            } else {
                /* Assume that we are getting an object of the type Catalog from the context's
                 * attribute because that is the historical contract. */
                catalog = (Catalog<String, Object, ServletWebContext<String, Object>>)catalogRef;
            }
        }

        // Construct the configuration resource parser we will use
        ClassLoader cl = Thread.currentThread().getContextClassLoader() == null ?
                this.getClass().getClassLoader() :
                Thread.currentThread().getContextClassLoader();

        XmlConfigParser parser = ruleSet == null ?
                new XmlConfigParser() : new XmlConfigParser(ruleSet, cl);

        // Parse the resources specified in our init parameters (if any)
        if (attr == null) {
            parseJarResources(context, parser, log);
            ChainResources.parseClassResources
                (classResources, parser);
            ChainResources.parseWebResources
                (context, webResources, parser);
        } else {
            parseJarResources(context, parser, log);
            ChainResources.parseClassResources
                (classResources, parser);
            ChainResources.parseWebResources
                (context, webResources, parser);
        }

        // Expose the completed catalog (if requested)
        if (attr != null) {
            context.setAttribute(attr, catalog);
        }
    }