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