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