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