1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.convert;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.util.MaintenanceUtil;
20  
21  import org.apache.commons.lang.time.StopWatch;
22  
23  /**
24   * <a href="ConvertProcess.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Alexander Chow
27   */
28  public abstract class ConvertProcess {
29  
30      public void convert() throws ConvertException {
31          try {
32              if (getPath() != null) {
33                  return;
34              }
35  
36              StopWatch stopWatch = null;
37  
38              if (_log.isInfoEnabled()) {
39                  stopWatch = new StopWatch();
40  
41                  stopWatch.start();
42  
43                  _log.info("Starting conversion for " + getClass().getName());
44              }
45  
46              doConvert();
47  
48              if (_log.isInfoEnabled()) {
49                  _log.info(
50                      "Finished conversion for " + getClass().getName() + " in " +
51                          stopWatch.getTime() + " ms");
52              }
53          }
54          catch (Exception e) {
55              throw new ConvertException(e);
56          }
57          finally {
58              setParameterValues(null);
59  
60              MaintenanceUtil.cancel();
61          }
62      }
63  
64      public abstract String getDescription();
65  
66      public String getParameterDescription() {
67          return null;
68      }
69  
70      public String[] getParameterNames() {
71          return null;
72      }
73  
74      public String[] getParameterValues() {
75          return _paramValues;
76      }
77  
78      public String getPath() {
79          return null;
80      }
81  
82      public abstract boolean isEnabled();
83  
84      public void setParameterValues(String[] values) {
85          _paramValues = values;
86      }
87  
88      protected abstract void doConvert() throws Exception;
89  
90      private static Log _log = LogFactoryUtil.getLog(ConvertProcess.class);
91  
92      private String[] _paramValues = null;
93  
94  }