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