001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.util.ArrayList;
018 import java.util.List;
019
020
023 public class PortalLifecycleUtil {
024
025 public static void flushDestroys() {
026 _inFlushDestroys = true;
027
028 for (PortalLifecycle portalLifecycle : _portalLifecyclesDestroy) {
029 portalLifecycle.portalDestroy();
030 }
031
032 _portalLifecyclesDestroy.clear();
033
034 _inFlushDestroys = false;
035 }
036
037 @SuppressWarnings("deprecation")
038 public static void flushInits() {
039 if (_portalLifecyclesInit != null) {
040 List<PortalLifecycle> portalLifecyclesInit = _portalLifecyclesInit;
041
042 _portalLifecyclesInit = null;
043
044 for (PortalLifecycle portalLifecycle : portalLifecyclesInit) {
045 portalLifecycle.portalInit();
046 }
047 }
048
049 PortalInitableUtil.flushInitables();
050 }
051
052 public static void register(PortalLifecycle portalLifecycle) {
053 register(portalLifecycle, PortalLifecycle.METHOD_ALL);
054 }
055
056 public static void register(PortalLifecycle portalLifecycle, int method) {
057 if ((method == PortalLifecycle.METHOD_ALL) ||
058 (method == PortalLifecycle.METHOD_INIT)) {
059
060 if (_portalLifecyclesInit == null) {
061 portalLifecycle.portalInit();
062 }
063 else {
064 _portalLifecyclesInit.add(portalLifecycle);
065 }
066 }
067
068 if ((method == PortalLifecycle.METHOD_ALL) ||
069 (method == PortalLifecycle.METHOD_DESTROY)) {
070
071 _portalLifecyclesDestroy.add(portalLifecycle);
072 }
073 }
074
075 public static void removeDestroy(PortalLifecycle portalLifecycle) {
076 if (!_inFlushDestroys) {
077 _portalLifecyclesDestroy.remove(portalLifecycle);
078 }
079 }
080
081 private static boolean _inFlushDestroys;
082 private static List<PortalLifecycle> _portalLifecyclesDestroy =
083 new ArrayList<PortalLifecycle>();
084 private static List<PortalLifecycle> _portalLifecyclesInit =
085 new ArrayList<PortalLifecycle>();
086
087 }