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
;
19 import java
.io
.IOException
;
20 import java
.util
.HashMap
;
21 import java
.util
.Iterator
;
25 import org
.apache
.xmlbeans
.XmlException
;
26 import org
.apache
.xmlbeans
.XmlObject
;
27 import org
.tianocore
.build
.id
.ModuleIdentification
;
28 import org
.tianocore
.build
.id
.PackageIdentification
;
29 import org
.tianocore
.common
.exception
.EdkException
;
33 This class is to generate a global table for the content of spd file.
40 Map
<ModuleIdentification
, File
> msaInfo
= new HashMap
<ModuleIdentification
, File
>();
43 /// Map of module info.
45 /// Value: moduletype related include file
47 Map
<String
, String
> packageHeaderInfo
= new HashMap
<String
, String
>();
52 /// value: String[] a. PPI C_NAME; b. PPI GUID;
54 Map
<String
, String
[]> ppiInfo
= new HashMap
<String
, String
[]>();
57 /// Map of Protocol info.
58 /// Key : Protocol name
59 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;
61 Map
<String
, String
[]> protocolInfo
= new HashMap
<String
, String
[]>();
66 /// value: String[] a. Guid C_NAME; b. Guid's GUID;
68 Map
<String
, String
[]> guidInfo
= new HashMap
<String
, String
[]>();
73 /// value: String Guid's GUID
75 Map
<String
, String
> guidCnameInfo
= new HashMap
<String
, String
>();
77 /// Map of library class and its exposed header file.
78 /// Key : library class name
79 /// value : library class corresponding header file
81 Map
<String
, String
[]> libClassHeaderList
= new HashMap
<String
, String
[]>();
86 PackageIdentification packageId
;
91 This function mainly initialize some member variables.
93 Spd(File packageFile
) throws EdkException
{
95 // If specified package file not exists
97 if ( ! packageFile
.exists()) {
98 throw new EdkException("Package file [" + packageFile
.getPath() + "] does not exist!");
101 XmlObject spdDoc
= XmlObject
.Factory
.parse(packageFile
);
103 // Verify SPD file, if is invalid, throw Exception
105 if (! spdDoc
.validate()) {
106 throw new EdkException("Package Surface Area file [" + packageFile
.getPath() + "] format is invalid!");
109 // We can change Map to XmlObject
111 Map
<String
, XmlObject
> spdDocMap
= new HashMap
<String
, XmlObject
>();
112 spdDocMap
.put("PackageSurfaceArea", spdDoc
);
113 SurfaceAreaQuery saq
= new SurfaceAreaQuery(spdDocMap
);
115 packageId
= saq
.getSpdHeader();
116 packageId
.setSpdFile(packageFile
);
119 // initialize Msa Files
120 // MSA file is absolute file path
122 String
[] msaFilenames
= saq
.getSpdMsaFile();
123 for (int i
= 0; i
< msaFilenames
.length
; i
++){
124 File msaFile
= new File(packageId
.getPackageDir() + File
.separatorChar
+ msaFilenames
[i
]);
125 Map
<String
, XmlObject
> msaDoc
= GlobalData
.getNativeMsa( msaFile
);
127 ModuleIdentification moduleId
= saq
.getMsaHeader();
129 moduleId
.setPackage(packageId
);
130 moduleId
.setMsaFile(msaFile
);
131 if (msaInfo
.containsKey(moduleId
)) {
132 throw new EdkException("Found two modules with the same GUID and Version in package " + packageId
+ ".\nThey are module [" + msaInfo
.get(moduleId
) + "] and MSA file [" + msaFile
+ "]!");
134 msaInfo
.put(moduleId
, msaFile
);
138 // initialize Package header files
140 Map
<String
, String
> packageHeaders
= saq
.getSpdPackageHeaderFiles();
141 Set keys
= packageHeaders
.keySet();
142 Iterator iter
= keys
.iterator();
143 while (iter
.hasNext()){
144 String moduleType
= (String
)iter
.next();
145 String header
= packageId
.getPackageRelativeDir() + File
.separatorChar
+ packageHeaders
.get(moduleType
);
148 // Change path seperator to system-dependent path separator
150 File file
= new File (header
);
151 header
= file
.getPath();
152 packageHeaderInfo
.put(moduleType
, header
);
156 // initialize Guid Info
158 guidInfo
.putAll(saq
.getSpdGuid());
161 // For Pcd get TokenSpaceGuid
163 Set
<String
> key
= guidInfo
.keySet();
164 Iterator item
= key
.iterator();
165 String
[] nameValue
= new String
[2];
166 while(item
.hasNext()){
167 nameValue
= guidInfo
.get(item
.next());
168 guidCnameInfo
.put(nameValue
[0], nameValue
[1]);
172 // initialize PPI info
174 ppiInfo
.putAll(saq
.getSpdPpi());
177 // initialize Protocol info
179 protocolInfo
.putAll(saq
.getSpdProtocol());
182 // initialize library class declaration
184 Map
<String
, String
[]> libraryClassHeaders
= saq
.getSpdLibraryClasses();
185 keys
= libraryClassHeaders
.keySet();
186 iter
= keys
.iterator();
187 while (iter
.hasNext()){
188 String libraryClassName
= (String
)iter
.next();
189 String
[] headerFiles
= libraryClassHeaders
.get(libraryClassName
);
190 for (int i
= 0; i
< headerFiles
.length
; i
++){
191 headerFiles
[i
] = packageId
.getPackageRelativeDir() + File
.separatorChar
+ headerFiles
[i
];
194 // Change path separator to system system-dependent path separator.
196 File file
= new File (headerFiles
[i
]);
197 headerFiles
[i
] = file
.getPath();
199 libClassHeaderList
.put(libraryClassName
, headerFiles
);
201 } catch (IOException ex
) {
202 EdkException edkException
= new EdkException("Parse of the package description file [" + packageFile
.getPath() + "] failed!\n" + ex
.getMessage());
203 edkException
.setStackTrace(ex
.getStackTrace());
205 } catch (XmlException ex
) {
206 EdkException edkException
= new EdkException("Parse of the package description file [" + packageFile
.getPath() + "] failed!\n" + ex
.getMessage());
207 edkException
.setStackTrace(ex
.getStackTrace());
212 public PackageIdentification
getPackageId() {
216 public File
getModuleFile(ModuleIdentification moduleId
) {
217 return msaInfo
.get(moduleId
);
220 public Set
<ModuleIdentification
> getModules(){
221 return msaInfo
.keySet();
225 return two value {CName, Guid}. If not found, return null.
227 public String
[] getPpi(String ppiName
) {
228 return ppiInfo
.get(ppiName
);
232 return two value {CName, Guid}. If not found, return null.
234 public String
[] getProtocol(String protocolName
) {
235 return protocolInfo
.get(protocolName
);
239 return two value {CName, Guid}. If not found, return null.
241 public String
[] getGuid(String guidName
) {
242 return guidInfo
.get(guidName
);
248 public String
getGuidFromCname(String cName
){
249 return guidCnameInfo
.get(cName
);
255 This function is to get the library exposed header file name according
258 @param libName Name of library class
259 @return Name of header file
261 String
[] getLibClassIncluder(String libName
) {
262 return libClassHeaderList
.get(libName
);
266 getModuleTypeIncluder
268 This function is to get the header file name from module info map
269 according to module type.
271 @param moduleType Module type.
272 @return Name of header file.
274 String
getPackageIncluder(String moduleType
) {
275 return packageHeaderInfo
.get(moduleType
);