in web/src/main/java/org/apache/commons/chain2/web/ChainServlet.java [157:210]
public void init() throws ServletException {
Log log = LogFactory.getLog(ChainServlet.class);
ServletConfig config = getServletConfig();
ServletContext context = getServletContext();
if (log.isInfoEnabled()) {
log.info("Initializing chain servlet '"
+ config.getServletName() + "'");
}
// Retrieve servlet init parameters that we need
String attr = config.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 {
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) {
ChainResources.parseClassResources
(classResources, parser);
ChainResources.parseWebResources
(context, webResources, parser);
} else {
ChainResources.parseClassResources
(classResources, parser);
ChainResources.parseWebResources
(context, webResources, parser);
}
// Expose the completed catalog (if requested)
if (attr != null) {
context.setAttribute(attr, catalog);
}
}