1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Base class for project file parsers |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.project; |
|
20 |
|
21 import java.io.File; |
|
22 |
|
23 import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.FileErrorParameters; |
|
24 import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode; |
|
25 import com.nokia.tracecompiler.model.TraceCompilerException; |
|
26 import com.nokia.tracecompiler.model.TraceModel; |
|
27 |
|
28 /** |
|
29 * Base class for project file parsers |
|
30 * |
|
31 */ |
|
32 public abstract class ProjectFileParser { |
|
33 |
|
34 /** |
|
35 * Trace model |
|
36 */ |
|
37 protected TraceModel model; |
|
38 |
|
39 /** |
|
40 * Project file to be parsed |
|
41 */ |
|
42 protected File projectFile; |
|
43 |
|
44 /** |
|
45 * Constructor |
|
46 * |
|
47 * @param model |
|
48 * the trace model |
|
49 * @param fileName |
|
50 * the project file name |
|
51 * @throws TraceCompilerException |
|
52 * if file does not exist |
|
53 */ |
|
54 protected ProjectFileParser(TraceModel model, String fileName) |
|
55 throws TraceCompilerException { |
|
56 File file = new File(fileName); |
|
57 if (file.exists()) { |
|
58 this.model = model; |
|
59 this.projectFile = file; |
|
60 createParser(); |
|
61 } else { |
|
62 FileErrorParameters params = new FileErrorParameters(); |
|
63 params.file = fileName; |
|
64 throw new TraceCompilerException( |
|
65 TraceCompilerErrorCode.FILE_NOT_FOUND, params); |
|
66 } |
|
67 } |
|
68 |
|
69 /** |
|
70 * Creates the file parser |
|
71 * |
|
72 * @throws TraceCompilerException |
|
73 * if creation fails |
|
74 */ |
|
75 protected abstract void createParser() throws TraceCompilerException; |
|
76 |
|
77 /** |
|
78 * Parses the project file |
|
79 * |
|
80 * @throws TraceCompilerException |
|
81 * if parser fails |
|
82 */ |
|
83 public abstract void parse() throws TraceCompilerException; |
|
84 |
|
85 } |
|