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
= GlobalData
.parseXmlFile(packageFile
);
103 // We can change Map to XmlObject
105 Map
<String
, XmlObject
> spdDocMap
= new HashMap
<String
, XmlObject
>();
106 spdDocMap
.put("PackageSurfaceArea", spdDoc
);
107 SurfaceAreaQuery saq
= new SurfaceAreaQuery(spdDocMap
);
109 packageId
= saq
.getSpdHeader();
110 packageId
.setSpdFile(packageFile
);
113 // initialize Msa Files
114 // MSA file is absolute file path
116 String
[] msaFilenames
= saq
.getSpdMsaFile();
117 for (int i
= 0; i
< msaFilenames
.length
; i
++){
118 File msaFile
= new File(packageId
.getPackageDir() + File
.separatorChar
+ msaFilenames
[i
]);
119 Map
<String
, XmlObject
> msaDoc
= GlobalData
.getNativeMsa( msaFile
);
121 ModuleIdentification moduleId
= saq
.getMsaHeader();
123 moduleId
.setPackage(packageId
);
124 moduleId
.setMsaFile(msaFile
);
125 if (msaInfo
.containsKey(moduleId
)) {
126 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
+ "]!");
128 msaInfo
.put(moduleId
, msaFile
);
132 // initialize Package header files
134 Map
<String
, String
> packageHeaders
= saq
.getSpdPackageHeaderFiles();
135 Set keys
= packageHeaders
.keySet();
136 Iterator iter
= keys
.iterator();
137 while (iter
.hasNext()){
138 String moduleType
= (String
)iter
.next();
139 String header
= packageId
.getPackageRelativeDir() + File
.separatorChar
+ packageHeaders
.get(moduleType
);
142 // Change path seperator to system-dependent path separator
144 File file
= new File (header
);
145 header
= file
.getPath();
146 packageHeaderInfo
.put(moduleType
, header
);
150 // initialize Guid Info
152 guidInfo
.putAll(saq
.getSpdGuid());
155 // For Pcd get TokenSpaceGuid
157 Set
<String
> key
= guidInfo
.keySet();
158 Iterator item
= key
.iterator();
159 String
[] nameValue
= new String
[2];
160 while(item
.hasNext()){
161 nameValue
= guidInfo
.get(item
.next());
162 guidCnameInfo
.put(nameValue
[0], nameValue
[1]);
166 // initialize PPI info
168 ppiInfo
.putAll(saq
.getSpdPpi());
171 // initialize Protocol info
173 protocolInfo
.putAll(saq
.getSpdProtocol());
176 // initialize library class declaration
178 Map
<String
, String
[]> libraryClassHeaders
= saq
.getSpdLibraryClasses();
179 keys
= libraryClassHeaders
.keySet();
180 iter
= keys
.iterator();
181 while (iter
.hasNext()){
182 String libraryClassName
= (String
)iter
.next();
183 String
[] headerFiles
= libraryClassHeaders
.get(libraryClassName
);
184 for (int i
= 0; i
< headerFiles
.length
; i
++){
185 headerFiles
[i
] = packageId
.getPackageRelativeDir() + File
.separatorChar
+ headerFiles
[i
];
188 // Change path separator to system system-dependent path separator.
190 File file
= new File (headerFiles
[i
]);
191 headerFiles
[i
] = file
.getPath();
193 libClassHeaderList
.put(libraryClassName
, headerFiles
);
195 } catch (IOException ex
) {
196 EdkException edkException
= new EdkException("Parse of the package description file [" + packageFile
.getPath() + "] failed!\n" + ex
.getMessage());
197 edkException
.setStackTrace(ex
.getStackTrace());
199 } catch (XmlException ex
) {
200 EdkException edkException
= new EdkException("Parse of the package description file [" + packageFile
.getPath() + "] failed!\n" + ex
.getMessage());
201 edkException
.setStackTrace(ex
.getStackTrace());
206 public PackageIdentification
getPackageId() {
210 public File
getModuleFile(ModuleIdentification moduleId
) {
211 return msaInfo
.get(moduleId
);
214 public Set
<ModuleIdentification
> getModules(){
215 return msaInfo
.keySet();
219 return two value {CName, Guid}. If not found, return null.
221 public String
[] getPpi(String ppiName
) {
222 return ppiInfo
.get(ppiName
);
226 return two value {CName, Guid}. If not found, return null.
228 public String
[] getProtocol(String protocolName
) {
229 return protocolInfo
.get(protocolName
);
233 return two value {CName, Guid}. If not found, return null.
235 public String
[] getGuid(String guidName
) {
236 return guidInfo
.get(guidName
);
242 public String
getGuidFromCname(String cName
){
243 return guidCnameInfo
.get(cName
);
249 This function is to get the library exposed header file name according
252 @param libName Name of library class
253 @return Name of header file
255 String
[] getLibClassIncluder(String libName
) {
256 return libClassHeaderList
.get(libName
);
260 getModuleTypeIncluder
262 This function is to get the header file name from module info map
263 according to module type.
265 @param moduleType Module type.
266 @return Name of header file.
268 String
getPackageIncluder(String moduleType
) {
269 return packageHeaderInfo
.get(moduleType
);