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