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.HashMap;
14  import java.util.Map;
15  
16  import org.mod4j.crossx.mm.crossx.ModelInfo;
17  import org.eclipse.emf.mwe.core.WorkflowRunner;
18  import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor;
19  
20  public class RunCrossxWorkflow {
21  
22      public ModelInfo crossxModel = null;
23  
24      /**
25       * @param wfFile
26       * @param modelfile
27       * @param crossxfile
28       * @throws Mod4jWorkflowException
29       */
30      public void runWorkflow(String wfFile, String project, String modelfile, String crossxfile, boolean isStandaloneSetup)
31              throws Mod4jWorkflowException {
32          System.err.println("Run [" + wfFile + "] on:");
33          System.err.println("    modelfile  [" + modelfile + "]");
34          System.err.println("    crossxfile [" + crossxfile + "]");
35  
36          Map<String, Object> slotContents = new HashMap<String, Object>();
37          Map<String, String> properties = new HashMap<String, String>();
38  
39          properties.put("modelfile", modelfile);
40          properties.put("crossxfile", "file:/" + crossxfile);
41          properties.put("project", project);
42          properties.put("isStandaloneSetup", isStandaloneSetup ? "true" : "false");
43          properties.put("isEclipseSetup", isStandaloneSetup ? "false" : "true");
44  
45          WorkflowRunner runner = new WorkflowRunner();
46          if (!runner.run(wfFile, new NullProgressMonitor(), properties, slotContents)) {
47              throw new Mod4jWorkflowException("ERROR(S) detected while running crossx workflow on "
48                      + properties.get("modelfile") + "! See logging.");
49          }
50  
51          Object tmp = properties.get("crossxModel");
52          if ((tmp != null)) {
53              if ((tmp instanceof ModelInfo)) {
54                  crossxModel = (ModelInfo) tmp;
55                  System.err.println("Crossx Model of [" + crossxModel.getResource() + "]");
56              } else {
57                  System.err.println("Crossx Model not empty");
58              }
59          } else {
60              System.err.println("Crossx Model NULL");
61          }
62          System.err.println("Crossx workflow SUCCESSFUL!");
63      }
64  }