1   /**
2    * Copyright (c) 2000-2010 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   *
12   * 
13   */
14  
15  package com.liferay.portlet;
16  
17  import com.liferay.portal.model.Layout;
18  import com.liferay.portal.model.User;
19  import com.liferay.portal.util.PropsValues;
20  
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.commons.pool.BasePoolableObjectFactory;
24  import org.apache.commons.pool.ObjectPool;
25  import org.apache.commons.pool.impl.StackObjectPool;
26  
27  /**
28   * <a href="EventResponseFactory.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class EventResponseFactory {
33  
34      public static EventResponseImpl create(
35              EventRequestImpl eventRequestImpl, HttpServletResponse response,
36              String portletName, User user, Layout layout)
37          throws Exception {
38  
39          EventResponseImpl eventResponseImpl = null;
40  
41          if (PropsValues.COMMONS_POOL_ENABLED) {
42              eventResponseImpl =
43                  (EventResponseImpl)_instance._pool.borrowObject();
44          }
45          else {
46              eventResponseImpl = new EventResponseImpl();
47          }
48  
49          eventResponseImpl.init(
50              eventRequestImpl, response, portletName, user, layout);
51  
52          return eventResponseImpl;
53      }
54  
55      public static void recycle(EventResponseImpl eventResponseImpl)
56          throws Exception {
57  
58          if (PropsValues.COMMONS_POOL_ENABLED) {
59              _instance._pool.returnObject(eventResponseImpl);
60          }
61          else if (eventResponseImpl != null) {
62              eventResponseImpl.recycle();
63          }
64      }
65  
66      private EventResponseFactory() {
67          _pool = new StackObjectPool(new Factory());
68      }
69  
70      private static EventResponseFactory _instance =
71          new EventResponseFactory();
72  
73      private ObjectPool _pool;
74  
75      private class Factory extends BasePoolableObjectFactory {
76  
77          public Object makeObject() {
78              return new EventResponseImpl();
79          }
80  
81          public void passivateObject(Object obj) {
82              EventResponseImpl eventResponseImpl = (EventResponseImpl)obj;
83  
84              eventResponseImpl.recycle();
85          }
86  
87      }
88  
89  }