KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > builders > MuleXmlBuilderContextListener


1 /*
2  * $Id: MuleXmlBuilderContextListener.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.config.builders;
12
13 import org.mule.MuleManager;
14 import org.mule.config.ConfigurationException;
15 import org.mule.umo.manager.UMOManager;
16
17 import javax.servlet.ServletContext JavaDoc;
18 import javax.servlet.ServletContextEvent JavaDoc;
19 import javax.servlet.ServletContextListener JavaDoc;
20
21 /**
22  * <code>MuleXmlBuilderContextListener</code> is a bootstrap listener used to
23  * construct a MuleManager instance. This listener delegates to the
24  * <i>MuleXmlConfigurationBuilder</i>.
25  * <p>
26  * The location of the configuration file can be specified in a init parameter called
27  * <i>org.mule.config</i>, the value can be a path on the local file system or on
28  * the classpath. If a config parameter is not specified a default
29  * <i>/mule-config.xml</i> will be used.
30  * </p>
31  *
32  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
33  * @version $Revision: 3798 $
34  * @see MuleXmlConfigurationBuilder
35  */

36
37 public class MuleXmlBuilderContextListener implements ServletContextListener JavaDoc
38 {
39     public static final String JavaDoc CONFIG_INIT_PARAMETER = "org.mule.config";
40
41     public void contextInitialized(ServletContextEvent JavaDoc event)
42     {
43         String JavaDoc config = event.getServletContext().getInitParameter(CONFIG_INIT_PARAMETER);
44         if (config == null)
45         {
46             config = getDefaultConfigResource();
47         }
48         try
49         {
50             createManager(config, event.getServletContext());
51         }
52         catch (ConfigurationException e)
53         {
54             event.getServletContext().log(e.getMessage(), e);
55         }
56         catch (Error JavaDoc error)
57         {
58             // WSAD doesn't always report the java.lang.Error, log it
59
event.getServletContext().log(error.getMessage(), error);
60             throw error;
61         }
62
63     }
64
65     /**
66      * Used to actually construct the UMOManager instance
67      *
68      * @param configResource the location of the config resource, this can be on the
69      * local file system or on the classpath.
70      * @return A configured UMOManager instance
71      */

72     protected UMOManager createManager(String JavaDoc configResource, ServletContext JavaDoc context)
73         throws ConfigurationException
74     {
75         WebappMuleXmlConfigurationBuilder builder = new WebappMuleXmlConfigurationBuilder(context);
76         return builder.configure(configResource, null);
77     }
78
79     /**
80      * If no config location resource is configured on the servlet context, the value
81      * returned from this method will be used to initialise the MuleManager.
82      *
83      * @return the default config resource location
84      */

85     protected String JavaDoc getDefaultConfigResource()
86     {
87         return "/WEB-INF/mule-config.xml";
88     }
89
90     public void contextDestroyed(ServletContextEvent JavaDoc event)
91     {
92         MuleManager.getInstance().dispose();
93     }
94 }
95
Popular Tags