View Javadoc

1   /*
2    * Copyright 2007 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.kew.batch;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.core.config.ConfigContext;
20  import org.kuali.rice.core.lifecycle.BaseLifecycle;
21  
22  /**
23   * A lifecycle for loading KEW XML datasets.
24   * This lifecycle will not be run (even if it is listed in the lifecycles list)
25   * if the 'use.kewXmlmlDataLoaderLifecycle' configuration property is defined, and is
26   * not 'true'.  If the property is omitted the lifecycle runs as normal.
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class KEWXmlDataLoaderLifecycle extends BaseLifecycle {
31      private static final Logger LOG = Logger.getLogger(KEWXmlDataLoaderLifecycle.class);
32  
33      private String filename;
34  
35      /**
36       * Configures the KEWXmlDataLoaderLifecycle to load the "default" data set from the classpath,
37       * classpath:DefaultTestData.xml files
38       */
39      public KEWXmlDataLoaderLifecycle() {
40          this("classpath:DefaultTestData.xml");
41      }
42  
43      /**
44       * Specifies the XML resource to load.  The resource path should be in Spring resource notation.
45       * @param resource the XML resource to load
46       */
47      public KEWXmlDataLoaderLifecycle(String resource) {
48          this.filename = resource;
49      }
50  
51      public void start() throws Exception {
52          String useKewXmlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.kewXmlmlDataLoaderLifecycle");
53  
54          if (useKewXmlDataLoaderLifecycle != null && !Boolean.valueOf(useKewXmlDataLoaderLifecycle)) {
55              LOG.debug("Skipping KEWXmlDataLoaderLifecycle due to property: use.kewXmlmlDataLoaderLifecycle=" + useKewXmlDataLoaderLifecycle);
56              return;
57          }
58  
59          LOG.info("################################");
60          LOG.info("#");
61          LOG.info("#  Begin Loading file '" + filename + "'");
62          LOG.info("#");
63          LOG.info("################################");
64          loadData();
65          super.start();
66      }
67  
68      /**
69       * Does the work of loading the data
70       * @throws Exception
71       */
72      protected void loadData() throws Exception {
73          KEWXmlDataLoader.loadXmlResource(filename);
74      }
75  }