Remove empty FfsFileNameGuid element under ModuleSaBuildOptions if user input empty...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
CommitLineData
a13899c5 1/** @file\r
2 Java class FpdFileContents is used to parse fpd xml file.\r
3 \r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13package org.tianocore.frameworkwizard.platform.ui;\r
14\r
15import java.io.File;\r
16import java.io.IOException;\r
17import java.math.BigInteger;\r
18import java.util.ArrayList;\r
19import java.util.HashMap;\r
20import java.util.Iterator;\r
21import java.util.LinkedHashMap;\r
22import java.util.List;\r
23import java.util.ListIterator;\r
24import java.util.Map;\r
25import java.util.Set;\r
6a09eb19 26import java.util.Vector;\r
a13899c5 27\r
28import javax.xml.namespace.QName;\r
29\r
30import org.apache.xmlbeans.XmlCursor;\r
31import org.apache.xmlbeans.XmlObject;\r
32import org.apache.xmlbeans.XmlOptions;\r
33import org.tianocore.AntTaskDocument;\r
34import org.tianocore.BuildOptionsDocument;\r
35import org.tianocore.DynamicPcdBuildDefinitionsDocument;\r
6cba26e8 36import org.tianocore.EfiSectionType;\r
a13899c5 37import org.tianocore.FlashDefinitionFileDocument;\r
a13899c5 38import org.tianocore.FlashDocument;\r
39import org.tianocore.FrameworkModulesDocument;\r
6a09eb19 40import org.tianocore.IntermediateOutputType;\r
a13899c5 41import org.tianocore.LibrariesDocument;\r
42import org.tianocore.ModuleSADocument;\r
8f55ea73 43import org.tianocore.ModuleSaBuildOptionsDocument;\r
a13899c5 44import org.tianocore.ModuleSurfaceAreaDocument;\r
45import org.tianocore.OptionDocument;\r
46import org.tianocore.OptionsDocument;\r
47import org.tianocore.PcdBuildDefinitionDocument;\r
48import org.tianocore.PcdCodedDocument;\r
49import org.tianocore.PcdDataTypes;\r
50import org.tianocore.PcdDeclarationsDocument;\r
51import org.tianocore.PcdItemTypes;\r
52import org.tianocore.PlatformDefinitionsDocument;\r
53import org.tianocore.PlatformSurfaceAreaDocument;\r
54import org.tianocore.FvImageTypes;\r
55import org.tianocore.FvImagesDocument;\r
56import org.tianocore.LicenseDocument;\r
57import org.tianocore.PlatformHeaderDocument;\r
58import org.tianocore.SkuInfoDocument;\r
59import org.tianocore.UserDefinedAntTasksDocument;\r
60import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;\r
61import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r
62import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;\r
63import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;\r
64\r
65/**\r
66 This class processes fpd file contents such as add remove xml elements. \r
67 @since PackageEditor 1.0\r
68**/\r
69public class FpdFileContents {\r
70\r
71 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";\r
72 \r
73 private PlatformSurfaceAreaDocument fpdd = null;\r
74 \r
75 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;\r
76 \r
77 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;\r
78 \r
79 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;\r
80 \r
81 private FlashDocument.Flash fpdFlash = null;\r
82 \r
83 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;\r
84 \r
85 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;\r
86 \r
87 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;\r
88 \r
908b1c05 89 private HashMap<String, ArrayList<String>> dynPcdMap = null;\r
a13899c5 90 \r
91 /**\r
92 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.\r
93 */\r
94 public void initDynPcdMap() {\r
95 if (dynPcdMap == null) {\r
96 dynPcdMap = new HashMap<String, ArrayList<String>>();\r
97 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();\r
98 if (l == null) {\r
99 return;\r
100 }\r
101 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();\r
102 while (li.hasNext()) {\r
103 ModuleSADocument.ModuleSA msa = li.next();\r
104 if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) {\r
105 continue;\r
106 }\r
107 String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() +\r
bf5abaff 108 " " + msa.getPackageGuid() + " " + msa.getPackageVersion() + " " + listToString(msa.getSupArchList());\r
a13899c5 109 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = msa.getPcdBuildDefinition().getPcdDataList();\r
110 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();\r
111 while (lpi.hasNext()) {\r
112 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();\r
113 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r
114 if (dynPcdMap.get(pcdKey) == null) {\r
115 ArrayList<String> al = new ArrayList<String>();\r
116 al.add(ModuleInfo + " " + pcdData.getItemType().toString());\r
117 dynPcdMap.put(pcdKey, al);\r
118 }\r
119 else{\r
120 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());\r
121 }\r
122 }\r
123 }\r
124 }\r
125 }\r
908b1c05 126 \r
127 public ArrayList<String> getDynPcdMapValue(String key) {\r
128 return dynPcdMap.get(key);\r
129 }\r
a13899c5 130 /**\r
131 Constructor to create a new spd file\r
132 **/\r
133 public FpdFileContents() {\r
134\r
135 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();\r
136 fpdRoot = fpdd.addNewPlatformSurfaceArea();\r
137\r
138 }\r
139\r
140 /**\r
141 Constructor for existing document object\r
142 @param psa\r
143 **/\r
144 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {\r
145 fpdRoot = fpd;\r
146 fpdHdr = fpdRoot.getPlatformHeader();\r
147 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();\r
148 fpdBuildOpts = fpdRoot.getBuildOptions();\r
149 fpdFrameworkModules = fpdRoot.getFrameworkModules();\r
150 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();\r
151 fpdFlash = fpdRoot.getFlash();\r
152 }\r
153\r
154 /**\r
155 Constructor based on an existing spd file\r
156 \r
157 @param f Existing spd file\r
158 **/\r
159 public FpdFileContents(File f) {\r
160 try {\r
161 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);\r
162 fpdRoot = fpdd.getPlatformSurfaceArea();\r
163 } catch (Exception e) {\r
164 System.out.println(e.toString());\r
165 }\r
166 }\r
167 \r
168 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {\r
169 if (fpdDynPcdBuildDefs == null){\r
170 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();\r
171 }\r
172 return fpdDynPcdBuildDefs;\r
173 }\r
174 \r
175 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {\r
176 if (fpdFrameworkModules == null){\r
177 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();\r
178 }\r
179 return fpdFrameworkModules;\r
180 }\r
181 \r
a13899c5 182 public int getFrameworkModulesCount() {\r
183 if (getfpdFrameworkModules().getModuleSAList() == null){\r
184 return 0;\r
185 }\r
186 return getfpdFrameworkModules().getModuleSAList().size();\r
187 }\r
188 \r
189 public void getFrameworkModulesInfo(String[][] saa) {\r
190 if (getFrameworkModulesCount() == 0){\r
191 return;\r
192 }\r
193 \r
194 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
195 int i = 0;\r
196 while(li.hasNext()) {\r
197 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r
bf5abaff 198 saa[i][0] = msa.getModuleGuid();\r
199 saa[i][1] = msa.getModuleVersion();\r
a13899c5 200 \r
bf5abaff 201 saa[i][2] = msa.getPackageGuid();\r
202 saa[i][3] = msa.getPackageVersion();\r
203 saa[i][4] = listToString(msa.getSupArchList());\r
a13899c5 204 ++i;\r
205 }\r
206 }\r
207 \r
bf5abaff 208 public void getFrameworkModuleInfo(int i, String[] sa) {\r
209 ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
210 if (msa == null) {\r
211 return;\r
212 }\r
213 sa[0] = msa.getModuleGuid();\r
214 sa[1] = msa.getModuleVersion();\r
215 sa[2] = msa.getPackageGuid();\r
216 sa[3] = msa.getPackageVersion();\r
217 sa[4] = listToString(msa.getSupArchList());\r
218 }\r
219 \r
a13899c5 220 public ModuleSADocument.ModuleSA getModuleSA(String key) {\r
221 String[] s = key.split(" ");\r
222 if (getfpdFrameworkModules().getModuleSAList() == null) {\r
223 return null;\r
224 }\r
225 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
226 while(li.hasNext()) {\r
227 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r
f3b0ed9a 228 if (msa.getModuleGuid().equals(s[0]) && msa.getPackageGuid().equals(s[2])) {\r
12e17a0a 229 if (msa.getModuleVersion() != null) {\r
230 if (!msa.getModuleVersion().equals(s[1])) {\r
231 continue;\r
232 }\r
233 }\r
234 if (msa.getPackageVersion() != null) {\r
235 if (!msa.getPackageVersion().equals(s[3])) {\r
236 continue;\r
237 }\r
238 }\r
bf5abaff 239 //ToDo add arch check for s[4]\r
240 if (msa.getSupArchList() != null) {\r
241 if (!listToString(msa.getSupArchList()).equals(s[4])) {\r
242 continue;\r
243 }\r
244 }\r
a13899c5 245 return msa;\r
246 }\r
247 }\r
248 return null;\r
249 }\r
bf5abaff 250 \r
251 private ModuleSADocument.ModuleSA getModuleSA(int i) {\r
252 ModuleSADocument.ModuleSA msa = null;\r
253 XmlCursor cursor = getfpdFrameworkModules().newCursor();\r
254 if (cursor.toFirstChild()) {\r
255 for (int j = 0; j < i; ++j) {\r
256 cursor.toNextSibling();\r
257 }\r
258 msa = (ModuleSADocument.ModuleSA)cursor.getObject();\r
259 }\r
260 cursor.dispose();\r
261 return msa;\r
262 }\r
263 \r
a13899c5 264 public void removeModuleSA(int i) {\r
265 XmlObject o = getfpdFrameworkModules();\r
266 if (o == null) {\r
267 return;\r
268 }\r
269 \r
270 XmlCursor cursor = o.newCursor();\r
271 if (cursor.toFirstChild()) {\r
272 for (int j = 0; j < i; ++j) {\r
273 cursor.toNextSibling();\r
274 }\r
275 //\r
276 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.\r
277 //\r
278 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();\r
279 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +\r
bf5abaff 280 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());\r
a13899c5 281 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();\r
908b1c05 282 if (pcdBuildDef != null && pcdBuildDef.getPcdDataList() != null) {\r
283 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> li = pcdBuildDef.getPcdDataList().listIterator();\r
284 while(li.hasNext()) {\r
285 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();\r
286 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleInfo);\r
287 }\r
a13899c5 288 }\r
289 cursor.removeXml();\r
af25df16 290 if (getFrameworkModulesCount() == 0) {\r
291 cursor.toParent();\r
292 cursor.removeXml();\r
293 }\r
a13899c5 294 }\r
295 cursor.dispose();\r
296 }\r
297 \r
908b1c05 298 private void maintainDynPcdMap(String pcdKey, String moduleInfo) {\r
299 \r
300 ArrayList<String> al = dynPcdMap.get(pcdKey);\r
301 if (al == null) {\r
a13899c5 302 return;\r
303 }\r
908b1c05 304 String[] s = moduleInfo.split(" ");\r
a13899c5 305 for(int i = 0; i < al.size(); ++i){\r
908b1c05 306 String consumer = al.get(i);\r
307 if (consumer.contains(s[0]) && consumer.contains(s[2])){\r
bf5abaff 308 String[] consumerPart = consumer.split(" ");\r
309 if (!consumerPart[4].equals(s[4])) {\r
310 continue;\r
311 }\r
908b1c05 312 al.remove(consumer);\r
a13899c5 313 break;\r
314 }\r
315 }\r
908b1c05 316\r
a13899c5 317 if (al.size() == 0) {\r
318 dynPcdMap.remove(pcdKey);\r
908b1c05 319 String[] s1 = pcdKey.split(" ");\r
320 removeDynamicPcdBuildData(s1[0], s1[1]);\r
a13899c5 321 }\r
322 \r
a13899c5 323 }\r
324 //\r
bf5abaff 325 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"\r
a13899c5 326 //\r
055e7ae6 327 public int getPcdDataCount(int i){\r
bf5abaff 328 ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
055e7ae6 329 \r
a13899c5 330 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
331 return 0;\r
332 }\r
333 return msa.getPcdBuildDefinition().getPcdDataList().size();\r
055e7ae6 334 \r
a13899c5 335 }\r
336 \r
055e7ae6 337 public void getPcdData(int i, String[][] saa) {\r
bf5abaff 338 ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
055e7ae6 339 \r
a13899c5 340 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
341 return;\r
342 }\r
343 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();\r
055e7ae6 344 for (int k = 0; k < saa.length; ++k) {\r
a13899c5 345 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();\r
055e7ae6 346 saa[k][0] = pcdData.getCName();\r
347 saa[k][1] = pcdData.getTokenSpaceGuidCName();\r
348 saa[k][2] = pcdData.getItemType()+"";\r
349 saa[k][3] = pcdData.getToken().toString();\r
350 saa[k][4] = pcdData.getMaxDatumSize()+"";\r
351 saa[k][5] = pcdData.getDatumType()+"";\r
352 saa[k][6] = pcdData.getValue();\r
a13899c5 353 \r
354 }\r
355 }\r
908b1c05 356 \r
357 public void updatePcdData(String key, String cName, String tsGuid, String itemType, String maxSize, String value){\r
358 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
359 if (msa == null || msa.getPcdBuildDefinition() == null){\r
360 return;\r
361 }\r
362 \r
363 XmlCursor cursor = msa.getPcdBuildDefinition().newCursor();\r
364 if (cursor.toFirstChild()){\r
365 do {\r
366 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
367 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
368 pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
369 if(pcdData.getDatumType().equals("VOID*")) {\r
370 pcdData.setMaxDatumSize(new Integer(maxSize));\r
371 }\r
372 pcdData.setValue(value);\r
373 break;\r
374 }\r
375 }\r
376 while(cursor.toNextSibling());\r
377 }\r
378 cursor.dispose();\r
379 }\r
380 \r
381 /**Get original Pcd info from MSA & SPD files.\r
382 * @param mi ModuleIdentification from which MSA & SPD come\r
383 * @param cName PCD cName\r
384 * @param sa Results: HelpText, Original item type.\r
385 * @return\r
386 */\r
387 public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String[] sa) throws Exception{\r
388 try {\r
389 \r
390 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r
391 if (msa.getPcdCoded() == null) {\r
392 return false;\r
393 }\r
394 \r
395 Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
396 m.put("ModuleSurfaceArea", msa);\r
397 SurfaceAreaQuery.setDoc(m);\r
398 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);\r
399 //\r
400 // First look through MSA pcd entries.\r
401 //\r
402 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
403 ListIterator li = l.listIterator();\r
404 while(li.hasNext()) {\r
405 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r
406 if (!msaPcd.getCName().equals(cName)) {\r
407 continue;\r
408 }\r
409 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
410 if (spdPcd == null) {\r
411 //\r
412 // ToDo Error \r
413 //\r
414 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());\r
415 }\r
416 //\r
417 // Get Pcd help text and original item type.\r
418 //\r
419 sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();\r
420 sa[1] = msaPcd.getPcdItemType()+"";\r
421 return true;\r
422 }\r
423 \r
424 \r
425 }\r
426 catch (Exception e){\r
af25df16 427// e.printStackTrace();\r
908b1c05 428 throw e;\r
429 }\r
430 \r
431 return false;\r
432 }\r
433 \r
434 /**Remove PCDBuildDefinition entries from ModuleSA\r
435 * @param moduleKey identifier of ModuleSA.\r
436 * @param consumer where these entries come from.\r
437 */\r
438 public void removePcdData(String moduleKey, ModuleIdentification consumer) {\r
439 try {\r
440 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(consumer);\r
441 if (msa.getPcdCoded() == null) {\r
442 return;\r
443 }\r
444 \r
445 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
446 ListIterator li = l.listIterator();\r
447 \r
448 while(li.hasNext()) {\r
449 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r
450 ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey);\r
451 XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();\r
452 if (cursor.toFirstChild()) {\r
453 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
454 if (msaPcd.getCName().equals(pcdData.getCName()) && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {\r
455 \r
456 maintainDynPcdMap(pcdData.getCName()+" "+pcdData.getTokenSpaceGuidCName(), moduleKey);\r
457 cursor.removeXml();\r
458 break;\r
459 }\r
460 while (cursor.toNextSibling()) {\r
461 pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
462 if (msaPcd.getCName().equals(pcdData.getCName()) && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {\r
463 maintainDynPcdMap(pcdData.getCName()+" "+pcdData.getTokenSpaceGuidCName(), moduleKey);\r
464 cursor.removeXml();\r
465 break;\r
466 }\r
467 }\r
468 }\r
469 cursor.dispose();\r
470 }\r
471 \r
472 }\r
473 catch (Exception e){\r
474 e.printStackTrace();\r
475 \r
476 }\r
477 }\r
a13899c5 478 //\r
bf5abaff 479 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"\r
a13899c5 480 //\r
481 public int getLibraryInstancesCount(String key) {\r
482 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
483 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){\r
484 return 0;\r
485 }\r
486 return msa.getLibraries().getInstanceList().size();\r
487 }\r
488 \r
489 public void getLibraryInstances(String key, String[][] saa){\r
490 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
491 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){\r
492 return ;\r
493 }\r
494 \r
495 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();\r
496 for (int i = 0; i < saa.length; ++i) {\r
497 LibrariesDocument.Libraries.Instance instance = li.next();\r
498 saa[i][1] = instance.getModuleGuid();\r
499 saa[i][2] = instance.getModuleVersion();\r
500 saa[i][3] = instance.getPackageGuid();\r
501 saa[i][4] = instance.getPackageVersion();\r
502 }\r
503 }\r
504 \r
908b1c05 505 public void removeLibraryInstance(String key, int i) {\r
a13899c5 506 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
507 if (msa == null || msa.getLibraries() == null){\r
508 return ;\r
509 }\r
510 \r
511 XmlCursor cursor = msa.getLibraries().newCursor();\r
908b1c05 512 if (cursor.toFirstChild()) {\r
513 for (int j = 0; j < i; ++j) {\r
514 cursor.toNextSibling();\r
515 }\r
516 cursor.removeXml();\r
517 }\r
518 \r
a13899c5 519 cursor.dispose();\r
520 }\r
521 \r
522 public void genLibraryInstance(String mg, String mv, String pg, String pv, String key) {\r
523 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
524 if (msa == null){\r
525 msa = getfpdFrameworkModules().addNewModuleSA();\r
526 }\r
527 LibrariesDocument.Libraries libs = msa.getLibraries();\r
528 if(libs == null){\r
529 libs = msa.addNewLibraries();\r
530 }\r
531 \r
532 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();\r
533 instance.setModuleGuid(mg);\r
534 instance.setModuleVersion(mv);\r
535 instance.setPackageGuid(pg);\r
536 instance.setPackageVersion(pv);\r
537 \r
538 }\r
1800d80f 539 \r
540 public String getFvBinding(String moduleKey){\r
541 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
542 if (msa == null || msa.getModuleSaBuildOptions() == null) {\r
543 return null;\r
544 }\r
545 return msa.getModuleSaBuildOptions().getFvBinding();\r
546 }\r
547 \r
548 public void setFvBinding(String moduleKey, String fvBinding){\r
549 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
550 if (msa == null ) {\r
551 return;\r
552 }\r
553 if(msa.getModuleSaBuildOptions() == null){\r
554 msa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);\r
555 return;\r
556 }\r
557 msa.getModuleSaBuildOptions().setFvBinding(fvBinding);\r
558 }\r
559 \r
560 public String getFfsFileNameGuid(String moduleKey){\r
561 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
562 if (msa == null || msa.getModuleSaBuildOptions() == null) {\r
563 return null;\r
564 }\r
565 return msa.getModuleSaBuildOptions().getFfsFileNameGuid();\r
566 }\r
567 \r
568 public void setFfsFileNameGuid(String moduleKey, String fileGuid){\r
569 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
570 if (msa == null ) {\r
571 return;\r
572 }\r
573 if(msa.getModuleSaBuildOptions() == null){\r
8f55ea73 574 msa.addNewModuleSaBuildOptions();\r
575 \r
1800d80f 576 }\r
8f55ea73 577 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions msaBuildOpts= msa.getModuleSaBuildOptions();\r
578 if (fileGuid != null) {\r
579 msaBuildOpts.setFfsFileNameGuid(fileGuid);\r
580 }\r
581 else{\r
582 XmlCursor cursor = msaBuildOpts.newCursor();\r
583 if (cursor.toChild(xmlNs, "FfsFileNameGuid")) {\r
584 cursor.removeXml();\r
585 }\r
586 cursor.dispose();\r
587 }\r
588 \r
1800d80f 589 }\r
590 \r
591 public String getFfsFormatKey(String moduleKey){\r
592 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
593 if (msa == null || msa.getModuleSaBuildOptions() == null) {\r
594 return null;\r
595 }\r
596 return msa.getModuleSaBuildOptions().getFfsFormatKey();\r
597 }\r
598 \r
599 public void setFfsFormatKey(String moduleKey, String ffsKey){\r
600 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
601 if (msa == null ) {\r
602 return;\r
603 }\r
604 if(msa.getModuleSaBuildOptions() == null){\r
605 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);\r
606 return;\r
607 }\r
bf5abaff 608 msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);\r
1800d80f 609 }\r
610 \r
611 public void getModuleSAOptions(String moduleKey, String[][] saa) {\r
612 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
613 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null\r
614 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {\r
615 return ;\r
616 }\r
617 \r
618 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();\r
619 ListIterator li = lOpt.listIterator();\r
620 int i = 0;\r
621 while(li.hasNext()) {\r
622 OptionDocument.Option opt = (OptionDocument.Option)li.next();\r
623 if (opt.getBuildTargets() != null) {\r
624 saa[i][0] = listToString(opt.getBuildTargets());\r
625 }\r
626 saa[i][1] = opt.getToolChainFamily();\r
bf5abaff 627 saa[i][2] = opt.getTagName();\r
628 saa[i][3] = opt.getToolCode();\r
629 \r
1800d80f 630 if (opt.getSupArchList() != null){\r
bf5abaff 631 saa[i][4] = listToString(opt.getSupArchList());\r
1800d80f 632\r
633 }\r
bf5abaff 634 \r
1800d80f 635 saa[i][5] = opt.getStringValue();\r
636 \r
637 ++i;\r
638 }\r
639 }\r
640 \r
641 public int getModuleSAOptionsCount(String moduleKey){\r
642 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
643 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null\r
644 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {\r
645 return 0;\r
646 }\r
647 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();\r
648 }\r
649 \r
650 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {\r
651 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
652 if (msa.getModuleSaBuildOptions() == null) {\r
653 msa.addNewModuleSaBuildOptions();\r
654 }\r
655 if (msa.getModuleSaBuildOptions().getOptions() == null){\r
656 msa.getModuleSaBuildOptions().addNewOptions();\r
657 }\r
658 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();\r
659 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
660 }\r
661 \r
662 public void removeModuleSAOptionsOpt(String moduleKey, int i) {\r
663 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
664 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {\r
665 return ;\r
666 }\r
667 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();\r
668 XmlCursor cursor = opts.newCursor();\r
669 if (cursor.toFirstChild()) {\r
670 for (int j = 0; j < i; ++j){\r
671 cursor.toNextSibling();\r
672 }\r
673 cursor.removeXml();\r
674 }\r
675 cursor.dispose();\r
676 }\r
677 \r
678 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {\r
679 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
680 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {\r
681 return ;\r
682 }\r
683 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();\r
684 XmlCursor cursor = opts.newCursor();\r
685 if (cursor.toFirstChild()) {\r
686 for (int j = 0; j < i; ++j){\r
687 cursor.toNextSibling();\r
688 }\r
689 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();\r
690 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
691 }\r
692 cursor.dispose();\r
693 }\r
694 \r
a13899c5 695 /**add pcd information of module mi to a ModuleSA. \r
696 * @param mi\r
697 * @param moduleSa if null, generate a new ModuleSA.\r
698 */\r
bf5abaff 699 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {\r
a13899c5 700 //ToDo add Arch filter\r
701 \r
702 try {\r
af25df16 703 if (moduleSa == null) {\r
bf5abaff 704 moduleSa = genModuleSA(mi, arch);\r
af25df16 705 }\r
706 \r
a13899c5 707 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r
708 if (msa.getPcdCoded() == null) {\r
709 return;\r
710 }\r
af25df16 711 \r
a13899c5 712 Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
713 m.put("ModuleSurfaceArea", msa);\r
714 SurfaceAreaQuery.setDoc(m);\r
715 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);\r
716 //\r
717 // Implementing InitializePlatformPcdBuildDefinitions\r
718 //\r
719 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
720 ListIterator li = l.listIterator();\r
721 while(li.hasNext()) {\r
722 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r
723 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
724 if (spdPcd == null) {\r
725 //\r
726 // ToDo Error \r
727 //\r
82961247 728 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());\r
a13899c5 729 }\r
730 //\r
731 // AddItem to ModuleSA PcdBuildDefinitions\r
732 //\r
733 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();\r
908b1c05 734 \r
a13899c5 735 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);\r
736 }\r
737 \r
738 }\r
739 catch (Exception e){\r
af25df16 740// e.printStackTrace();\r
82961247 741 throw e; \r
a13899c5 742 }\r
743 \r
744 }\r
745 \r
746 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {\r
747 \r
748 Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
749 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;\r
750 for (int i = 0; i < depPkgs.length; ++i) {\r
751 m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));\r
752 SurfaceAreaQuery.setDoc(m);\r
753 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();\r
754 if (xo == null) {\r
755 continue;\r
756 }\r
757 for (int j = 0; j < xo.length; ++j) {\r
758 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];\r
759 if (msaPcd.getTokenSpaceGuidCName() == null) {\r
760 if (spdPcd.getCName().equals(msaPcd.getCName())) {\r
761 return spdPcd;\r
762 }\r
763 }\r
764 else{\r
765 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {\r
766 return spdPcd;\r
767 }\r
768 }\r
769 \r
770 }\r
771 \r
772 }\r
773 return null;\r
774 }\r
775 \r
bf5abaff 776 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {\r
a13899c5 777 PackageIdentification pi = GlobalData.getPackageForModule(mi);\r
778 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();\r
779 msa.setModuleGuid(mi.getGuid());\r
780 msa.setModuleVersion(mi.getVersion());\r
781 msa.setPackageGuid(pi.getGuid());\r
782 msa.setPackageVersion(pi.getVersion());\r
bf5abaff 783 if (arch != null) {\r
784 Vector<String> v = new Vector<String>();\r
785 v.add(arch);\r
786 msa.setSupArchList(v); \r
787 }\r
a13899c5 788 \r
789 return msa;\r
790 }\r
791 \r
82961247 792 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) \r
793 throws PcdItemTypeConflictException, PcdValueMalFormed{\r
a13899c5 794 if (moduleSa.getPcdBuildDefinition() == null){\r
795 moduleSa.addNewPcdBuildDefinition();\r
796 }\r
797 //\r
798 // constructe pcd to modulesa mapping first.\r
799 // Attention : for any error condition, remove from map this pcd.\r
800 //\r
801 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);\r
802 if (pcdConsumer == null) {\r
803 pcdConsumer = new ArrayList<String>();\r
804 }\r
805 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() \r
bf5abaff 806 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())\r
a13899c5 807 + " " + itemType;\r
808 pcdConsumer.add(listValue);\r
809 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);\r
810 //\r
811 // Special dynamic type, if this pcd already exists in other ModuleSA\r
812 //\r
813 if (itemType.equals("DYNAMIC")) {\r
814 \r
815 ListIterator li = pcdConsumer.listIterator();\r
816 while(li.hasNext()) {\r
817 String value = li.next().toString();\r
818 String[] valuePart= value.split(" ");\r
819 if (!valuePart[4].equals("DYNAMIC")) {\r
820 //ToDo error for same pcd, other type than dynamic\r
821 pcdConsumer.remove(listValue);\r
82961247 822 throw new PcdItemTypeConflictException(value);\r
a13899c5 823 }\r
824 }\r
825 }\r
826 else {\r
827 ListIterator li = pcdConsumer.listIterator();\r
828 while(li.hasNext()) {\r
829 String value = li.next().toString();\r
830 String[] valuePart= value.split(" ");\r
831 if (valuePart[4].equals("DYNAMIC")) {\r
832 //ToDo error for same pcd, other type than non-dynamic\r
833 pcdConsumer.remove(listValue);\r
82961247 834 throw new PcdItemTypeConflictException(value);\r
a13899c5 835 }\r
836 }\r
837 }\r
838 \r
839 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();\r
840 fpdPcd.setCName(cName);\r
841 fpdPcd.setToken(token);\r
842 fpdPcd.setTokenSpaceGuidCName(tsGuid);\r
843 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
844 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));\r
845 \r
846 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {\r
847 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);\r
848 //\r
849 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.\r
850 // so need to add one dyn pcd.\r
851 //\r
852 if (al.size() == 1) {\r
853 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);\r
854 }\r
855 }\r
856 else {\r
857 if (defaultVal != null){\r
858 fpdPcd.setValue(defaultVal);\r
859 }\r
860 else {\r
861 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {\r
862 fpdPcd.setValue("0");\r
863 }\r
864 if (dataType.equals("BOOLEAN")){\r
865 fpdPcd.setValue("false");\r
866 }\r
867 if (dataType.equals("VOID*")) {\r
868 fpdPcd.setValue("");\r
869 }\r
870 }\r
871 if (dataType.equals("UINT8")){\r
872 fpdPcd.setMaxDatumSize(1);\r
873 }\r
874 if (dataType.equals("UINT16")) {\r
875 fpdPcd.setMaxDatumSize(2);\r
876 }\r
877 if (dataType.equals("UINT32")) {\r
878 fpdPcd.setMaxDatumSize(4);\r
879 }\r
880 if (dataType.equals("UINT64")){\r
881 fpdPcd.setMaxDatumSize(8);\r
882 }\r
883 if (dataType.equals("BOOLEAN")){\r
884 fpdPcd.setMaxDatumSize(1);\r
885 }\r
886 if (dataType.equals("VOID*")) {\r
887 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());\r
888 fpdPcd.setMaxDatumSize(maxSize);\r
889 }\r
890 }\r
891 }\r
892 \r
908b1c05 893 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{\r
a13899c5 894 if (datum == null) {\r
895 return 0;\r
896 }\r
897 char ch = datum.charAt(0);\r
898 int start, end;\r
899 String strValue;\r
900 //\r
901 // For void* type PCD, only three datum is support:\r
902 // 1) Unicode: string with start char is "L"\r
903 // 2) Ansci: String is ""\r
904 // 3) byte array: String start char "{"\r
905 // \r
906 if (ch == 'L') {\r
907 start = datum.indexOf('\"');\r
908 end = datum.lastIndexOf('\"');\r
909 if ((start > end) || \r
910 (end > datum.length())||\r
911 ((start == end) && (datum.length() > 0))) {\r
912 //ToDo Error handling here\r
82961247 913 throw new PcdValueMalFormed (datum);\r
a13899c5 914 }\r
915\r
916 strValue = datum.substring(start + 1, end);\r
917 return strValue.length() * 2;\r
918 } else if (ch == '\"'){\r
919 start = datum.indexOf('\"');\r
920 end = datum.lastIndexOf('\"');\r
921 if ((start > end) || \r
922 (end > datum.length())||\r
923 ((start == end) && (datum.length() > 0))) {\r
82961247 924 throw new PcdValueMalFormed (datum);\r
a13899c5 925 }\r
926 strValue = datum.substring(start + 1, end);\r
927 return strValue.length();\r
928 } else if (ch =='{') {\r
929 String[] strValueArray;\r
930\r
931 start = datum.indexOf('{');\r
932 end = datum.lastIndexOf('}');\r
933 strValue = datum.substring(start + 1, end);\r
934 strValue = strValue.trim();\r
935 if (strValue.length() == 0) {\r
936 return 0;\r
937 }\r
938 strValueArray = strValue.split(",");\r
939 for (int index = 0; index < strValueArray.length; index ++) {\r
940 Integer value = Integer.decode(strValueArray[index].trim());\r
941 \r
942 if (value > 0xFF) {\r
943// "[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
944// "it is byte array in fact. But the element of %s exceed the byte range",\r
82961247 945 throw new PcdValueMalFormed (datum); \r
a13899c5 946 }\r
947 }\r
948 return strValueArray.length;\r
949\r
950\r
951 } else {\r
952// "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
953// "1) UNICODE string: like L\"xxxx\";\r\n"+\r
954// "2) ANSIC string: like \"xxx\";\r\n"+\r
955// "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
956// "but the datum in seems does not following above format!",\r
82961247 957 throw new PcdValueMalFormed (datum);\r
a13899c5 958 \r
959 }\r
960 }\r
961 \r
962 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {\r
963 ArrayList<String> al = dynPcdMap.get(dynPcdKey);\r
964 \r
965 return al;\r
966 }\r
967 \r
968 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {\r
969 \r
970 return dynPcdMap.get("pcdKey");\r
971 }\r
972 \r
973 public int getDynamicPcdBuildDataCount() {\r
974 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r
975 return 0;\r
976 }\r
977 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();\r
978 }\r
979 \r
980 public void getDynamicPcdBuildData(String[][] saa) {\r
981 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r
982 return ;\r
983 }\r
984 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();\r
985 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();\r
986 int i = 0;\r
987 while(li.hasNext()) {\r
988 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();\r
989 saa[i][0] = dynPcd.getCName();\r
990 saa[i][1] = dynPcd.getToken().toString();\r
991 saa[i][2] = dynPcd.getTokenSpaceGuidCName();\r
992 saa[i][3] = dynPcd.getMaxDatumSize()+"";\r
993 saa[i][4] = dynPcd.getDatumType().toString();\r
994 \r
995 ++i;\r
996 }\r
997 }\r
998 \r
908b1c05 999 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) \r
82961247 1000 throws PcdValueMalFormed{\r
a13899c5 1001 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();\r
1002 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
1003 dynPcdData.setCName(cName);\r
1004 dynPcdData.setToken(token);\r
1005 dynPcdData.setTokenSpaceGuidCName(tsGuid);\r
1006 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
1007 \r
1008 BigInteger bigInt = new BigInteger("0");\r
1009 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();\r
1010 skuInfo.setSkuId(bigInt);\r
1011 if (defaultVal != null){\r
1012 skuInfo.setValue(defaultVal);\r
1013 }\r
1014 else {\r
1015 if (dataType.equals("UINT8")){\r
1016 skuInfo.setValue("0");\r
1017 }\r
1018 if (dataType.equals("UINT16")) {\r
1019 skuInfo.setValue("0");\r
1020 }\r
1021 if (dataType.equals("UINT32")) {\r
1022 skuInfo.setValue("0");\r
1023 }\r
1024 if (dataType.equals("UINT64")){\r
1025 skuInfo.setValue("0");\r
1026 }\r
1027 if (dataType.equals("BOOLEAN")){\r
1028 skuInfo.setValue("false");\r
1029 }\r
1030 if (dataType.equals("VOID*")) {\r
1031 skuInfo.setValue("");\r
1032 }\r
1033 }\r
1034 if (dataType.equals("UINT8")){\r
1035 dynPcdData.setMaxDatumSize(1);\r
1036 }\r
1037 if (dataType.equals("UINT16")) {\r
1038 dynPcdData.setMaxDatumSize(2);\r
1039 }\r
1040 if (dataType.equals("UINT32")) {\r
1041 dynPcdData.setMaxDatumSize(4);\r
1042 }\r
1043 if (dataType.equals("UINT64")){\r
1044 dynPcdData.setMaxDatumSize(8);\r
1045 }\r
1046 if (dataType.equals("BOOLEAN")){\r
1047 dynPcdData.setMaxDatumSize(1);\r
1048 }\r
1049 if (dataType.equals("VOID*")) {\r
1050 int maxSize = setMaxSizeForPointer(defaultVal);\r
1051 dynPcdData.setMaxDatumSize(maxSize);\r
1052 }\r
1053 }\r
1054 \r
908b1c05 1055 public void removeDynamicPcdBuildData(String cName, String tsGuid) {\r
a13899c5 1056 XmlObject o = getfpdDynPcdBuildDefs();\r
1057 \r
1058 XmlCursor cursor = o.newCursor();\r
1059 if (cursor.toFirstChild()) {\r
af25df16 1060 do {\r
1061 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = \r
1062 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
908b1c05 1063 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
1064 cursor.removeXml();\r
af25df16 1065 if (getDynamicPcdBuildDataCount() == 0) {\r
1066 cursor.toParent();\r
1067 cursor.removeXml();\r
1068 }\r
908b1c05 1069 cursor.dispose();\r
1070 return;\r
1071 }\r
a13899c5 1072 }\r
af25df16 1073 while (cursor.toNextSibling());\r
a13899c5 1074 }\r
1075 cursor.dispose();\r
1076 }\r
1077 //\r
1078 // Get the Sku Info count of ith dyn pcd element.\r
1079 //\r
1080 public int getDynamicPcdSkuInfoCount(int i){\r
1081 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1082 return 0;\r
1083 }\r
1084 \r
1085 int skuInfoCount = 0;\r
1086 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1087 if (cursor.toFirstChild()) {\r
1088 for (int j = 0; j < i; ++j) {\r
1089 cursor.toNextSibling();\r
1090 }\r
1091 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1092 if (pcdData.getSkuInfoList() == null) {\r
1093 skuInfoCount = 0;\r
1094 }\r
1095 else {\r
1096 skuInfoCount = pcdData.getSkuInfoList().size();\r
1097 }\r
1098 }\r
1099 cursor.dispose();\r
1100 return skuInfoCount;\r
1101 }\r
1102 \r
1103 public void getDynamicPcdSkuInfos(int i, String[][] saa){\r
1104 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1105 return;\r
1106 }\r
1107 \r
1108 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1109 if (cursor.toFirstChild()) {\r
1110 for (int j = 0; j < i; ++j) {\r
1111 cursor.toNextSibling();\r
1112 }\r
1113 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1114 if (pcdData.getSkuInfoList() == null) {\r
1115 cursor.dispose();\r
1116 return;\r
1117 }\r
1118 else {\r
1119 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r
1120 int k = 0;\r
1121 while (li.hasNext()) {\r
1122 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r
1123 saa[k][0] = skuInfo.getSkuId()+"";\r
1124 saa[k][1] = skuInfo.getVariableName();\r
1125 saa[k][2] = skuInfo.getVariableGuid();\r
1126 saa[k][3] = skuInfo.getVariableOffset();\r
1127 saa[k][4] = skuInfo.getHiiDefaultValue();\r
1128 saa[k][5] = skuInfo.getVpdOffset();\r
1129 saa[k][6] = skuInfo.getValue();\r
1130 ++k;\r
1131 }\r
1132 \r
1133 }\r
1134 }\r
1135 cursor.dispose();\r
1136 \r
1137 }\r
1138 \r
1139 public String getDynamicPcdBuildDataValue(int i){\r
1140 String value = null;\r
1141 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1142 return value;\r
1143 }\r
1144 \r
1145 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1146 if (cursor.toFirstChild()) {\r
1147 for (int j = 0; j < i; ++j) {\r
1148 cursor.toNextSibling();\r
1149 }\r
1150 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1151 if (pcdData.getSkuInfoList() == null) {\r
1152 value = null;\r
1153 }\r
1154 else {\r
1155 value = pcdData.getSkuInfoArray(0).getValue();\r
1156 }\r
1157 }\r
1158 cursor.dispose();\r
1159 return value;\r
1160 }\r
1161 \r
1162 public String getDynamicPcdBuildDataVpdOffset(int i){\r
1163 String vpdOffset = null;\r
1164 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1165 return vpdOffset;\r
1166 }\r
1167 \r
1168 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1169 if (cursor.toFirstChild()) {\r
1170 for (int j = 0; j < i; ++j) {\r
1171 cursor.toNextSibling();\r
1172 }\r
1173 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1174 if (pcdData.getSkuInfoList() == null) {\r
1175 vpdOffset = null;\r
1176 }\r
1177 else {\r
1178 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();\r
1179 }\r
1180 }\r
1181 cursor.dispose();\r
1182 return vpdOffset;\r
1183 }\r
1184 \r
1185 public void removeDynamicPcdBuildDataSkuInfo(int i) {\r
1186 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1187 return;\r
1188 }\r
1189 \r
1190 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1191 if (cursor.toFirstChild()) {\r
1192 for (int j = 0; j < i; ++j) {\r
1193 cursor.toNextSibling();\r
1194 }\r
1195 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1196 if (pcdData.getSkuInfoList() == null) {\r
1197 cursor.dispose();\r
1198 return;\r
1199 }\r
1200 else {\r
1201 QName qSkuInfo = new QName(xmlNs, "SkuInfo");\r
1202 cursor.toChild(qSkuInfo);\r
1203 cursor.removeXml();\r
1204 }\r
1205 }\r
1206 cursor.dispose();\r
1207 }\r
1208 //\r
1209 // generate sku info for ith dyn pcd build data.\r
1210 //\r
1211 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
1212 String hiiDefault, String vpdOffset, String value, int i) {\r
1213 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1214 return;\r
1215 }\r
1216 \r
1217 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1218 if (cursor.toFirstChild()) {\r
1219 for (int j = 0; j < i; ++j) {\r
1220 cursor.toNextSibling();\r
1221 }\r
1222 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1223 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();\r
1224 skuInfo.setSkuId(new BigInteger(id));\r
1225 if (varName != null){\r
1226 skuInfo.setVariableName(varName);\r
1227 skuInfo.setVariableGuid(varGuid);\r
1228 skuInfo.setVariableOffset(varOffset);\r
1229 skuInfo.setHiiDefaultValue(hiiDefault);\r
1230 }\r
1231 else if (vpdOffset != null){\r
1232 skuInfo.setVpdOffset(vpdOffset);\r
1233 }\r
1234 else{\r
1235 skuInfo.setValue(value);\r
1236 }\r
1237 }\r
1238 }\r
1239 \r
1240 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
1241 String hiiDefault, String vpdOffset, String value, int i){\r
1242 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1243 return;\r
1244 }\r
1245 \r
1246 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1247 if (cursor.toFirstChild()) {\r
1248 for (int j = 0; j < i; ++j) {\r
1249 cursor.toNextSibling();\r
1250 }\r
1251 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1252 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r
1253 while (li.hasNext()) {\r
1254 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r
1255 if (skuInfo.getSkuId().toString().equals(id)){\r
1256 if (varName != null){\r
1257 skuInfo.setVariableName(varName);\r
1258 skuInfo.setVariableGuid(varGuid);\r
1259 skuInfo.setVariableOffset(varOffset);\r
1260 skuInfo.setHiiDefaultValue(hiiDefault);\r
1261 }\r
1262 else if (vpdOffset != null){\r
1263 skuInfo.setVpdOffset(vpdOffset);\r
1264 }\r
1265 else{\r
1266 skuInfo.setValue(value);\r
1267 }\r
1268 break;\r
1269 }\r
1270 }\r
1271 }\r
1272 }\r
1273 \r
a13899c5 1274 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {\r
1275 if (fpdBuildOpts == null) {\r
1276 fpdBuildOpts = fpdRoot.addNewBuildOptions();\r
1277 }\r
1278 return fpdBuildOpts;\r
1279 }\r
1280 \r
1281 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {\r
1282 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1283 if (udats == null) {\r
1284 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();\r
1285 }\r
1286 \r
1287 AntTaskDocument.AntTask at = udats.addNewAntTask();\r
1288 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r
1289 }\r
1290 \r
1291 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {\r
1292 at.setId(new Integer(id));\r
bf5abaff 1293 XmlCursor cursor = at.newCursor();\r
a13899c5 1294 if (fileName != null){\r
1295 at.setFilename(fileName);\r
1296 }\r
bf5abaff 1297 else if (cursor.toChild(xmlNs, "Filename")) {\r
1298 cursor.removeXml();\r
1299 }\r
202c4f38 1300 if (execOrder != null) {\r
a13899c5 1301 at.setAntCmdOptions(execOrder);\r
1302 }\r
bf5abaff 1303 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {\r
1304 cursor.removeXml();\r
1305 }\r
1306 cursor.dispose();\r
a13899c5 1307 }\r
1308 \r
1309 public void removeBuildOptionsUserDefAntTask(int i) {\r
1310 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r
1311 if (o == null) {\r
1312 return;\r
1313 }\r
1314 XmlCursor cursor = o.newCursor();\r
1315 if (cursor.toFirstChild()) {\r
1316 for (int j = 0; j < i; ++j) {\r
1317 cursor.toNextSibling();\r
1318 }\r
1319 cursor.removeXml();\r
af25df16 1320 if (getBuildOptionsUserDefAntTaskCount() == 0) {\r
1321 cursor.toParent();\r
1322 cursor.removeXml();\r
1323 }\r
a13899c5 1324 }\r
1325 cursor.dispose();\r
1326 }\r
1327 \r
1328 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){\r
1329 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r
1330 if (o == null) {\r
1331 return;\r
1332 }\r
1333 XmlCursor cursor = o.newCursor();\r
1334 if (cursor.toFirstChild()) {\r
1335 for (int j = 0; j < i; ++j) {\r
1336 cursor.toNextSibling();\r
1337 }\r
1338 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();\r
1339 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r
1340 }\r
1341 cursor.dispose();\r
1342 }\r
1343 \r
1344 public int getBuildOptionsUserDefAntTaskCount() {\r
1345 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1346 if (udats == null || udats.getAntTaskList() == null) {\r
1347 return 0;\r
1348 }\r
1349 \r
1350 return udats.getAntTaskList().size();\r
1351 }\r
1352 \r
1353 public void getBuildOptionsUserDefAntTasks(String[][] saa) {\r
1354 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1355 if (udats == null || udats.getAntTaskList() == null) {\r
1356 return ;\r
1357 }\r
1358 \r
1359 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();\r
1360 ListIterator li = l.listIterator();\r
1361 int i = 0;\r
1362 while (li.hasNext()) {\r
1363 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();\r
1364 saa[i][0] = at.getId() + "";\r
1365 saa[i][1] = saa[i][2] = "";\r
1366 if (at.getFilename() != null){\r
1367 saa[i][1] = at.getFilename();\r
1368 }\r
1369 if (at.getAntCmdOptions() != null) {\r
1370 saa[i][2] = at.getAntCmdOptions();\r
1371 }\r
1372 ++i;\r
1373 }\r
1374 }\r
1800d80f 1375 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {\r
a13899c5 1376 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();\r
1377 if (opts == null) {\r
1378 opts = getfpdBuildOpts().addNewOptions();\r
1379 }\r
1380 OptionDocument.Option opt = opts.addNewOption();\r
1381 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
1382 }\r
1383 \r
1800d80f 1384 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){\r
a13899c5 1385 opt.setStringValue(contents);\r
1800d80f 1386 \r
1387 opt.setBuildTargets(buildTargets);\r
a13899c5 1388 opt.setToolChainFamily(toolChain);\r
1389 opt.setTagName(tagName);\r
1390 opt.setToolCode(toolCmd);\r
1800d80f 1391 \r
bf5abaff 1392 if (archList != null) {\r
1393 opt.setSupArchList(archList);\r
1394 }\r
1395 else {\r
1396 if (opt.isSetSupArchList()) {\r
1397 opt.unsetSupArchList();\r
1398 }\r
1399 }\r
a13899c5 1400 }\r
1401 \r
1402 public void removeBuildOptionsOpt(int i){\r
1403 \r
1404 XmlObject o = getfpdBuildOpts().getOptions();\r
1405 if (o == null) {\r
1406 return;\r
1407 }\r
1408 \r
1409 XmlCursor cursor = o.newCursor();\r
1410 if (cursor.toFirstChild()) {\r
1411 for (int j = 0; j < i; ++j) {\r
1412 cursor.toNextSibling();\r
1413 }\r
1414 cursor.removeXml();\r
af25df16 1415 if (getBuildOptionsOptCount() == 0) {\r
1416 cursor.toParent();\r
1417 cursor.removeXml();\r
1418 }\r
a13899c5 1419 }\r
1420 cursor.dispose();\r
1421 }\r
1422 \r
1800d80f 1423 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {\r
a13899c5 1424 XmlObject o = getfpdBuildOpts().getOptions();\r
1425 if (o == null) {\r
1426 return;\r
1427 }\r
1428 \r
1429 XmlCursor cursor = o.newCursor();\r
1430 if (cursor.toFirstChild()) {\r
1431 for (int j = 0; j < i; ++j) {\r
1432 cursor.toNextSibling();\r
1433 }\r
1434 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();\r
1435 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
1436 }\r
1437 cursor.dispose();\r
1438 }\r
1439 \r
1440 public int getBuildOptionsOptCount(){\r
1441 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r
1442 return 0;\r
1443 }\r
1444 return getfpdBuildOpts().getOptions().getOptionList().size();\r
1445 }\r
1446 \r
1447 public void getBuildOptionsOpts(String[][] saa) {\r
1448 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r
1449 return ;\r
1450 }\r
1451 \r
1452 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();\r
1453 ListIterator li = lOpt.listIterator();\r
1454 int i = 0;\r
1455 while(li.hasNext()) {\r
1456 OptionDocument.Option opt = (OptionDocument.Option)li.next();\r
6cba26e8 1457 if (opt.getBuildTargets() != null) {\r
1458 saa[i][0] = listToString(opt.getBuildTargets());\r
1459 }\r
a13899c5 1460 saa[i][1] = opt.getToolChainFamily();\r
1461 if (opt.getSupArchList() != null){\r
6cba26e8 1462 saa[i][2] = listToString(opt.getSupArchList());\r
1463\r
a13899c5 1464 }\r
1465 saa[i][3] = opt.getToolCode();\r
1466 saa[i][4] = opt.getTagName();\r
1467 saa[i][5] = opt.getStringValue();\r
1468 \r
1469 ++i;\r
1470 }\r
1471 }\r
1472 \r
6cba26e8 1473 public void genBuildOptionsFfs(String ffsKey, String type) {\r
1474 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();\r
1475 ffs.setFfsKey(ffsKey);\r
1476 if (type != null) {\r
1477 ffs.addNewSections().setEncapsulationType(type);\r
1478 }\r
1479 }\r
1480 \r
3b405e9b 1481 public void updateBuildOptionsFfsSectionsType(int i, String type) {\r
1482 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();\r
1483 if (type != null) {\r
1484 ffs.addNewSections().setEncapsulationType(type);\r
1485 }\r
1486 }\r
1487 \r
6cba26e8 1488 public void genBuildOptionsFfsAttribute(int i, String name, String value) {\r
1489 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1490 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();\r
1491 attrib.setName(name);\r
1492 attrib.setValue(value);\r
1493 }\r
1494 \r
1495 /**update jth attribute of ith ffs.\r
1496 * @param i\r
1497 * @param j\r
1498 */\r
1499 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){\r
1500 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1501 XmlCursor cursor = ffs.newCursor();\r
1502 QName qAttrib = new QName(xmlNs, "Attribute");\r
1503 if (cursor.toChild(qAttrib)) {\r
1504 for (int k = 0; k < j; ++k) {\r
1505 cursor.toNextSibling(qAttrib);\r
1506 }\r
1507 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();\r
1508 attrib.setName(name);\r
1509 attrib.setValue(value);\r
1510 }\r
1511 cursor.dispose();\r
1512 }\r
1513 \r
1514 public void removeBuildOptionsFfsAttribute(int i, int j){\r
1515 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1516 XmlCursor cursor = ffs.newCursor();\r
1517 QName qAttrib = new QName(xmlNs, "Attribute");\r
1518 if (cursor.toChild(qAttrib)) {\r
1519 for (int k = 0; k < j; ++k) {\r
1520 cursor.toNextSibling(qAttrib);\r
1521 }\r
1522 cursor.removeXml();\r
1523 }\r
1524 cursor.dispose();\r
1525 }\r
1526 \r
1527 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {\r
1528 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1529 if (ffs == null) {\r
1530 return;\r
1531 }\r
1532 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1533 \r
1534 if (sections == null){\r
1535 sections = ffs.addNewSections();\r
1536 }\r
1537 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));\r
1538 }\r
1539 \r
3b405e9b 1540 public void removeBuildOptionsFfsSectionsSection(int i, int j) {\r
1541 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1542 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1543 if (sections == null) {\r
1544 return;\r
1545 }\r
1546 XmlCursor cursor = sections.newCursor();\r
1547 QName qSection = new QName(xmlNs, "Section");\r
1548 if (cursor.toChild(qSection)) {\r
1549 for (int k = 0; k < j; ++k) {\r
1550 cursor.toNextSibling(qSection);\r
1551 }\r
1552 cursor.removeXml();\r
1553 }\r
1554 cursor.dispose();\r
1555 }\r
1556 \r
1557 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){\r
1558 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1559 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1560 if (sections == null) {\r
1561 return;\r
1562 }\r
1563 XmlCursor cursor = sections.newCursor();\r
1564 QName qSection = new QName(xmlNs, "Section");\r
1565 if (cursor.toChild(qSection)) {\r
1566 for (int k = 0; k < j; ++k) {\r
1567 cursor.toNextSibling(qSection);\r
1568 }\r
1569 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();\r
1570 section.setSectionType(EfiSectionType.Enum.forString(type));\r
1571 }\r
1572 cursor.dispose();\r
1573 } \r
1574 \r
6cba26e8 1575 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {\r
1576 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1577 if (ffs == null) {\r
1578 return;\r
1579 }\r
1580 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1581 \r
1582 if (sections == null){\r
1583 sections = ffs.addNewSections();\r
1584 }\r
1585 sections.addNewSections().setEncapsulationType(encapType);\r
1586 }\r
1587 \r
3b405e9b 1588 public void removeBuildOptionsFfsSectionsSections(int i, int j) {\r
1589 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1590 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1591 if (sections == null) {\r
1592 return;\r
1593 }\r
1594 XmlCursor cursor = sections.newCursor();\r
1595 QName qSections = new QName(xmlNs, "Sections");\r
1596 if (cursor.toChild(qSections)) {\r
1597 for (int k = 0; k < j; ++k) {\r
1598 cursor.toNextSibling(qSections);\r
1599 }\r
1600 cursor.removeXml();\r
1601 }\r
1602 cursor.dispose();\r
1603 }\r
1604 \r
1605 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {\r
1606 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1607 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1608 if (sections == null) {\r
1609 return;\r
1610 }\r
1611 XmlCursor cursor = sections.newCursor();\r
1612 QName qSections = new QName(xmlNs, "Sections");\r
1613 if (cursor.toChild(qSections)) {\r
1614 for (int k = 0; k < j; ++k) {\r
1615 cursor.toNextSibling(qSections);\r
1616 }\r
1617 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r
1618 sections2.setEncapsulationType(type);\r
1619 }\r
1620 cursor.dispose();\r
1621 }\r
1622 \r
6cba26e8 1623 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {\r
1624 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1625 if (ffs == null) {\r
1626 return;\r
1627 }\r
1628 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1629 XmlCursor cursor = sections.newCursor();\r
1630 QName qSections = new QName(xmlNs, "Sections");\r
1631 if (cursor.toChild(qSections)){\r
1632 for (int k = 0; k < j; ++k) {\r
1633 cursor.toNextSibling(qSections);\r
1634 }\r
1635 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r
1636 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));\r
1637 }\r
1638 cursor.dispose();\r
1639 }\r
1640 \r
3b405e9b 1641 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {\r
1642 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1643 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1644 if (sections == null) {\r
1645 return;\r
1646 }\r
1647 XmlCursor cursor = sections.newCursor();\r
1648 QName qSections = new QName(xmlNs, "Sections");\r
1649 if (cursor.toChild(qSections)) {\r
1650 for (int l = 0; l < j; ++l) {\r
1651 cursor.toNextSibling(qSections);\r
1652 }\r
1653 if (cursor.toFirstChild()) {\r
af25df16 1654 int m = 0;\r
1655 for (; m < k; ++m) {\r
3b405e9b 1656 cursor.toNextSibling();\r
1657 }\r
1658 cursor.removeXml();\r
af25df16 1659 if (m == 0) {\r
1660 cursor.toParent();\r
1661 cursor.removeXml();\r
1662 }\r
3b405e9b 1663 }\r
1664 }\r
1665 cursor.dispose();\r
1666 }\r
1667 \r
1668 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {\r
1669 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1670 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1671 if (sections == null) {\r
1672 return;\r
1673 }\r
1674 XmlCursor cursor = sections.newCursor();\r
1675 QName qSections = new QName(xmlNs, "Sections");\r
1676 if (cursor.toChild(qSections)) {\r
1677 for (int l = 0; l < j; ++l) {\r
1678 cursor.toNextSibling(qSections);\r
1679 }\r
1680 if (cursor.toFirstChild()) {\r
1681 for (int m = 0; m < k; ++m) {\r
1682 cursor.toNextSibling();\r
1683 }\r
1684 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();\r
1685 section.setSectionType(EfiSectionType.Enum.forString(type));\r
1686 }\r
1687 }\r
1688 cursor.dispose();\r
1689 }\r
1690 \r
6cba26e8 1691 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {\r
1692 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1693 if (ffs == null) {\r
1694 return;\r
1695 }\r
1696 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1697 XmlCursor cursor = sections.newCursor();\r
1698 QName qSections = new QName(xmlNs, "Sections");\r
1699 if (cursor.toChild(qSections)){\r
1700 for (int k = 0; k < j; ++k) {\r
1701 cursor.toNextSibling(qSections);\r
1702 }\r
1703 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r
1704 if (sections2.getSectionList() == null){\r
1705 cursor.dispose();\r
1706 return;\r
1707 }\r
1708 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();\r
1709 while(li.hasNext()) {\r
1710 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();\r
3b405e9b 1711 if (section.isSetSectionType()) {\r
1800d80f 1712 al.add(section.getSectionType().toString());\r
1713 }\r
3b405e9b 1714 \r
1715 }\r
6cba26e8 1716 }\r
1717 cursor.dispose();\r
1718 \r
1719 }\r
1720 \r
1721 public int getBuildOptionsFfsCount(){\r
1722 if (getfpdBuildOpts().getFfsList() == null) {\r
1723 return 0;\r
1724 }\r
1725 return getfpdBuildOpts().getFfsList().size();\r
1726 }\r
1727 \r
1728 public void getBuildOptionsFfsKey(String[][] saa) {\r
1729 if (getfpdBuildOpts().getFfsList() == null) {\r
1730 return;\r
1731 }\r
1732 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();\r
1733 int i = 0;\r
1734 while(li.hasNext()){\r
1735 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();\r
1736 saa[i][0] = ffs.getFfsKey();\r
1737 ++i;\r
1738 }\r
1739 }\r
1740 \r
3b405e9b 1741 public void updateBuildOptionsFfsKey(int i, String key) {\r
1742 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1743 ffs.setFfsKey(key);\r
1744 }\r
1745 \r
6cba26e8 1746 /**Get ith FFS key and contents.\r
1747 * @param saa\r
1748 */\r
1749 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {\r
1750 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1751 \r
1752 if (ffs != null) {\r
1753 \r
1754 sa[0] = ffs.getFfsKey();\r
1755 if (ffs.getSections() != null) {\r
1756 if(ffs.getSections().getEncapsulationType() != null){\r
1757 sa[1] = ffs.getSections().getEncapsulationType();\r
1758 }\r
1759 if (ffs.getSections().getSectionList() != null){\r
1760 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();\r
1761 while (li.hasNext()) {\r
1762 firstLevelSection.add(li.next().getSectionType().toString());\r
1763 }\r
1764 }\r
1765 if (ffs.getSections().getSectionsList() != null) {\r
1766 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();\r
1767 while(li.hasNext()) {\r
1768 firstLevelSections.add(li.next().getEncapsulationType());\r
1769 }\r
1770 }\r
1771 }\r
1772 if (ffs.getAttributeList() != null) {\r
1773 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();\r
1774 while(li.hasNext()) {\r
1775 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();\r
1776 ffsAttribMap.put(attrib.getName(), attrib.getValue());\r
1777 }\r
1778 \r
1779 }\r
1780 }\r
1781\r
1782 \r
1783 }\r
1784 \r
1785 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {\r
1786 XmlObject o = getfpdBuildOpts();\r
1787 BuildOptionsDocument.BuildOptions.Ffs ffs = null;\r
1788 \r
1789 XmlCursor cursor = o.newCursor();\r
1790 QName qFfs = new QName(xmlNs, "Ffs");\r
1791 if (cursor.toChild(qFfs)) {\r
1792 for (int j = 0; j < i; ++j) {\r
1793 cursor.toNextSibling(qFfs);\r
1794 }\r
1795 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();\r
1796 }\r
1797 cursor.dispose();\r
1798 return ffs;\r
1799 }\r
1800 \r
1801 public void removeBuildOptionsFfs(int i) {\r
1802 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1803 if (ffs == null){\r
1804 return;\r
1805 }\r
1806 \r
1807 XmlCursor cursor = ffs.newCursor();\r
1808 cursor.removeXml();\r
1809 cursor.dispose();\r
1810 }\r
1811 \r
3b405e9b 1812 \r
1813 \r
a13899c5 1814 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){\r
1815 if (fpdPlatformDefs == null){\r
1816 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();\r
1817 }\r
1818 return fpdPlatformDefs;\r
1819 }\r
1820 \r
6a09eb19 1821 public void getPlatformDefsSupportedArchs(Vector<Object> archs){\r
1822 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {\r
1823 return;\r
1824 }\r
1825 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();\r
1826 while(li.hasNext()) {\r
1827 archs.add(li.next());\r
1828 }\r
1829 }\r
1830 \r
1831 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {\r
bf5abaff 1832 if (archs != null) {\r
1833 getfpdPlatformDefs().setSupportedArchitectures(archs);\r
1834 }\r
1835// else {\r
1836// XmlCursor cursor = getfpdPlatformDefs().newCursor();\r
1837// if (cursor.toChild(xmlNs, "SupportedArchitectures")) {\r
1838// cursor.removeXml();\r
1839// }\r
1840// cursor.dispose();\r
1841// }\r
6a09eb19 1842 }\r
1843 \r
1844 public void getPlatformDefsBuildTargets(Vector<Object> targets) {\r
1845 if (getfpdPlatformDefs().getBuildTargets() == null) {\r
1846 return;\r
1847 }\r
1848 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();\r
1849 while(li.hasNext()) {\r
1850 targets.add(li.next());\r
1851 }\r
1852 }\r
1853 \r
1854 public void setPlatformDefsBuildTargets(Vector<Object> targets) {\r
1855 getfpdPlatformDefs().setBuildTargets(targets);\r
1856 }\r
1857 \r
1858 public void genPlatformDefsSkuInfo(String id, String name) {\r
1859 SkuInfoDocument.SkuInfo skuInfo = null;\r
1860 if (getfpdPlatformDefs().getSkuInfo() == null) {\r
1861 skuInfo = getfpdPlatformDefs().addNewSkuInfo();\r
1862 }\r
1863 skuInfo = getfpdPlatformDefs().getSkuInfo();\r
1864 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {\r
1865 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r
1866 skuName.setSkuID(new BigInteger("0"));\r
1867 skuName.setStringValue("DEFAULT");\r
1868 }\r
1869 if (id.equals("0")) {\r
1870 return;\r
1871 }\r
1872 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r
1873 skuName.setSkuID(new BigInteger(id));\r
1874 skuName.setStringValue(name);\r
1875 }\r
1876 \r
1877 public int getPlatformDefsSkuInfoCount(){\r
1878 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r
1879 return 0;\r
1880 }\r
1881 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();\r
1882 }\r
1883 \r
1884 public void getPlatformDefsSkuInfos(String[][] saa){\r
1885 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r
1886 return ;\r
1887 }\r
1888 \r
1889 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();\r
1890 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();\r
1891 int i = 0;\r
1892 while(li.hasNext()) {\r
1893 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();\r
1894 saa[i][0] = sku.getSkuID()+"";\r
1895 saa[i][1] = sku.getStringValue();\r
1896 ++i;\r
1897 }\r
1898 }\r
1899 \r
1900 public void removePlatformDefsSkuInfo(int i) {\r
1901 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();\r
1902 if (skuInfo == null || i == 0) {\r
1903 return ;\r
1904 }\r
1905 \r
1906 XmlCursor cursor = skuInfo.newCursor();\r
1907 if (cursor.toFirstChild()) {\r
1908 for (int j = 0; j < i; ++j) {\r
1909 cursor.toNextSibling();\r
1910 }\r
1911 cursor.removeXml();\r
1912 }\r
1913 cursor.dispose();\r
1914 }\r
1915 \r
1916 public void updatePlatformDefsSkuInfo(int i, String id, String name) {\r
1917 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();\r
1918 if (skuInfo == null || i == 0) {\r
1919 return ;\r
1920 }\r
1921 \r
1922 XmlCursor cursor = skuInfo.newCursor();\r
1923 if (cursor.toFirstChild()) {\r
1924 for (int j = 0; j < i; ++j) {\r
1925 cursor.toNextSibling();\r
1926 }\r
1927 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();\r
1928 sku.setSkuID(new BigInteger(id));\r
1929 sku.setStringValue(name);\r
1930 }\r
1931 cursor.dispose();\r
1932 }\r
1933 \r
1934 public String getPlatformDefsInterDir(){\r
1935 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {\r
1936 return null;\r
1937 }\r
1938 return getfpdPlatformDefs().getIntermediateDirectories().toString();\r
1939 }\r
1940 \r
1941 public void setPlatformDefsInterDir(String interDir){\r
1942 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));\r
1943 }\r
1944 \r
1945 public String getPlatformDefsOutputDir() {\r
1946 return getfpdPlatformDefs().getOutputDirectory();\r
1947 }\r
1948 \r
1949 public void setPlatformDefsOutputDir(String outputDir) {\r
af25df16 1950 if (outputDir != null && outputDir.length() > 0) {\r
1951 getfpdPlatformDefs().setOutputDirectory(outputDir);\r
1952 }\r
1953 else{\r
1954 XmlCursor cursor = getfpdPlatformDefs().newCursor();\r
1955 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {\r
1956 cursor.removeXml();\r
1957 }\r
1958 cursor.dispose();\r
1959 }\r
6a09eb19 1960 }\r
1961 \r
a13899c5 1962 public FlashDocument.Flash getfpdFlash() {\r
1963 if (fpdFlash == null) {\r
1964 fpdFlash = fpdRoot.addNewFlash();\r
1965 }\r
1966 return fpdFlash;\r
1967 }\r
1968 \r
1969 public void genFlashDefinitionFile(String file) {\r
1970 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r
1971 if (fdf == null) {\r
1972 fdf = getfpdFlash().addNewFlashDefinitionFile();\r
1973 }\r
1974 \r
1975 fdf.setStringValue(file);\r
1976 }\r
1977 \r
1978 public String getFlashDefinitionFile() {\r
1979 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r
1980 if (fdf == null) {\r
1981 return "";\r
1982 }\r
1983 \r
1984 return fdf.getStringValue();\r
1985 }\r
1986 \r
a13899c5 1987 public void genFvImagesNameValue(String name, String value) {\r
1988 \r
1989 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r
1990 if (fi == null) {\r
1991 fi = getfpdFlash().addNewFvImages();\r
1992 }\r
1993 \r
1994 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();\r
1995 nv.setName(name);\r
1996 nv.setValue(value);\r
1997 }\r
1998 \r
1999 public void removeFvImagesNameValue(int i){\r
2000 \r
2001 XmlObject o = getfpdFlash().getFvImages();\r
2002 if (o == null) {\r
2003 return;\r
2004 }\r
2005 \r
2006 QName qNameValue = new QName(xmlNs, "NameValue");\r
2007 XmlCursor cursor = o.newCursor();\r
2008 if (cursor.toChild(qNameValue)) {\r
2009 for (int j = 0; j < i; ++j) {\r
2010 cursor.toNextSibling(qNameValue);\r
2011 }\r
2012 cursor.removeXml();\r
2013 }\r
2014 cursor.dispose();\r
2015 }\r
2016 \r
2017 public void updateFvImagesNameValue(int i, String name, String value){\r
2018 \r
2019 XmlObject o = getfpdFlash().getFvImages();\r
2020 if (o == null) {\r
2021 return;\r
2022 }\r
2023 \r
2024 QName qNameValue = new QName(xmlNs, "NameValue");\r
2025 XmlCursor cursor = o.newCursor();\r
2026 if (cursor.toChild(qNameValue)) {\r
2027 for (int j = 0; j < i; ++j) {\r
2028 cursor.toNextSibling(qNameValue);\r
2029 }\r
2030 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();\r
2031 nv.setName(name);\r
2032 nv.setValue(value);\r
2033 }\r
2034 cursor.dispose();\r
2035 }\r
2036 \r
2037 public int getFvImagesNameValueCount() {\r
2038 \r
2039 FvImagesDocument.FvImages fi = null;\r
2040 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {\r
2041 return 0;\r
2042 }\r
2043 return fi.getNameValueList().size();\r
2044 }\r
2045 \r
2046 public void getFvImagesNameValues(String[][] nv) {\r
2047 \r
2048 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r
2049 if (fi == null){\r
2050 return;\r
2051 }\r
2052 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();\r
2053 int i = 0;\r
2054 ListIterator li = l.listIterator();\r
2055 while (li.hasNext()) {\r
2056 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li\r
2057 .next();\r
2058 nv[i][0] = e.getName();\r
2059 nv[i][1] = e.getValue();\r
2060 \r
2061 i++;\r
2062 }\r
2063 }\r
2064 \r
2065 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r
2066 \r
2067 FvImagesDocument.FvImages fis = null;\r
2068 if ((fis = getfpdFlash().getFvImages()) == null) {\r
2069 fis = getfpdFlash().addNewFvImages();\r
2070 }\r
2071 \r
2072 //\r
2073 //gen FvImage with FvImageNames array\r
2074 //\r
2075 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();\r
2076 for (int i = 0; i < names.length; ++i) {\r
2077 fi.addFvImageNames(names[i]);\r
2078 }\r
2079 fi.setType(FvImageTypes.Enum.forString(types));\r
2080 if (options != null){\r
2081 setFvImagesFvImageFvImageOptions(options, fi);\r
2082 }\r
2083 }\r
2084 \r
2085 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){\r
2086 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();\r
2087 if (fio == null){\r
2088 fio = fi.addNewFvImageOptions();\r
2089 }\r
2090 \r
2091 Set<String> key = options.keySet();\r
2092 Iterator<String> i = key.iterator();\r
2093 while (i.hasNext()) {\r
44053733 2094 \r
a13899c5 2095 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();\r
2096 String k = (String)i.next();\r
ae0d4fd2 2097 \r
a13899c5 2098 nv.setName(k);\r
2099 nv.setValue((String)options.get(k));\r
2100 \r
2101 }\r
2102 \r
2103 }\r
2104 \r
44053733 2105 \r
a13899c5 2106 public void removeFvImagesFvImage(int i) {\r
2107 \r
2108 XmlObject o = getfpdFlash().getFvImages();\r
2109 if (o == null) {\r
2110 return;\r
2111 }\r
2112 \r
2113 QName qFvImage = new QName(xmlNs, "FvImage");\r
2114 XmlCursor cursor = o.newCursor();\r
2115 if (cursor.toChild(qFvImage)) {\r
2116 for (int j = 0; j < i; ++j) {\r
2117 cursor.toNextSibling(qFvImage);\r
2118 }\r
2119 cursor.removeXml();\r
2120 }\r
2121 cursor.dispose();\r
2122 }\r
2123 \r
2124 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r
2125 \r
2126 XmlObject o = getfpdFlash().getFvImages();\r
2127 if (o == null) {\r
2128 return;\r
2129 }\r
2130 XmlCursor cursor = o.newCursor();\r
2131 QName qFvImage = new QName(xmlNs, "FvImage");\r
2132 if (cursor.toChild(qFvImage)) {\r
2133 for (int j = 0; j < i; ++j) {\r
2134 cursor.toNextSibling(qFvImage);\r
2135 }\r
2136 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
2137 fi.setType(FvImageTypes.Enum.forString(types));\r
2138 \r
2139 //\r
2140 // remove old FvImageNames before adding new ones\r
2141 //\r
2142 QName qFvImageNames = new QName(xmlNs, "FvImageNames"); \r
2143 cursor.toChild(qFvImageNames);\r
2144 cursor.removeXml();\r
2145 while (cursor.toNextSibling(qFvImageNames)) {\r
2146 cursor.removeXml();\r
2147 }\r
2148 \r
2149 for (int k = 0; k < names.length; ++k) {\r
2150 fi.addFvImageNames(names[k]);\r
2151 }\r
2152 //\r
2153 // remove old FvImageOptions before adding new options\r
2154 //\r
2155 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");\r
2156 cursor.toNextSibling(qFvImageOptions);\r
2157 cursor.removeXml();\r
2158 \r
2159 setFvImagesFvImageFvImageOptions(options, fi);\r
2160 }\r
2161 cursor.dispose();\r
2162 }\r
2163 \r
2164 public int getFvImagesFvImageCount() {\r
2165 \r
2166 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
2167 return 0;\r
2168 }\r
2169 return getfpdFlash().getFvImages().getFvImageList().size();\r
2170 }\r
2171 \r
ae0d4fd2 2172 /**Only Get Fv image setting - name and type.\r
2173 * @param saa\r
2174 */\r
2175 public void getFvImagesFvImages(String[][] saa) {\r
a13899c5 2176 \r
2177 if (getfpdFlash().getFvImages() == null) {\r
2178 return;\r
2179 }\r
2180 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
2181 if (l == null) {\r
2182 return;\r
2183 }\r
2184 ListIterator li = l.listIterator();\r
2185 int i = 0;\r
2186 while(li.hasNext()) {\r
2187 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
2188 //\r
2189 // get FvImageNames array, space separated\r
2190 //\r
2191 List<String> lfn = fi.getFvImageNamesList();\r
2192 ListIterator lfni = lfn.listIterator();\r
2193 saa[i][0] = " ";\r
2194 while (lfni.hasNext()) {\r
2195 saa[i][0] += (String)lfni.next();\r
2196 saa[i][0] += " ";\r
2197 }\r
2198 saa[i][0] = saa[i][0].trim();\r
2199 \r
2200 saa[i][1] = fi.getType()+"";\r
2201 \r
ae0d4fd2 2202 ++i;\r
2203 }\r
2204 }\r
2205 \r
2206 /**Get FvImage Options for FvImage i\r
2207 * @param i the ith FvImage\r
2208 */\r
2209 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {\r
2210 XmlObject o = getfpdFlash().getFvImages();\r
2211 if (o == null) {\r
2212 return;\r
2213 }\r
2214 XmlCursor cursor = o.newCursor();\r
2215 QName qFvImage = new QName(xmlNs, "FvImage");\r
2216 if (cursor.toChild(qFvImage)) {\r
2217 for (int j = 0; j < i; ++j) {\r
2218 cursor.toNextSibling(qFvImage);\r
a13899c5 2219 }\r
ae0d4fd2 2220 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
2221 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){\r
2222 return;\r
a13899c5 2223 }\r
ae0d4fd2 2224 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();\r
2225 while(li.hasNext()){\r
2226 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r
a13899c5 2227 m.put(nv.getName(), nv.getValue());\r
2228 }\r
a13899c5 2229 }\r
2230 }\r
2231 \r
2232 /**\r
2233 Get platform header element\r
2234 @return PlatformHeaderDocument.PlatformHeader\r
2235 **/\r
2236 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {\r
2237 if (fpdHdr == null) {\r
2238 fpdHdr = fpdRoot.addNewPlatformHeader();\r
2239 }\r
2240 genPlatformDefsSkuInfo("0", "DEFAULT");\r
2241 return fpdHdr;\r
2242 }\r
2243 \r
a13899c5 2244 public String getFpdHdrPlatformName() {\r
2245 return getFpdHdr().getPlatformName();\r
2246 }\r
2247 \r
2248 public String getFpdHdrGuidValue() {\r
2249 return getFpdHdr().getGuidValue();\r
2250 }\r
2251 \r
2252 public String getFpdHdrVer() {\r
2253 return getFpdHdr().getVersion();\r
2254 }\r
2255 \r
2256 public String getFpdHdrAbs() {\r
2257 return getFpdHdr().getAbstract();\r
2258 }\r
2259 \r
2260 public String getFpdHdrDescription() {\r
2261 return getFpdHdr().getDescription();\r
2262 }\r
2263 \r
2264 public String getFpdHdrCopyright() {\r
2265 return getFpdHdr().getCopyright();\r
2266 }\r
2267 \r
2268 public String getFpdHdrLicense() {\r
2269 LicenseDocument.License l = getFpdHdr().getLicense();\r
2270 if (l == null) {\r
2271 return null;\r
2272 }\r
2273 return l.getStringValue();\r
2274 }\r
2275 \r
2276 public String getFpdHdrUrl() {\r
2277 LicenseDocument.License l = getFpdHdr().getLicense();\r
2278 if (l == null) {\r
2279 return null;\r
2280 }\r
2281 return l.getURL();\r
2282 }\r
2283 \r
2284 public String getFpdHdrSpec() {\r
2285\r
c06e8657 2286 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
a13899c5 2287// return getFpdHdr().getSpecification();\r
2288 }\r
2289 \r
2290 public void setFpdHdrPlatformName(String name){\r
2291 getFpdHdr().setPlatformName(name);\r
2292 }\r
2293 \r
2294 public void setFpdHdrGuidValue(String guid){\r
2295 getFpdHdr().setGuidValue(guid);\r
2296 }\r
2297 \r
2298 public void setFpdHdrVer(String v){\r
2299 getFpdHdr().setVersion(v);\r
2300 }\r
2301 \r
2302 public void setFpdHdrAbs(String abs) {\r
2303 getFpdHdr().setAbstract(abs);\r
2304 }\r
2305 \r
2306 public void setFpdHdrDescription(String desc){\r
2307 getFpdHdr().setDescription(desc);\r
2308 }\r
2309 \r
2310 public void setFpdHdrCopyright(String cr) {\r
2311 getFpdHdr().setCopyright(cr);\r
2312 }\r
2313 \r
2314 public void setFpdHdrLicense(String license){\r
2315 LicenseDocument.License l = getFpdHdr().getLicense();\r
2316 if (l == null) {\r
2317 getFpdHdr().addNewLicense().setStringValue(license);\r
2318 }\r
2319 else {\r
2320 l.setStringValue(license);\r
2321 }\r
2322 }\r
2323\r
2324 public void setFpdHdrUrl(String url){\r
2325 LicenseDocument.License l = getFpdHdr().getLicense();\r
2326 \r
2327 l.setURL(url);\r
2328 \r
2329 }\r
2330 \r
2331 public void setFpdHdrSpec(String s){\r
c06e8657 2332 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
a13899c5 2333 getFpdHdr().setSpecification(s);\r
2334 }\r
2335 /**\r
2336 Save the processed xml contents to file\r
2337 \r
2338 @param fpdFile The file to save xml contents\r
2339 @throws IOException Exceptions during file operation\r
2340 **/\r
2341 public void saveAs(File fpdFile) throws IOException {\r
2342\r
2343 XmlOptions options = new XmlOptions();\r
2344\r
2345 options.setCharacterEncoding("UTF-8");\r
2346 options.setSavePrettyPrint();\r
2347 options.setSavePrettyPrintIndent(2);\r
2348 try {\r
2349 fpdd.save(fpdFile, options);\r
2350 } catch (IOException e) {\r
2351 e.printStackTrace();\r
2352 }\r
2353\r
2354 }\r
2355 \r
1800d80f 2356 private String listToString(List l) {\r
a13899c5 2357 if (l == null) {\r
2358 return null;\r
2359 }\r
2360 String s = " ";\r
2361 ListIterator li = l.listIterator();\r
2362 while(li.hasNext()) {\r
2363 s += li.next();\r
2364 s += " ";\r
2365 }\r
2366 return s.trim();\r
2367 }\r
2368}\r
82961247 2369\r
2370class PcdItemTypeConflictException extends Exception {\r
2371\r
2372 /**\r
2373 * \r
2374 */\r
2375 private static final long serialVersionUID = 1L;\r
2376 private String details = null;\r
2377 \r
2378 PcdItemTypeConflictException(String info){\r
2379 details = info;\r
2380 }\r
2381 \r
2382 public String getMessage() {\r
2383 return details;\r
2384 }\r
2385}\r
2386\r
2387class PcdDeclNotFound extends Exception {\r
2388\r
2389 /**\r
2390 * \r
2391 */\r
2392 private static final long serialVersionUID = 1L;\r
2393 private String details = null;\r
2394 \r
2395 PcdDeclNotFound(String info) {\r
2396 details = info;\r
2397 }\r
2398 \r
2399 public String getMessage() {\r
2400 return details;\r
2401 }\r
2402}\r
2403\r
2404class PcdValueMalFormed extends Exception {\r
2405\r
2406 /**\r
2407 * \r
2408 */\r
2409 private static final long serialVersionUID = 1L;\r
2410 private String details = null;\r
2411 \r
2412 PcdValueMalFormed(String info) {\r
2413 details = info;\r
2414 }\r
2415 \r
2416 public String getMessage() {\r
2417 return details;\r
2418 }\r
2419}\r