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