dol: initial dol commit
[jump.git] / dol / src / dol / visitor / PipeAndFilter / PipeAndFilterVisitor.java
1 /* $Id: PipeAndFilterVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.PipeAndFilter;
3
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7
8 import dol.datamodel.pn.ProcessNetwork;
9 import dol.util.Copier;
10 import dol.visitor.PNVisitor;
11
12 /**
13  *
14  */
15 public class PipeAndFilterVisitor extends PNVisitor {
16
17     /**
18      * Constructor.
19      */
20     public PipeAndFilterVisitor(String packageName) {
21         _packageName = packageName;
22     }
23
24     /**
25      *
26      */
27     public void visitComponent(ProcessNetwork x) {
28         try {
29             _generateDirHierarchy();
30
31             x.accept(new PipeAndFilterMakefileVisitor(_srcDir));
32             x.accept(new PipeAndFilterModuleVisitor(_srcDir));
33             x.accept(new PipeAndFilterProcessVisitor(_wrapperDir));
34
35         } catch (Exception e) {
36             System.out.println(" SystemC PN Visitor: exception " +
37                                "occured: " + e.getMessage());
38             e.printStackTrace();
39         }
40
41     }
42
43     /**
44      *
45      */
46     private void _generateDirHierarchy()
47         throws IOException, FileNotFoundException {
48
49         File dir = new File(_packageName);
50         dir.mkdirs();
51
52         _srcDir = _packageName + _delimiter + _srcDirName;
53         dir = new File(_srcDir);
54         dir.mkdirs();
55
56         _libDir = _srcDir + _delimiter + _libDirName;
57         dir = new File(_libDir);
58         dir.mkdirs();
59
60         _processDir = _srcDir + _delimiter + _processDirName;
61         dir = new File(_processDir);
62         dir.mkdirs();
63
64         _wrapperDir = _srcDir + _delimiter + _wrapperDirName;
65         dir = new File(_wrapperDir);
66         dir.mkdirs();
67
68         // copy library
69         String libraryPath = _ui.getMySystemCLib();
70         libraryPath = libraryPath.replaceAll("systemC",
71                 "PipeAndFilter");
72         File source = new File(libraryPath);
73         File destination = new File(_libDir);
74         new Copier().copy(source, destination);
75
76         //copy process src code
77         source = new File(_srcDirName);
78         destination = new File(_processDir);
79         new Copier().copy(source, destination);
80     }
81
82     protected String _packageName = null;
83
84     protected String _srcDir = "";
85     protected static String _srcDirName = "src";
86
87     protected String _libDir = "";
88     protected static String _libDirName = "lib";
89
90     protected String _processDir = "";
91     protected static String _processDirName = "processes";
92
93     protected String _wrapperDir = "";
94     protected static String _wrapperDirName = "wrappers";
95 }
96