1
2
3
4
5
6
7
8
9
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
21
22 public class CrossxDirectoryVisitor implements IDirectoryVisitor {
23
24 private DslExtension dsl = null;
25
26 private String project;
27
28
29
30
31
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
42
43
44
45 public Object visitDirectoryBefore(File directory) {
46 return null;
47 }
48
49
50
51
52
53
54 public Object visitDirectoryAfter(File directory) {
55 return null;
56 }
57
58
59
60
61
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
76
77
78 private void initialize() {
79 oawWorkflow = dsl.getDsl2crossxWorkflow();
80 if ((oawWorkflow == null) || (oawWorkflow.length() == 0)) {
81
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
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 }