1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet;
21  
22  import com.liferay.portal.model.Portlet;
23  import com.liferay.portal.util.PropsValues;
24  
25  import javax.portlet.PortletContext;
26  import javax.portlet.PortletMode;
27  import javax.portlet.PortletPreferences;
28  import javax.portlet.WindowState;
29  
30  import javax.servlet.http.HttpServletRequest;
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="ActionRequestFactory.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class ActionRequestFactory {
43  
44      public static ActionRequestImpl create(
45              HttpServletRequest request, Portlet portlet,
46              InvokerPortlet invokerPortlet, PortletContext portletContext,
47              WindowState windowState, PortletMode portletMode,
48              PortletPreferences prefs, long plid)
49          throws Exception {
50  
51          ActionRequestImpl actionRequestImpl = null;
52  
53          if (PropsValues.COMMONS_POOL_ENABLED) {
54              actionRequestImpl =
55                  (ActionRequestImpl)_instance._pool.borrowObject();
56          }
57          else {
58              actionRequestImpl = new ActionRequestImpl();
59          }
60  
61          actionRequestImpl.init(
62              request, portlet, invokerPortlet, portletContext, windowState,
63              portletMode, prefs, plid);
64  
65          return actionRequestImpl;
66      }
67  
68      public static void recycle(ActionRequestImpl actionRequestImpl)
69          throws Exception {
70  
71          if (PropsValues.COMMONS_POOL_ENABLED) {
72              _instance._pool.returnObject(actionRequestImpl);
73          }
74          else if (actionRequestImpl != null) {
75              actionRequestImpl.recycle();
76          }
77      }
78  
79      private ActionRequestFactory() {
80          _pool = new StackObjectPool(new Factory());
81      }
82  
83      private static ActionRequestFactory _instance = new ActionRequestFactory();
84  
85      private ObjectPool _pool;
86  
87      private class Factory extends BasePoolableObjectFactory {
88  
89          public Object makeObject() {
90              return new ActionRequestImpl();
91          }
92  
93          public void passivateObject(Object obj) {
94              ActionRequestImpl actionRequestImpl = (ActionRequestImpl)obj;
95  
96              actionRequestImpl.recycle();
97          }
98  
99      }
100 
101 }