1
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
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 }