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.kernel.util;
16  
17  import java.util.List;
18  import java.util.Vector;
19  
20  /**
21   * <a href="PortalLifecycleUtil.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class PortalLifecycleUtil {
26  
27      public static synchronized void flushDestroys() {
28          _inFlushDestroys = true;
29  
30          for (PortalLifecycle portalLifecycle : _portalLifecyclesDestroy) {
31              portalLifecycle.portalDestroy();
32          }
33  
34          _portalLifecyclesDestroy.clear();
35  
36          _inFlushDestroys = false;
37      }
38  
39      @SuppressWarnings("deprecation")
40      public static synchronized void flushInits() {
41          if (_portalLifecyclesInit != null) {
42              for (PortalLifecycle portalLifecycle : _portalLifecyclesInit) {
43                  portalLifecycle.portalInit();
44              }
45  
46              _portalLifecyclesInit = null;
47          }
48  
49          PortalInitableUtil.flushInitables();
50      }
51  
52      public static synchronized void register(PortalLifecycle portalLifecycle) {
53          register(portalLifecycle, PortalLifecycle.METHOD_ALL);
54      }
55  
56      public static synchronized void register(
57          PortalLifecycle portalLifecycle, int method) {
58  
59          if ((method == PortalLifecycle.METHOD_ALL) ||
60              (method == PortalLifecycle.METHOD_INIT)) {
61  
62              if (_portalLifecyclesInit == null) {
63                  portalLifecycle.portalInit();
64              }
65              else {
66                  _portalLifecyclesInit.add(portalLifecycle);
67              }
68          }
69  
70          if ((method == PortalLifecycle.METHOD_ALL) ||
71              (method == PortalLifecycle.METHOD_DESTROY)) {
72  
73              _portalLifecyclesDestroy.add(portalLifecycle);
74          }
75      }
76  
77      public static synchronized void removeDestroy(
78          PortalLifecycle portalLifecycle) {
79  
80          if (!_inFlushDestroys) {
81              _portalLifecyclesDestroy.remove(portalLifecycle);
82          }
83      }
84  
85      private static boolean _inFlushDestroys;
86      private static List<PortalLifecycle> _portalLifecyclesDestroy =
87          new Vector<PortalLifecycle>();
88      private static List<PortalLifecycle> _portalLifecyclesInit =
89          new Vector<PortalLifecycle>();
90  
91  }