4 This class is to generate a global table for the content of spd file.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.build
.global
;
17 import java
.util
.HashMap
;
18 import java
.util
.List
;
21 import org
.tianocore
.PackageSurfaceAreaDocument
;
22 import org
.tianocore
.GuidDeclarationsDocument
.GuidDeclarations
;
23 import org
.tianocore
.IncludeHeaderDocument
.IncludeHeader
;
24 import org
.tianocore
.LibraryClassDeclarationDocument
.LibraryClassDeclaration
;
25 import org
.tianocore
.LibraryClassDeclarationsDocument
.LibraryClassDeclarations
;
26 import org
.tianocore
.PackageHeadersDocument
.PackageHeaders
;
27 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
28 import org
.tianocore
.PpiDeclarationsDocument
.PpiDeclarations
;
29 import org
.tianocore
.ProtocolDeclarationsDocument
.ProtocolDeclarations
;
33 This class is to generate a global table for the content of spd file.
38 /// Map of module name and package it belongs to.
39 /// Key : Module BaseName
40 /// Value: Relative Path to Package
42 Map
<String
, String
[]> msaInfo
= new HashMap
<String
, String
[]>();
45 /// Map of module info.
47 /// Value: moduletype related include file
49 Map
<String
, String
> moduleInfo
= new HashMap
<String
, String
>();
54 /// value: String[] a. PPI C_NAME; b. PPI GUID;
56 Map
<String
, String
[]> ppiInfo
= new HashMap
<String
, String
[]>();
59 /// Map of Protocol info.
60 /// Key : Protocol name
61 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;
63 Map
<String
, String
[]> protocolInfo
= new HashMap
<String
, String
[]>();
68 /// value: String[] a. Guid C_NAME; b. Guid's GUID;
70 Map
<String
, String
[]> guidInfo
= new HashMap
<String
, String
[]>();
74 /// Map of library class and its exposed header file.
75 /// Key : library class name
76 /// value : library class corresponding header file
78 Map
<String
, String
> libClassHeaderList
= new HashMap
<String
, String
>();
83 String packagePath
= null;
88 This function mainly initialize some member variables.
90 @param spdDoc Handle of spd document.
91 @param spdPath Path of spd file.
93 Spd (PackageSurfaceAreaDocument spdDoc
, String spdPath
) {
95 PackageSurfaceArea spd
= spdDoc
.getPackageSurfaceArea();
96 this.packagePath
= spdPath
;
98 GuidDeclarations spdGuidInfo
= spd
.getGuidDeclarations();
99 genGuidInfoList(spdGuidInfo
);
101 PpiDeclarations spdPpiInfo
= spd
.getPpiDeclarations();
102 genPpiInfoList(spdPpiInfo
);
104 ProtocolDeclarations spdProtocolInfo
= spd
.getProtocolDeclarations();
105 genProtocolInfoList(spdProtocolInfo
);
107 LibraryClassDeclarations spdLibClassDeclare
= spd
108 .getLibraryClassDeclarations();
109 genLibClassDeclare(spdLibClassDeclare
);
111 PackageHeaders spdPackageHeaderInfo
= spd
.getPackageHeaders();
112 genModuleInfoList(spdPackageHeaderInfo
);
119 This function is to generate Module info map.
121 @param packageHeader The information of packageHeader which descripted
124 public void genModuleInfoList(PackageHeaders packageHeader
) {
126 if (packageHeader
!= null) {
127 List
<IncludeHeader
> headerList
= packageHeader
.getIncludeHeaderList();
128 for (int i
= 0; i
< headerList
.size(); i
++) {
131 .put(headerList
.get(i
).getModuleType()
132 .toString(), headerList
.get(i
)
134 } catch (Exception e
) {
136 .print("can't find ModuleHeaders ModuleType & includeHeader!\n");
145 This function is to generate Ppi info map.
147 @param ppiInfo The information of PpiDeclarations which descripted
150 public void genPpiInfoList(PpiDeclarations ppiInfo
) {
151 String
[] cNameGuid
= new String
[2];
153 if (ppiInfo
!= null) {
154 List
<PpiDeclarations
.Entry
> ppiEntryList
= ppiInfo
.getEntryList();
155 for (int i
= 0; i
< ppiEntryList
.size(); i
++) {
157 cNameGuid
[0] = ppiEntryList
.get(i
).getCName();
158 cNameGuid
[1] = formatGuidName(ppiEntryList
.get(i
)
159 .getGuid().getStringValue());
160 this.ppiInfo
.put(ppiEntryList
.get(i
).getName(), new String
[] {
161 cNameGuid
[0], cNameGuid
[1] });
162 } catch (Exception e
) {
164 .print("can't find GuidDeclarations C_Name & Guid!\n");
173 This function is to generate Protocol info map.
175 @param proInfo The information of ProtocolDeclarations which
176 descripted in spd file.
178 public void genProtocolInfoList(ProtocolDeclarations proInfo
) {
179 String
[] cNameGuid
= new String
[2];
180 if (proInfo
!= null) {
181 List
<ProtocolDeclarations
.Entry
> protocolEntryList
= proInfo
.getEntryList();
182 for (int i
= 0; i
< protocolEntryList
.size(); i
++) {
184 cNameGuid
[0] = protocolEntryList
.get(i
).getCName();
185 cNameGuid
[1] = formatGuidName(protocolEntryList
.get(i
)
186 .getGuid().getStringValue());
188 String temp
= new String(protocolEntryList
.get(i
).getName());
189 this.protocolInfo
.put(temp
, new String
[] { cNameGuid
[0],
191 } catch (Exception e
) {
193 .print("can't find ProtocolDeclarations C_Name & Guid!\n");
202 This function is to generate GUID inf map.
204 @param guidInfo The information of GuidDeclarations which descripted
208 public void genGuidInfoList(GuidDeclarations guidInfo
) {
209 String
[] cNameGuid
= new String
[2];
210 if (guidInfo
!= null) {
212 List
<GuidDeclarations
.Entry
> guidEntryList
= guidInfo
.getEntryList();
213 for (int i
= 0; i
< guidEntryList
.size(); i
++) {
214 cNameGuid
[0] = guidEntryList
.get(i
).getCName();
215 cNameGuid
[1] = formatGuidName(guidEntryList
.get(i
)
216 .getGuid().getStringValue());
217 this.guidInfo
.put(guidEntryList
.get(i
).getName(), new String
[] {
218 cNameGuid
[0], cNameGuid
[1] });
226 This function is to generate the libClassHeader list.
228 @param libClassDeclares The information of LibraryClassDeclarations which
229 descripted in spd file.
231 public void genLibClassDeclare(LibraryClassDeclarations libClassDeclares
) {
232 if (libClassDeclares
!= null && libClassDeclares
.getLibraryClassDeclarationList() != null) {
233 if (libClassDeclares
.getLibraryClassDeclarationList().size() > 0) {
234 List
<LibraryClassDeclaration
> libDeclareList
= libClassDeclares
.getLibraryClassDeclarationList();
235 for (int i
= 0; i
< libDeclareList
.size(); i
++) {
236 libClassHeaderList
.put(libDeclareList
.get(i
).getLibraryClass()
237 .getStringValue(), libDeclareList
.get(i
)
238 .getIncludeHeader().getStringValue());
247 This function is to get ppi GUID according ppi name.
249 @param ppiStr Name of ppi.
252 public String
getPpiGuid(String ppiStr
) {
253 if (ppiInfo
.get(ppiStr
) != null) {
254 return ppiInfo
.get(ppiStr
)[1];
264 This function is to get the ppi CName and it's GUID according to ppi name.
266 @param ppiName Name of ppi.
267 @return Ppi CName and it's GUID.
269 public String
[] getPpiCnameGuidArray(String ppiName
) {
270 return this.ppiInfo
.get(ppiName
);
276 This function is to get the protocol GUID according to protocol's name.
278 @param protocolStr Name of protocol.
279 @return Protocol's GUID.
281 public String
getProtocolGuid(String protocolStr
) {
282 if (protocolInfo
.get(protocolStr
) != null) {
283 return this.protocolInfo
.get(protocolStr
)[0];
290 getProtocolNameGuidArray
292 This function is to get the protocol's CName ant it's GUID according to
295 @param protocolName Name of protocl.
296 @return Protocol's CName and it's GUID.
298 public String
[] getProtocolNameGuidArray(String protocolName
) {
299 return this.protocolInfo
.get(protocolName
);
305 This function is to get the GUID according to GUID's name
307 @param guidStr Name of GUID
310 public String
getGUIDGuid(String guidStr
) {
311 if (guidInfo
.get(guidStr
) != null) {
312 return guidInfo
.get(guidStr
)[1];
322 This function is to get the GUID's CName and it's GUID according to
325 @param guidName Name of GUID
326 @return CName and GUID.
328 public String
[] getGuidNameArray(String guidName
) {
329 return this.guidInfo
.get(guidName
);
335 This function is to get the library exposed header file name according
338 @param libName Name of library class
339 @return Name of header file
341 String
getLibClassIncluder(String libName
) {
342 return libClassHeaderList
.get(libName
);
346 getModuleTypeIncluder
348 This function is to get the header file name from module info map
349 according to module type.
351 @param moduleType Module type.
352 @return Name of header file.
354 String
getModuleTypeIncluder(String moduleType
) {
355 return moduleInfo
.get(moduleType
);
361 This function is to formate GUID to ANSI c form.
363 @param guidNameCon String of GUID.
364 @return Formated GUID.
366 public static String
formatGuidName (String guidNameConv
) {
371 .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {
372 strList
= guidNameConv
.split("-");
373 guid
= "0x" + strList
[0] + ", ";
374 guid
= guid
+ "0x" + strList
[1] + ", ";
375 guid
= guid
+ "0x" + strList
[2] + ", ";
377 guid
= guid
+ "0x" + strList
[3].substring(0, 2) + ", ";
378 guid
= guid
+ "0x" + strList
[3].substring(2, 4);
380 while (index
< strList
[4].length()) {
382 guid
= guid
+ "0x" + strList
[4].substring(index
, index
+ 2);
387 } else if (guidNameConv
388 .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {
389 strList
= guidNameConv
.split(",");
392 // chang Microsoft specific form to ANSI c form
394 for (int i
= 0; i
< 3; i
++){
395 guid
= guid
+ strList
[i
] + ",";
399 for (int i
= 3; i
< strList
.length
; i
++){
400 if (i
== strList
.length
- 1){
401 guid
= guid
+ strList
[i
];
403 guid
= guid
+ strList
[i
] + ",";
409 System
.out
.println("Check GUID Value, it don't conform to the schema!!!");