KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > web > container > JSPPicoContainerFactory


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: JSPPicoContainerFactory.java,v $
31  * Revision 1.2 2005/04/09 17:19:58 colinmacleod
32  * Changed copyright text to GPL v2 explicitly.
33  *
34  * Revision 1.1.1.1 2005/03/10 17:51:35 colinmacleod
35  * Restructured ivata op around Hibernate/PicoContainer.
36  * Renamed ivata groupware.
37  *
38  * Revision 1.1 2004/09/30 15:16:01 colinmacleod
39  * Split off addressbook elements into security subproject.
40  *
41  * Revision 1.1 2004/07/13 19:41:15 colinmacleod
42  * Moved project to POJOs from EJBs.
43  * Applied PicoContainer to services layer (replacing session EJBs).
44  * Applied Hibernate to persistence layer (replacing entity EJBs).
45  * -----------------------------------------------------------------------------
46  */

47 package com.ivata.groupware.web.container;
48
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50 import javax.servlet.http.HttpSession JavaDoc;
51 import javax.servlet.jsp.PageContext JavaDoc;
52
53 import org.picocontainer.PicoContainer;
54
55 import com.ivata.groupware.admin.security.server.SecuritySession;
56
57 /**
58  * @author Colin MacLeod
59  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
60  * @since Apr 18, 2004
61  * @version $Revision: 1.2 $
62  */

63 public final class JSPPicoContainerFactory {
64     /**
65      * Get the current security session pico container from the JSP page context.
66      *
67      * @return current session container.
68      */

69     public static PicoContainer getContainerFromPageContext(PageContext JavaDoc pageContext) {
70         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
71         return getContainerFromRequest(request);
72     }
73     /**
74      * Get the current security session pico container from the JSP request.
75      *
76      * @return current session container.
77      */

78     public static PicoContainer getContainerFromRequest(HttpServletRequest JavaDoc request) {
79         HttpSession JavaDoc session = request.getSession();
80         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
81         return securitySession.getContainer();
82     }
83     /**
84      * Convenience method. Get the PicoContainer from the page context and then
85      * use it to get the implementation.
86      *
87      * @return valid instance from the current pico container.
88      */

89     public static Object JavaDoc getInstanceFromPageContext(PageContext JavaDoc pageContext, Object JavaDoc componentKey) {
90         PicoContainer container = getContainerFromPageContext(pageContext);
91         return container.getComponentInstance(componentKey);
92     }
93 }
94
Popular Tags