a13899c5 |
1 | /** @file\r |
2 | Java class FpdFileContents is used to parse fpd xml file.\r |
3 | \r |
4 | Copyright (c) 2006, Intel Corporation\r |
5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r |
8 | http://opensource.org/licenses/bsd-license.php\r |
9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
12 | **/\r |
13 | package org.tianocore.frameworkwizard.platform.ui;\r |
14 | \r |
15 | import java.io.File;\r |
16 | import java.io.IOException;\r |
17 | import java.math.BigInteger;\r |
18 | import java.util.ArrayList;\r |
19 | import java.util.HashMap;\r |
20 | import java.util.Iterator;\r |
21 | import java.util.LinkedHashMap;\r |
22 | import java.util.List;\r |
23 | import java.util.ListIterator;\r |
24 | import java.util.Map;\r |
25 | import java.util.Set;\r |
26 | \r |
27 | import javax.xml.namespace.QName;\r |
28 | \r |
29 | import org.apache.xmlbeans.XmlCursor;\r |
30 | import org.apache.xmlbeans.XmlObject;\r |
31 | import org.apache.xmlbeans.XmlOptions;\r |
32 | import org.tianocore.AntTaskDocument;\r |
33 | import org.tianocore.BuildOptionsDocument;\r |
34 | import org.tianocore.DynamicPcdBuildDefinitionsDocument;\r |
6cba26e8 |
35 | import org.tianocore.EfiSectionType;\r |
a13899c5 |
36 | import org.tianocore.FlashDefinitionFileDocument;\r |
a13899c5 |
37 | import org.tianocore.FlashDocument;\r |
38 | import org.tianocore.FrameworkModulesDocument;\r |
a13899c5 |
39 | import org.tianocore.LibrariesDocument;\r |
40 | import org.tianocore.ModuleSADocument;\r |
41 | import org.tianocore.ModuleSurfaceAreaDocument;\r |
42 | import org.tianocore.OptionDocument;\r |
43 | import org.tianocore.OptionsDocument;\r |
44 | import org.tianocore.PcdBuildDefinitionDocument;\r |
45 | import org.tianocore.PcdCodedDocument;\r |
46 | import org.tianocore.PcdDataTypes;\r |
47 | import org.tianocore.PcdDeclarationsDocument;\r |
48 | import org.tianocore.PcdItemTypes;\r |
49 | import org.tianocore.PlatformDefinitionsDocument;\r |
50 | import org.tianocore.PlatformSurfaceAreaDocument;\r |
51 | import org.tianocore.FvImageTypes;\r |
52 | import org.tianocore.FvImagesDocument;\r |
53 | import org.tianocore.LicenseDocument;\r |
54 | import org.tianocore.PlatformHeaderDocument;\r |
55 | import org.tianocore.SkuInfoDocument;\r |
56 | import org.tianocore.UserDefinedAntTasksDocument;\r |
57 | import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;\r |
58 | import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r |
59 | import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;\r |
60 | import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;\r |
61 | \r |
62 | /**\r |
63 | This class processes fpd file contents such as add remove xml elements. \r |
64 | @since PackageEditor 1.0\r |
65 | **/\r |
66 | public class FpdFileContents {\r |
67 | \r |
68 | static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";\r |
69 | \r |
70 | private PlatformSurfaceAreaDocument fpdd = null;\r |
71 | \r |
72 | private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;\r |
73 | \r |
74 | private PlatformHeaderDocument.PlatformHeader fpdHdr = null;\r |
75 | \r |
76 | private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;\r |
77 | \r |
78 | private FlashDocument.Flash fpdFlash = null;\r |
79 | \r |
80 | private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;\r |
81 | \r |
82 | private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;\r |
83 | \r |
84 | private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;\r |
85 | \r |
86 | public static HashMap<String, ArrayList<String>> dynPcdMap = null;\r |
87 | \r |
88 | /**\r |
89 | * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.\r |
90 | */\r |
91 | public void initDynPcdMap() {\r |
92 | if (dynPcdMap == null) {\r |
93 | dynPcdMap = new HashMap<String, ArrayList<String>>();\r |
94 | List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();\r |
95 | if (l == null) {\r |
96 | return;\r |
97 | }\r |
98 | ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();\r |
99 | while (li.hasNext()) {\r |
100 | ModuleSADocument.ModuleSA msa = li.next();\r |
101 | if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) {\r |
102 | continue;\r |
103 | }\r |
104 | String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() +\r |
105 | " " + msa.getPackageGuid() + " " + msa.getPackageVersion();\r |
106 | List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = msa.getPcdBuildDefinition().getPcdDataList();\r |
107 | ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();\r |
108 | while (lpi.hasNext()) {\r |
109 | PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();\r |
110 | String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r |
111 | if (dynPcdMap.get(pcdKey) == null) {\r |
112 | ArrayList<String> al = new ArrayList<String>();\r |
113 | al.add(ModuleInfo + " " + pcdData.getItemType().toString());\r |
114 | dynPcdMap.put(pcdKey, al);\r |
115 | }\r |
116 | else{\r |
117 | dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());\r |
118 | }\r |
119 | }\r |
120 | }\r |
121 | }\r |
122 | }\r |
123 | /**\r |
124 | Constructor to create a new spd file\r |
125 | **/\r |
126 | public FpdFileContents() {\r |
127 | \r |
128 | fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();\r |
129 | fpdRoot = fpdd.addNewPlatformSurfaceArea();\r |
130 | \r |
131 | }\r |
132 | \r |
133 | /**\r |
134 | Constructor for existing document object\r |
135 | @param psa\r |
136 | **/\r |
137 | public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {\r |
138 | fpdRoot = fpd;\r |
139 | fpdHdr = fpdRoot.getPlatformHeader();\r |
140 | fpdPlatformDefs = fpdRoot.getPlatformDefinitions();\r |
141 | fpdBuildOpts = fpdRoot.getBuildOptions();\r |
142 | fpdFrameworkModules = fpdRoot.getFrameworkModules();\r |
143 | fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();\r |
144 | fpdFlash = fpdRoot.getFlash();\r |
145 | }\r |
146 | \r |
147 | /**\r |
148 | Constructor based on an existing spd file\r |
149 | \r |
150 | @param f Existing spd file\r |
151 | **/\r |
152 | public FpdFileContents(File f) {\r |
153 | try {\r |
154 | fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);\r |
155 | fpdRoot = fpdd.getPlatformSurfaceArea();\r |
156 | } catch (Exception e) {\r |
157 | System.out.println(e.toString());\r |
158 | }\r |
159 | }\r |
160 | \r |
161 | public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {\r |
162 | if (fpdDynPcdBuildDefs == null){\r |
163 | fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();\r |
164 | }\r |
165 | return fpdDynPcdBuildDefs;\r |
166 | }\r |
167 | \r |
168 | public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {\r |
169 | if (fpdFrameworkModules == null){\r |
170 | fpdFrameworkModules = fpdRoot.addNewFrameworkModules();\r |
171 | }\r |
172 | return fpdFrameworkModules;\r |
173 | }\r |
174 | \r |
175 | public int getPlatformDefsSkuInfoCount(){\r |
176 | if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r |
177 | return 0;\r |
178 | }\r |
179 | return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();\r |
180 | }\r |
181 | \r |
182 | public void getPlatformDefsSkuInfos(String[][] saa){\r |
183 | if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r |
184 | return ;\r |
185 | }\r |
186 | \r |
187 | List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();\r |
188 | ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();\r |
189 | int i = 0;\r |
190 | while(li.hasNext()) {\r |
191 | SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();\r |
192 | saa[i][0] = sku.getSkuID()+"";\r |
193 | saa[i][1] = sku.getStringValue();\r |
194 | ++i;\r |
195 | }\r |
196 | }\r |
197 | \r |
198 | public int getFrameworkModulesCount() {\r |
199 | if (getfpdFrameworkModules().getModuleSAList() == null){\r |
200 | return 0;\r |
201 | }\r |
202 | return getfpdFrameworkModules().getModuleSAList().size();\r |
203 | }\r |
204 | \r |
205 | public void getFrameworkModulesInfo(String[][] saa) {\r |
206 | if (getFrameworkModulesCount() == 0){\r |
207 | return;\r |
208 | }\r |
209 | \r |
210 | ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r |
211 | int i = 0;\r |
212 | while(li.hasNext()) {\r |
213 | ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r |
214 | saa[i][1] = msa.getModuleGuid();\r |
215 | saa[i][2] = msa.getModuleVersion();\r |
216 | \r |
217 | saa[i][3] = msa.getPackageGuid();\r |
218 | saa[i][4] = msa.getPackageVersion();\r |
219 | // saa[i][4] = listToString(msa.getSupArchList());\r |
220 | ++i;\r |
221 | }\r |
222 | }\r |
223 | \r |
224 | public ModuleSADocument.ModuleSA getModuleSA(String key) {\r |
225 | String[] s = key.split(" ");\r |
226 | if (getfpdFrameworkModules().getModuleSAList() == null) {\r |
227 | return null;\r |
228 | }\r |
229 | ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r |
230 | while(li.hasNext()) {\r |
231 | ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r |
232 | if (msa.getModuleGuid().equals(s[0]) && msa.getModuleVersion().equals(s[1])\r |
233 | && msa.getPackageGuid().equals(s[2]) && msa.getPackageVersion().equals(s[3])) {\r |
234 | \r |
235 | return msa;\r |
236 | }\r |
237 | }\r |
238 | return null;\r |
239 | }\r |
240 | public void removeModuleSA(int i) {\r |
241 | XmlObject o = getfpdFrameworkModules();\r |
242 | if (o == null) {\r |
243 | return;\r |
244 | }\r |
245 | \r |
246 | XmlCursor cursor = o.newCursor();\r |
247 | if (cursor.toFirstChild()) {\r |
248 | for (int j = 0; j < i; ++j) {\r |
249 | cursor.toNextSibling();\r |
250 | }\r |
251 | //\r |
252 | // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.\r |
253 | //\r |
254 | ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();\r |
255 | String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +\r |
256 | moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion();\r |
257 | PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();\r |
258 | if (pcdBuildDef != null) {\r |
259 | maintainDynPcdMap(pcdBuildDef, moduleInfo);\r |
260 | }\r |
261 | cursor.removeXml();\r |
262 | }\r |
263 | cursor.dispose();\r |
264 | }\r |
265 | \r |
266 | private void maintainDynPcdMap(PcdBuildDefinitionDocument.PcdBuildDefinition o, String moduleInfo) {\r |
267 | XmlCursor cursor = o.newCursor();\r |
268 | boolean fromLibInstance = false;\r |
269 | if (!cursor.toFirstChild()){\r |
270 | return;\r |
271 | }\r |
272 | //\r |
273 | // deal with first child, same process in the while loop below for siblings.\r |
274 | //\r |
275 | PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r |
276 | String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r |
277 | ArrayList<String> al = dynPcdMap.get(pcdKey);\r |
278 | for(int i = 0; i < al.size(); ++i){\r |
279 | if (al.get(i).startsWith(moduleInfo)){\r |
280 | fromLibInstance = true;\r |
281 | break;\r |
282 | }\r |
283 | }\r |
284 | al.remove(moduleInfo + " " + pcdData.getItemType().toString());\r |
285 | if (al.size() == 0) {\r |
286 | dynPcdMap.remove(pcdKey);\r |
287 | }\r |
288 | \r |
289 | if (pcdData.getItemType().toString().equals("DYNAMIC")) {\r |
290 | if (dynPcdMap.get(pcdKey) == null) {\r |
291 | removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());\r |
292 | }\r |
293 | }\r |
294 | if (fromLibInstance){\r |
295 | cursor.removeXml();\r |
296 | }\r |
297 | while(cursor.toNextSibling()) {\r |
298 | fromLibInstance = false;\r |
299 | pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r |
300 | //\r |
301 | // remove each pcd record from dynPcdMap\r |
302 | //\r |
303 | pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r |
304 | al = dynPcdMap.get(pcdKey);\r |
305 | for(int i = 0; i < al.size(); ++i){\r |
306 | if (al.get(i).startsWith(moduleInfo)){\r |
307 | fromLibInstance = true;\r |
308 | break;\r |
309 | }\r |
310 | }\r |
311 | al.remove(moduleInfo + " " + pcdData.getItemType().toString());\r |
312 | if (al.size() == 0) {\r |
313 | dynPcdMap.remove(pcdKey);\r |
314 | }\r |
315 | \r |
316 | if (pcdData.getItemType().toString().equals("DYNAMIC")) {\r |
317 | //\r |
318 | // First check whether this is the only consumer of this dyn pcd.\r |
319 | //\r |
320 | if (dynPcdMap.get(pcdKey) == null) {\r |
321 | //\r |
322 | // delete corresponding entry in DynamicPcdBuildData\r |
323 | //\r |
324 | removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());\r |
325 | }\r |
326 | }\r |
327 | if (fromLibInstance){\r |
328 | cursor.removeXml();\r |
329 | }\r |
330 | }\r |
331 | }\r |
332 | //\r |
333 | // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"\r |
334 | //\r |
335 | public int getPcdDataCount(String key){\r |
336 | ModuleSADocument.ModuleSA msa = getModuleSA(key);\r |
337 | if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r |
338 | return 0;\r |
339 | }\r |
340 | return msa.getPcdBuildDefinition().getPcdDataList().size();\r |
341 | }\r |
342 | \r |
343 | public void getPcdData(String key, String[][] saa) {\r |
344 | ModuleSADocument.ModuleSA msa = getModuleSA(key);\r |
345 | if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r |
346 | return;\r |
347 | }\r |
348 | ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();\r |
349 | for (int i = 0; i < saa.length; ++i) {\r |
350 | PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();\r |
351 | saa[i][0] = pcdData.getCName();\r |
352 | saa[i][1] = pcdData.getTokenSpaceGuidCName();\r |
353 | saa[i][2] = pcdData.getItemType().toString();\r |
354 | saa[i][3] = pcdData.getToken().toString();\r |
355 | saa[i][4] = pcdData.getDatumType().toString();\r |
356 | saa[i][5] = pcdData.getValue();\r |
357 | \r |
358 | }\r |
359 | }\r |
360 | //\r |
361 | // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"\r |
362 | //\r |
363 | public int getLibraryInstancesCount(String key) {\r |
364 | ModuleSADocument.ModuleSA msa = getModuleSA(key);\r |
365 | if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){\r |
366 | return 0;\r |
367 | }\r |
368 | return msa.getLibraries().getInstanceList().size();\r |
369 | }\r |
370 | \r |
371 | public void getLibraryInstances(String key, String[][] saa){\r |
372 | ModuleSADocument.ModuleSA msa = getModuleSA(key);\r |
373 | if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){\r |
374 | return ;\r |
375 | }\r |
376 | \r |
377 | ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();\r |
378 | for (int i = 0; i < saa.length; ++i) {\r |
379 | LibrariesDocument.Libraries.Instance instance = li.next();\r |
380 | saa[i][1] = instance.getModuleGuid();\r |
381 | saa[i][2] = instance.getModuleVersion();\r |
382 | saa[i][3] = instance.getPackageGuid();\r |
383 | saa[i][4] = instance.getPackageVersion();\r |
384 | }\r |
385 | }\r |
386 | \r |
387 | public void removeLibraryInstances(String key) {\r |
388 | ModuleSADocument.ModuleSA msa = getModuleSA(key);\r |
389 | if (msa == null || msa.getLibraries() == null){\r |
390 | return ;\r |
391 | }\r |
392 | \r |
393 | XmlCursor cursor = msa.getLibraries().newCursor();\r |
394 | cursor.removeXml();\r |
395 | cursor.dispose();\r |
396 | }\r |
397 | \r |
398 | public void genLibraryInstance(String mg, String mv, String pg, String pv, String key) {\r |
399 | ModuleSADocument.ModuleSA msa = getModuleSA(key);\r |
400 | if (msa == null){\r |
401 | msa = getfpdFrameworkModules().addNewModuleSA();\r |
402 | }\r |
403 | LibrariesDocument.Libraries libs = msa.getLibraries();\r |
404 | if(libs == null){\r |
405 | libs = msa.addNewLibraries();\r |
406 | }\r |
407 | \r |
408 | LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();\r |
409 | instance.setModuleGuid(mg);\r |
410 | instance.setModuleVersion(mv);\r |
411 | instance.setPackageGuid(pg);\r |
412 | instance.setPackageVersion(pv);\r |
413 | \r |
414 | }\r |
415 | /**add pcd information of module mi to a ModuleSA. \r |
416 | * @param mi\r |
417 | * @param moduleSa if null, generate a new ModuleSA.\r |
418 | */\r |
419 | public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, ModuleSADocument.ModuleSA moduleSa){\r |
420 | //ToDo add Arch filter\r |
421 | \r |
422 | try {\r |
423 | ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r |
424 | if (msa.getPcdCoded() == null) {\r |
425 | return;\r |
426 | }\r |
427 | if (moduleSa == null) {\r |
428 | moduleSa = genModuleSA(mi);\r |
429 | }\r |
430 | Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r |
431 | m.put("ModuleSurfaceArea", msa);\r |
432 | SurfaceAreaQuery.setDoc(m);\r |
433 | PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);\r |
434 | //\r |
435 | // Implementing InitializePlatformPcdBuildDefinitions\r |
436 | //\r |
437 | List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r |
438 | ListIterator li = l.listIterator();\r |
439 | while(li.hasNext()) {\r |
440 | PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r |
441 | PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r |
442 | if (spdPcd == null) {\r |
443 | //\r |
444 | // ToDo Error \r |
445 | //\r |
446 | break;\r |
447 | }\r |
448 | //\r |
449 | // AddItem to ModuleSA PcdBuildDefinitions\r |
450 | //\r |
451 | String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();\r |
452 | genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);\r |
453 | }\r |
454 | \r |
455 | }\r |
456 | catch (Exception e){\r |
457 | e.printStackTrace();\r |
458 | }\r |
459 | \r |
460 | }\r |
461 | \r |
462 | private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {\r |
463 | \r |
464 | Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r |
465 | PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;\r |
466 | for (int i = 0; i < depPkgs.length; ++i) {\r |
467 | m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));\r |
468 | SurfaceAreaQuery.setDoc(m);\r |
469 | XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();\r |
470 | if (xo == null) {\r |
471 | continue;\r |
472 | }\r |
473 | for (int j = 0; j < xo.length; ++j) {\r |
474 | spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];\r |
475 | if (msaPcd.getTokenSpaceGuidCName() == null) {\r |
476 | if (spdPcd.getCName().equals(msaPcd.getCName())) {\r |
477 | return spdPcd;\r |
478 | }\r |
479 | }\r |
480 | else{\r |
481 | if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {\r |
482 | return spdPcd;\r |
483 | }\r |
484 | }\r |
485 | \r |
486 | }\r |
487 | \r |
488 | }\r |
489 | return null;\r |
490 | }\r |
491 | \r |
492 | private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi) {\r |
493 | PackageIdentification pi = GlobalData.getPackageForModule(mi);\r |
494 | ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();\r |
495 | msa.setModuleGuid(mi.getGuid());\r |
496 | msa.setModuleVersion(mi.getVersion());\r |
497 | msa.setPackageGuid(pi.getGuid());\r |
498 | msa.setPackageVersion(pi.getVersion());\r |
499 | \r |
500 | return msa;\r |
501 | }\r |
502 | \r |
503 | private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) {\r |
504 | if (moduleSa.getPcdBuildDefinition() == null){\r |
505 | moduleSa.addNewPcdBuildDefinition();\r |
506 | }\r |
507 | //\r |
508 | // constructe pcd to modulesa mapping first.\r |
509 | // Attention : for any error condition, remove from map this pcd.\r |
510 | //\r |
511 | ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);\r |
512 | if (pcdConsumer == null) {\r |
513 | pcdConsumer = new ArrayList<String>();\r |
514 | }\r |
515 | String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() \r |
516 | + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() \r |
517 | + " " + itemType;\r |
518 | pcdConsumer.add(listValue);\r |
519 | dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);\r |
520 | //\r |
521 | // Special dynamic type, if this pcd already exists in other ModuleSA\r |
522 | //\r |
523 | if (itemType.equals("DYNAMIC")) {\r |
524 | \r |
525 | ListIterator li = pcdConsumer.listIterator();\r |
526 | while(li.hasNext()) {\r |
527 | String value = li.next().toString();\r |
528 | String[] valuePart= value.split(" ");\r |
529 | if (!valuePart[4].equals("DYNAMIC")) {\r |
530 | //ToDo error for same pcd, other type than dynamic\r |
531 | pcdConsumer.remove(listValue);\r |
532 | return;\r |
533 | }\r |
534 | }\r |
535 | }\r |
536 | else {\r |
537 | ListIterator li = pcdConsumer.listIterator();\r |
538 | while(li.hasNext()) {\r |
539 | String value = li.next().toString();\r |
540 | String[] valuePart= value.split(" ");\r |
541 | if (valuePart[4].equals("DYNAMIC")) {\r |
542 | //ToDo error for same pcd, other type than non-dynamic\r |
543 | pcdConsumer.remove(listValue);\r |
544 | return;\r |
545 | }\r |
546 | }\r |
547 | }\r |
548 | \r |
549 | PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();\r |
550 | fpdPcd.setCName(cName);\r |
551 | fpdPcd.setToken(token);\r |
552 | fpdPcd.setTokenSpaceGuidCName(tsGuid);\r |
553 | fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));\r |
554 | fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));\r |
555 | \r |
556 | if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {\r |
557 | ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);\r |
558 | //\r |
559 | // if only one module mapped to this pcd, then the one is myself. so no other module mapped.\r |
560 | // so need to add one dyn pcd.\r |
561 | //\r |
562 | if (al.size() == 1) {\r |
563 | addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);\r |
564 | }\r |
565 | }\r |
566 | else {\r |
567 | if (defaultVal != null){\r |
568 | fpdPcd.setValue(defaultVal);\r |
569 | }\r |
570 | else {\r |
571 | if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {\r |
572 | fpdPcd.setValue("0");\r |
573 | }\r |
574 | if (dataType.equals("BOOLEAN")){\r |
575 | fpdPcd.setValue("false");\r |
576 | }\r |
577 | if (dataType.equals("VOID*")) {\r |
578 | fpdPcd.setValue("");\r |
579 | }\r |
580 | }\r |
581 | if (dataType.equals("UINT8")){\r |
582 | fpdPcd.setMaxDatumSize(1);\r |
583 | }\r |
584 | if (dataType.equals("UINT16")) {\r |
585 | fpdPcd.setMaxDatumSize(2);\r |
586 | }\r |
587 | if (dataType.equals("UINT32")) {\r |
588 | fpdPcd.setMaxDatumSize(4);\r |
589 | }\r |
590 | if (dataType.equals("UINT64")){\r |
591 | fpdPcd.setMaxDatumSize(8);\r |
592 | }\r |
593 | if (dataType.equals("BOOLEAN")){\r |
594 | fpdPcd.setMaxDatumSize(1);\r |
595 | }\r |
596 | if (dataType.equals("VOID*")) {\r |
597 | int maxSize = setMaxSizeForPointer(fpdPcd.getValue());\r |
598 | fpdPcd.setMaxDatumSize(maxSize);\r |
599 | }\r |
600 | }\r |
601 | }\r |
602 | \r |
603 | private int setMaxSizeForPointer(String datum) {\r |
604 | if (datum == null) {\r |
605 | return 0;\r |
606 | }\r |
607 | char ch = datum.charAt(0);\r |
608 | int start, end;\r |
609 | String strValue;\r |
610 | //\r |
611 | // For void* type PCD, only three datum is support:\r |
612 | // 1) Unicode: string with start char is "L"\r |
613 | // 2) Ansci: String is ""\r |
614 | // 3) byte array: String start char "{"\r |
615 | // \r |
616 | if (ch == 'L') {\r |
617 | start = datum.indexOf('\"');\r |
618 | end = datum.lastIndexOf('\"');\r |
619 | if ((start > end) || \r |
620 | (end > datum.length())||\r |
621 | ((start == end) && (datum.length() > 0))) {\r |
622 | //ToDo Error handling here\r |
623 | }\r |
624 | \r |
625 | strValue = datum.substring(start + 1, end);\r |
626 | return strValue.length() * 2;\r |
627 | } else if (ch == '\"'){\r |
628 | start = datum.indexOf('\"');\r |
629 | end = datum.lastIndexOf('\"');\r |
630 | if ((start > end) || \r |
631 | (end > datum.length())||\r |
632 | ((start == end) && (datum.length() > 0))) {\r |
633 | \r |
634 | }\r |
635 | strValue = datum.substring(start + 1, end);\r |
636 | return strValue.length();\r |
637 | } else if (ch =='{') {\r |
638 | String[] strValueArray;\r |
639 | \r |
640 | start = datum.indexOf('{');\r |
641 | end = datum.lastIndexOf('}');\r |
642 | strValue = datum.substring(start + 1, end);\r |
643 | strValue = strValue.trim();\r |
644 | if (strValue.length() == 0) {\r |
645 | return 0;\r |
646 | }\r |
647 | strValueArray = strValue.split(",");\r |
648 | for (int index = 0; index < strValueArray.length; index ++) {\r |
649 | Integer value = Integer.decode(strValueArray[index].trim());\r |
650 | \r |
651 | if (value > 0xFF) {\r |
652 | // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r |
653 | // "it is byte array in fact. But the element of %s exceed the byte range",\r |
654 | \r |
655 | }\r |
656 | }\r |
657 | return strValueArray.length;\r |
658 | \r |
659 | \r |
660 | } else {\r |
661 | // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r |
662 | // "1) UNICODE string: like L\"xxxx\";\r\n"+\r |
663 | // "2) ANSIC string: like \"xxx\";\r\n"+\r |
664 | // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r |
665 | // "but the datum in seems does not following above format!",\r |
666 | return -1; \r |
667 | \r |
668 | }\r |
669 | }\r |
670 | \r |
671 | private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {\r |
672 | ArrayList<String> al = dynPcdMap.get(dynPcdKey);\r |
673 | \r |
674 | return al;\r |
675 | }\r |
676 | \r |
677 | private ArrayList<String> LookupPlatformPcdData(String pcdKey) {\r |
678 | \r |
679 | return dynPcdMap.get("pcdKey");\r |
680 | }\r |
681 | \r |
682 | public int getDynamicPcdBuildDataCount() {\r |
683 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r |
684 | return 0;\r |
685 | }\r |
686 | return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();\r |
687 | }\r |
688 | \r |
689 | public void getDynamicPcdBuildData(String[][] saa) {\r |
690 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r |
691 | return ;\r |
692 | }\r |
693 | List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();\r |
694 | ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();\r |
695 | int i = 0;\r |
696 | while(li.hasNext()) {\r |
697 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();\r |
698 | saa[i][0] = dynPcd.getCName();\r |
699 | saa[i][1] = dynPcd.getToken().toString();\r |
700 | saa[i][2] = dynPcd.getTokenSpaceGuidCName();\r |
701 | saa[i][3] = dynPcd.getMaxDatumSize()+"";\r |
702 | saa[i][4] = dynPcd.getDatumType().toString();\r |
703 | \r |
704 | ++i;\r |
705 | }\r |
706 | }\r |
707 | \r |
708 | private void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) {\r |
709 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();\r |
710 | dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r |
711 | dynPcdData.setCName(cName);\r |
712 | dynPcdData.setToken(token);\r |
713 | dynPcdData.setTokenSpaceGuidCName(tsGuid);\r |
714 | dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));\r |
715 | \r |
716 | BigInteger bigInt = new BigInteger("0");\r |
717 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();\r |
718 | skuInfo.setSkuId(bigInt);\r |
719 | if (defaultVal != null){\r |
720 | skuInfo.setValue(defaultVal);\r |
721 | }\r |
722 | else {\r |
723 | if (dataType.equals("UINT8")){\r |
724 | skuInfo.setValue("0");\r |
725 | }\r |
726 | if (dataType.equals("UINT16")) {\r |
727 | skuInfo.setValue("0");\r |
728 | }\r |
729 | if (dataType.equals("UINT32")) {\r |
730 | skuInfo.setValue("0");\r |
731 | }\r |
732 | if (dataType.equals("UINT64")){\r |
733 | skuInfo.setValue("0");\r |
734 | }\r |
735 | if (dataType.equals("BOOLEAN")){\r |
736 | skuInfo.setValue("false");\r |
737 | }\r |
738 | if (dataType.equals("VOID*")) {\r |
739 | skuInfo.setValue("");\r |
740 | }\r |
741 | }\r |
742 | if (dataType.equals("UINT8")){\r |
743 | dynPcdData.setMaxDatumSize(1);\r |
744 | }\r |
745 | if (dataType.equals("UINT16")) {\r |
746 | dynPcdData.setMaxDatumSize(2);\r |
747 | }\r |
748 | if (dataType.equals("UINT32")) {\r |
749 | dynPcdData.setMaxDatumSize(4);\r |
750 | }\r |
751 | if (dataType.equals("UINT64")){\r |
752 | dynPcdData.setMaxDatumSize(8);\r |
753 | }\r |
754 | if (dataType.equals("BOOLEAN")){\r |
755 | dynPcdData.setMaxDatumSize(1);\r |
756 | }\r |
757 | if (dataType.equals("VOID*")) {\r |
758 | int maxSize = setMaxSizeForPointer(defaultVal);\r |
759 | dynPcdData.setMaxDatumSize(maxSize);\r |
760 | }\r |
761 | }\r |
762 | \r |
763 | private void removeDynamicPcdBuildData(String cName, String tsGuid) {\r |
764 | XmlObject o = getfpdDynPcdBuildDefs();\r |
765 | \r |
766 | XmlCursor cursor = o.newCursor();\r |
767 | if (cursor.toFirstChild()) {\r |
768 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = \r |
769 | (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
770 | while (!(pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid))) {\r |
771 | cursor.toNextSibling();\r |
772 | pcdBuildData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
773 | }\r |
774 | \r |
775 | cursor.removeXml();\r |
776 | }\r |
777 | cursor.dispose();\r |
778 | }\r |
779 | //\r |
780 | // Get the Sku Info count of ith dyn pcd element.\r |
781 | //\r |
782 | public int getDynamicPcdSkuInfoCount(int i){\r |
783 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
784 | return 0;\r |
785 | }\r |
786 | \r |
787 | int skuInfoCount = 0;\r |
788 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
789 | if (cursor.toFirstChild()) {\r |
790 | for (int j = 0; j < i; ++j) {\r |
791 | cursor.toNextSibling();\r |
792 | }\r |
793 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
794 | if (pcdData.getSkuInfoList() == null) {\r |
795 | skuInfoCount = 0;\r |
796 | }\r |
797 | else {\r |
798 | skuInfoCount = pcdData.getSkuInfoList().size();\r |
799 | }\r |
800 | }\r |
801 | cursor.dispose();\r |
802 | return skuInfoCount;\r |
803 | }\r |
804 | \r |
805 | public void getDynamicPcdSkuInfos(int i, String[][] saa){\r |
806 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
807 | return;\r |
808 | }\r |
809 | \r |
810 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
811 | if (cursor.toFirstChild()) {\r |
812 | for (int j = 0; j < i; ++j) {\r |
813 | cursor.toNextSibling();\r |
814 | }\r |
815 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
816 | if (pcdData.getSkuInfoList() == null) {\r |
817 | cursor.dispose();\r |
818 | return;\r |
819 | }\r |
820 | else {\r |
821 | ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r |
822 | int k = 0;\r |
823 | while (li.hasNext()) {\r |
824 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r |
825 | saa[k][0] = skuInfo.getSkuId()+"";\r |
826 | saa[k][1] = skuInfo.getVariableName();\r |
827 | saa[k][2] = skuInfo.getVariableGuid();\r |
828 | saa[k][3] = skuInfo.getVariableOffset();\r |
829 | saa[k][4] = skuInfo.getHiiDefaultValue();\r |
830 | saa[k][5] = skuInfo.getVpdOffset();\r |
831 | saa[k][6] = skuInfo.getValue();\r |
832 | ++k;\r |
833 | }\r |
834 | \r |
835 | }\r |
836 | }\r |
837 | cursor.dispose();\r |
838 | \r |
839 | }\r |
840 | \r |
841 | public String getDynamicPcdBuildDataValue(int i){\r |
842 | String value = null;\r |
843 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
844 | return value;\r |
845 | }\r |
846 | \r |
847 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
848 | if (cursor.toFirstChild()) {\r |
849 | for (int j = 0; j < i; ++j) {\r |
850 | cursor.toNextSibling();\r |
851 | }\r |
852 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
853 | if (pcdData.getSkuInfoList() == null) {\r |
854 | value = null;\r |
855 | }\r |
856 | else {\r |
857 | value = pcdData.getSkuInfoArray(0).getValue();\r |
858 | }\r |
859 | }\r |
860 | cursor.dispose();\r |
861 | return value;\r |
862 | }\r |
863 | \r |
864 | public String getDynamicPcdBuildDataVpdOffset(int i){\r |
865 | String vpdOffset = null;\r |
866 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
867 | return vpdOffset;\r |
868 | }\r |
869 | \r |
870 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
871 | if (cursor.toFirstChild()) {\r |
872 | for (int j = 0; j < i; ++j) {\r |
873 | cursor.toNextSibling();\r |
874 | }\r |
875 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
876 | if (pcdData.getSkuInfoList() == null) {\r |
877 | vpdOffset = null;\r |
878 | }\r |
879 | else {\r |
880 | vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();\r |
881 | }\r |
882 | }\r |
883 | cursor.dispose();\r |
884 | return vpdOffset;\r |
885 | }\r |
886 | \r |
887 | public void removeDynamicPcdBuildDataSkuInfo(int i) {\r |
888 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
889 | return;\r |
890 | }\r |
891 | \r |
892 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
893 | if (cursor.toFirstChild()) {\r |
894 | for (int j = 0; j < i; ++j) {\r |
895 | cursor.toNextSibling();\r |
896 | }\r |
897 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
898 | if (pcdData.getSkuInfoList() == null) {\r |
899 | cursor.dispose();\r |
900 | return;\r |
901 | }\r |
902 | else {\r |
903 | QName qSkuInfo = new QName(xmlNs, "SkuInfo");\r |
904 | cursor.toChild(qSkuInfo);\r |
905 | cursor.removeXml();\r |
906 | }\r |
907 | }\r |
908 | cursor.dispose();\r |
909 | }\r |
910 | //\r |
911 | // generate sku info for ith dyn pcd build data.\r |
912 | //\r |
913 | public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r |
914 | String hiiDefault, String vpdOffset, String value, int i) {\r |
915 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
916 | return;\r |
917 | }\r |
918 | \r |
919 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
920 | if (cursor.toFirstChild()) {\r |
921 | for (int j = 0; j < i; ++j) {\r |
922 | cursor.toNextSibling();\r |
923 | }\r |
924 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
925 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();\r |
926 | skuInfo.setSkuId(new BigInteger(id));\r |
927 | if (varName != null){\r |
928 | skuInfo.setVariableName(varName);\r |
929 | skuInfo.setVariableGuid(varGuid);\r |
930 | skuInfo.setVariableOffset(varOffset);\r |
931 | skuInfo.setHiiDefaultValue(hiiDefault);\r |
932 | }\r |
933 | else if (vpdOffset != null){\r |
934 | skuInfo.setVpdOffset(vpdOffset);\r |
935 | }\r |
936 | else{\r |
937 | skuInfo.setValue(value);\r |
938 | }\r |
939 | }\r |
940 | }\r |
941 | \r |
942 | public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r |
943 | String hiiDefault, String vpdOffset, String value, int i){\r |
944 | if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r |
945 | return;\r |
946 | }\r |
947 | \r |
948 | XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r |
949 | if (cursor.toFirstChild()) {\r |
950 | for (int j = 0; j < i; ++j) {\r |
951 | cursor.toNextSibling();\r |
952 | }\r |
953 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r |
954 | ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r |
955 | while (li.hasNext()) {\r |
956 | DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r |
957 | if (skuInfo.getSkuId().toString().equals(id)){\r |
958 | if (varName != null){\r |
959 | skuInfo.setVariableName(varName);\r |
960 | skuInfo.setVariableGuid(varGuid);\r |
961 | skuInfo.setVariableOffset(varOffset);\r |
962 | skuInfo.setHiiDefaultValue(hiiDefault);\r |
963 | }\r |
964 | else if (vpdOffset != null){\r |
965 | skuInfo.setVpdOffset(vpdOffset);\r |
966 | }\r |
967 | else{\r |
968 | skuInfo.setValue(value);\r |
969 | }\r |
970 | break;\r |
971 | }\r |
972 | }\r |
973 | }\r |
974 | }\r |
975 | \r |
976 | public void removePcdDataFromLibraryInstance(String moduleKey, String libInstanceKey){\r |
977 | ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r |
978 | //\r |
979 | // should better maintain pcd from lib instance only, but maintain all is acceptable now. \r |
980 | //\r |
981 | maintainDynPcdMap(moduleSa.getPcdBuildDefinition(), libInstanceKey);\r |
982 | \r |
983 | }\r |
984 | \r |
985 | public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {\r |
986 | if (fpdBuildOpts == null) {\r |
987 | fpdBuildOpts = fpdRoot.addNewBuildOptions();\r |
988 | }\r |
989 | return fpdBuildOpts;\r |
990 | }\r |
991 | \r |
992 | public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {\r |
993 | UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r |
994 | if (udats == null) {\r |
995 | udats = getfpdBuildOpts().addNewUserDefinedAntTasks();\r |
996 | }\r |
997 | \r |
998 | AntTaskDocument.AntTask at = udats.addNewAntTask();\r |
999 | setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r |
1000 | }\r |
1001 | \r |
1002 | private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {\r |
1003 | at.setId(new Integer(id));\r |
1004 | if (fileName != null){\r |
1005 | at.setFilename(fileName);\r |
1006 | }\r |
202c4f38 |
1007 | if (execOrder != null) {\r |
a13899c5 |
1008 | at.setAntCmdOptions(execOrder);\r |
1009 | }\r |
1010 | }\r |
1011 | \r |
1012 | public void removeBuildOptionsUserDefAntTask(int i) {\r |
1013 | XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r |
1014 | if (o == null) {\r |
1015 | return;\r |
1016 | }\r |
1017 | XmlCursor cursor = o.newCursor();\r |
1018 | if (cursor.toFirstChild()) {\r |
1019 | for (int j = 0; j < i; ++j) {\r |
1020 | cursor.toNextSibling();\r |
1021 | }\r |
1022 | cursor.removeXml();\r |
1023 | }\r |
1024 | cursor.dispose();\r |
1025 | }\r |
1026 | \r |
1027 | public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){\r |
1028 | XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r |
1029 | if (o == null) {\r |
1030 | return;\r |
1031 | }\r |
1032 | XmlCursor cursor = o.newCursor();\r |
1033 | if (cursor.toFirstChild()) {\r |
1034 | for (int j = 0; j < i; ++j) {\r |
1035 | cursor.toNextSibling();\r |
1036 | }\r |
1037 | AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();\r |
1038 | setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r |
1039 | }\r |
1040 | cursor.dispose();\r |
1041 | }\r |
1042 | \r |
1043 | public int getBuildOptionsUserDefAntTaskCount() {\r |
1044 | UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r |
1045 | if (udats == null || udats.getAntTaskList() == null) {\r |
1046 | return 0;\r |
1047 | }\r |
1048 | \r |
1049 | return udats.getAntTaskList().size();\r |
1050 | }\r |
1051 | \r |
1052 | public void getBuildOptionsUserDefAntTasks(String[][] saa) {\r |
1053 | UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r |
1054 | if (udats == null || udats.getAntTaskList() == null) {\r |
1055 | return ;\r |
1056 | }\r |
1057 | \r |
1058 | List<AntTaskDocument.AntTask> l = udats.getAntTaskList();\r |
1059 | ListIterator li = l.listIterator();\r |
1060 | int i = 0;\r |
1061 | while (li.hasNext()) {\r |
1062 | AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();\r |
1063 | saa[i][0] = at.getId() + "";\r |
1064 | saa[i][1] = saa[i][2] = "";\r |
1065 | if (at.getFilename() != null){\r |
1066 | saa[i][1] = at.getFilename();\r |
1067 | }\r |
1068 | if (at.getAntCmdOptions() != null) {\r |
1069 | saa[i][2] = at.getAntCmdOptions();\r |
1070 | }\r |
1071 | ++i;\r |
1072 | }\r |
1073 | }\r |
1074 | public void genBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {\r |
1075 | OptionsDocument.Options opts = getfpdBuildOpts().getOptions();\r |
1076 | if (opts == null) {\r |
1077 | opts = getfpdBuildOpts().addNewOptions();\r |
1078 | }\r |
1079 | OptionDocument.Option opt = opts.addNewOption();\r |
1080 | setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r |
1081 | }\r |
1082 | \r |
1083 | private void setBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents, OptionDocument.Option opt){\r |
1084 | opt.setStringValue(contents);\r |
1085 | // opt.setBuildTargets(buildTargets);\r |
1086 | opt.setToolChainFamily(toolChain);\r |
1087 | opt.setTagName(tagName);\r |
1088 | opt.setToolCode(toolCmd);\r |
1089 | String[] s = archList.split(" ");\r |
1090 | ArrayList<String> al = new ArrayList<String>();\r |
1091 | for (int i = 0; i < s.length; ++i) {\r |
1092 | al.add(s[i]);\r |
1093 | }\r |
1094 | opt.setSupArchList(al);\r |
1095 | }\r |
1096 | \r |
1097 | public void removeBuildOptionsOpt(int i){\r |
1098 | \r |
1099 | XmlObject o = getfpdBuildOpts().getOptions();\r |
1100 | if (o == null) {\r |
1101 | return;\r |
1102 | }\r |
1103 | \r |
1104 | XmlCursor cursor = o.newCursor();\r |
1105 | if (cursor.toFirstChild()) {\r |
1106 | for (int j = 0; j < i; ++j) {\r |
1107 | cursor.toNextSibling();\r |
1108 | }\r |
1109 | cursor.removeXml();\r |
1110 | }\r |
1111 | cursor.dispose();\r |
1112 | }\r |
1113 | \r |
1114 | public void updateBuildOptionsOpt(int i, String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {\r |
1115 | XmlObject o = getfpdBuildOpts().getOptions();\r |
1116 | if (o == null) {\r |
1117 | return;\r |
1118 | }\r |
1119 | \r |
1120 | XmlCursor cursor = o.newCursor();\r |
1121 | if (cursor.toFirstChild()) {\r |
1122 | for (int j = 0; j < i; ++j) {\r |
1123 | cursor.toNextSibling();\r |
1124 | }\r |
1125 | OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();\r |
1126 | setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r |
1127 | }\r |
1128 | cursor.dispose();\r |
1129 | }\r |
1130 | \r |
1131 | public int getBuildOptionsOptCount(){\r |
1132 | if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r |
1133 | return 0;\r |
1134 | }\r |
1135 | return getfpdBuildOpts().getOptions().getOptionList().size();\r |
1136 | }\r |
1137 | \r |
1138 | public void getBuildOptionsOpts(String[][] saa) {\r |
1139 | if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r |
1140 | return ;\r |
1141 | }\r |
1142 | \r |
1143 | List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();\r |
1144 | ListIterator li = lOpt.listIterator();\r |
1145 | int i = 0;\r |
1146 | while(li.hasNext()) {\r |
1147 | OptionDocument.Option opt = (OptionDocument.Option)li.next();\r |
6cba26e8 |
1148 | if (opt.getBuildTargets() != null) {\r |
1149 | saa[i][0] = listToString(opt.getBuildTargets());\r |
1150 | }\r |
a13899c5 |
1151 | saa[i][1] = opt.getToolChainFamily();\r |
1152 | if (opt.getSupArchList() != null){\r |
6cba26e8 |
1153 | saa[i][2] = listToString(opt.getSupArchList());\r |
1154 | \r |
a13899c5 |
1155 | }\r |
1156 | saa[i][3] = opt.getToolCode();\r |
1157 | saa[i][4] = opt.getTagName();\r |
1158 | saa[i][5] = opt.getStringValue();\r |
1159 | \r |
1160 | ++i;\r |
1161 | }\r |
1162 | }\r |
1163 | \r |
6cba26e8 |
1164 | public void genBuildOptionsFfs(String ffsKey, String type) {\r |
1165 | BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();\r |
1166 | ffs.setFfsKey(ffsKey);\r |
1167 | if (type != null) {\r |
1168 | ffs.addNewSections().setEncapsulationType(type);\r |
1169 | }\r |
1170 | }\r |
1171 | \r |
1172 | public void genBuildOptionsFfsAttribute(int i, String name, String value) {\r |
1173 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1174 | BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();\r |
1175 | attrib.setName(name);\r |
1176 | attrib.setValue(value);\r |
1177 | }\r |
1178 | \r |
1179 | /**update jth attribute of ith ffs.\r |
1180 | * @param i\r |
1181 | * @param j\r |
1182 | */\r |
1183 | public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){\r |
1184 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1185 | XmlCursor cursor = ffs.newCursor();\r |
1186 | QName qAttrib = new QName(xmlNs, "Attribute");\r |
1187 | if (cursor.toChild(qAttrib)) {\r |
1188 | for (int k = 0; k < j; ++k) {\r |
1189 | cursor.toNextSibling(qAttrib);\r |
1190 | }\r |
1191 | BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();\r |
1192 | attrib.setName(name);\r |
1193 | attrib.setValue(value);\r |
1194 | }\r |
1195 | cursor.dispose();\r |
1196 | }\r |
1197 | \r |
1198 | public void removeBuildOptionsFfsAttribute(int i, int j){\r |
1199 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1200 | XmlCursor cursor = ffs.newCursor();\r |
1201 | QName qAttrib = new QName(xmlNs, "Attribute");\r |
1202 | if (cursor.toChild(qAttrib)) {\r |
1203 | for (int k = 0; k < j; ++k) {\r |
1204 | cursor.toNextSibling(qAttrib);\r |
1205 | }\r |
1206 | cursor.removeXml();\r |
1207 | }\r |
1208 | cursor.dispose();\r |
1209 | }\r |
1210 | \r |
1211 | public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {\r |
1212 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1213 | if (ffs == null) {\r |
1214 | return;\r |
1215 | }\r |
1216 | BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r |
1217 | \r |
1218 | if (sections == null){\r |
1219 | sections = ffs.addNewSections();\r |
1220 | }\r |
1221 | sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));\r |
1222 | }\r |
1223 | \r |
1224 | public void genBuildOptionsFfsSectionsSections(int i, String encapType) {\r |
1225 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1226 | if (ffs == null) {\r |
1227 | return;\r |
1228 | }\r |
1229 | BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r |
1230 | \r |
1231 | if (sections == null){\r |
1232 | sections = ffs.addNewSections();\r |
1233 | }\r |
1234 | sections.addNewSections().setEncapsulationType(encapType);\r |
1235 | }\r |
1236 | \r |
1237 | public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {\r |
1238 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1239 | if (ffs == null) {\r |
1240 | return;\r |
1241 | }\r |
1242 | BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r |
1243 | XmlCursor cursor = sections.newCursor();\r |
1244 | QName qSections = new QName(xmlNs, "Sections");\r |
1245 | if (cursor.toChild(qSections)){\r |
1246 | for (int k = 0; k < j; ++k) {\r |
1247 | cursor.toNextSibling(qSections);\r |
1248 | }\r |
1249 | BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r |
1250 | sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));\r |
1251 | }\r |
1252 | cursor.dispose();\r |
1253 | }\r |
1254 | \r |
1255 | public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {\r |
1256 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1257 | if (ffs == null) {\r |
1258 | return;\r |
1259 | }\r |
1260 | BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r |
1261 | XmlCursor cursor = sections.newCursor();\r |
1262 | QName qSections = new QName(xmlNs, "Sections");\r |
1263 | if (cursor.toChild(qSections)){\r |
1264 | for (int k = 0; k < j; ++k) {\r |
1265 | cursor.toNextSibling(qSections);\r |
1266 | }\r |
1267 | BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r |
1268 | if (sections2.getSectionList() == null){\r |
1269 | cursor.dispose();\r |
1270 | return;\r |
1271 | }\r |
1272 | ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();\r |
1273 | while(li.hasNext()) {\r |
1274 | BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();\r |
1275 | al.add(section.getSectionType().toString());\r |
1276 | }\r |
1277 | }\r |
1278 | cursor.dispose();\r |
1279 | \r |
1280 | }\r |
1281 | \r |
1282 | public int getBuildOptionsFfsCount(){\r |
1283 | if (getfpdBuildOpts().getFfsList() == null) {\r |
1284 | return 0;\r |
1285 | }\r |
1286 | return getfpdBuildOpts().getFfsList().size();\r |
1287 | }\r |
1288 | \r |
1289 | public void getBuildOptionsFfsKey(String[][] saa) {\r |
1290 | if (getfpdBuildOpts().getFfsList() == null) {\r |
1291 | return;\r |
1292 | }\r |
1293 | ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();\r |
1294 | int i = 0;\r |
1295 | while(li.hasNext()){\r |
1296 | BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();\r |
1297 | saa[i][0] = ffs.getFfsKey();\r |
1298 | ++i;\r |
1299 | }\r |
1300 | }\r |
1301 | \r |
1302 | /**Get ith FFS key and contents.\r |
1303 | * @param saa\r |
1304 | */\r |
1305 | public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {\r |
1306 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1307 | \r |
1308 | if (ffs != null) {\r |
1309 | \r |
1310 | sa[0] = ffs.getFfsKey();\r |
1311 | if (ffs.getSections() != null) {\r |
1312 | if(ffs.getSections().getEncapsulationType() != null){\r |
1313 | sa[1] = ffs.getSections().getEncapsulationType();\r |
1314 | }\r |
1315 | if (ffs.getSections().getSectionList() != null){\r |
1316 | ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();\r |
1317 | while (li.hasNext()) {\r |
1318 | firstLevelSection.add(li.next().getSectionType().toString());\r |
1319 | }\r |
1320 | }\r |
1321 | if (ffs.getSections().getSectionsList() != null) {\r |
1322 | ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();\r |
1323 | while(li.hasNext()) {\r |
1324 | firstLevelSections.add(li.next().getEncapsulationType());\r |
1325 | }\r |
1326 | }\r |
1327 | }\r |
1328 | if (ffs.getAttributeList() != null) {\r |
1329 | ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();\r |
1330 | while(li.hasNext()) {\r |
1331 | BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();\r |
1332 | ffsAttribMap.put(attrib.getName(), attrib.getValue());\r |
1333 | }\r |
1334 | \r |
1335 | }\r |
1336 | }\r |
1337 | \r |
1338 | \r |
1339 | }\r |
1340 | \r |
1341 | private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {\r |
1342 | XmlObject o = getfpdBuildOpts();\r |
1343 | BuildOptionsDocument.BuildOptions.Ffs ffs = null;\r |
1344 | \r |
1345 | XmlCursor cursor = o.newCursor();\r |
1346 | QName qFfs = new QName(xmlNs, "Ffs");\r |
1347 | if (cursor.toChild(qFfs)) {\r |
1348 | for (int j = 0; j < i; ++j) {\r |
1349 | cursor.toNextSibling(qFfs);\r |
1350 | }\r |
1351 | ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();\r |
1352 | }\r |
1353 | cursor.dispose();\r |
1354 | return ffs;\r |
1355 | }\r |
1356 | \r |
1357 | public void removeBuildOptionsFfs(int i) {\r |
1358 | BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r |
1359 | if (ffs == null){\r |
1360 | return;\r |
1361 | }\r |
1362 | \r |
1363 | XmlCursor cursor = ffs.newCursor();\r |
1364 | cursor.removeXml();\r |
1365 | cursor.dispose();\r |
1366 | }\r |
1367 | \r |
a13899c5 |
1368 | public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){\r |
1369 | if (fpdPlatformDefs == null){\r |
1370 | fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();\r |
1371 | }\r |
1372 | return fpdPlatformDefs;\r |
1373 | }\r |
1374 | \r |
1375 | public FlashDocument.Flash getfpdFlash() {\r |
1376 | if (fpdFlash == null) {\r |
1377 | fpdFlash = fpdRoot.addNewFlash();\r |
1378 | }\r |
1379 | return fpdFlash;\r |
1380 | }\r |
1381 | \r |
1382 | public void genFlashDefinitionFile(String file) {\r |
1383 | FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r |
1384 | if (fdf == null) {\r |
1385 | fdf = getfpdFlash().addNewFlashDefinitionFile();\r |
1386 | }\r |
1387 | \r |
1388 | fdf.setStringValue(file);\r |
1389 | }\r |
1390 | \r |
1391 | public String getFlashDefinitionFile() {\r |
1392 | FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r |
1393 | if (fdf == null) {\r |
1394 | return "";\r |
1395 | }\r |
1396 | \r |
1397 | return fdf.getStringValue();\r |
1398 | }\r |
1399 | \r |
1400 | \r |
1401 | \r |
1402 | public void genFvImagesNameValue(String name, String value) {\r |
1403 | \r |
1404 | FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r |
1405 | if (fi == null) {\r |
1406 | fi = getfpdFlash().addNewFvImages();\r |
1407 | }\r |
1408 | \r |
1409 | FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();\r |
1410 | nv.setName(name);\r |
1411 | nv.setValue(value);\r |
1412 | }\r |
1413 | \r |
1414 | public void removeFvImagesNameValue(int i){\r |
1415 | \r |
1416 | XmlObject o = getfpdFlash().getFvImages();\r |
1417 | if (o == null) {\r |
1418 | return;\r |
1419 | }\r |
1420 | \r |
1421 | QName qNameValue = new QName(xmlNs, "NameValue");\r |
1422 | XmlCursor cursor = o.newCursor();\r |
1423 | if (cursor.toChild(qNameValue)) {\r |
1424 | for (int j = 0; j < i; ++j) {\r |
1425 | cursor.toNextSibling(qNameValue);\r |
1426 | }\r |
1427 | cursor.removeXml();\r |
1428 | }\r |
1429 | cursor.dispose();\r |
1430 | }\r |
1431 | \r |
1432 | public void updateFvImagesNameValue(int i, String name, String value){\r |
1433 | \r |
1434 | XmlObject o = getfpdFlash().getFvImages();\r |
1435 | if (o == null) {\r |
1436 | return;\r |
1437 | }\r |
1438 | \r |
1439 | QName qNameValue = new QName(xmlNs, "NameValue");\r |
1440 | XmlCursor cursor = o.newCursor();\r |
1441 | if (cursor.toChild(qNameValue)) {\r |
1442 | for (int j = 0; j < i; ++j) {\r |
1443 | cursor.toNextSibling(qNameValue);\r |
1444 | }\r |
1445 | FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();\r |
1446 | nv.setName(name);\r |
1447 | nv.setValue(value);\r |
1448 | }\r |
1449 | cursor.dispose();\r |
1450 | }\r |
1451 | \r |
1452 | public int getFvImagesNameValueCount() {\r |
1453 | \r |
1454 | FvImagesDocument.FvImages fi = null;\r |
1455 | if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {\r |
1456 | return 0;\r |
1457 | }\r |
1458 | return fi.getNameValueList().size();\r |
1459 | }\r |
1460 | \r |
1461 | public void getFvImagesNameValues(String[][] nv) {\r |
1462 | \r |
1463 | FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r |
1464 | if (fi == null){\r |
1465 | return;\r |
1466 | }\r |
1467 | List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();\r |
1468 | int i = 0;\r |
1469 | ListIterator li = l.listIterator();\r |
1470 | while (li.hasNext()) {\r |
1471 | FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li\r |
1472 | .next();\r |
1473 | nv[i][0] = e.getName();\r |
1474 | nv[i][1] = e.getValue();\r |
1475 | \r |
1476 | i++;\r |
1477 | }\r |
1478 | }\r |
1479 | \r |
1480 | public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r |
1481 | \r |
1482 | FvImagesDocument.FvImages fis = null;\r |
1483 | if ((fis = getfpdFlash().getFvImages()) == null) {\r |
1484 | fis = getfpdFlash().addNewFvImages();\r |
1485 | }\r |
1486 | \r |
1487 | //\r |
1488 | //gen FvImage with FvImageNames array\r |
1489 | //\r |
1490 | FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();\r |
1491 | for (int i = 0; i < names.length; ++i) {\r |
1492 | fi.addFvImageNames(names[i]);\r |
1493 | }\r |
1494 | fi.setType(FvImageTypes.Enum.forString(types));\r |
1495 | if (options != null){\r |
1496 | setFvImagesFvImageFvImageOptions(options, fi);\r |
1497 | }\r |
1498 | }\r |
1499 | \r |
1500 | private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){\r |
1501 | FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();\r |
1502 | if (fio == null){\r |
1503 | fio = fi.addNewFvImageOptions();\r |
1504 | }\r |
1505 | \r |
1506 | Set<String> key = options.keySet();\r |
1507 | Iterator<String> i = key.iterator();\r |
1508 | while (i.hasNext()) {\r |
44053733 |
1509 | \r |
a13899c5 |
1510 | FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();\r |
1511 | String k = (String)i.next();\r |
ae0d4fd2 |
1512 | \r |
a13899c5 |
1513 | nv.setName(k);\r |
1514 | nv.setValue((String)options.get(k));\r |
1515 | \r |
1516 | }\r |
1517 | \r |
1518 | }\r |
1519 | \r |
44053733 |
1520 | \r |
a13899c5 |
1521 | public void removeFvImagesFvImage(int i) {\r |
1522 | \r |
1523 | XmlObject o = getfpdFlash().getFvImages();\r |
1524 | if (o == null) {\r |
1525 | return;\r |
1526 | }\r |
1527 | \r |
1528 | QName qFvImage = new QName(xmlNs, "FvImage");\r |
1529 | XmlCursor cursor = o.newCursor();\r |
1530 | if (cursor.toChild(qFvImage)) {\r |
1531 | for (int j = 0; j < i; ++j) {\r |
1532 | cursor.toNextSibling(qFvImage);\r |
1533 | }\r |
1534 | cursor.removeXml();\r |
1535 | }\r |
1536 | cursor.dispose();\r |
1537 | }\r |
1538 | \r |
1539 | public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r |
1540 | \r |
1541 | XmlObject o = getfpdFlash().getFvImages();\r |
1542 | if (o == null) {\r |
1543 | return;\r |
1544 | }\r |
1545 | XmlCursor cursor = o.newCursor();\r |
1546 | QName qFvImage = new QName(xmlNs, "FvImage");\r |
1547 | if (cursor.toChild(qFvImage)) {\r |
1548 | for (int j = 0; j < i; ++j) {\r |
1549 | cursor.toNextSibling(qFvImage);\r |
1550 | }\r |
1551 | FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r |
1552 | fi.setType(FvImageTypes.Enum.forString(types));\r |
1553 | \r |
1554 | //\r |
1555 | // remove old FvImageNames before adding new ones\r |
1556 | //\r |
1557 | QName qFvImageNames = new QName(xmlNs, "FvImageNames"); \r |
1558 | cursor.toChild(qFvImageNames);\r |
1559 | cursor.removeXml();\r |
1560 | while (cursor.toNextSibling(qFvImageNames)) {\r |
1561 | cursor.removeXml();\r |
1562 | }\r |
1563 | \r |
1564 | for (int k = 0; k < names.length; ++k) {\r |
1565 | fi.addFvImageNames(names[k]);\r |
1566 | }\r |
1567 | //\r |
1568 | // remove old FvImageOptions before adding new options\r |
1569 | //\r |
1570 | QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");\r |
1571 | cursor.toNextSibling(qFvImageOptions);\r |
1572 | cursor.removeXml();\r |
1573 | \r |
1574 | setFvImagesFvImageFvImageOptions(options, fi);\r |
1575 | }\r |
1576 | cursor.dispose();\r |
1577 | }\r |
1578 | \r |
1579 | public int getFvImagesFvImageCount() {\r |
1580 | \r |
1581 | if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r |
1582 | return 0;\r |
1583 | }\r |
1584 | return getfpdFlash().getFvImages().getFvImageList().size();\r |
1585 | }\r |
1586 | \r |
ae0d4fd2 |
1587 | /**Only Get Fv image setting - name and type.\r |
1588 | * @param saa\r |
1589 | */\r |
1590 | public void getFvImagesFvImages(String[][] saa) {\r |
a13899c5 |
1591 | \r |
1592 | if (getfpdFlash().getFvImages() == null) {\r |
1593 | return;\r |
1594 | }\r |
1595 | List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r |
1596 | if (l == null) {\r |
1597 | return;\r |
1598 | }\r |
1599 | ListIterator li = l.listIterator();\r |
1600 | int i = 0;\r |
1601 | while(li.hasNext()) {\r |
1602 | FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r |
1603 | //\r |
1604 | // get FvImageNames array, space separated\r |
1605 | //\r |
1606 | List<String> lfn = fi.getFvImageNamesList();\r |
1607 | ListIterator lfni = lfn.listIterator();\r |
1608 | saa[i][0] = " ";\r |
1609 | while (lfni.hasNext()) {\r |
1610 | saa[i][0] += (String)lfni.next();\r |
1611 | saa[i][0] += " ";\r |
1612 | }\r |
1613 | saa[i][0] = saa[i][0].trim();\r |
1614 | \r |
1615 | saa[i][1] = fi.getType()+"";\r |
1616 | \r |
ae0d4fd2 |
1617 | ++i;\r |
1618 | }\r |
1619 | }\r |
1620 | \r |
1621 | /**Get FvImage Options for FvImage i\r |
1622 | * @param i the ith FvImage\r |
1623 | */\r |
1624 | public void getFvImagesFvImageOptions(int i, Map<String, String> m) {\r |
1625 | XmlObject o = getfpdFlash().getFvImages();\r |
1626 | if (o == null) {\r |
1627 | return;\r |
1628 | }\r |
1629 | XmlCursor cursor = o.newCursor();\r |
1630 | QName qFvImage = new QName(xmlNs, "FvImage");\r |
1631 | if (cursor.toChild(qFvImage)) {\r |
1632 | for (int j = 0; j < i; ++j) {\r |
1633 | cursor.toNextSibling(qFvImage);\r |
a13899c5 |
1634 | }\r |
ae0d4fd2 |
1635 | FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r |
1636 | if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){\r |
1637 | return;\r |
a13899c5 |
1638 | }\r |
ae0d4fd2 |
1639 | ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();\r |
1640 | while(li.hasNext()){\r |
1641 | FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r |
a13899c5 |
1642 | m.put(nv.getName(), nv.getValue());\r |
1643 | }\r |
a13899c5 |
1644 | }\r |
1645 | }\r |
1646 | \r |
1647 | /**\r |
1648 | Get platform header element\r |
1649 | @return PlatformHeaderDocument.PlatformHeader\r |
1650 | **/\r |
1651 | public PlatformHeaderDocument.PlatformHeader getFpdHdr() {\r |
1652 | if (fpdHdr == null) {\r |
1653 | fpdHdr = fpdRoot.addNewPlatformHeader();\r |
1654 | }\r |
1655 | genPlatformDefsSkuInfo("0", "DEFAULT");\r |
1656 | return fpdHdr;\r |
1657 | }\r |
1658 | \r |
1659 | public void genPlatformDefsSkuInfo(String id, String name) {\r |
1660 | SkuInfoDocument.SkuInfo skuInfo = null;\r |
1661 | if (getfpdPlatformDefs().getSkuInfo() == null) {\r |
1662 | skuInfo = getfpdPlatformDefs().addNewSkuInfo();\r |
1663 | }\r |
1664 | skuInfo = getfpdPlatformDefs().getSkuInfo();\r |
1665 | if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {\r |
1666 | SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r |
1667 | skuName.setSkuID(new BigInteger("0"));\r |
1668 | skuName.setStringValue("DEFAULT");\r |
1669 | }\r |
1670 | if (id.equals("0")) {\r |
1671 | return;\r |
1672 | }\r |
1673 | SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r |
1674 | skuName.setSkuID(new BigInteger(id));\r |
1675 | skuName.setStringValue(name);\r |
1676 | \r |
1677 | \r |
1678 | }\r |
1679 | public String getFpdHdrPlatformName() {\r |
1680 | return getFpdHdr().getPlatformName();\r |
1681 | }\r |
1682 | \r |
1683 | public String getFpdHdrGuidValue() {\r |
1684 | return getFpdHdr().getGuidValue();\r |
1685 | }\r |
1686 | \r |
1687 | public String getFpdHdrVer() {\r |
1688 | return getFpdHdr().getVersion();\r |
1689 | }\r |
1690 | \r |
1691 | public String getFpdHdrAbs() {\r |
1692 | return getFpdHdr().getAbstract();\r |
1693 | }\r |
1694 | \r |
1695 | public String getFpdHdrDescription() {\r |
1696 | return getFpdHdr().getDescription();\r |
1697 | }\r |
1698 | \r |
1699 | public String getFpdHdrCopyright() {\r |
1700 | return getFpdHdr().getCopyright();\r |
1701 | }\r |
1702 | \r |
1703 | public String getFpdHdrLicense() {\r |
1704 | LicenseDocument.License l = getFpdHdr().getLicense();\r |
1705 | if (l == null) {\r |
1706 | return null;\r |
1707 | }\r |
1708 | return l.getStringValue();\r |
1709 | }\r |
1710 | \r |
1711 | public String getFpdHdrUrl() {\r |
1712 | LicenseDocument.License l = getFpdHdr().getLicense();\r |
1713 | if (l == null) {\r |
1714 | return null;\r |
1715 | }\r |
1716 | return l.getURL();\r |
1717 | }\r |
1718 | \r |
1719 | public String getFpdHdrSpec() {\r |
1720 | \r |
1721 | return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r |
1722 | // return getFpdHdr().getSpecification();\r |
1723 | }\r |
1724 | \r |
1725 | public void setFpdHdrPlatformName(String name){\r |
1726 | getFpdHdr().setPlatformName(name);\r |
1727 | }\r |
1728 | \r |
1729 | public void setFpdHdrGuidValue(String guid){\r |
1730 | getFpdHdr().setGuidValue(guid);\r |
1731 | }\r |
1732 | \r |
1733 | public void setFpdHdrVer(String v){\r |
1734 | getFpdHdr().setVersion(v);\r |
1735 | }\r |
1736 | \r |
1737 | public void setFpdHdrAbs(String abs) {\r |
1738 | getFpdHdr().setAbstract(abs);\r |
1739 | }\r |
1740 | \r |
1741 | public void setFpdHdrDescription(String desc){\r |
1742 | getFpdHdr().setDescription(desc);\r |
1743 | }\r |
1744 | \r |
1745 | public void setFpdHdrCopyright(String cr) {\r |
1746 | getFpdHdr().setCopyright(cr);\r |
1747 | }\r |
1748 | \r |
1749 | public void setFpdHdrLicense(String license){\r |
1750 | LicenseDocument.License l = getFpdHdr().getLicense();\r |
1751 | if (l == null) {\r |
1752 | getFpdHdr().addNewLicense().setStringValue(license);\r |
1753 | }\r |
1754 | else {\r |
1755 | l.setStringValue(license);\r |
1756 | }\r |
1757 | }\r |
1758 | \r |
1759 | public void setFpdHdrUrl(String url){\r |
1760 | LicenseDocument.License l = getFpdHdr().getLicense();\r |
1761 | \r |
1762 | l.setURL(url);\r |
1763 | \r |
1764 | }\r |
1765 | \r |
1766 | public void setFpdHdrSpec(String s){\r |
1767 | s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r |
1768 | getFpdHdr().setSpecification(s);\r |
1769 | }\r |
1770 | /**\r |
1771 | Save the processed xml contents to file\r |
1772 | \r |
1773 | @param fpdFile The file to save xml contents\r |
1774 | @throws IOException Exceptions during file operation\r |
1775 | **/\r |
1776 | public void saveAs(File fpdFile) throws IOException {\r |
1777 | \r |
1778 | XmlOptions options = new XmlOptions();\r |
1779 | \r |
1780 | options.setCharacterEncoding("UTF-8");\r |
1781 | options.setSavePrettyPrint();\r |
1782 | options.setSavePrettyPrintIndent(2);\r |
1783 | try {\r |
1784 | fpdd.save(fpdFile, options);\r |
1785 | } catch (IOException e) {\r |
1786 | e.printStackTrace();\r |
1787 | }\r |
1788 | \r |
1789 | }\r |
1790 | \r |
1791 | private String listToString(List<String> l) {\r |
1792 | if (l == null) {\r |
1793 | return null;\r |
1794 | }\r |
1795 | String s = " ";\r |
1796 | ListIterator li = l.listIterator();\r |
1797 | while(li.hasNext()) {\r |
1798 | s += li.next();\r |
1799 | s += " ";\r |
1800 | }\r |
1801 | return s.trim();\r |
1802 | }\r |
1803 | }\r |