View Javadoc

1   /*
2    * $Id: MuleServletContextListener.java 18803 2010-08-04 18:34:05Z rossmason $
3    * -------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.servlet;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.config.MuleProperties;
15  
16  import javax.servlet.ServletContextEvent;
17  import javax.servlet.ServletContextListener;
18  
19  public class MuleServletContextListener implements ServletContextListener
20  {
21      public static final String CONNECTOR_NAME = "mule.connector.name";
22  
23      private MuleContext muleContext;
24      private String connectorName;
25  
26      public MuleServletContextListener(MuleContext context, String name)
27      {
28          super();
29          muleContext = context;
30          connectorName = name;
31      }
32      
33      public void contextDestroyed(ServletContextEvent sce)
34      {
35          // nothing to do
36      }
37  
38      public void contextInitialized(ServletContextEvent event)
39      {
40          event.getServletContext().setAttribute(MuleProperties.MULE_CONTEXT_PROPERTY, muleContext);
41          //We keep this for backward compatability
42          event.getServletContext().setAttribute(AbstractReceiverServlet.SERVLET_CONNECTOR_NAME_PROPERTY, connectorName);
43          event.getServletContext().setAttribute(CONNECTOR_NAME, connectorName);
44      }
45  }