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
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.
13 package org
.tianocore
.migration
;
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";
23 DatabasePath
= System
.getenv("WORKSPACE") + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration";
26 importDBLib("Library.csv");
27 importDBGuid("Guid.csv", "Guid");
28 importDBGuid("Ppi.csv", "Ppi");
29 importDBGuid("Protocol.csv", "Protocol");
30 importDBMacro("Macro.csv");
33 public static String defaultpath
= "C:" + File
.separator
+ "tianocore" + File
.separator
+ "edk2" + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration";
35 public String DatabasePath
;
36 public Set
<String
> error
= new HashSet
<String
>();
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
>();
42 private void importDBLib(String filename
) throws Exception
{
43 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
60 private void importDBGuid(String filename
, String type
) throws Exception
{
61 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
78 private void importDBMacro(String filename
) throws Exception
{
79 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
96 public String
getR9Lib(String r8funcname
) {
98 if (hashfunc
.containsKey(r8funcname
)) {
99 temp
= hashfunc
.get(r8funcname
).r9libname
;
104 public String
getR9Func(String r8funcname
) {
106 if (hashfunc
.containsKey(r8funcname
)) {
107 temp
= hashfunc
.get(r8funcname
).r9funcname
;
112 public boolean hasFunc(String r8lib
) {
113 return hashfunc
.containsKey(r8lib
);
116 public boolean hasGuid(String r8guid
) {
117 return hashguid
.containsKey(r8guid
);
120 public boolean hasMacro(String r8macro
) {
121 return hashmacro
.containsKey(r8macro
);
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
128 public String
getR9Guidname(String r8Guid
) {
131 temp
= hashguid
.get(r8Guid
).r9name
;
132 } catch (NullPointerException e
) {
133 error
.add("getR9Guidname :" + r8Guid
);
138 public String
getGuidType(String r8Guid
) {
141 temp
= hashguid
.get(r8Guid
).type
;
142 } catch (NullPointerException e
) {
143 error
.add("getR9Guidname :" + r8Guid
);