001    /**
002     * Copyright (c) 2000-2013 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            @Override
026            public void portalDestroy() {
027                    if (!_calledPortalDestroy) {
028                            PortalLifecycleUtil.removeDestroy(this);
029    
030                            try {
031                                    doPortalDestroy();
032                            }
033                            catch (Exception e) {
034                                    _log.error(e, e);
035                            }
036    
037                            _calledPortalDestroy = true;
038                    }
039            }
040    
041            @Override
042            public void portalInit() {
043                    try {
044                            doPortalInit();
045                    }
046                    catch (Exception e) {
047                            _log.error(e, e);
048    
049                            throw new IllegalStateException("Unable to initialize portal", e);
050                    }
051            }
052    
053            public void registerPortalLifecycle() {
054                    PortalLifecycleUtil.register(this);
055            }
056    
057            public void registerPortalLifecycle(int method) {
058                    PortalLifecycleUtil.register(this, method);
059            }
060    
061            protected abstract void doPortalDestroy() throws Exception;
062    
063            protected abstract void doPortalInit() throws Exception;
064    
065            private static Log _log = LogFactoryUtil.getLog(BasePortalLifecycle.class);
066    
067            private boolean _calledPortalDestroy;
068    
069    }