KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: MuleXmlBuilderContextServlet.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 javax.servlet.ServletContext JavaDoc;
14 import javax.servlet.ServletException JavaDoc;
15 import javax.servlet.http.HttpServlet JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18
19 import java.io.IOException JavaDoc;
20
21 import org.mule.MuleManager;
22 import org.mule.config.ConfigurationException;
23 import org.mule.umo.manager.UMOManager;
24
25 /**
26  * @author EAF Team
27  */

28 public class MuleXmlBuilderContextServlet extends HttpServlet JavaDoc
29 {
30     /**
31      * Serial version
32      */

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

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

81     protected String JavaDoc getDefaultConfigResource()
82     {
83         return "/WEB-INF/mule-config.xml";
84     }
85
86     protected void service(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
87         throws ServletException JavaDoc, IOException JavaDoc
88     {
89         getServletContext().log(
90             "("
91                             + request.getRequestURI()
92                             + ")"
93                             + "MuleXmlBuilderContextServlet.service(HttpServletRequest request, HttpServletResponse response) call ignored.");
94         response.sendError(HttpServletResponse.SC_BAD_REQUEST);
95     }
96
97     public void destroy()
98     {
99         MuleManager.getInstance().dispose();
100     }
101 }
102
Popular Tags