Add License Head to all files
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
17\r
18public class Database {\r
19 Database() throws Exception {\r
20 if (System.getenv("WORKSPACE") == null) {\r
21 DatabasePath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
22 } else {\r
23 DatabasePath = System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
24 }\r
25 \r
26 importDBLib("Library.csv");\r
27 importDBGuid("Guid.csv", "Guid");\r
28 importDBGuid("Ppi.csv", "Ppi");\r
29 importDBGuid("Protocol.csv", "Protocol");\r
30 importDBMacro("Macro.csv");\r
31 }\r
32 \r
33 public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
34 \r
35 public String DatabasePath;\r
36 public Set<String> error = new HashSet<String>();\r
37 \r
38 private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
39 private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
40 private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
41 \r
42 private void importDBLib(String filename) throws Exception {\r
43 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
44 String line;\r
45 String[] linecontext;\r
46 Func lf;\r
47 \r
48 if (rd.ready()) {\r
49 System.out.println("Found " + filename + " , Importing Library Database");\r
50 while ((line = rd.readLine()) != null) {\r
51 if (line.length() != 0) {\r
52 linecontext = line.split(",");\r
53 lf = new Func(linecontext);\r
54 hashfunc.put(lf.r8funcname,lf);\r
55 }\r
56 }\r
57 }\r
58 }\r
59 \r
60 private void importDBGuid(String filename, String type) throws Exception {\r
61 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
62 String line;\r
63 String[] linecontext;\r
64 Guid gu;\r
65 \r
66 if (rd.ready()) {\r
67 System.out.println("Found " + filename + " , Importing " + type + " Database");\r
68 while ((line = rd.readLine()) != null) {\r
69 if (line.length() != 0) {\r
70 linecontext = line.split(",");\r
71 gu = new Guid(linecontext, type);\r
72 hashguid.put(gu.r8name,gu);\r
73 }\r
74 }\r
75 }\r
76 }\r
77 \r
78 private void importDBMacro(String filename) throws Exception {\r
79 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
80 String line;\r
81 String[] linecontext;\r
82 Macro mc;\r
83 \r
84 if (rd.ready()) {\r
85 System.out.println("Found " + filename + " , Importing Macro Database");\r
86 while ((line = rd.readLine()) != null) {\r
87 if (line.length() != 0) {\r
88 linecontext = line.split(",");\r
89 mc = new Macro(linecontext);\r
90 hashmacro.put(mc.r8name,mc);\r
91 }\r
92 }\r
93 }\r
94 }\r
95 \r
96 public String getR9Lib(String r8funcname) {\r
97 String temp = null;\r
98 if (hashfunc.containsKey(r8funcname)) {\r
99 temp = hashfunc.get(r8funcname).r9libname;\r
100 }\r
101 return temp;\r
102 }\r
103 \r
104 public String getR9Func(String r8funcname) {\r
105 String temp = null;\r
106 if (hashfunc.containsKey(r8funcname)) {\r
107 temp = hashfunc.get(r8funcname).r9funcname;\r
108 }\r
109 return temp;\r
110 }\r
111 \r
112 public boolean hasFunc(String r8lib) {\r
113 return hashfunc.containsKey(r8lib);\r
114 }\r
115\r
116 public boolean hasGuid(String r8guid) {\r
117 return hashguid.containsKey(r8guid);\r
118 }\r
119\r
120 public boolean hasMacro(String r8macro) {\r
121 return hashmacro.containsKey(r8macro);\r
122 }\r
123 \r
124 public String getR9Macro(String r8macro) {\r
125 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
126 }\r
127 \r
128 public String getR9Guidname(String r8Guid) {\r
129 String temp = null;\r
130 try {\r
131 temp = hashguid.get(r8Guid).r9name;\r
132 } catch (NullPointerException e) {\r
133 error.add("getR9Guidname :" + r8Guid);\r
134 }\r
135 return temp;\r
136 }\r
137 \r
138 public String getGuidType(String r8Guid) {\r
139 String temp = null;\r
140 try {\r
141 temp = hashguid.get(r8Guid).type;\r
142 } catch (NullPointerException e) {\r
143 error.add("getR9Guidname :" + r8Guid);\r
144 }\r
145 return temp;\r
146 }\r
147}\r