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.io.File;
14  import java.net.URL;
15  
16  import org.mod4j.dslcommon.generator.helpers.StringHelpers;
17  import org.mod4j.dslcommon.io.IDirectoryVisitor;
18  
19  /**
20   * @author jos
21   */
22  public class CrossxDirectoryVisitor implements IDirectoryVisitor {
23  
24      private DslExtension dsl = null;
25  
26      private String project;
27  
28      /**
29       * @param dsl
30       * @param theWorkDir
31       * @param standaloneSetup
32       */
33      public CrossxDirectoryVisitor(DslExtension dsl, String theWorkDir, boolean standaloneSetup) {
34          this.dsl = dsl;
35          this.project = theWorkDir;
36          this.standaloneSetup = standaloneSetup;
37          initialize();
38      }
39  
40      /*
41       * (non-Javadoc)
42       * 
43       * @see nl.klasse.tools.io.IDirectoryVisitor#visitDirectoryBefore(java.io.File)
44       */
45      public Object visitDirectoryBefore(File directory) {
46          return null;
47      }
48  
49      /*
50       * (non-Javadoc)
51       * 
52       * @see nl.klasse.tools.io.IDirectoryVisitor#visitDirectoryAfter(java.io.File)
53       */
54      public Object visitDirectoryAfter(File directory) {
55          return null;
56      }
57  
58      /*
59       * (non-Javadoc)
60       * 
61       * @see nl.klasse.tools.io.IDirectoryVisitor#visitFile(java.io.File)
62       */
63      public Object visitFile(File file) throws Mod4jWorkflowException {
64          if (file.isFile() && file.getName().endsWith(dsl.getDslFileExtension())) {
65              generateCrossxSymbols(file);
66          }
67          return null;
68      }
69  
70      private String oawWorkflow = null;
71  
72      private boolean standaloneSetup;
73  
74      /**
75       * Initialize stuff for running the visitor.
76       * 
77       */
78      private void initialize() {
79          oawWorkflow = dsl.getDsl2crossxWorkflow();
80          if ((oawWorkflow == null) || (oawWorkflow.length() == 0)) {
81              // do nothing
82              oawWorkflow = null;
83              return;
84          }
85          ClassLoader cls = CrossxDirectoryVisitor.class.getClassLoader();
86          URL url = cls.getResource(oawWorkflow);
87          if (url == null) {
88              System.err.println("Crossx oaW file [" + oawWorkflow + "] not found");
89              System.exit(1);
90          }
91          oawWorkflow = url.toString();
92      }
93  
94      // TODO extensions import from other files
95      private static final String CROSSX_EXTENSION = ".crossx~";
96  
97      private void generateCrossxSymbols(File file) throws Mod4jWorkflowException {
98          if (oawWorkflow == null) {
99              return;
100         }
101         String modelfile = file.getAbsolutePath();
102         modelfile = StringHelpers.replaceAllSubstrings(modelfile, "\\", "/");
103         String crossxfile = modelfile + CROSSX_EXTENSION;
104         modelfile = "file:/" + modelfile;
105 
106         RunCrossxWorkflow wf = new RunCrossxWorkflow();
107         wf.runWorkflow(oawWorkflow, project, modelfile, crossxfile, standaloneSetup);
108     }
109 }