]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Database.java
a4b0d47872f374c599e8dc69b8eb2b5e6d167fab
[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 final class Database {
19 Database(String path) throws Exception {
20 DatabasePath = path;
21
22 importDBLib("Library.csv");
23 importDBGuid("Guid.csv", "Guid");
24 importDBGuid("Ppi.csv", "Ppi");
25 importDBGuid("Protocol.csv", "Protocol");
26 importDBMacro("Macro.csv");
27 }
28
29 public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";
30
31 public String DatabasePath;
32 public Set<String> error = new HashSet<String>();
33
34 private Map<String,Guid> hashguid = new HashMap<String,Guid>();
35 private Map<String,Func> hashfunc = new HashMap<String,Func>();
36 private Map<String,Macro> hashmacro = new HashMap<String,Macro>();
37
38 private void importDBLib(String filename) throws Exception {
39 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
40 String line;
41 String[] linecontext;
42 Func lf;
43
44 if (rd.ready()) {
45 System.out.println("Found " + filename + ", Importing Library Database.");
46 while ((line = rd.readLine()) != null) {
47 if (line.length() != 0) {
48 linecontext = line.split(",");
49 lf = new Func(linecontext);
50 hashfunc.put(lf.r8funcname,lf);
51 }
52 }
53 }
54 }
55
56 private void importDBGuid(String filename, String type) throws Exception {
57 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
58 String line;
59 String[] linecontext;
60 Guid gu;
61
62 if (rd.ready()) {
63 System.out.println("Found " + filename + ", Importing " + type + " Database.");
64 while ((line = rd.readLine()) != null) {
65 if (line.length() != 0) {
66 linecontext = line.split(",");
67 gu = new Guid(linecontext, type);
68 hashguid.put(gu.r8name,gu);
69 }
70 }
71 }
72 }
73
74 private void importDBMacro(String filename) throws Exception {
75 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
76 String line;
77 String[] linecontext;
78 Macro mc;
79
80 if (rd.ready()) {
81 System.out.println("Found " + filename + ", Importing Macro Database.");
82 while ((line = rd.readLine()) != null) {
83 if (line.length() != 0) {
84 linecontext = line.split(",");
85 mc = new Macro(linecontext);
86 hashmacro.put(mc.r8name,mc);
87 }
88 }
89 }
90 }
91
92 public String getR9Lib(String r8funcname) {
93 String temp = null;
94 if (hashfunc.containsKey(r8funcname)) {
95 temp = hashfunc.get(r8funcname).r9libname;
96 }
97 return temp;
98 }
99
100 public String getR9Func(String r8funcname) {
101 String temp = null;
102 if (hashfunc.containsKey(r8funcname)) {
103 temp = hashfunc.get(r8funcname).r9funcname;
104 }
105 return temp;
106 }
107
108 public boolean hasFunc(String r8lib) {
109 return hashfunc.containsKey(r8lib);
110 }
111
112 public boolean hasGuid(String r8guid) {
113 return hashguid.containsKey(r8guid);
114 }
115
116 public boolean hasMacro(String r8macro) {
117 return hashmacro.containsKey(r8macro);
118 }
119
120 public String getR9Macro(String r8macro) {
121 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it
122 }
123
124 public String getR9Guidname(String r8Guid) {
125 String temp = null;
126 try {
127 temp = hashguid.get(r8Guid).r9name;
128 } catch (NullPointerException e) {
129 error.add("getR9Guidname :" + r8Guid);
130 }
131 return temp;
132 }
133
134 public String getGuidType(String r8Guid) {
135 String temp = null;
136 try {
137 temp = hashguid.get(r8Guid).type;
138 } catch (NullPointerException e) {
139 error.add("getR9Guidname :" + r8Guid);
140 }
141 return temp;
142 }
143
144 public static Database init() throws Exception {
145 if (System.getenv("WORKSPACE") == null) {
146 return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
147 } else {
148 return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
149 }
150 }
151 }