Skip to contentMethod: action()
      1: /**
2:  * 
3:  */
4: package controller.buildingphase;
5: 
6: import java.io.File;
7: import java.io.FileInputStream;
8: import java.io.IOException;
9: 
10: import basic.Buffer;
11: import controller.BuildingPhase;
12: import model.Package;
13: import model.RouterSoftware;
14: import model.type.TypeFile;
15: import parser.ParserException;
16: import parser.TypeFileParser;
17: import reader.ReaderException;
18: import scanner.ScannerException;
19: import scanner.TypeFileScanner;
20: import symbols.AbstractSymbol;
21: 
22: /**
23:  * Scans and parses a type file.
24:  */
25: public class ScanAndParseTypeFile extends BuildingPhase {
26:         /**
27:          * The associated package.
28:          */
29:         private final Package pkg;
30:         /**
31:          * The path to the type file.
32:          */
33:         private final File typeFile;
34: 
35:         /**
36:          * Constructor. No side effects.
37:          * 
38:          * @param pkg
39:          *            The associated package.
40:          * @param typeFile
41:          *            the path to the type file.
42:          */
43: 
44:         private final RouterSoftware rs;
45: 
46:         /**
47:          * Constructor.
48:          * 
49:          * @param pkg
50:          *            Package
51:          * @param typeFile
52:          *            TypeFile to parse
53:          * @param rs
54:          *            RouterSoftware package
55:          */
56:         public ScanAndParseTypeFile(final Package pkg, final File typeFile, final RouterSoftware rs) {
57:                 super();
58:                 this.pkg = pkg;
59:                 this.typeFile = typeFile;
60:                 this.rs = rs;
61:         }
62: 
63:         @Override
64:         public void action() throws ScannerException, InterruptedException, IOException,
65:                         ReaderException, ParserException {
66:                 final Buffer<AbstractSymbol> typeBuffer = new Buffer<AbstractSymbol>(10000000);
67:                 TypeFileScanner.toSymbolSequence(new FileInputStream(typeFile.getPath()),
68:                                 typeFile.getPath(), typeBuffer);
69:                 final TypeFile tp =
70:                                 new TypeFileParser(this.pkg.getRouterSoftware(), typeBuffer).getTypeFile();
71:                 this.rs.getTypeFileManager().addTypeFile(tp);
72: 
73:                 pkg.setTypeFile(tp);
74:         }
75: }