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