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
.frameworkwizard
.platform
.ui
.global
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
24 import org
.apache
.xmlbeans
.XmlObject
;
25 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
26 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
30 This class is to generate a global table for the content of spd file.
37 Map
<ModuleIdentification
, File
> msaInfo
= new HashMap
<ModuleIdentification
, File
>();
40 /// Map of module info.
42 /// Value: moduletype related include file
44 Map
<String
, String
> packageHeaderInfo
= new HashMap
<String
, String
>();
49 /// value: String[] a. PPI C_NAME; b. PPI GUID;
51 Map
<String
, String
[]> ppiInfo
= new HashMap
<String
, String
[]>();
54 /// Map of Protocol info.
55 /// Key : Protocol name
56 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;
58 Map
<String
, String
[]> protocolInfo
= new HashMap
<String
, String
[]>();
63 /// value: String[] a. Guid C_NAME; b. Guid's GUID;
65 Map
<String
, String
[]> guidInfo
= new HashMap
<String
, String
[]>();
68 /// Map of library class and its exposed header file.
69 /// Key : library class name
70 /// value : library class corresponding header file
72 Map
<String
, String
[]> libClassHeaderList
= new HashMap
<String
, String
[]>();
75 // Xml Doc of Spd file, Msa file
77 public Map
<String
, XmlObject
> spdDocMap
= new HashMap
<String
, XmlObject
>();
78 public Map
<ModuleIdentification
, XmlObject
> msaDocMap
= new HashMap
<ModuleIdentification
, XmlObject
>();
82 PackageIdentification packageId
;
87 This function mainly initialize some member variables.
89 Spd(File packageFile
) throws Exception
{
91 XmlObject spdDoc
= XmlObject
.Factory
.parse(packageFile
);
93 // Verify SPD file, if is invalid, throw Exception
95 // if (! spdDoc.validate()) {
96 // throw new Exception("Package Surface Area file [" + packageFile.getPath() + "] is invalid. ");
98 // We can change Map to XmlObject
100 spdDocMap
.put("PackageSurfaceArea", spdDoc
);
101 SurfaceAreaQuery
.setDoc(spdDocMap
);
105 packageId
= SurfaceAreaQuery
.getSpdHeader();
106 packageId
.setSpdFile(packageFile
);
109 // initialize Msa Files
110 // MSA file is absolute file path
112 String
[] msaFilenames
= SurfaceAreaQuery
.getSpdMsaFile();
113 for (int i
= 0; i
< msaFilenames
.length
; i
++){
114 File msaFile
= new File(packageId
.getPackageDir() + File
.separatorChar
+ msaFilenames
[i
]);
115 Map
<String
, XmlObject
> msaDoc
= GlobalData
.getNativeMsa( msaFile
);
116 SurfaceAreaQuery
.push(msaDoc
);
117 ModuleIdentification moduleId
= SurfaceAreaQuery
.getMsaHeader();
118 SurfaceAreaQuery
.pop();
119 moduleId
.setPackage(packageId
);
120 msaInfo
.put(moduleId
, msaFile
);
121 msaDocMap
.put(moduleId
, msaDoc
.get("ModuleSurfaceArea"));
124 // initialize Package header files
126 // Map<String, String> packageHeaders = SurfaceAreaQuery.getSpdPackageHeaderFiles();
127 // Set keys = packageHeaders.keySet();
128 // Iterator iter = keys.iterator();
129 // while (iter.hasNext()){
130 // String moduleType = (String)iter.next();
131 // String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType);
133 // // Change path seperator to system-dependent path separator
135 // File file = new File (header);
136 // header = file.getParent();
137 // packageHeaderInfo.put(moduleType, header);
140 // initialize Guid Info
142 guidInfo
.putAll(SurfaceAreaQuery
.getSpdGuid());
144 // initialize PPI info
146 ppiInfo
.putAll(SurfaceAreaQuery
.getSpdPpi());
148 // initialize Protocol info
150 protocolInfo
.putAll(SurfaceAreaQuery
.getSpdProtocol());
152 // initialize library class declaration
154 Map
<String
, String
[]> libraryClassHeaders
= SurfaceAreaQuery
.getSpdLibraryClasses();
155 Set
<String
> keys
= libraryClassHeaders
.keySet();
156 Iterator iter
= keys
.iterator();
157 while (iter
.hasNext()){
158 String libraryClassName
= (String
)iter
.next();
159 String
[] headerFiles
= libraryClassHeaders
.get(libraryClassName
);
160 for (int i
= 0; i
< headerFiles
.length
; i
++){
161 headerFiles
[i
] = packageId
.getPackageRelativeDir() + File
.separatorChar
+ headerFiles
[i
];
164 // Change path separator to system system-dependent path separator.
166 File file
= new File (headerFiles
[i
]);
167 headerFiles
[i
] = file
.getPath();
169 libClassHeaderList
.put(libraryClassName
, headerFiles
);
172 catch (Exception e
) {
173 e
.setStackTrace(e
.getStackTrace());
174 throw new Exception("Parse package description file [" + packageId
.getSpdFile() + "] Error.\n"
179 public PackageIdentification
getPackageId() {
183 public File
getModuleFile(ModuleIdentification moduleId
) {
184 return msaInfo
.get(moduleId
);
187 public Set
<ModuleIdentification
> getModules(){
188 return msaInfo
.keySet();
192 return two value {CName, Guid}. If not found, return null.
194 public String
[] getPpi(String ppiName
) {
195 return ppiInfo
.get(ppiName
);
199 return two value {CName, Guid}. If not found, return null.
201 public String
[] getProtocol(String protocolName
) {
202 return protocolInfo
.get(protocolName
);
206 return two value {CName, Guid}. If not found, return null.
208 public String
[] getGuid(String guidName
) {
209 return guidInfo
.get(guidName
);
215 This function is to get the library exposed header file name according
218 @param libName Name of library class
219 @return Name of header file
221 String
[] getLibClassIncluder(String libName
) {
222 return libClassHeaderList
.get(libName
);
226 getModuleTypeIncluder
228 This function is to get the header file name from module info map
229 according to module type.
231 @param moduleType Module type.
232 @return Name of header file.
234 String
getPackageIncluder(String moduleType
) {
235 return packageHeaderInfo
.get(moduleType
);