01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portlet;
22:
23: import com.liferay.portal.model.Portlet;
24: import com.liferay.portal.util.PropsValues;
25:
26: import javax.portlet.PortletContext;
27: import javax.portlet.PortletMode;
28: import javax.portlet.PortletPreferences;
29: import javax.portlet.WindowState;
30:
31: import javax.servlet.http.HttpServletRequest;
32:
33: import org.apache.commons.pool.BasePoolableObjectFactory;
34: import org.apache.commons.pool.ObjectPool;
35: import org.apache.commons.pool.impl.StackObjectPool;
36:
37: /**
38: * <a href="ActionRequestFactory.java.html"><b><i>View Source</i></b></a>
39: *
40: * @author Brian Wing Shun Chan
41: *
42: */
43: public class ActionRequestFactory {
44:
45: public static ActionRequestImpl create(HttpServletRequest req,
46: Portlet portlet, CachePortlet cachePortlet,
47: PortletContext portletCtx, WindowState windowState,
48: PortletMode portletMode, PortletPreferences prefs, long plid)
49: throws Exception {
50:
51: ActionRequestImpl actionRequestImpl = null;
52:
53: if (PropsValues.COMMONS_POOL_ENABLED) {
54: actionRequestImpl = (ActionRequestImpl) _instance._pool
55: .borrowObject();
56: } else {
57: actionRequestImpl = new ActionRequestImpl();
58: }
59:
60: actionRequestImpl.init(req, portlet, cachePortlet, portletCtx,
61: windowState, portletMode, prefs, plid);
62:
63: return actionRequestImpl;
64: }
65:
66: public static void recycle(ActionRequestImpl actionRequestImpl)
67: throws Exception {
68:
69: if (PropsValues.COMMONS_POOL_ENABLED) {
70: _instance._pool.returnObject(actionRequestImpl);
71: } else if (actionRequestImpl != null) {
72: actionRequestImpl.recycle();
73: }
74: }
75:
76: private ActionRequestFactory() {
77: _pool = new StackObjectPool(new Factory());
78: }
79:
80: private static ActionRequestFactory _instance = new ActionRequestFactory();
81:
82: private ObjectPool _pool;
83:
84: private class Factory extends BasePoolableObjectFactory {
85:
86: public Object makeObject() {
87: return new ActionRequestImpl();
88: }
89:
90: public void passivateObject(Object obj) {
91: ActionRequestImpl actionRequestImpl = (ActionRequestImpl) obj;
92:
93: actionRequestImpl.recycle();
94: }
95:
96: }
97:
98: }
|