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