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="ThemeDisplayFactory.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class ThemeDisplayFactory {
29  
30      public static ThemeDisplay create() throws Exception {
31          if (PropsValues.COMMONS_POOL_ENABLED) {
32              return (ThemeDisplay)_instance._pool.borrowObject();
33          }
34          else {
35              return new ThemeDisplay();
36          }
37      }
38  
39      public static void recycle(ThemeDisplay themeDisplay) throws Exception {
40          if (PropsValues.COMMONS_POOL_ENABLED) {
41              _instance._pool.returnObject(themeDisplay);
42          }
43          else if (themeDisplay != null) {
44              themeDisplay.recycle();
45          }
46      }
47  
48      private ThemeDisplayFactory() {
49          _pool = new StackObjectPool(new Factory());
50      }
51  
52      private static ThemeDisplayFactory _instance = new ThemeDisplayFactory();
53  
54      private ObjectPool _pool;
55  
56      private class Factory extends BasePoolableObjectFactory {
57  
58          public Object makeObject() {
59              return new ThemeDisplay();
60          }
61  
62          public void passivateObject(Object obj) {
63              ThemeDisplay themeDisplay = (ThemeDisplay)obj;
64  
65              themeDisplay.recycle();
66          }
67  
68      }
69  
70  }