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.Layout;
24: import com.liferay.portal.model.User;
25: import com.liferay.portal.util.PropsValues;
26:
27: import javax.portlet.PortletMode;
28: import javax.portlet.WindowState;
29:
30: import javax.servlet.http.HttpServletResponse;
31:
32: import org.apache.commons.pool.BasePoolableObjectFactory;
33: import org.apache.commons.pool.ObjectPool;
34: import org.apache.commons.pool.impl.StackObjectPool;
35:
36: /**
37: * <a href="ActionResponseFactory.java.html"><b><i>View Source</i></b></a>
38: *
39: * @author Brian Wing Shun Chan
40: *
41: */
42: public class ActionResponseFactory {
43:
44: public static ActionResponseImpl create(ActionRequestImpl req,
45: HttpServletResponse res, String portletName, User user,
46: Layout layout, WindowState windowState,
47: PortletMode portletMode) throws Exception {
48:
49: ActionResponseImpl actionResponseImpl = null;
50:
51: if (PropsValues.COMMONS_POOL_ENABLED) {
52: actionResponseImpl = (ActionResponseImpl) _instance._pool
53: .borrowObject();
54: } else {
55: actionResponseImpl = new ActionResponseImpl();
56: }
57:
58: actionResponseImpl.init(req, res, portletName, user, layout,
59: windowState, portletMode);
60:
61: return actionResponseImpl;
62: }
63:
64: public static void recycle(ActionResponseImpl actionResponseImpl)
65: throws Exception {
66:
67: if (PropsValues.COMMONS_POOL_ENABLED) {
68: _instance._pool.returnObject(actionResponseImpl);
69: } else if (actionResponseImpl != null) {
70: actionResponseImpl.recycle();
71: }
72: }
73:
74: private ActionResponseFactory() {
75: _pool = new StackObjectPool(new Factory());
76: }
77:
78: private static ActionResponseFactory _instance = new ActionResponseFactory();
79:
80: private ObjectPool _pool;
81:
82: private class Factory extends BasePoolableObjectFactory {
83:
84: public Object makeObject() {
85: return new ActionResponseImpl();
86: }
87:
88: public void passivateObject(Object obj) {
89: ActionResponseImpl actionResponseImpl = (ActionResponseImpl) obj;
90:
91: actionResponseImpl.recycle();
92: }
93:
94: }
95:
96: }
|