]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
e0a0137ef79988474b007c8d2c1525b5aeafa348
[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 if (dataType.equals("UINT8")){
910 fpdPcd.setMaxDatumSize(1);
911 }
912 if (dataType.equals("UINT16")) {
913 fpdPcd.setMaxDatumSize(2);
914 }
915 if (dataType.equals("UINT32")) {
916 fpdPcd.setMaxDatumSize(4);
917 }
918 if (dataType.equals("UINT64")){
919 fpdPcd.setMaxDatumSize(8);
920 }
921 if (dataType.equals("BOOLEAN")){
922 fpdPcd.setMaxDatumSize(1);
923 }
924 if (dataType.equals("VOID*")) {
925 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
926 fpdPcd.setMaxDatumSize(maxSize);
927 }
928
929 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
930 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
931 //
932 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
933 // so need to add one dyn pcd.
934 //
935 if (al.size() == 1) {
936 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
937 }
938 }
939 else {
940 if (defaultVal != null){
941 fpdPcd.setValue(defaultVal);
942 }
943 else {
944 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
945 fpdPcd.setValue("0");
946 }
947 if (dataType.equals("BOOLEAN")){
948 fpdPcd.setValue("false");
949 }
950 if (dataType.equals("VOID*")) {
951 fpdPcd.setValue("");
952 }
953 }
954 /*
955 if (dataType.equals("UINT8")){
956 fpdPcd.setMaxDatumSize(1);
957 }
958 if (dataType.equals("UINT16")) {
959 fpdPcd.setMaxDatumSize(2);
960 }
961 if (dataType.equals("UINT32")) {
962 fpdPcd.setMaxDatumSize(4);
963 }
964 if (dataType.equals("UINT64")){
965 fpdPcd.setMaxDatumSize(8);
966 }
967 if (dataType.equals("BOOLEAN")){
968 fpdPcd.setMaxDatumSize(1);
969 }
970 if (dataType.equals("VOID*")) {
971 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
972 fpdPcd.setMaxDatumSize(maxSize);
973 }
974 */
975 }
976 }
977
978 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
979 if (datum == null) {
980 return 0;
981 }
982 char ch = datum.charAt(0);
983 int start, end;
984 String strValue;
985 //
986 // For void* type PCD, only three datum is support:
987 // 1) Unicode: string with start char is "L"
988 // 2) Ansci: String is ""
989 // 3) byte array: String start char "{"
990 //
991 if (ch == 'L') {
992 start = datum.indexOf('\"');
993 end = datum.lastIndexOf('\"');
994 if ((start > end) ||
995 (end > datum.length())||
996 ((start == end) && (datum.length() > 0))) {
997 //ToDo Error handling here
998 throw new PcdValueMalFormed (datum);
999 }
1000
1001 strValue = datum.substring(start + 1, end);
1002 return strValue.length() * 2;
1003 } else if (ch == '\"'){
1004 start = datum.indexOf('\"');
1005 end = datum.lastIndexOf('\"');
1006 if ((start > end) ||
1007 (end > datum.length())||
1008 ((start == end) && (datum.length() > 0))) {
1009 throw new PcdValueMalFormed (datum);
1010 }
1011 strValue = datum.substring(start + 1, end);
1012 return strValue.length();
1013 } else if (ch =='{') {
1014 String[] strValueArray;
1015
1016 start = datum.indexOf('{');
1017 end = datum.lastIndexOf('}');
1018 strValue = datum.substring(start + 1, end);
1019 strValue = strValue.trim();
1020 if (strValue.length() == 0) {
1021 return 0;
1022 }
1023 strValueArray = strValue.split(",");
1024 for (int index = 0; index < strValueArray.length; index ++) {
1025 Integer value = Integer.decode(strValueArray[index].trim());
1026
1027 if (value > 0xFF) {
1028 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1029 // "it is byte array in fact. But the element of %s exceed the byte range",
1030 throw new PcdValueMalFormed (datum);
1031 }
1032 }
1033 return strValueArray.length;
1034
1035
1036 } else {
1037 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1038 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1039 // "2) ANSIC string: like \"xxx\";\r\n"+
1040 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1041 // "but the datum in seems does not following above format!",
1042 throw new PcdValueMalFormed (datum);
1043
1044 }
1045 }
1046
1047 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1048 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1049
1050 return al;
1051 }
1052
1053 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1054
1055 return dynPcdMap.get(pcdKey);
1056 }
1057
1058 public int getDynamicPcdBuildDataCount() {
1059 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1060 removeElement(getfpdDynPcdBuildDefs());
1061 fpdDynPcdBuildDefs = null;
1062 return 0;
1063 }
1064 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1065 }
1066
1067 public void getDynamicPcdBuildData(String[][] saa) {
1068 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1069 removeElement(getfpdDynPcdBuildDefs());
1070 fpdDynPcdBuildDefs = null;
1071 return ;
1072 }
1073 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1074 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1075 int i = 0;
1076 while(li.hasNext()) {
1077 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1078 saa[i][0] = dynPcd.getCName();
1079 saa[i][1] = dynPcd.getToken().toString();
1080 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1081 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1082 saa[i][4] = dynPcd.getDatumType().toString();
1083
1084 ++i;
1085 }
1086 }
1087
1088 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1089 throws PcdValueMalFormed{
1090 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1091 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1092 dynPcdData.setCName(cName);
1093 dynPcdData.setToken(token);
1094 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1095 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1096
1097 BigInteger bigInt = new BigInteger("0");
1098 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1099 skuInfo.setSkuId(bigInt);
1100 if (defaultVal != null){
1101 skuInfo.setValue(defaultVal);
1102 }
1103 else {
1104 if (dataType.equals("UINT8")){
1105 skuInfo.setValue("0");
1106 }
1107 if (dataType.equals("UINT16")) {
1108 skuInfo.setValue("0");
1109 }
1110 if (dataType.equals("UINT32")) {
1111 skuInfo.setValue("0");
1112 }
1113 if (dataType.equals("UINT64")){
1114 skuInfo.setValue("0");
1115 }
1116 if (dataType.equals("BOOLEAN")){
1117 skuInfo.setValue("false");
1118 }
1119 if (dataType.equals("VOID*")) {
1120 skuInfo.setValue("");
1121 }
1122 }
1123 if (dataType.equals("UINT8")){
1124 dynPcdData.setMaxDatumSize(1);
1125 }
1126 if (dataType.equals("UINT16")) {
1127 dynPcdData.setMaxDatumSize(2);
1128 }
1129 if (dataType.equals("UINT32")) {
1130 dynPcdData.setMaxDatumSize(4);
1131 }
1132 if (dataType.equals("UINT64")){
1133 dynPcdData.setMaxDatumSize(8);
1134 }
1135 if (dataType.equals("BOOLEAN")){
1136 dynPcdData.setMaxDatumSize(1);
1137 }
1138 if (dataType.equals("VOID*")) {
1139 int maxSize = setMaxSizeForPointer(defaultVal);
1140 dynPcdData.setMaxDatumSize(maxSize);
1141 }
1142 }
1143
1144 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1145 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1146 if (o == null) {
1147 return;
1148 }
1149
1150 XmlCursor cursor = o.newCursor();
1151 if (cursor.toFirstChild()) {
1152 do {
1153 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1154 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1155 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1156 cursor.removeXml();
1157 if (getDynamicPcdBuildDataCount() == 0) {
1158 cursor.toParent();
1159 cursor.removeXml();
1160 }
1161 cursor.dispose();
1162 return;
1163 }
1164 }
1165 while (cursor.toNextSibling());
1166 }
1167 cursor.dispose();
1168 }
1169 //
1170 // Get the Sku Info count of ith dyn pcd element.
1171 //
1172 public int getDynamicPcdSkuInfoCount(int i){
1173 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1174 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1175 return 0;
1176 }
1177
1178 int skuInfoCount = 0;
1179 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1180 if (cursor.toFirstChild()) {
1181 for (int j = 0; j < i; ++j) {
1182 cursor.toNextSibling();
1183 }
1184 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1185 if (pcdData.getSkuInfoList() == null) {
1186 skuInfoCount = 0;
1187 }
1188 else {
1189 skuInfoCount = pcdData.getSkuInfoList().size();
1190 }
1191 }
1192 cursor.dispose();
1193 return skuInfoCount;
1194 }
1195
1196 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1197 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1198 removeElement(getfpdDynPcdBuildDefs());
1199 fpdDynPcdBuildDefs = null;
1200 return;
1201 }
1202
1203 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1204 if (cursor.toFirstChild()) {
1205 for (int j = 0; j < i; ++j) {
1206 cursor.toNextSibling();
1207 }
1208 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1209 if (pcdData.getSkuInfoList() == null) {
1210 cursor.dispose();
1211 return;
1212 }
1213 else {
1214 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1215 int k = 0;
1216 while (li.hasNext()) {
1217 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1218 saa[k][0] = skuInfo.getSkuId()+"";
1219 saa[k][1] = skuInfo.getVariableName();
1220 saa[k][2] = skuInfo.getVariableGuid();
1221 saa[k][3] = skuInfo.getVariableOffset();
1222 saa[k][4] = skuInfo.getHiiDefaultValue();
1223 saa[k][5] = skuInfo.getVpdOffset();
1224 saa[k][6] = skuInfo.getValue();
1225 ++k;
1226 }
1227
1228 }
1229 }
1230 cursor.dispose();
1231
1232 }
1233
1234 public String getDynamicPcdBuildDataValue(int i){
1235 String value = null;
1236 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1237 removeElement(getfpdDynPcdBuildDefs());
1238 fpdDynPcdBuildDefs = null;
1239 return value;
1240 }
1241
1242 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1243 if (cursor.toFirstChild()) {
1244 for (int j = 0; j < i; ++j) {
1245 cursor.toNextSibling();
1246 }
1247 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1248 if (pcdData.getSkuInfoList() == null) {
1249 value = null;
1250 }
1251 else {
1252 value = pcdData.getSkuInfoArray(0).getValue();
1253 }
1254 }
1255 cursor.dispose();
1256 return value;
1257 }
1258
1259 public String getDynamicPcdBuildDataVpdOffset(int i){
1260 String vpdOffset = null;
1261 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1262 removeElement(getfpdDynPcdBuildDefs());
1263 fpdDynPcdBuildDefs = null;
1264 return vpdOffset;
1265 }
1266
1267 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1268 if (cursor.toFirstChild()) {
1269 for (int j = 0; j < i; ++j) {
1270 cursor.toNextSibling();
1271 }
1272 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1273 if (pcdData.getSkuInfoList() == null) {
1274 vpdOffset = null;
1275 }
1276 else {
1277 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1278 }
1279 }
1280 cursor.dispose();
1281 return vpdOffset;
1282 }
1283
1284 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1285 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1286 removeElement(getfpdDynPcdBuildDefs());
1287 fpdDynPcdBuildDefs = null;
1288 return;
1289 }
1290
1291 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1292 if (cursor.toFirstChild()) {
1293 for (int j = 0; j < i; ++j) {
1294 cursor.toNextSibling();
1295 }
1296 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1297 if (pcdData.getSkuInfoList() == null) {
1298 cursor.dispose();
1299 return;
1300 }
1301 else {
1302 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1303 cursor.toChild(qSkuInfo);
1304 cursor.removeXml();
1305 }
1306 }
1307 cursor.dispose();
1308 }
1309 //
1310 // generate sku info for ith dyn pcd build data.
1311 //
1312 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1313 String hiiDefault, String vpdOffset, String value, int i) {
1314 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1315 // return;
1316 // }
1317
1318 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1319 if (cursor.toFirstChild()) {
1320 for (int j = 0; j < i; ++j) {
1321 cursor.toNextSibling();
1322 }
1323 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1324 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1325 skuInfo.setSkuId(new BigInteger(id));
1326 if (varName != null){
1327 skuInfo.setVariableName(varName);
1328 skuInfo.setVariableGuid(varGuid);
1329 skuInfo.setVariableOffset(varOffset);
1330 skuInfo.setHiiDefaultValue(hiiDefault);
1331 }
1332 else if (vpdOffset != null){
1333 skuInfo.setVpdOffset(vpdOffset);
1334 }
1335 else{
1336 skuInfo.setValue(value);
1337 }
1338 }
1339 }
1340
1341 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1342 String hiiDefault, String vpdOffset, String value, int i){
1343 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1344 // return;
1345 // }
1346
1347 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1348 if (cursor.toFirstChild()) {
1349 for (int j = 0; j < i; ++j) {
1350 cursor.toNextSibling();
1351 }
1352 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1353 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1354 while (li.hasNext()) {
1355 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1356 if (skuInfo.getSkuId().toString().equals(id)){
1357 if (varName != null){
1358 skuInfo.setVariableName(varName);
1359 skuInfo.setVariableGuid(varGuid);
1360 skuInfo.setVariableOffset(varOffset);
1361 skuInfo.setHiiDefaultValue(hiiDefault);
1362 }
1363 else if (vpdOffset != null){
1364 skuInfo.setVpdOffset(vpdOffset);
1365 }
1366 else{
1367 skuInfo.setValue(value);
1368 }
1369 break;
1370 }
1371 }
1372 }
1373 }
1374
1375 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1376 if (fpdBuildOpts == null) {
1377 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1378 }
1379 return fpdBuildOpts;
1380 }
1381
1382 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
1383 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1384 if (udats == null) {
1385 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
1386 }
1387
1388 AntTaskDocument.AntTask at = udats.addNewAntTask();
1389 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1390 }
1391
1392 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1393 at.setId(new Integer(id));
1394 XmlCursor cursor = at.newCursor();
1395 if (fileName != null){
1396 at.setFilename(fileName);
1397 }
1398 else if (cursor.toChild(xmlNs, "Filename")) {
1399 cursor.removeXml();
1400 }
1401 if (execOrder != null) {
1402 at.setAntCmdOptions(execOrder);
1403 }
1404 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
1405 cursor.removeXml();
1406 }
1407 cursor.dispose();
1408 }
1409
1410 public void removeBuildOptionsUserDefAntTask(int i) {
1411 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1412 if (o == null) {
1413 return;
1414 }
1415 XmlCursor cursor = o.newCursor();
1416 if (cursor.toFirstChild()) {
1417 for (int j = 0; j < i; ++j) {
1418 cursor.toNextSibling();
1419 }
1420 cursor.removeXml();
1421 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1422 cursor.toParent();
1423 cursor.removeXml();
1424 }
1425 }
1426 cursor.dispose();
1427 }
1428
1429 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1430 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1431 if (o == null) {
1432 return;
1433 }
1434 XmlCursor cursor = o.newCursor();
1435 if (cursor.toFirstChild()) {
1436 for (int j = 0; j < i; ++j) {
1437 cursor.toNextSibling();
1438 }
1439 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1440 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1441 }
1442 cursor.dispose();
1443 }
1444
1445 public int getBuildOptionsUserDefAntTaskCount() {
1446 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1447 if (udats == null || udats.getAntTaskList() == null) {
1448 return 0;
1449 }
1450
1451 return udats.getAntTaskList().size();
1452 }
1453
1454 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1455 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1456 if (udats == null || udats.getAntTaskList() == null) {
1457 return ;
1458 }
1459
1460 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1461 ListIterator li = l.listIterator();
1462 int i = 0;
1463 while (li.hasNext()) {
1464 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1465 saa[i][0] = at.getId() + "";
1466 saa[i][1] = saa[i][2] = "";
1467 if (at.getFilename() != null){
1468 saa[i][1] = at.getFilename();
1469 }
1470 if (at.getAntCmdOptions() != null) {
1471 saa[i][2] = at.getAntCmdOptions();
1472 }
1473 ++i;
1474 }
1475 }
1476 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1477 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1478 if (opts == null) {
1479 opts = getfpdBuildOpts().addNewOptions();
1480 }
1481 OptionDocument.Option opt = opts.addNewOption();
1482 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1483 }
1484
1485 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
1486 opt.setStringValue(contents);
1487
1488 opt.setBuildTargets(buildTargets);
1489 opt.setToolChainFamily(toolChain);
1490 opt.setTagName(tagName);
1491 opt.setToolCode(toolCmd);
1492
1493 if (archList != null) {
1494 opt.setSupArchList(archList);
1495 }
1496 else {
1497 if (opt.isSetSupArchList()) {
1498 opt.unsetSupArchList();
1499 }
1500 }
1501 }
1502
1503 public void removeBuildOptionsOpt(int i){
1504
1505 XmlObject o = getfpdBuildOpts().getOptions();
1506 if (o == null) {
1507 return;
1508 }
1509
1510 XmlCursor cursor = o.newCursor();
1511 if (cursor.toFirstChild()) {
1512 for (int j = 0; j < i; ++j) {
1513 cursor.toNextSibling();
1514 }
1515 cursor.removeXml();
1516 if (getBuildOptionsOptCount() == 0) {
1517 cursor.toParent();
1518 cursor.removeXml();
1519 }
1520 }
1521 cursor.dispose();
1522 }
1523
1524 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1525 XmlObject o = getfpdBuildOpts().getOptions();
1526 if (o == null) {
1527 return;
1528 }
1529
1530 XmlCursor cursor = o.newCursor();
1531 if (cursor.toFirstChild()) {
1532 for (int j = 0; j < i; ++j) {
1533 cursor.toNextSibling();
1534 }
1535 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1536 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1537 }
1538 cursor.dispose();
1539 }
1540
1541 public int getBuildOptionsOptCount(){
1542 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1543 return 0;
1544 }
1545 return getfpdBuildOpts().getOptions().getOptionList().size();
1546 }
1547
1548 public void getBuildOptionsOpts(String[][] saa) {
1549 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1550 return ;
1551 }
1552
1553 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
1554 ListIterator li = lOpt.listIterator();
1555 int i = 0;
1556 while(li.hasNext()) {
1557 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1558 if (opt.getBuildTargets() != null) {
1559 saa[i][0] = listToString(opt.getBuildTargets());
1560 }
1561 saa[i][1] = opt.getToolChainFamily();
1562 if (opt.getSupArchList() != null){
1563 saa[i][2] = listToString(opt.getSupArchList());
1564
1565 }
1566 saa[i][3] = opt.getToolCode();
1567 saa[i][4] = opt.getTagName();
1568 saa[i][5] = opt.getStringValue();
1569
1570 ++i;
1571 }
1572 }
1573
1574 public void genBuildOptionsFfs(String ffsKey, String type) {
1575 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1576 ffs.setFfsKey(ffsKey);
1577 if (type != null) {
1578 ffs.addNewSections().setEncapsulationType(type);
1579 }
1580 }
1581
1582 public void updateBuildOptionsFfsSectionsType(int i, String type) {
1583 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1584 if (type != null) {
1585 ffs.addNewSections().setEncapsulationType(type);
1586 }
1587 }
1588
1589 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
1590 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1591 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
1592 attrib.setName(name);
1593 attrib.setValue(value);
1594 }
1595
1596 /**update jth attribute of ith ffs.
1597 * @param i
1598 * @param j
1599 */
1600 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
1601 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1602 XmlCursor cursor = ffs.newCursor();
1603 QName qAttrib = new QName(xmlNs, "Attribute");
1604 if (cursor.toChild(qAttrib)) {
1605 for (int k = 0; k < j; ++k) {
1606 cursor.toNextSibling(qAttrib);
1607 }
1608 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
1609 attrib.setName(name);
1610 attrib.setValue(value);
1611 }
1612 cursor.dispose();
1613 }
1614
1615 public void removeBuildOptionsFfsAttribute(int i, int j){
1616 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1617 XmlCursor cursor = ffs.newCursor();
1618 QName qAttrib = new QName(xmlNs, "Attribute");
1619 if (cursor.toChild(qAttrib)) {
1620 for (int k = 0; k < j; ++k) {
1621 cursor.toNextSibling(qAttrib);
1622 }
1623 cursor.removeXml();
1624 }
1625 cursor.dispose();
1626 }
1627
1628 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
1629 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1630 if (ffs == null) {
1631 return;
1632 }
1633 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1634
1635 if (sections == null){
1636 sections = ffs.addNewSections();
1637 }
1638 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
1639 }
1640
1641 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
1642 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1643 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1644 if (sections == null) {
1645 return;
1646 }
1647 XmlCursor cursor = sections.newCursor();
1648 QName qSection = new QName(xmlNs, "Section");
1649 if (cursor.toChild(qSection)) {
1650 for (int k = 0; k < j; ++k) {
1651 cursor.toNextSibling(qSection);
1652 }
1653 cursor.removeXml();
1654 }
1655 cursor.dispose();
1656 }
1657
1658 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
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 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
1671 section.setSectionType(EfiSectionType.Enum.forString(type));
1672 }
1673 cursor.dispose();
1674 }
1675
1676 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
1677 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1678 if (ffs == null) {
1679 return;
1680 }
1681 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1682
1683 if (sections == null){
1684 sections = ffs.addNewSections();
1685 }
1686 sections.addNewSections().setEncapsulationType(encapType);
1687 }
1688
1689 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
1690 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1691 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1692 if (sections == null) {
1693 return;
1694 }
1695 XmlCursor cursor = sections.newCursor();
1696 QName qSections = new QName(xmlNs, "Sections");
1697 if (cursor.toChild(qSections)) {
1698 for (int k = 0; k < j; ++k) {
1699 cursor.toNextSibling(qSections);
1700 }
1701 cursor.removeXml();
1702 }
1703 cursor.dispose();
1704 }
1705
1706 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
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 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1719 sections2.setEncapsulationType(type);
1720 }
1721 cursor.dispose();
1722 }
1723
1724 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
1725 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1726 if (ffs == null) {
1727 return;
1728 }
1729 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1730 XmlCursor cursor = sections.newCursor();
1731 QName qSections = new QName(xmlNs, "Sections");
1732 if (cursor.toChild(qSections)){
1733 for (int k = 0; k < j; ++k) {
1734 cursor.toNextSibling(qSections);
1735 }
1736 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1737 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
1738 }
1739 cursor.dispose();
1740 }
1741
1742 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
1743 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1744 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1745 if (sections == null) {
1746 return;
1747 }
1748 XmlCursor cursor = sections.newCursor();
1749 QName qSections = new QName(xmlNs, "Sections");
1750 if (cursor.toChild(qSections)) {
1751 for (int l = 0; l < j; ++l) {
1752 cursor.toNextSibling(qSections);
1753 }
1754 if (cursor.toFirstChild()) {
1755 int m = 0;
1756 for (; m < k; ++m) {
1757 cursor.toNextSibling();
1758 }
1759 cursor.removeXml();
1760 if (m == 0) {
1761 cursor.toParent();
1762 cursor.removeXml();
1763 }
1764 }
1765 }
1766 cursor.dispose();
1767 }
1768
1769 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
1770 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1771 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1772 if (sections == null) {
1773 return;
1774 }
1775 XmlCursor cursor = sections.newCursor();
1776 QName qSections = new QName(xmlNs, "Sections");
1777 if (cursor.toChild(qSections)) {
1778 for (int l = 0; l < j; ++l) {
1779 cursor.toNextSibling(qSections);
1780 }
1781 if (cursor.toFirstChild()) {
1782 for (int m = 0; m < k; ++m) {
1783 cursor.toNextSibling();
1784 }
1785 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
1786 section.setSectionType(EfiSectionType.Enum.forString(type));
1787 }
1788 }
1789 cursor.dispose();
1790 }
1791
1792 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
1793 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1794 if (ffs == null) {
1795 return;
1796 }
1797 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1798 XmlCursor cursor = sections.newCursor();
1799 QName qSections = new QName(xmlNs, "Sections");
1800 if (cursor.toChild(qSections)){
1801 for (int k = 0; k < j; ++k) {
1802 cursor.toNextSibling(qSections);
1803 }
1804 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1805 if (sections2.getSectionList() == null){
1806 cursor.dispose();
1807 return;
1808 }
1809 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
1810 while(li.hasNext()) {
1811 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
1812 if (section.isSetSectionType()) {
1813 al.add(section.getSectionType().toString());
1814 }
1815
1816 }
1817 }
1818 cursor.dispose();
1819
1820 }
1821
1822 public int getBuildOptionsFfsCount(){
1823 if (getfpdBuildOpts().getFfsList() == null) {
1824 return 0;
1825 }
1826 return getfpdBuildOpts().getFfsList().size();
1827 }
1828
1829 public void getBuildOptionsFfsKey(String[][] saa) {
1830 if (getfpdBuildOpts().getFfsList() == null) {
1831 return;
1832 }
1833 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
1834 int i = 0;
1835 while(li.hasNext()){
1836 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
1837 saa[i][0] = ffs.getFfsKey();
1838 ++i;
1839 }
1840 }
1841
1842 public void updateBuildOptionsFfsKey(int i, String key) {
1843 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1844 ffs.setFfsKey(key);
1845 }
1846
1847 /**Get ith FFS key and contents.
1848 * @param saa
1849 */
1850 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
1851 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1852
1853 if (ffs != null) {
1854
1855 sa[0] = ffs.getFfsKey();
1856 if (ffs.getSections() != null) {
1857 if(ffs.getSections().getEncapsulationType() != null){
1858 sa[1] = ffs.getSections().getEncapsulationType();
1859 }
1860 if (ffs.getSections().getSectionList() != null){
1861 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
1862 while (li.hasNext()) {
1863 firstLevelSection.add(li.next().getSectionType().toString());
1864 }
1865 }
1866 if (ffs.getSections().getSectionsList() != null) {
1867 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
1868 while(li.hasNext()) {
1869 firstLevelSections.add(li.next().getEncapsulationType());
1870 }
1871 }
1872 }
1873 if (ffs.getAttributeList() != null) {
1874 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
1875 while(li.hasNext()) {
1876 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
1877 ffsAttribMap.put(attrib.getName(), attrib.getValue());
1878 }
1879
1880 }
1881 }
1882
1883
1884 }
1885
1886 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
1887 XmlObject o = getfpdBuildOpts();
1888 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
1889
1890 XmlCursor cursor = o.newCursor();
1891 QName qFfs = new QName(xmlNs, "Ffs");
1892 if (cursor.toChild(qFfs)) {
1893 for (int j = 0; j < i; ++j) {
1894 cursor.toNextSibling(qFfs);
1895 }
1896 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
1897 }
1898 cursor.dispose();
1899 return ffs;
1900 }
1901
1902 public void removeBuildOptionsFfs(int i) {
1903 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1904 if (ffs == null){
1905 return;
1906 }
1907
1908 XmlCursor cursor = ffs.newCursor();
1909 cursor.removeXml();
1910 cursor.dispose();
1911 }
1912
1913
1914
1915 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
1916 if (fpdPlatformDefs == null){
1917 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
1918 }
1919 return fpdPlatformDefs;
1920 }
1921
1922 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
1923 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
1924 return;
1925 }
1926 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
1927 while(li.hasNext()) {
1928 archs.add(li.next());
1929 }
1930 }
1931
1932 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
1933 if (archs != null) {
1934 getfpdPlatformDefs().setSupportedArchitectures(archs);
1935 }
1936 // else {
1937 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
1938 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
1939 // cursor.removeXml();
1940 // }
1941 // cursor.dispose();
1942 // }
1943 }
1944
1945 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
1946 if (getfpdPlatformDefs().getBuildTargets() == null) {
1947 return;
1948 }
1949 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
1950 while(li.hasNext()) {
1951 targets.add(li.next());
1952 }
1953 }
1954
1955 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
1956 getfpdPlatformDefs().setBuildTargets(targets);
1957 }
1958
1959 public void genPlatformDefsSkuInfo(String id, String name) {
1960 SkuInfoDocument.SkuInfo skuInfo = null;
1961 if (getfpdPlatformDefs().getSkuInfo() == null) {
1962 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
1963 }
1964 skuInfo = getfpdPlatformDefs().getSkuInfo();
1965 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
1966 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1967 skuName.setSkuID(new BigInteger("0"));
1968 skuName.setStringValue("DEFAULT");
1969 }
1970 if (id.equals("0")) {
1971 return;
1972 }
1973 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1974 skuName.setSkuID(new BigInteger(id));
1975 skuName.setStringValue(name);
1976 }
1977
1978 public int getPlatformDefsSkuInfoCount(){
1979 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
1980 return 0;
1981 }
1982 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
1983 }
1984
1985 public void getPlatformDefsSkuInfos(String[][] saa){
1986 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
1987 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
1988 removeElement(getfpdDynPcdBuildDefs());
1989 fpdDynPcdBuildDefs = null;
1990 }
1991 return ;
1992 }
1993
1994 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
1995 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
1996 int i = 0;
1997 while(li.hasNext()) {
1998 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
1999 saa[i][0] = sku.getSkuID()+"";
2000 saa[i][1] = sku.getStringValue();
2001 ++i;
2002 }
2003 }
2004
2005 public void removePlatformDefsSkuInfo(int i) {
2006 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2007 if (skuInfo == null || i == 0) {
2008 return ;
2009 }
2010
2011 XmlCursor cursor = skuInfo.newCursor();
2012 if (cursor.toFirstChild()) {
2013 for (int j = 0; j < i; ++j) {
2014 cursor.toNextSibling();
2015 }
2016 cursor.removeXml();
2017 }
2018 cursor.dispose();
2019 }
2020
2021 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2022 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2023 if (skuInfo == null || i == 0) {
2024 return ;
2025 }
2026
2027 XmlCursor cursor = skuInfo.newCursor();
2028 if (cursor.toFirstChild()) {
2029 for (int j = 0; j < i; ++j) {
2030 cursor.toNextSibling();
2031 }
2032 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2033 sku.setSkuID(new BigInteger(id));
2034 sku.setStringValue(name);
2035 }
2036 cursor.dispose();
2037 }
2038
2039 public String getPlatformDefsInterDir(){
2040 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2041 return null;
2042 }
2043 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2044 }
2045
2046 public void setPlatformDefsInterDir(String interDir){
2047 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2048 }
2049
2050 public String getPlatformDefsOutputDir() {
2051 return getfpdPlatformDefs().getOutputDirectory();
2052 }
2053
2054 public void setPlatformDefsOutputDir(String outputDir) {
2055 if (outputDir != null && outputDir.length() > 0) {
2056 getfpdPlatformDefs().setOutputDirectory(outputDir);
2057 }
2058 else{
2059 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2060 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2061 cursor.removeXml();
2062 }
2063 cursor.dispose();
2064 }
2065 }
2066
2067 public FlashDocument.Flash getfpdFlash() {
2068 if (fpdFlash == null) {
2069 fpdFlash = fpdRoot.addNewFlash();
2070 }
2071 return fpdFlash;
2072 }
2073
2074 public void genFlashDefinitionFile(String file) {
2075 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2076 if (fdf == null) {
2077 fdf = getfpdFlash().addNewFlashDefinitionFile();
2078 }
2079
2080 fdf.setStringValue(file);
2081 }
2082
2083 public String getFlashDefinitionFile() {
2084 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2085 if (fdf == null) {
2086 return "";
2087 }
2088
2089 return fdf.getStringValue();
2090 }
2091
2092 public void genFvImagesNameValue(String name, String value) {
2093
2094 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2095 if (fi == null) {
2096 fi = getfpdFlash().addNewFvImages();
2097 }
2098
2099 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2100 nv.setName(name);
2101 nv.setValue(value);
2102 }
2103
2104 public void removeFvImagesNameValue(int i){
2105
2106 XmlObject o = getfpdFlash().getFvImages();
2107 if (o == null) {
2108 return;
2109 }
2110
2111 QName qNameValue = new QName(xmlNs, "NameValue");
2112 XmlCursor cursor = o.newCursor();
2113 if (cursor.toChild(qNameValue)) {
2114 for (int j = 0; j < i; ++j) {
2115 cursor.toNextSibling(qNameValue);
2116 }
2117 cursor.removeXml();
2118 }
2119 cursor.dispose();
2120 }
2121
2122 public void updateFvImagesNameValue(int i, String name, String value){
2123
2124 XmlObject o = getfpdFlash().getFvImages();
2125 if (o == null) {
2126 return;
2127 }
2128
2129 QName qNameValue = new QName(xmlNs, "NameValue");
2130 XmlCursor cursor = o.newCursor();
2131 if (cursor.toChild(qNameValue)) {
2132 for (int j = 0; j < i; ++j) {
2133 cursor.toNextSibling(qNameValue);
2134 }
2135 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2136 nv.setName(name);
2137 nv.setValue(value);
2138 }
2139 cursor.dispose();
2140 }
2141
2142 public int getFvImagesNameValueCount() {
2143
2144 FvImagesDocument.FvImages fi = null;
2145 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2146 return 0;
2147 }
2148 return fi.getNameValueList().size();
2149 }
2150
2151 public void getFvImagesNameValues(String[][] nv) {
2152
2153 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2154 if (fi == null){
2155 return;
2156 }
2157 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2158 int i = 0;
2159 ListIterator li = l.listIterator();
2160 while (li.hasNext()) {
2161 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2162 .next();
2163 nv[i][0] = e.getName();
2164 nv[i][1] = e.getValue();
2165
2166 i++;
2167 }
2168 }
2169
2170 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
2171
2172 FvImagesDocument.FvImages fis = null;
2173 if ((fis = getfpdFlash().getFvImages()) == null) {
2174 fis = getfpdFlash().addNewFvImages();
2175 }
2176
2177 //
2178 //gen FvImage with FvImageNames array
2179 //
2180 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
2181 for (int i = 0; i < names.length; ++i) {
2182 fi.addFvImageNames(names[i]);
2183 }
2184 fi.setType(FvImageTypes.Enum.forString(types));
2185 if (options != null){
2186 setFvImagesFvImageFvImageOptions(options, fi);
2187 }
2188 }
2189
2190 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
2191 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
2192 if (fio == null){
2193 fio = fi.addNewFvImageOptions();
2194 }
2195
2196 Set<String> key = options.keySet();
2197 Iterator<String> i = key.iterator();
2198 while (i.hasNext()) {
2199
2200 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
2201 String k = (String)i.next();
2202
2203 nv.setName(k);
2204 nv.setValue((String)options.get(k));
2205
2206 }
2207
2208 }
2209
2210
2211 public void removeFvImagesFvImage(int i) {
2212
2213 XmlObject o = getfpdFlash().getFvImages();
2214 if (o == null) {
2215 return;
2216 }
2217
2218 QName qFvImage = new QName(xmlNs, "FvImage");
2219 XmlCursor cursor = o.newCursor();
2220 if (cursor.toChild(qFvImage)) {
2221 for (int j = 0; j < i; ++j) {
2222 cursor.toNextSibling(qFvImage);
2223 }
2224 cursor.removeXml();
2225 }
2226 cursor.dispose();
2227 }
2228
2229 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
2230
2231 XmlObject o = getfpdFlash().getFvImages();
2232 if (o == null) {
2233 return;
2234 }
2235 XmlCursor cursor = o.newCursor();
2236 QName qFvImage = new QName(xmlNs, "FvImage");
2237 if (cursor.toChild(qFvImage)) {
2238 for (int j = 0; j < i; ++j) {
2239 cursor.toNextSibling(qFvImage);
2240 }
2241 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2242 fi.setType(FvImageTypes.Enum.forString(types));
2243
2244 //
2245 // remove old FvImageNames before adding new ones
2246 //
2247 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
2248 cursor.toChild(qFvImageNames);
2249 cursor.removeXml();
2250 while (cursor.toNextSibling(qFvImageNames)) {
2251 cursor.removeXml();
2252 }
2253
2254 for (int k = 0; k < names.length; ++k) {
2255 fi.addFvImageNames(names[k]);
2256 }
2257 //
2258 // remove old FvImageOptions before adding new options
2259 //
2260 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
2261 cursor.toNextSibling(qFvImageOptions);
2262 cursor.removeXml();
2263
2264 setFvImagesFvImageFvImageOptions(options, fi);
2265 }
2266 cursor.dispose();
2267 }
2268
2269 public int getFvImagesFvImageCount() {
2270
2271 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2272 return 0;
2273 }
2274 return getfpdFlash().getFvImages().getFvImageList().size();
2275 }
2276
2277 /**Only Get Fv image setting - name and type.
2278 * @param saa
2279 */
2280 public void getFvImagesFvImages(String[][] saa) {
2281
2282 if (getfpdFlash().getFvImages() == null) {
2283 return;
2284 }
2285 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2286 if (l == null) {
2287 return;
2288 }
2289 ListIterator li = l.listIterator();
2290 int i = 0;
2291 while(li.hasNext()) {
2292 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2293 //
2294 // get FvImageNames array, space separated
2295 //
2296 List<String> lfn = fi.getFvImageNamesList();
2297 ListIterator lfni = lfn.listIterator();
2298 saa[i][0] = " ";
2299 while (lfni.hasNext()) {
2300 saa[i][0] += (String)lfni.next();
2301 saa[i][0] += " ";
2302 }
2303 saa[i][0] = saa[i][0].trim();
2304
2305 saa[i][1] = fi.getType()+"";
2306
2307 ++i;
2308 }
2309 }
2310
2311 /**Get FvImage Options for FvImage i
2312 * @param i the ith FvImage
2313 */
2314 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
2315 XmlObject o = getfpdFlash().getFvImages();
2316 if (o == null) {
2317 return;
2318 }
2319 XmlCursor cursor = o.newCursor();
2320 QName qFvImage = new QName(xmlNs, "FvImage");
2321 if (cursor.toChild(qFvImage)) {
2322 for (int j = 0; j < i; ++j) {
2323 cursor.toNextSibling(qFvImage);
2324 }
2325 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2326 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
2327 return;
2328 }
2329 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
2330 while(li.hasNext()){
2331 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
2332 m.put(nv.getName(), nv.getValue());
2333 }
2334 }
2335 }
2336
2337 /**
2338 Get platform header element
2339 @return PlatformHeaderDocument.PlatformHeader
2340 **/
2341 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
2342 if (fpdHdr == null) {
2343 fpdHdr = fpdRoot.addNewPlatformHeader();
2344 }
2345
2346 return fpdHdr;
2347 }
2348
2349 public String getFpdHdrPlatformName() {
2350 return getFpdHdr().getPlatformName();
2351 }
2352
2353 public String getFpdHdrGuidValue() {
2354 return getFpdHdr().getGuidValue();
2355 }
2356
2357 public String getFpdHdrVer() {
2358 return getFpdHdr().getVersion();
2359 }
2360
2361 public String getFpdHdrAbs() {
2362 return getFpdHdr().getAbstract();
2363 }
2364
2365 public String getFpdHdrDescription() {
2366 return getFpdHdr().getDescription();
2367 }
2368
2369 public String getFpdHdrCopyright() {
2370 return getFpdHdr().getCopyright();
2371 }
2372
2373 public String getFpdHdrLicense() {
2374 LicenseDocument.License l = getFpdHdr().getLicense();
2375 if (l == null) {
2376 return null;
2377 }
2378 return l.getStringValue();
2379 }
2380
2381 public String getFpdHdrUrl() {
2382 LicenseDocument.License l = getFpdHdr().getLicense();
2383 if (l == null) {
2384 return null;
2385 }
2386 return l.getURL();
2387 }
2388
2389 public String getFpdHdrSpec() {
2390
2391 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2392 // return getFpdHdr().getSpecification();
2393 }
2394
2395 public void setFpdHdrPlatformName(String name){
2396 getFpdHdr().setPlatformName(name);
2397 }
2398
2399 public void setFpdHdrGuidValue(String guid){
2400 getFpdHdr().setGuidValue(guid);
2401 }
2402
2403 public void setFpdHdrVer(String v){
2404 getFpdHdr().setVersion(v);
2405 }
2406
2407 public void setFpdHdrAbs(String abs) {
2408 getFpdHdr().setAbstract(abs);
2409 }
2410
2411 public void setFpdHdrDescription(String desc){
2412 getFpdHdr().setDescription(desc);
2413 }
2414
2415 public void setFpdHdrCopyright(String cr) {
2416 getFpdHdr().setCopyright(cr);
2417 }
2418
2419 public void setFpdHdrLicense(String license){
2420 LicenseDocument.License l = getFpdHdr().getLicense();
2421 if (l == null) {
2422 getFpdHdr().addNewLicense().setStringValue(license);
2423 }
2424 else {
2425 l.setStringValue(license);
2426 }
2427 }
2428
2429 public void setFpdHdrUrl(String url){
2430 LicenseDocument.License l = getFpdHdr().getLicense();
2431
2432 l.setURL(url);
2433
2434 }
2435
2436 public void setFpdHdrSpec(String s){
2437 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2438 getFpdHdr().setSpecification(s);
2439 }
2440 /**
2441 Save the processed xml contents to file
2442
2443 @param fpdFile The file to save xml contents
2444 @throws IOException Exceptions during file operation
2445 **/
2446 public void saveAs(File fpdFile) throws IOException {
2447
2448 XmlOptions options = new XmlOptions();
2449
2450 options.setCharacterEncoding("UTF-8");
2451 options.setSavePrettyPrint();
2452 options.setSavePrettyPrintIndent(2);
2453 try {
2454 fpdd.save(fpdFile, options);
2455 } catch (IOException e) {
2456 e.printStackTrace();
2457 }
2458
2459 }
2460
2461 private String listToString(List l) {
2462 if (l == null) {
2463 return null;
2464 }
2465 String s = " ";
2466 ListIterator li = l.listIterator();
2467 while(li.hasNext()) {
2468 s += li.next();
2469 s += " ";
2470 }
2471 return s.trim();
2472 }
2473
2474 private void removeElement(XmlObject o) {
2475 XmlCursor cursor = o.newCursor();
2476 cursor.removeXml();
2477 cursor.dispose();
2478 }
2479 }
2480
2481 class PcdItemTypeConflictException extends Exception {
2482
2483 /**
2484 *
2485 */
2486 private static final long serialVersionUID = 1L;
2487 private String details = null;
2488
2489 PcdItemTypeConflictException(String pcdName, String info){
2490 ModuleIdentification mi = GlobalData.getModuleId(info);
2491 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackage().getName();
2492 }
2493
2494 public String getMessage() {
2495 return details;
2496 }
2497 }
2498
2499 class PcdDeclNotFound extends Exception {
2500
2501 /**
2502 *
2503 */
2504 private static final long serialVersionUID = 1L;
2505 private String details = null;
2506
2507 PcdDeclNotFound(String info) {
2508 details = "PcdDeclNotFound: " + info;
2509 }
2510
2511 public String getMessage() {
2512 return details;
2513 }
2514 }
2515
2516 class PcdValueMalFormed extends Exception {
2517
2518 /**
2519 *
2520 */
2521 private static final long serialVersionUID = 1L;
2522 private String details = null;
2523
2524 PcdValueMalFormed(String info) {
2525 details = "PcdValueMalFormed: " + info;
2526 }
2527
2528 public String getMessage() {
2529 return details;
2530 }
2531 }