1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.builders;
12
13 import org.mule.MuleManager;
14 import org.mule.MuleServer;
15 import org.mule.config.ConfigurationException;
16 import org.mule.umo.UMOException;
17 import org.mule.umo.manager.UMOManager;
18 import org.mule.util.StringUtils;
19
20 import javax.servlet.ServletContext;
21 import javax.servlet.ServletContextEvent;
22 import javax.servlet.ServletContextListener;
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public class MuleXmlBuilderContextListener implements ServletContextListener
37 {
38
39
40
41 public static final String INIT_PARAMETER_MULE_CONFIG = "org.mule.config";
42
43
44
45
46
47 public static final String INIT_PARAMETER_WEBAPP_CLASSPATH = "org.mule.webapp.classpath";
48
49 public void contextInitialized(ServletContextEvent event)
50 {
51 initialize(event.getServletContext());
52 }
53
54 public void initialize(ServletContext context)
55 {
56 String config = context.getInitParameter(INIT_PARAMETER_MULE_CONFIG);
57 if (config == null)
58 {
59 config = getDefaultConfigResource();
60 }
61
62 String webappClasspath = context.getInitParameter(INIT_PARAMETER_WEBAPP_CLASSPATH);
63 if (StringUtils.isBlank(webappClasspath))
64 {
65 webappClasspath = null;
66 }
67
68 try
69 {
70 createManager(config, webappClasspath, context);
71 }
72 catch (UMOException ex)
73 {
74 context.log(ex.getMessage(), ex);
75
76 ex.printStackTrace();
77 }
78 catch (Error error)
79 {
80
81 context.log(error.getMessage(), error);
82
83 error.printStackTrace();
84 throw error;
85 }
86 }
87
88
89
90
91
92
93
94
95 protected UMOManager createManager(String configResource, String webappClasspath, ServletContext context)
96 throws ConfigurationException
97 {
98 WebappMuleXmlConfigurationBuilder builder = new WebappMuleXmlConfigurationBuilder(context, webappClasspath);
99 return builder.configure(configResource, null);
100 }
101
102
103
104
105
106
107
108 protected String getDefaultConfigResource()
109 {
110 return MuleServer.DEFAULT_CONFIGURATION;
111 }
112
113 public void contextDestroyed(ServletContextEvent event)
114 {
115 destroy();
116 }
117
118 public void destroy()
119 {
120 MuleManager.getInstance().dispose();
121 }
122 }