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