View Javadoc

1   /*
2    * Copyright 2007 Hippo
3    *
4    * Licensed under the Apache License, Version 2.0 (the  "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" 
12   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  package nl.hippo.portal;
17  
18  import javax.servlet.ServletContextEvent;
19  import javax.servlet.ServletContextListener;
20  
21  import nl.hippo.portal.cms.CMSApplicationRegistry;
22  import nl.hippo.portal.registry.HippoPortalRegistry;
23  
24  import org.springframework.web.context.WebApplicationContext;
25  import org.springframework.web.context.support.WebApplicationContextUtils;
26  
27  /***
28   * @version $Id: PortalServletContentListener.java 6122 2007-04-18 14:34:48Z pduin $
29   *
30   */
31  public class PortalServletContentListener implements ServletContextListener
32  {
33      /* (non-Javadoc)
34       * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
35       */
36      public void contextInitialized(ServletContextEvent event)
37      {
38          try
39          {
40              WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
41              CMSApplicationRegistry registry = (CMSApplicationRegistry)context.getBean(CMSApplicationRegistry.class.getName());
42              HippoPortalRegistry.getInstance().register(registry);
43          }
44          catch (Exception e)
45          {
46              if ( e instanceof RuntimeException )
47              {
48                  throw (RuntimeException)e;
49              }
50              throw new RuntimeException(e);
51          }
52      }
53  
54      /* (non-Javadoc)
55       * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
56       */
57      public void contextDestroyed(ServletContextEvent event)
58      {
59          try
60          {
61              WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
62              CMSApplicationRegistry registry = (CMSApplicationRegistry)context.getBean(CMSApplicationRegistry.class.getName());
63              HippoPortalRegistry.getInstance().unregister(registry.getRegistryName());
64          }
65          catch (Exception e)
66          {
67              if ( e instanceof RuntimeException )
68              {
69                  throw (RuntimeException)e;
70              }
71              throw new RuntimeException(e);
72          }
73      }
74  }