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 = null;
035    
036                            if (_log.isInfoEnabled()) {
037                                    stopWatch = new StopWatch();
038    
039                                    stopWatch.start();
040    
041                                    _log.info("Starting conversion for " + getClass().getName());
042                            }
043    
044                            doConvert();
045    
046                            if (_log.isInfoEnabled()) {
047                                    _log.info(
048                                            "Finished conversion for " + getClass().getName() + " in " +
049                                                    stopWatch.getTime() + " ms");
050                            }
051                    }
052                    catch (Exception e) {
053                            throw new ConvertException(e);
054                    }
055                    finally {
056                            setParameterValues(null);
057    
058                            MaintenanceUtil.cancel();
059                    }
060            }
061    
062            public abstract String getDescription();
063    
064            public String getParameterDescription() {
065                    return null;
066            }
067    
068            public String[] getParameterNames() {
069                    return null;
070            }
071    
072            public String[] getParameterValues() {
073                    return _paramValues;
074            }
075    
076            public String getPath() {
077                    return null;
078            }
079    
080            public abstract boolean isEnabled();
081    
082            public void setParameterValues(String[] values) {
083                    _paramValues = values;
084            }
085    
086            protected abstract void doConvert() throws Exception;
087    
088            private static Log _log = LogFactoryUtil.getLog(ConvertProcess.class);
089    
090            private String[] _paramValues = null;
091    
092    }