KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > filter > AxisFilter


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5
6 package org.exoplatform.filter;
7
8 import java.io.IOException JavaDoc;
9
10 import javax.servlet.Filter JavaDoc;
11 import javax.servlet.FilterChain JavaDoc;
12 import javax.servlet.FilterConfig JavaDoc;
13 import javax.servlet.ServletException JavaDoc;
14 import javax.servlet.ServletRequest JavaDoc;
15 import javax.servlet.ServletResponse JavaDoc;
16
17 import org.exoplatform.container.PortalContainer;
18 import org.exoplatform.container.RootContainer;
19 import org.exoplatform.services.database.HibernateServiceContainer;
20
21
22 /**
23  * Created y the eXo platform team
24  * User: Benjamin Mestrallet
25  * Date: 26 juil. 2004
26  */

27 public class AxisFilter implements Filter JavaDoc {
28
29   public static final String JavaDoc WSRP_CONTAINER = "portal";
30   private HibernateServiceContainer hserviceContainer_;
31
32   public void init(FilterConfig JavaDoc filterConfig) throws ServletException JavaDoc {
33   }
34
35   public void doFilter(ServletRequest JavaDoc servletRequest, ServletResponse JavaDoc servletResponse, FilterChain JavaDoc filterChain)
36       throws IOException JavaDoc, ServletException JavaDoc {
37     PortalContainer pcontainer = RootContainer.getInstance().getPortalContainer(WSRP_CONTAINER);
38     PortalContainer.setInstance(pcontainer);
39     try {
40       filterChain.doFilter(servletRequest, servletResponse);
41     } finally {
42       getHibernateServiceContainer(pcontainer).closeAllSessions() ;
43     }
44   }
45
46   public void destroy() {
47   }
48   
49   private HibernateServiceContainer getHibernateServiceContainer(PortalContainer pcontainer){
50     if(hserviceContainer_ == null){
51       hserviceContainer_ = (HibernateServiceContainer) pcontainer.getComponentInstanceOfType(
52           HibernateServiceContainer.class) ;
53     }
54     return hserviceContainer_;
55   }
56
57 }
58
Popular Tags