View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2009 Ordina and committers to Mod4j
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *     Ordina - initial implementation
10   *******************************************************************************/
11  package org.mod4j.dslcommon.openarchitectureware;
12  
13  import java.util.Date;
14  import java.util.HashMap;
15  import java.util.Map;
16  
17  import org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  import org.eclipse.emf.mwe.core.WorkflowRunner;
20  import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor;
21  //import org.eclipse.emf.mwe.core.resources.CachingResourceLoaderImpl;
22  //import org.eclipse.emf.mwe.core.resources.OsgiResourceLoader;
23  //import org.eclipse.emf.mwe.core.resources.ResourceLoader;
24  //import org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory;
25  //import org.mod4j.common.generator.admin.FileTrack;
26  /**
27   * @author johan
28   * 
29   */
30  public class Mod4jWorkflowRunner {
31  
32      private final Log logger = LogFactory.getLog(getClass());
33  
34      /**
35       * General Mod4j workflow runner. 
36       * 
37       * @param wfFile
38       *            absolute path string of the workflow file to execute
39       * @param properties
40       *            Map containing the properties for <code>wfFile</code>.
41       * @throws Mod4jWorkflowException
42       */
43      public void runWorkflow(final String wfFile, final Map<String, String> properties) throws Mod4jWorkflowException {
44  
45  
46          Map<String, Object> slotContents = new HashMap<String, Object>();
47          WorkflowRunner runner = new WorkflowRunner();
48  
49          String propertiesListing = "";
50          for (Map.Entry<String, String> prop: properties.entrySet()) {
51              propertiesListing += "\t\t" + prop.toString() + "\n";
52          } 
53  
54          logger.info("Running workflow [" + wfFile + "] with properties : \n" + propertiesListing); 
55  
56          Date date = new Date(System.currentTimeMillis());
57  //        System.err.println("03 ================== " + date.toString() + ": workflow [" + wfFile + "]");
58  //        ResourceLoader loader = ResourceLoaderFactory.getCurrentThreadResourceLoader();
59  //        
60  //        System.err.println("Classloader: " + (loader == null ? "NULL" : loader.toString() ) ) ;
61  //        if( loader == null ){
62  //              CachingResourceLoaderImpl crl = new CachingResourceLoaderImpl(
63  //                      new OsgiResourceLoader("org.mod4j.common", FileTrack.class.getClassLoader() )
64  //              ); 
65  //    
66  //              ResourceLoaderFactory.setCurrentThreadResourceLoader(crl);
67  //        }
68  //
69  //        date = new Date(System.currentTimeMillis());
70          System.err.println("04 ================== " + date.toString() + ": workflow [" + wfFile + "]");
71          if (!runner.run(wfFile, new NullProgressMonitor(), properties, slotContents)) {
72              logger.error("--------------------------------------------------------------------------------------");
73              logger.error("------- ERROR(S) detected while running workflow : [" + wfFile + "] ");
74              logger.error("------- See logging above for more details.");
75              logger.error("--------------------------------------------------------------------------------------");
76              throw new Mod4jWorkflowException("ERROR(S) detected while running workflow :" + wfFile);
77          }
78          date = new Date(System.currentTimeMillis());
79          System.err.println("05 ================== " + date.toString() + ": workflow [" + wfFile + "]");
80          logger.info("--------------------------------------------------------------------------");
81          logger.info("-------- Workflow SUCCESSFUL! ");
82          logger.info("--------------------------------------------------------------------------");
83      }
84  }