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