001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public abstract class BasePortalLifecycle implements PortalLifecycle {
024    
025            public void portalDestroy() {
026                    if (!_calledPortalDestroy) {
027                            PortalLifecycleUtil.removeDestroy(this);
028    
029                            try {
030                                    doPortalDestroy();
031                            }
032                            catch (Exception e) {
033                                    _log.error(e, e);
034                            }
035    
036                            _calledPortalDestroy = true;
037                    }
038            }
039    
040            public void portalInit() {
041                    try {
042                            doPortalInit();
043                    }
044                    catch (Exception e) {
045                            _log.error(e, e);
046                    }
047            }
048    
049            public void registerPortalLifecycle() {
050                    PortalLifecycleUtil.register(this);
051            }
052    
053            protected abstract void doPortalDestroy() throws Exception;
054    
055            protected abstract void doPortalInit() throws Exception;
056    
057            private static Log _log = LogFactoryUtil.getLog(BasePortalLifecycle.class);
058    
059            private boolean _calledPortalDestroy;
060    
061    }