1
22
23 package com.liferay.portlet;
24
25 import com.liferay.portal.model.Layout;
26 import com.liferay.portal.model.User;
27 import com.liferay.portal.util.PropsValues;
28
29 import javax.portlet.PortletMode;
30 import javax.portlet.WindowState;
31
32 import javax.servlet.http.HttpServletResponse;
33
34 import org.apache.commons.pool.BasePoolableObjectFactory;
35 import org.apache.commons.pool.ObjectPool;
36 import org.apache.commons.pool.impl.StackObjectPool;
37
38
44 public class ActionResponseFactory {
45
46 public static ActionResponseImpl create(
47 ActionRequestImpl actionRequestImpl, HttpServletResponse response,
48 String portletName, User user, Layout layout,
49 WindowState windowState, PortletMode portletMode)
50 throws Exception {
51
52 ActionResponseImpl actionResponseImpl = null;
53
54 if (PropsValues.COMMONS_POOL_ENABLED) {
55 actionResponseImpl =
56 (ActionResponseImpl)_instance._pool.borrowObject();
57 }
58 else {
59 actionResponseImpl = new ActionResponseImpl();
60 }
61
62 actionResponseImpl.init(
63 actionRequestImpl, response, portletName, user, layout, windowState,
64 portletMode);
65
66 return actionResponseImpl;
67 }
68
69 public static void recycle(ActionResponseImpl actionResponseImpl)
70 throws Exception {
71
72 if (PropsValues.COMMONS_POOL_ENABLED) {
73 _instance._pool.returnObject(actionResponseImpl);
74 }
75 else if (actionResponseImpl != null) {
76 actionResponseImpl.recycle();
77 }
78 }
79
80 private ActionResponseFactory() {
81 _pool = new StackObjectPool(new Factory());
82 }
83
84 private static ActionResponseFactory _instance =
85 new ActionResponseFactory();
86
87 private ObjectPool _pool;
88
89 private class Factory extends BasePoolableObjectFactory {
90
91 public Object makeObject() {
92 return new ActionResponseImpl();
93 }
94
95 public void passivateObject(Object obj) {
96 ActionResponseImpl actionResponseImpl = (ActionResponseImpl)obj;
97
98 actionResponseImpl.recycle();
99 }
100
101 }
102
103 }