001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            public void registerPortalLifecycle(int method) {
054                    PortalLifecycleUtil.register(this, method);
055            }
056    
057            protected abstract void doPortalDestroy() throws Exception;
058    
059            protected abstract void doPortalInit() throws Exception;
060    
061            private static Log _log = LogFactoryUtil.getLog(BasePortalLifecycle.class);
062    
063            private boolean _calledPortalDestroy;
064    
065    }