View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.test.lifecycles;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.core.api.config.property.ConfigContext;
20  import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
21  import org.kuali.rice.kew.batch.KEWXmlDataLoader;
22  
23  
24  public class KPMEXmlDataLoaderLifecycle extends BaseLifecycle {
25      private static final Logger LOG = Logger.getLogger(KEWXmlDataLoaderLifecycle.class);
26  
27      private String filename;
28  
29      /**
30       * Specifies the XML resource to load.  The resource path should be in Spring resource notation.
31       * @param resource the XML resource to load
32       */
33      public KPMEXmlDataLoaderLifecycle(String resource) {
34          this.filename = resource;
35      }
36  
37      public void start() throws Exception {
38          String useKewXmlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.kewXmlmlDataLoaderLifecycle");
39  
40          if (useKewXmlDataLoaderLifecycle != null && !Boolean.valueOf(useKewXmlDataLoaderLifecycle)) {
41              LOG.debug("Skipping KEWXmlDataLoaderLifecycle due to property: use.kewXmlmlDataLoaderLifecycle=" + useKewXmlDataLoaderLifecycle);
42              return;
43          }
44  
45          LOG.info("################################");
46          LOG.info("#");
47          LOG.info("#  Begin Loading file '" + filename + "'");
48          LOG.info("#");
49          LOG.info("################################");
50          loadData();
51          super.start();
52      }
53  
54      /**
55       * Does the work of loading the data
56       * @throws Exception
57       */
58      protected void loadData() throws Exception {
59          KEWXmlDataLoader.loadXmlFile(filename);
60      }
61  }