git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1247 6f19259b...
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
CommitLineData
0dc8c589 1package org.tianocore.migration;\r
2\r
3import java.io.*;\r
4import java.util.*;\r
5\r
6public class Database {\r
7 Database() throws Exception {\r
8 if (System.getenv("WORKSPACE") == null) {\r
9 DatabasePath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
10 } else {\r
11 DatabasePath = System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
12 }\r
13 \r
14 importDBLib("Library.csv");\r
15 importDBGuid("Guid.csv", "Guid");\r
16 importDBGuid("Ppi.csv", "Ppi");\r
17 importDBGuid("Protocol.csv", "Protocol");\r
18 importDBMacro("Macro.csv");\r
19 }\r
20 \r
21 public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
22 \r
23 public String DatabasePath;\r
24 public Set<String> error = new HashSet<String>();\r
25 \r
26 private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
27 private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
28 private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
29 \r
30 private void importDBLib(String filename) throws Exception {\r
31 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
32 String line;\r
33 String[] linecontext;\r
34 Func lf;\r
35 \r
36 if (rd.ready()) {\r
37 System.out.println("Found " + filename + " , Importing Library Database");\r
38 while ((line = rd.readLine()) != null) {\r
39 if (line.length() != 0) {\r
40 linecontext = line.split(",");\r
41 lf = new Func(linecontext);\r
42 hashfunc.put(lf.r8funcname,lf);\r
43 }\r
44 }\r
45 }\r
46 }\r
47 \r
48 private void importDBGuid(String filename, String type) throws Exception {\r
49 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
50 String line;\r
51 String[] linecontext;\r
52 Guid gu;\r
53 \r
54 if (rd.ready()) {\r
55 System.out.println("Found " + filename + " , Importing " + type + " Database");\r
56 while ((line = rd.readLine()) != null) {\r
57 if (line.length() != 0) {\r
58 linecontext = line.split(",");\r
59 gu = new Guid(linecontext, type);\r
60 hashguid.put(gu.r8name,gu);\r
61 }\r
62 }\r
63 }\r
64 }\r
65 \r
66 private void importDBMacro(String filename) throws Exception {\r
67 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
68 String line;\r
69 String[] linecontext;\r
70 Macro mc;\r
71 \r
72 if (rd.ready()) {\r
73 System.out.println("Found " + filename + " , Importing Macro Database");\r
74 while ((line = rd.readLine()) != null) {\r
75 if (line.length() != 0) {\r
76 linecontext = line.split(",");\r
77 mc = new Macro(linecontext);\r
78 hashmacro.put(mc.r8name,mc);\r
79 }\r
80 }\r
81 }\r
82 }\r
83 \r
84 public String getR9Lib(String r8funcname) {\r
85 String temp = null;\r
86 if (hashfunc.containsKey(r8funcname)) {\r
87 temp = hashfunc.get(r8funcname).r9libname;\r
88 }\r
89 return temp;\r
90 }\r
91 \r
92 public String getR9Func(String r8funcname) {\r
93 String temp = null;\r
94 if (hashfunc.containsKey(r8funcname)) {\r
95 temp = hashfunc.get(r8funcname).r9funcname;\r
96 }\r
97 return temp;\r
98 }\r
99 \r
100 public boolean hasFunc(String r8lib) {\r
101 return hashfunc.containsKey(r8lib);\r
102 }\r
103\r
104 public boolean hasGuid(String r8guid) {\r
105 return hashguid.containsKey(r8guid);\r
106 }\r
107\r
108 public boolean hasMacro(String r8macro) {\r
109 return hashmacro.containsKey(r8macro);\r
110 }\r
111 \r
112 public String getR9Macro(String r8macro) {\r
113 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
114 }\r
115 \r
116 public String getR9Guidname(String r8Guid) {\r
117 String temp = null;\r
118 try {\r
119 temp = hashguid.get(r8Guid).r9name;\r
120 } catch (NullPointerException e) {\r
121 error.add("getR9Guidname :" + r8Guid);\r
122 }\r
123 return temp;\r
124 }\r
125 \r
126 public String getGuidType(String r8Guid) {\r
127 String temp = null;\r
128 try {\r
129 temp = hashguid.get(r8Guid).type;\r
130 } catch (NullPointerException e) {\r
131 error.add("getR9Guidname :" + r8Guid);\r
132 }\r
133 return temp;\r
134 }\r
135}\r