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.portal.theme;
16  
17  import com.liferay.portal.util.PropsValues;
18  
19  import org.apache.commons.pool.BasePoolableObjectFactory;
20  import org.apache.commons.pool.ObjectPool;
21  import org.apache.commons.pool.impl.StackObjectPool;
22  
23  /**
24   * <a href="PortletDisplayFactory.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class PortletDisplayFactory {
29  
30      public static PortletDisplay create() throws Exception {
31          if (PropsValues.COMMONS_POOL_ENABLED) {
32              return (PortletDisplay)_instance._pool.borrowObject();
33          }
34          else {
35              return new PortletDisplay();
36          }
37      }
38  
39      public static void recycle(PortletDisplay portletDisplay) throws Exception {
40          if (PropsValues.COMMONS_POOL_ENABLED) {
41              _instance._pool.returnObject(portletDisplay);
42          }
43          else if (portletDisplay != null) {
44              portletDisplay.recycle();
45          }
46      }
47  
48      private PortletDisplayFactory() {
49          _pool = new StackObjectPool(new Factory());
50      }
51  
52      private static PortletDisplayFactory _instance =
53          new PortletDisplayFactory();
54  
55      private ObjectPool _pool;
56  
57      private class Factory extends BasePoolableObjectFactory {
58  
59          public Object makeObject() {
60              return new PortletDisplay();
61          }
62  
63          public void passivateObject(Object obj) {
64              PortletDisplay portletDisplay = (PortletDisplay)obj;
65  
66              portletDisplay.recycle();
67          }
68  
69      }
70  
71  }