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.convert;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.util.MaintenanceUtil;
020    
021    import org.apache.commons.lang.time.StopWatch;
022    
023    /**
024     * @author Alexander Chow
025     */
026    public abstract class ConvertProcess {
027    
028            public void convert() throws ConvertException {
029                    try {
030                            if (getPath() != null) {
031                                    return;
032                            }
033    
034                            StopWatch stopWatch = new StopWatch();
035    
036                            stopWatch.start();
037    
038                            if (_log.isInfoEnabled()) {
039                                    _log.info("Starting conversion for " + getClass().getName());
040                            }
041    
042                            doConvert();
043    
044                            if (_log.isInfoEnabled()) {
045                                    _log.info(
046                                            "Finished conversion for " + getClass().getName() + " in " +
047                                                    stopWatch.getTime() + " ms");
048                            }
049                    }
050                    catch (Exception e) {
051                            throw new ConvertException(e);
052                    }
053                    finally {
054                            setParameterValues(null);
055    
056                            MaintenanceUtil.cancel();
057                    }
058            }
059    
060            public abstract String getDescription();
061    
062            public String getParameterDescription() {
063                    return null;
064            }
065    
066            public String[] getParameterNames() {
067                    return null;
068            }
069    
070            public String[] getParameterValues() {
071                    return _paramValues;
072            }
073    
074            public String getPath() {
075                    return null;
076            }
077    
078            public abstract boolean isEnabled();
079    
080            public void setParameterValues(String[] values) {
081                    _paramValues = values;
082            }
083    
084            protected abstract void doConvert() throws Exception;
085    
086            private static Log _log = LogFactoryUtil.getLog(ConvertProcess.class);
087    
088            private String[] _paramValues = null;
089    
090    }