001    /**
002     * Copyright (c) 2000-present 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 BaseConvertProcess implements ConvertProcess {
027    
028            @Override
029            public void convert() throws ConvertException {
030                    try {
031                            if (getPath() != null) {
032                                    return;
033                            }
034    
035                            StopWatch stopWatch = new StopWatch();
036    
037                            stopWatch.start();
038    
039                            if (_log.isInfoEnabled()) {
040                                    Class<?> clazz = getClass();
041    
042                                    _log.info("Starting conversion for " + clazz.getName());
043                            }
044    
045                            doConvert();
046    
047                            if (_log.isInfoEnabled()) {
048                                    Class<?> clazz = getClass();
049    
050                                    _log.info(
051                                            "Finished conversion for " + clazz.getName() + " in " +
052                                                    stopWatch.getTime() + " ms");
053                            }
054                    }
055                    catch (Exception e) {
056                            throw new ConvertException(e);
057                    }
058                    finally {
059                            setParameterValues(null);
060    
061                            MaintenanceUtil.cancel();
062                    }
063            }
064    
065            @Override
066            public String getConfigurationErrorMessage() {
067                    return null;
068            }
069    
070            @Override
071            public abstract String getDescription();
072    
073            @Override
074            public String getParameterDescription() {
075                    return null;
076            }
077    
078            @Override
079            public String[] getParameterNames() {
080                    return null;
081            }
082    
083            public String[] getParameterValues() {
084                    return _paramValues;
085            }
086    
087            @Override
088            public String getPath() {
089                    return null;
090            }
091    
092            @Override
093            public abstract boolean isEnabled();
094    
095            @Override
096            public void setParameterValues(String[] values) {
097                    _paramValues = values;
098            }
099    
100            /**
101             * @throws ConvertException
102             */
103            @Override
104            public void validate() throws ConvertException {
105            }
106    
107            protected abstract void doConvert() throws Exception;
108    
109            private static final Log _log = LogFactoryUtil.getLog(
110                    BaseConvertProcess.class);
111    
112            private String[] _paramValues;
113    
114    }