]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/Spd.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / global / Spd.java
1 /** @file
2 Spd class.
3
4 This class is to generate a global table for the content of spd file.
5
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
11
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.
14
15 **/
16 package org.tianocore.frameworkwizard.platform.ui.global;
17
18 import java.io.File;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.Map;
22 import java.util.Set;
23
24 import org.apache.xmlbeans.XmlObject;
25 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
26 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
27
28 /**
29
30 This class is to generate a global table for the content of spd file.
31
32 **/
33 public class Spd {
34 ///
35 ///
36 ///
37 Map<ModuleIdentification, File> msaInfo = new HashMap<ModuleIdentification, File>();
38
39 ///
40 /// Map of module info.
41 /// Key : moduletype
42 /// Value: moduletype related include file
43 ///
44 Map<String, String> packageHeaderInfo = new HashMap<String, String>();
45
46 ///
47 /// Map of PPI info.
48 /// Key : PPI name
49 /// value: String[] a. PPI C_NAME; b. PPI GUID;
50 ///
51 Map<String, String[]> ppiInfo = new HashMap<String, String[]>();
52
53 ///
54 /// Map of Protocol info.
55 /// Key : Protocol name
56 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;
57 ///
58 Map<String, String[]> protocolInfo = new HashMap<String, String[]>();
59
60 ///
61 /// Map of Guid info.
62 /// Key : Guid name
63 /// value: String[] a. Guid C_NAME; b. Guid's GUID;
64 ///
65 Map<String, String[]> guidInfo = new HashMap<String, String[]>();
66
67 ///
68 /// Map of library class and its exposed header file.
69 /// Key : library class name
70 /// value : library class corresponding header file
71 ///
72 Map<String, String[]> libClassHeaderList = new HashMap<String, String[]>();
73
74 //
75 // Xml Doc of Spd file, Msa file
76 //
77 public Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();
78 public Map<ModuleIdentification, XmlObject> msaDocMap = new HashMap<ModuleIdentification, XmlObject>();
79 ///
80 /// Package path.
81 ///
82 PackageIdentification packageId;
83
84 /**
85 Constructor function
86
87 This function mainly initialize some member variables.
88 **/
89 Spd(File packageFile) throws Exception {
90 try {
91 XmlObject spdDoc = XmlObject.Factory.parse(packageFile);
92 //
93 // Verify SPD file, if is invalid, throw Exception
94 //
95 // if (! spdDoc.validate()) {
96 // throw new Exception("Package Surface Area file [" + packageFile.getPath() + "] is invalid. ");
97 // }
98 // We can change Map to XmlObject
99
100 spdDocMap.put("PackageSurfaceArea", spdDoc);
101 SurfaceAreaQuery.setDoc(spdDocMap);
102 //
103 //
104 //
105 packageId = SurfaceAreaQuery.getSpdHeader();
106 packageId.setSpdFile(packageFile);
107
108 //
109 // initialize Msa Files
110 // MSA file is absolute file path
111 //
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"));
122 }
123 //
124 // initialize Package header files
125 //
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);
132 // //
133 // // Change path seperator to system-dependent path separator
134 // //
135 // File file = new File (header);
136 // header = file.getParent();
137 // packageHeaderInfo.put(moduleType, header);
138 // }
139 //
140 // initialize Guid Info
141 //
142 guidInfo.putAll(SurfaceAreaQuery.getSpdGuid());
143 //
144 // initialize PPI info
145 //
146 ppiInfo.putAll(SurfaceAreaQuery.getSpdPpi());
147 //
148 // initialize Protocol info
149 //
150 protocolInfo.putAll(SurfaceAreaQuery.getSpdProtocol());
151 //
152 // initialize library class declaration
153 //
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];
162
163 //
164 // Change path separator to system system-dependent path separator.
165 //
166 File file = new File (headerFiles[i]);
167 headerFiles[i] = file.getPath();
168 }
169 libClassHeaderList.put(libraryClassName, headerFiles);
170 }
171 }
172 catch (Exception e) {
173 e.setStackTrace(e.getStackTrace());
174 throw new Exception("Parse package description file [" + packageId.getSpdFile() + "] Error.\n"
175 + e.getMessage());
176 }
177 }
178
179 public PackageIdentification getPackageId() {
180 return packageId;
181 }
182
183 public File getModuleFile(ModuleIdentification moduleId) {
184 return msaInfo.get(moduleId);
185 }
186
187 public Set<ModuleIdentification> getModules(){
188 return msaInfo.keySet();
189 }
190
191 /**
192 return two value {CName, Guid}. If not found, return null.
193 **/
194 public String[] getPpi(String ppiName) {
195 return ppiInfo.get(ppiName);
196 }
197
198 /**
199 return two value {CName, Guid}. If not found, return null.
200 **/
201 public String[] getProtocol(String protocolName) {
202 return protocolInfo.get(protocolName);
203 }
204
205 /**
206 return two value {CName, Guid}. If not found, return null.
207 **/
208 public String[] getGuid(String guidName) {
209 return guidInfo.get(guidName);
210 }
211
212 /**
213 getLibClassInclude
214
215 This function is to get the library exposed header file name according
216 library class name.
217
218 @param libName Name of library class
219 @return Name of header file
220 **/
221 String[] getLibClassIncluder(String libName) {
222 return libClassHeaderList.get(libName);
223 }
224
225 /**
226 getModuleTypeIncluder
227
228 This function is to get the header file name from module info map
229 according to module type.
230
231 @param moduleType Module type.
232 @return Name of header file.
233 **/
234 String getPackageIncluder(String moduleType) {
235 return packageHeaderInfo.get(moduleType);
236 }
237 }